RAPID JAVA Using APPLICATION JBoss Forge, Arquillian & Java EE 6 DEVELOPMENT Ray Ploski Director, Developer Programs & Strategy JBoss, by Red Hat, Inc.
DEVELOPER PRODUCTIVITY - WHAT IF? Faster Start-Up Times 80% Less Configuration ? 50% Less Code Open eco-system 25% Less Classes Vendor Agnostic Rapid Application Tooling Easier Integration Testing * Based on a Sample POJO/JPA/REST Based Application
GREAT !!!
J2EE #fail #fail EJB #fail
PURPOSE OF THIS TALK ¡  Demonstrate productivity gains §  Less Code, Classes and Configuration ¡  Address Concerns §  About Java EE, EJBs, App Servers & Lock-in ¡  Introduce new innovations §  JBoss Forge §  CDI and Apache DeltaSpike §  Arquillian
J2EE 1.4
EJB 2.X SESSION BEAN
EJB 2.X DEPLOYMENT DESCRIPTOR <!-- … à! <enterprise-beans>! <session>! <display-name>BankSB</display-name>! <ejb-name>BankBean</ejb-name>! <local-home>com.advocacy.legacy.ejb.BankLocalHome</local-home>! <local>com.advocacy.legacy.ejb.BankLocal</local>! <ejb-class>com.advocacy.legacy.ejb.BankBean</ejb-class>! <session-type>Stateless</session-type>! <transaction-type>Container</transaction-type>! </session>! </enterprise-beans>! <assembly-descriptor>! <container-transaction>! <method>! <ejb-name>BankSB</ejb-name>! <method-name>*</method-name>! </container-transaction>! </assembly-descriptor>!
EJB 2.X CLIENT VIEW try {! ! Context ctx = new InitialContext();! BankLocalHome home = (BankLocalHome) !ctx.lookup(“java:comp/env/ejb/bank”);! BankLocal bank = home.create();! bank.deposit(2500.00, new Account(12345)); ! } catch (Exception ex) {! ! // …! }!
J2EE #fail #fail EJB #fail
DEVELOPER PRODUCTIVITY WHAT IF? Faster Start-Up Times 80% Less Configuration ? 50% Less Code Open eco-system 25% Less Classes Vendor Agnostic Rapid Application Tooling Easier Integration Testing * Based on a Sample POJO/JPA/REST Based Application
JAVA EE 5 ¡ R esource injection in JEE5 §  @EJB, @Resource, @PersistenceContext, §  @PersistenceUnit ¡ I nto Container Components: § Servlets, JSF backing beans and other EJBs ¡ P rogress but still Problems §  No POJOs §  Cannot inject DAOs or helper classes that were not written as EJBs §  Hard to integrate anything but strictly business components
Java EE 6
EJB 3.1 SESSION BEAN OPTIONAL!
JAVA EE 6 DEPLOYMENT DESCRIPTOR
EJB 3.1 CLIENT VIEW @EJB BankLocal bank;! ! public void makeDeposit() ! {! bank.deposit(2500.00, new Account(12345));! }!
HOW DID THEY DO THAT? ¡ C onfiguration by exception with sensible defaults §  Security permissions defaults to UNCHECKED §  Transaction type defaults to CONTAINER §  Transaction attribute defaults to REQUIRED ¡ U se Annotations §  To choose explicitly (recommended) §  To override defaults ¡ D eployment descriptor is no longer required §  But can override above configurations
EASE-OF-USE IMPROVEMENTS ¡  Optional Local Interface ¡  Simplified Packaging ¡  EJB-Lite ¡  Portable JNDI Naming ¡  Simple Component Testing
Loose Coupling STRONG TYPING
DEPENDENCY INJECTION IN TWO PARTS DI (@Inject) CDI JSR 330 JSR 299 javax.inject! javax.enterprise.context! ! Alternatives! @Inject! Producers! @Named! Scopes! @Singleton! Stereotypes! @Qualifier! Decorators! @Scope! Extensions!
INJECTION 101 public class StatusUpdater {! ! @Inject! private UrlShortener shortener;! ! public void post (String username, String status) {! !String sStatus = shortener.shortenUrls(status);! !System.out.println(username + “ said “ + sStatus);! }! ! }! !
WHAT MAKES CDI UNIQUE? STANDARD TYPE SAFE EXTENSIBLE
QUALIFIED INJECTION OF RESOURCES @Path(“/items”) @ManagedBean! Strong Typing public class ItemRestService {! No Strings ! @Inject @NumberOfDigits(Digits.EIGHT)! private NumberGenerator numberGenerator;! …! }! ! ! @WebServlet(urlPatterns = “/itemServlet”)! public class ItemServlet extends HttpServlet {! ! @Inject @NumberOfDigits(Digits.THIRTEEN)! private NumberGenerator numberGenerator;! …! Loose Coupling }! No Reference to Implementation
DEFINING THE QUALIFIER ! @Qualifier! @Retention(RUNTIME)! @Target({FIELD, TYPE, METHOD, PARAMETER})! public @interface NumberOfDigits {! ! !Digits value();! ! }! ! public enum Digits {! !TWO, EIGHT, TEN, THIRTEEN! ! }! !
DEFINING THE BEANS @NumberOfDigits(Digits.EIGHT)! public class IssnGenerator implements NumberGenerator {! ! public String generateNumber() {! return “8-” + nextNumber();! }! ! // …! }! ! @NumberOfDigits(Digits.THIRTEEN)! public class IsbnGenerator implements NumberGenerator {! ! public String generateNumber() {! return “13-84356-” + nextNumber();! }! ! // …! }!
CDI - EXTENSIBLE BY DESIGN ¡ M any community projects of extensions: § Seam 3, CODI, Cambridge Technology Partners ¡ These multiple projects merging to deliver a vendor-neutral open ecosystem for extensions named DeltaSpike . ¡  Hosted on Apache. Works on all Java EE 6 servers + + CDISource DeltaSpike
Servlet Container vs. Java EE6 (After lots of tweaking)
DEVELOPER PRODUCTIVIT Y - WHAT IF? Faster Start-Up Times 80% Less Configuration ? 50% Less Code Open eco-system 25% Less Classes Vendor Agnostic Rapid Application Tooling Easier Integration Testing * Based on a Sample POJO/JPA/REST Based Application
ISN’T JAVA EE TOO SLOW & FAT? ¡  Startup Times w/ an Application Deployed §  JBoss AS 7.10 ~ 2 seconds §  GlassFish v3 ~ 4 seconds §  Tomcat 6 + Spring ~ 4 seconds § Java EE 6 War File < 100kb
MEMORY COMPARISON
JAVA EE 5
JAVA EE 6
JAVA EE 6 SPECIFICATION No Where in the Specification does it mention that App Servers must be slow and complex.
DEVELOPER PRODUCTIVIT Y - WHAT IF? 80% Less Configuration Faster Start-Up Times ? Open eco-system 50% Less Code 25% Less Classes Vendor Agnostic Rapid Application Tooling Easier Integration Testing * Based on a Sample POJO/JPA/REST Based Application
Start up Costs Gotchas Integration Details
I need one of those widgets for a marketing T YPICAL DEVELOPER meeting in an hour. NIGHTMARE
CARVE OUT A PROJECT WORK IT INTO SHAPE
Let’s get started
JAVA EE IN MINUTES
FORGE LEVERAGES FACETS & PLUGINS Project Java Facet Web Facet X Facet Plugin A Plugin B ... Plugin X
Demonstration of Forge and Java EE Application
GETS YOU STARTED Handles details, gives you perspective QUICKLY … and time HANDLES “GOTCHAS” ADDS & ACTIVATES TECH VIA PLUGINS
TESTING JAVA EE USED TO BE DIFFICULT
MANY STEPS REQUIRED FOR MODIFYING CODE PRODUCTIVELY
ARQUILLIAN REMOVES THE STEPS
ARQUILLIAN
ARQUILLIAN REMOVES THE STEPS SEE MORE AT コンテナでテストをまわせ!
A powerful programming model. Less code, greater portability. Optimized for productivity & automation. CDI and Forge plugins. Absolutely. You saw it first hand.
¡  Max Andersen §  “See Context & Dependency Injection from Java EE 6 in Action” §  http://www.slideshare.net/maxandersen/see-context- dependency-injection-from-java-ee-6-in-action ¡  Pete Muir REFERENCES §  “CDI in Action” ¡ Andrew Lee Rubinger §  “The Death of Slow” §  http://www.slideshare.net/ALRubinger/devoxx-2011- jboss-as7-death-of-the-slow ¡ B ert Ertman §  EJB 3.1 §  http://www.slideshare.net/stephanj/ejb-31-by-bert- ertman ¡  Antonio Goncalves §  “To inject or not to inject: CDI is the question” §  http://www.slideshare.net/agoncal/to-inject-or-not-to-inject-cdi-is-the- question

Developer Productivity with Forge, Java EE 6 and Arquillian

  • 1.
    RAPID JAVA Using APPLICATION JBoss Forge, Arquillian & Java EE 6 DEVELOPMENT Ray Ploski Director, Developer Programs & Strategy JBoss, by Red Hat, Inc.
  • 2.
    DEVELOPER PRODUCTIVITY - WHAT IF? Faster Start-Up Times 80% Less Configuration ? 50% Less Code Open eco-system 25% Less Classes Vendor Agnostic Rapid Application Tooling Easier Integration Testing * Based on a Sample POJO/JPA/REST Based Application
  • 3.
  • 4.
    J2EE #fail #fail EJB #fail
  • 5.
    PURPOSE OF THISTALK ¡  Demonstrate productivity gains §  Less Code, Classes and Configuration ¡  Address Concerns §  About Java EE, EJBs, App Servers & Lock-in ¡  Introduce new innovations §  JBoss Forge §  CDI and Apache DeltaSpike §  Arquillian
  • 6.
  • 7.
  • 8.
    EJB 2.X DEPLOYMENTDESCRIPTOR <!-- … à! <enterprise-beans>! <session>! <display-name>BankSB</display-name>! <ejb-name>BankBean</ejb-name>! <local-home>com.advocacy.legacy.ejb.BankLocalHome</local-home>! <local>com.advocacy.legacy.ejb.BankLocal</local>! <ejb-class>com.advocacy.legacy.ejb.BankBean</ejb-class>! <session-type>Stateless</session-type>! <transaction-type>Container</transaction-type>! </session>! </enterprise-beans>! <assembly-descriptor>! <container-transaction>! <method>! <ejb-name>BankSB</ejb-name>! <method-name>*</method-name>! </container-transaction>! </assembly-descriptor>!
  • 9.
    EJB 2.X CLIENTVIEW try {! ! Context ctx = new InitialContext();! BankLocalHome home = (BankLocalHome) !ctx.lookup(“java:comp/env/ejb/bank”);! BankLocal bank = home.create();! bank.deposit(2500.00, new Account(12345)); ! } catch (Exception ex) {! ! // …! }!
  • 10.
    J2EE #fail #fail EJB #fail
  • 11.
    DEVELOPER PRODUCTIVITY WHAT IF? Faster Start-Up Times 80% Less Configuration ? 50% Less Code Open eco-system 25% Less Classes Vendor Agnostic Rapid Application Tooling Easier Integration Testing * Based on a Sample POJO/JPA/REST Based Application
  • 12.
    JAVA EE 5 ¡ Resource injection in JEE5 §  @EJB, @Resource, @PersistenceContext, §  @PersistenceUnit ¡ I nto Container Components: § Servlets, JSF backing beans and other EJBs ¡ P rogress but still Problems §  No POJOs §  Cannot inject DAOs or helper classes that were not written as EJBs §  Hard to integrate anything but strictly business components
  • 13.
  • 14.
    EJB 3.1 SESSIONBEAN OPTIONAL!
  • 15.
    JAVA EE 6DEPLOYMENT DESCRIPTOR
  • 16.
    EJB 3.1 CLIENTVIEW @EJB BankLocal bank;! ! public void makeDeposit() ! {! bank.deposit(2500.00, new Account(12345));! }!
  • 17.
    HOW DID THEYDO THAT? ¡ C onfiguration by exception with sensible defaults §  Security permissions defaults to UNCHECKED §  Transaction type defaults to CONTAINER §  Transaction attribute defaults to REQUIRED ¡ U se Annotations §  To choose explicitly (recommended) §  To override defaults ¡ D eployment descriptor is no longer required §  But can override above configurations
  • 18.
    EASE-OF-USE IMPROVEMENTS ¡  OptionalLocal Interface ¡  Simplified Packaging ¡  EJB-Lite ¡  Portable JNDI Naming ¡  Simple Component Testing
  • 21.
  • 22.
    DEPENDENCY INJECTION IN TWO PARTS DI (@Inject) CDI JSR 330 JSR 299 javax.inject! javax.enterprise.context! ! Alternatives! @Inject! Producers! @Named! Scopes! @Singleton! Stereotypes! @Qualifier! Decorators! @Scope! Extensions!
  • 23.
    INJECTION 101 public classStatusUpdater {! ! @Inject! private UrlShortener shortener;! ! public void post (String username, String status) {! !String sStatus = shortener.shortenUrls(status);! !System.out.println(username + “ said “ + sStatus);! }! ! }! !
  • 24.
    WHAT MAKES CDIUNIQUE? STANDARD TYPE SAFE EXTENSIBLE
  • 25.
    QUALIFIED INJECTION OF RESOURCES @Path(“/items”) @ManagedBean! Strong Typing public class ItemRestService {! No Strings ! @Inject @NumberOfDigits(Digits.EIGHT)! private NumberGenerator numberGenerator;! …! }! ! ! @WebServlet(urlPatterns = “/itemServlet”)! public class ItemServlet extends HttpServlet {! ! @Inject @NumberOfDigits(Digits.THIRTEEN)! private NumberGenerator numberGenerator;! …! Loose Coupling }! No Reference to Implementation
  • 26.
    DEFINING THE QUALIFIER ! @Qualifier! @Retention(RUNTIME)! @Target({FIELD,TYPE, METHOD, PARAMETER})! public @interface NumberOfDigits {! ! !Digits value();! ! }! ! public enum Digits {! !TWO, EIGHT, TEN, THIRTEEN! ! }! !
  • 27.
    DEFINING THE BEANS @NumberOfDigits(Digits.EIGHT)! publicclass IssnGenerator implements NumberGenerator {! ! public String generateNumber() {! return “8-” + nextNumber();! }! ! // …! }! ! @NumberOfDigits(Digits.THIRTEEN)! public class IsbnGenerator implements NumberGenerator {! ! public String generateNumber() {! return “13-84356-” + nextNumber();! }! ! // …! }!
  • 29.
    CDI - EXTENSIBLEBY DESIGN ¡ M any community projects of extensions: § Seam 3, CODI, Cambridge Technology Partners ¡ These multiple projects merging to deliver a vendor-neutral open ecosystem for extensions named DeltaSpike . ¡  Hosted on Apache. Works on all Java EE 6 servers + + CDISource DeltaSpike
  • 30.
    Servlet Container vs. Java EE6 (After lots of tweaking)
  • 31.
    DEVELOPER PRODUCTIVIT Y - WHAT IF? Faster Start-Up Times 80% Less Configuration ? 50% Less Code Open eco-system 25% Less Classes Vendor Agnostic Rapid Application Tooling Easier Integration Testing * Based on a Sample POJO/JPA/REST Based Application
  • 32.
    ISN’T JAVA EETOO SLOW & FAT? ¡  Startup Times w/ an Application Deployed §  JBoss AS 7.10 ~ 2 seconds §  GlassFish v3 ~ 4 seconds §  Tomcat 6 + Spring ~ 4 seconds § Java EE 6 War File < 100kb
  • 41.
  • 42.
  • 43.
  • 46.
    JAVA EE 6SPECIFICATION No Where in the Specification does it mention that App Servers must be slow and complex.
  • 47.
    DEVELOPER PRODUCTIVIT Y - WHAT IF? 80% Less Configuration Faster Start-Up Times ? Open eco-system 50% Less Code 25% Less Classes Vendor Agnostic Rapid Application Tooling Easier Integration Testing * Based on a Sample POJO/JPA/REST Based Application
  • 48.
  • 49.
    I need oneof those widgets for a marketing T YPICAL DEVELOPER meeting in an hour. NIGHTMARE
  • 50.
    CARVE OUT APROJECT WORK IT INTO SHAPE
  • 51.
  • 52.
    JAVA EE INMINUTES
  • 53.
    FORGE LEVERAGES FACETS& PLUGINS Project Java Facet Web Facet X Facet Plugin A Plugin B ... Plugin X
  • 54.
    Demonstration of Forge andJava EE Application
  • 55.
    GETS YOU STARTED Handles details, gives you perspective QUICKLY … and time HANDLES “GOTCHAS” ADDS & ACTIVATES TECH VIA PLUGINS
  • 56.
    TESTING JAVA EEUSED TO BE DIFFICULT
  • 57.
    MANY STEPS REQUIREDFOR MODIFYING CODE PRODUCTIVELY
  • 58.
  • 59.
  • 61.
    ARQUILLIAN REMOVES THESTEPS SEE MORE AT コンテナでテストをまわせ!
  • 62.
    A powerful programmingmodel. Less code, greater portability. Optimized for productivity & automation. CDI and Forge plugins. Absolutely. You saw it first hand.
  • 63.
    ¡  Max Andersen §  “See Context & Dependency Injection from Java EE 6 in Action” §  http://www.slideshare.net/maxandersen/see-context- dependency-injection-from-java-ee-6-in-action ¡  Pete Muir REFERENCES §  “CDI in Action” ¡ Andrew Lee Rubinger §  “The Death of Slow” §  http://www.slideshare.net/ALRubinger/devoxx-2011- jboss-as7-death-of-the-slow ¡ B ert Ertman §  EJB 3.1 §  http://www.slideshare.net/stephanj/ejb-31-by-bert- ertman ¡  Antonio Goncalves §  “To inject or not to inject: CDI is the question” §  http://www.slideshare.net/agoncal/to-inject-or-not-to-inject-cdi-is-the- question