SlideShare a Scribd company logo
Creating Modern Java Web
Applications Based on
and
ApacheCon: Core Europe 2015 by   ( )Johannes Geppert @jogep
About me
Apache Member and Struts PMC Member
Software Developer @ 
Living and working in Leipzig
About Struts2
Action based Java
web framework
Built upon a
Request/Response
cycle
Clean architecture
Easy to extend
with plugins
Conceptual Overview
Struts 2.5 is on the way!
Cleanup and Maintenance!
Switch to Java7
Increased Security with
SMI
xwork­core merged into
struts­core
Removal of deprecated
plugins
Dojo Plugin
Code Behind Plugin
JSF Plugin
Struts1 Plugin
Support for bean validation
Now as a (built­in) plugin available
Log4j2 as new Logging Layer
Replacement for Struts2
Logging Layer
Support for multiple
logging implementations
Better performance
Beta2 is available!
Why AngularJS?
 AngularJS is a structural framework for dynamic web apps.
It lets you use HTML as your template language and lets
you extend HTML's syntax to express your application's
components clearly and succinctly. Angular's data binding
and dependency injection eliminate much of the code you
would otherwise have to write. And it all happens within the
browser, making it an ideal partner with any server
technology.
https://docs.angularjs.org/guide/introduction
AngularJS ­ Overview
Google Trends
AngularJS, React, Backbone and ember.js
Blue line is the trend for AngularJS
Quickstart with Maven
Archetypes
mvn archetype:generate ­B  
         ­DgroupId=com.mycompany.mysystem 
         ­DartifactId=myWebApp 
         ­DarchetypeGroupId=org.apache.struts 
         ­DarchetypeArtifactId=struts2­archetype­angularjs 
         ­DarchetypeVersion=<CURRENT_STRUTS_VERSION> 
         ­DremoteRepositories=http://struts.apache.org
cd myWebApp
mvn jetty:run
Open Browser http://localhost:8080
REST Based Actions
with Struts2 REST Plugin
REST ­ Action Mapping
HTTP method URI Class.method Paramete
GET /order OrderController.index  
GET /order/1 OrderController.show id="1"
POST /order OrderController.create  
PUT /order/1 OrderController.update id="1"
DELETE /order/1 OrderController.destroy id="1"
Configure the REST Plugin
Add the rest plugin to the dependencies
<dependency>
  <groupId>org.apache.struts</groupId>
  <artifactId>struts2­rest­plugin</artifactId>
  <version>${struts2.version}</version>
</dependency>
Disable restrictToGET default behaviour
<constant name="struts.rest.content.restrictToGET" value="false"/>
Create packages for applications
<constant name="struts.convention.default.parent.package"
             value="rest­angular"/>
<package name="rest­angular" extends="rest­default">
    <default­action­ref name="index" />
</package>
<package name="data" extends="rest­angular" namespace="/data">
</package>
REST ­ Content Type Handler
/order/1 or /order/1.action Dispatcher (e.g. JSP)
/order/1.xml XML Handler
/order/1.json JSON Handler
Easy to build e.g. for CSV result
Built­in Jackson support for JSON serialization
<bean type="org.apache.struts2.rest.handler.ContentTypeHandler"
        name="jackson"
        class="org.apache.struts2.rest.handler.JacksonLibHandler"/>
<constant name="struts.rest.handlerOverride.json"
        value="jackson"/>
Live Demo
https://github.com/apache/struts­examples/tree/master/rest­
angular
Exception Handling
Custom Exception
Interceptor
protected String doIntercept(ActionInvocation actionInvocation)
                            throws Exception {
    try{
        return actionInvocation.invoke();
    } catch (Exception exception) {
        Map<String, Object> errors = new HashMap<>();
        HttpHeaders httpHeaders = new DefaultHttpHeaders()
            .disableCaching().withStatus(HttpServletResponse.SC_BAD_REQUEST)
                            .renderResult(Action.INPUT);
        if(exception instanceof SecurityException) {
            errors.put(ACTION_ERROR, "Operation not allowed!");
            httpHeaders.setStatus(HttpServletResponse.SC_FORBIDDEN);
        }  else { errors.put(ACTION_ERROR, exception.getMessage()); }
        return manager.handleResult(actionInvocation.getProxy().getConfig(),
                            httpHeaders, errors);
    }
}
Extend the Default
Interceptor Stack
<package name="data" extends="rest­angular" namespace="/data">
    <interceptors>
        <interceptor name="dataError"
            class="....ExceptionHandlerInterceptor"/>
        <interceptor­stack name="dataDefaultStack">
            <interceptor­ref name="dataError"/>
            <interceptor­ref name="restDefaultStack"/>
        </interceptor­stack>
    </interceptors>
    <default­interceptor­ref name="dataDefaultStack"/>
