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)

PPTX
EMEA Airheads- Switch stacking_ ArubaOS Switch
Aruba, a Hewlett Packard Enterprise company
 
PPTX
LAN Switching and Wireless: Ch4 - VLAN Trunking Protocol (VTP)
Abdelkhalik Mosa
 
PPTX
Understanding REST APIs in 5 Simple Steps
Tessa Mero
 
PDF
Confie no seu pipeline: Teste automaticamente um aplicativo Java de ponta a p...
Elias Nogueira
 
PPT
L2 tp
Ramya Chowdary
 
PDF
주니어 개발자의 서버 로그 관리 개선기
Yeonhee Kim
 
PDF
HTTP Request Smuggling via higher HTTP versions
neexemil
 
PDF
BKK16-205 RDK-B IoT
Linaro
 
PDF
IOS Cisco - Cheat sheets
Alejandro Marin
 
PPTX
BGP Monitoring Protocol
Bertrand Duvivier
 
PDF
5.5.1.2 packet tracer configure ios intrusion prevention system (ips) using...
Salem Trabelsi
 
PPTX
게임 운영에 필요한 로그성 데이터들에 대하여
iFunFactory Inc.
 
PDF
Spanning-Tree
Thomas Moegli
 
PDF
Introduction To Appium With Robotframework
Syam Sasi
 
PPTX
Web Services and Introduction of SOAPUI
Dinesh Kaushik
 
PDF
14 palo alto quality of service(qos) concept
Mostafa El Lathy
 
PDF
Java Application Servers Are Dead!
Eberhard Wolff
 
PDF
Access Network Evolution
Cisco Canada
 
PDF
Jmeter Performance Testing
Atul Pant
 
PDF
Rediscovering Spring with Spring Boot(1)
Gunith Devasurendra
 
EMEA Airheads- Switch stacking_ ArubaOS Switch
Aruba, a Hewlett Packard Enterprise company
 
LAN Switching and Wireless: Ch4 - VLAN Trunking Protocol (VTP)
Abdelkhalik Mosa
 
Understanding REST APIs in 5 Simple Steps
Tessa Mero
 
Confie no seu pipeline: Teste automaticamente um aplicativo Java de ponta a p...
Elias Nogueira
 
주니어 개발자의 서버 로그 관리 개선기
Yeonhee Kim
 
HTTP Request Smuggling via higher HTTP versions
neexemil
 
BKK16-205 RDK-B IoT
Linaro
 
IOS Cisco - Cheat sheets
Alejandro Marin
 
BGP Monitoring Protocol
Bertrand Duvivier
 
5.5.1.2 packet tracer configure ios intrusion prevention system (ips) using...
Salem Trabelsi
 
게임 운영에 필요한 로그성 데이터들에 대하여
iFunFactory Inc.
 
Spanning-Tree
Thomas Moegli
 
Introduction To Appium With Robotframework
Syam Sasi
 
Web Services and Introduction of SOAPUI
Dinesh Kaushik
 
14 palo alto quality of service(qos) concept
Mostafa El Lathy
 
Java Application Servers Are Dead!
Eberhard Wolff
 
Access Network Evolution
Cisco Canada
 
Jmeter Performance Testing
Atul Pant
 
Rediscovering Spring with Spring Boot(1)
Gunith Devasurendra
 

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
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 

Creating modern java web applications based on struts2 and angularjs