</package>
Dispatch an error event
Extend the generic _request method in DataService
$http(req).success(function(data) {
    def.resolve(data);
}).error(function(data, code) {
    def.reject(data);
    if(data.actionError) {
        $rootScope.$emit('data­error', {  msg: data.actionError });
    }
});
Listen to error events
e.g in a Controller
$rootScope.$on('data­error', function(event, alert) {
    console.log(alert.msg);
});
Live Demo
https://github.com/apache/struts­examples/tree/master/rest­
angular
Bean Validation
Client and Server side
New bean validation plugin
Setup bean validation
Specify a validation http status code
like "Not Acceptable"
<!­­ Set validation failure status code ­­>
<constant name="struts.rest.validationFailureStatusCode" value="406"/>
Change rest interceptor stack
Default validation interceptor is using the old validation
interceptor
Copy the rest default interceptor stack
Define the new one
<interceptor name="beanValidation"
    class="....interceptor.BeanValidationInterceptor"/>
Replace the "validation" reference with "beanValidation"
reference in the stack
Live Demo
https://github.com/apache/struts­examples/tree/master/rest­
angular
Multi­Language Support
Where do we need it?
Frontend Validation Backend
Resource Bundles
Split them up!
<constant name="struts.custom.i18n.resources"
                            value="frontend,validation,exceptions"/>
Sample for validation messages
#validation_en.properties
validation.order.client = Client name can not be blank
validation.order.amount = Order amount needs to be between 10 and 666
#validation_de.properties
validation.order.client = Kunden Name darf nicht leer sein
validation.order.amount = Anzahl muss zwischen 10 und 666 sein
Language Controller
public class LanguageController extends RestActionSupport
    implements ModelDriven<Map<String, String>> {
    private Map<String, String> model;
    public String index() throws Exception {
        ResourceBundle bundle = getTexts("frontend");
        this.model = bundle.keySet().stream()
            .collect(Collectors.toMap(
                key ­> key, key ­> bundle::getString));
        return Action.SUCCESS;
    }
    public Map<String, String> getModel() { return model; }
}
Setup Angular Translate
(function() {
'use strict';
angular
.module('app', ['ngRoute', 'ui.bootstrap', 'pascalprecht.translate']);
})();
$translateProvider.registerAvailableLanguageKeys(['en', 'de']);
$translateProvider.fallbackLanguage('en');
$translateProvider.useUrlLoader('data/language.json', {
    queryParameter: 'request_locale'
});
$translateProvider.determinePreferredLanguage();
With translate filter in templates
{{'order.client' | translate}}
In validation messages
@NotBlank(message = "validation.order.client")
@Min(value = 10, message = "validation.order.amount")
@Max(value = 666, message = "validation.order.amount")
In java code
throw new RuntimeException(getText("exception.not.supported"));
Live Demo
https://github.com/apache/struts­examples/tree/master/rest­
angular
Thank you!
https://twitter.com/jogep
Resources
 ­ 
 ­ 
 ­ 
 ­ 
 ­ 
Apache Struts Project https://struts.apache.org
Struts2 Maven Archetypes https://struts.apache.org/docs/struts­2­maven­archetypes.html
Struts2 Examples https://github.com/apache/struts­examples
AngularJS https://angularjs.org
Angular Translate https://angular­translate.github.io
Attributions
Leipzig Pictures by 
 by 
 by 
 by 
 by 
 by 
 by 
Ruthe Cartoon by 
 by 
 by 
 by 
 by 
 by 
Johannes Geppert
Model in the wind tunnel DLR ­ German Aerospace Center
Road Nicola
Clean Up Allen Goldblatt
Beans Matthew
Matrix pills ThomasThomas
Shaking Hands Aaron Gilson
ruthe.de
Language Scramble Eric Andresen
Windows Box Perfection Rachel Kramer
Krakow Door John Finn
1949 Ford Coupe ­ flat head V8 engine dave_7
Questions Alexander Henning Drachmann

More Related Content

What's hot (20)

PDF
Accelerating Spark SQL Workloads to 50X Performance with Apache Arrow-Based F...
Databricks
 
PDF
Paul Angus - CloudStack Backup and Recovery Framework
ShapeBlue
 
PPTX
Virtual desktop infrastructure
Gokulan Subramani
 
PPTX
Slide #1:Introduction to Apache Storm
Md. Shamsur Rahim
 
PDF
ETL With Cassandra Streaming Bulk Loading
alex_araujo
 
PPTX
Storage talk
christkv
 
PPTX
Persistent memory
Benoit Hudzia
 
PDF
A Technical Introduction to WiredTiger
MongoDB
 
PDF
Comparison between Cisco ACI and VMWARE NSX
IOSRjournaljce
 
PPTX
Hive: Loading Data
Benjamin Leonhardi
 
PDF
Demystifying DataFrame and Dataset with Kazuaki Ishizaki
Databricks
 
PPTX
Oracle数据库高级安全选件ASO介绍
jenkin
 
ODP
OpenGurukul : Database : PostgreSQL
Open Gurukul
 
PDF
Local Apache NiFi Processor Debug
Deon Huang
 
PPTX
Apresentação MongoDB
David de Lucca
 
PDF
CloudStack - Top 5 Technical Issues and Troubleshooting
ShapeBlue
 
PDF
Hw maintainace guide
Nadeem Shariff
 
PPTX
Using Queryable State for Fun and Profit
Flink Forward
 
PDF
Everything You Need to Know About MySQL Group Replication
Nuno Carvalho
 
PDF
Monitoring in CloudStack
ShapeBlue
 
Accelerating Spark SQL Workloads to 50X Performance with Apache Arrow-Based F...
Databricks
 
Paul Angus - CloudStack Backup and Recovery Framework
ShapeBlue
 
Virtual desktop infrastructure
Gokulan Subramani
 
Slide #1:Introduction to Apache Storm
Md. Shamsur Rahim
 
ETL With Cassandra Streaming Bulk Loading
alex_araujo
 
Storage talk
christkv
 
Persistent memory
Benoit Hudzia
 
A Technical Introduction to WiredTiger
MongoDB
 
Comparison between Cisco ACI and VMWARE NSX
IOSRjournaljce
 
Hive: Loading Data
Benjamin Leonhardi
 
Demystifying DataFrame and Dataset with Kazuaki Ishizaki
Databricks
 
Oracle数据库高级安全选件ASO介绍
jenkin
 
OpenGurukul : Database : PostgreSQL
Open Gurukul
 
Local Apache NiFi Processor Debug
Deon Huang
 
Apresentação MongoDB
David de Lucca
 
CloudStack - Top 5 Technical Issues and Troubleshooting
ShapeBlue
 
Hw maintainace guide
Nadeem Shariff
 
Using Queryable State for Fun and Profit
Flink Forward
 
Everything You Need to Know About MySQL Group Replication
Nuno Carvalho
 
Monitoring in CloudStack
ShapeBlue
 

Viewers also liked (20)

PDF
An introduction to Struts 2 and RESTful applications
mrdon
 
PDF
Crash course of Mobile (SS7) privacy and security
Arturo Filastò
 
PDF
The Web Development Eco-system with VSTS, ASP.NET 2.0 & Microsoft Ajax
Darren Sim
 
PDF
M&L Webinar: “Open Source ILIAS Plugin: Interactive Videos"
Media & Learning Conference
 
KEY
Writing Your First Plugin
George Ornbo
 
PPTX
AngularJS Animations
Eyal Vardi
 
PPTX
Connections Plugins - Engage 2016
Hogne Pettersen
 
PPTX
Building ColdFusion And AngularJS Applications
ColdFusionConference
 
PDF
Why should you publish your plugin as open source and contribute to WordPress?
Otto Kekäläinen
 
PDF
Angular js best practice
Matteo Scandolo
 
PDF
Find WordPress performance bottlenecks with XDebug PHP profiling
Otto Kekäläinen
 
PPTX
HTTP, JSON, REST e AJAX com AngularJS
Rodrigo Branas
 
PDF
Fighting Against Chaotically Separated Values with Embulk
Sadayuki Furuhashi
 
PPTX
Open Source Monitoring Tools
m_richardson
 
PDF
Plugin-based software design with Ruby and RubyGems
Sadayuki Furuhashi
 
KEY
Monitoring solutions comparison
Wouter Hermans
 
PDF
An easy guide to Plugin Development
Shinichi Nishikawa
 
PDF
Worldwide attacks on SS7/SIGTRAN network
P1Security
 
PDF
XSS再入門
Hiroshi Tokumaru
 
PPT
Gstreamer plugin devpt_1
shiv_nj
 
An introduction to Struts 2 and RESTful applications
mrdon
 
Crash course of Mobile (SS7) privacy and security
Arturo Filastò
 
The Web Development Eco-system with VSTS, ASP.NET 2.0 & Microsoft Ajax
Darren Sim
 
M&L Webinar: “Open Source ILIAS Plugin: Interactive Videos"
Media & Learning Conference
 
Writing Your First Plugin
George Ornbo
 
AngularJS Animations
Eyal Vardi
 
Connections Plugins - Engage 2016
Hogne Pettersen
 
Building ColdFusion And AngularJS Applications
ColdFusionConference
 
Why should you publish your plugin as open source and contribute to WordPress?
Otto Kekäläinen
 
Angular js best practice
Matteo Scandolo
 
Find WordPress performance bottlenecks with XDebug PHP profiling
Otto Kekäläinen
 
HTTP, JSON, REST e AJAX com AngularJS
Rodrigo Branas
 
Fighting Against Chaotically Separated Values with Embulk
Sadayuki Furuhashi
 
Open Source Monitoring Tools
m_richardson
 
Plugin-based software design with Ruby and RubyGems
Sadayuki Furuhashi
 
Monitoring solutions comparison
Wouter Hermans
 
An easy guide to Plugin Development
Shinichi Nishikawa
 
Worldwide attacks on SS7/SIGTRAN network
P1Security
 
XSS再入門
Hiroshi Tokumaru
 
Gstreamer plugin devpt_1
shiv_nj
 
Ad

Similar to Creating modern java web applications based on struts2 and angularjs (20)

PDF
Java web applications based on new Struts 2.5 and AngularJS (ApacheCon NA 2016)
Johannes Geppert
 
PPT
Struts Ppt 1
JayaPrakash.m
 
PDF
Struts 2 In Action 1st Edition Don Brown Chad Michael Davis Scott Stanlick
akanalettsxz
 
DOCX
Struts ppt 1
pavanteja86
 
PPSX
Struts 2 - Introduction
Hitesh-Java
 
PPTX
Session 41 - Struts 2 Introduction
PawanMM
 
PPT
Struts 2-overview2
divzi1913
 
PDF
Struts2 tutorial
Achyuta Kumar
 
PDF
Struts2 tutorial
Suhas Kamble
 
PPT
Struts 2-overview2
Long Nguyen
 
PPT
Struts 2 Overview
skill-guru
 
DOCX
Struts Interview Questions
jbashask
 
PPTX
struts unit best pdf for struts java.pptx
ozakamal8
 
PPTX
Struts & hibernate ppt
Pankaj Patel
 
PPTX
Skillwise Struts.x
Skillwise Group
 
PPT
Struts2.x
Sandeep Rawat
 
PDF
01 Struts Intro
sdileepec
 
PDF
Struts Into
Vijay subedar
 
PDF
Struts2 tutorial
izdihara
 
PDF
Web Development with Apache Struts 2
Fabrizio Giudici
 
Java web applications based on new Struts 2.5 and AngularJS (ApacheCon NA 2016)
Johannes Geppert
 
Struts Ppt 1
JayaPrakash.m
 
Struts 2 In Action 1st Edition Don Brown Chad Michael Davis Scott Stanlick
akanalettsxz
 
Struts ppt 1
pavanteja86
 
Struts 2 - Introduction
Hitesh-Java
 
Session 41 - Struts 2 Introduction
PawanMM
 
Struts 2-overview2
divzi1913
 
Struts2 tutorial
Achyuta Kumar
 
Struts2 tutorial
Suhas Kamble
 
Struts 2-overview2
Long Nguyen
 
Struts 2 Overview
skill-guru
 
Struts Interview Questions
jbashask
 
struts unit best pdf for struts java.pptx
ozakamal8
 
Struts & hibernate ppt
Pankaj Patel
 
Skillwise Struts.x
Skillwise Group
 
Struts2.x
Sandeep Rawat
 
01 Struts Intro
sdileepec
 
Struts Into
Vijay subedar
 
Struts2 tutorial
izdihara
 
Web Development with Apache Struts 2
Fabrizio Giudici
 
Ad

Recently uploaded (20)

PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
Biography of Daniel Podor.pdf
Daniel Podor
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Biography of Daniel Podor.pdf
Daniel Podor
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 

Creating modern java web applications based on struts2 and angularjs