Your SlideShare is downloading. ×
0
<Insert Picture Here>Understanding the Nuts & Bolts of Java EE 6Arun Gupta, Java EE & GlassFish Guyblogs.sun.com/arungupta...
The following/preceding is intended to outline ourgeneral product direction. It is intended forinformation purposes only, ...
Are you tweeting ? #glassfish#sparkit2011                     3
Java EE: Past, Present, Future                                                   Cloud     NEW                            ...
Compatible Java EE 6 ImplsToday:                       Web Profile OnlyAnnounced:                                         ...
Light-weight• Java EE 6 Web Profile• Pruning   • Pruned today, means    • Optional in the next release    • Deleted in the...
• EJB-in-WAR• No-interface EJB• Optional  “web.xml”/”faces-  config.xml”• Annotation-driven  •   @Schedule  •   @Path  •  ...
<web-fragment>    <filter>          <filter-name>wicket.helloworld</filter-name>          <filter-class>org.apache.wicket....
Java EE 6 - Done                09• Specifications approved by the JCP              20• Reference Implementation is GlassF...
Java EE 6 Web Profile 1.0  Servlets 3.0     JPA 2.0          EJB 3.1     JDBC      StAX                 Interceptors    JS...
Managed Beans 1.0  EJB         CDI      JSF       JAX-WS JAX-RS      JPA       ...@Stateful                      @Managed ...
Managed Beans 1.0• POJO as managed component for the Java EE container • JavaBeans component model for Java EE • Simple an...
Lab #1Managed Beans                13
Managed Beans 1.0 - Sample@javax.annotation.ManagedBean                              @Resourcepublic class MyManagedBean {...
Interceptors 1.1• Interpose on invocations and lifecycle events  on a target class• Defined  • Using annotations or DD  • ...
Lab #2Interceptors               16
Interceptors – Business Method  (Logging)@InterceptorBinding                    @LoggingInterceptorBinding@Retention(RUNTI...
Why Interceptor Bindings ?• Remove dependency from the interceptor  implementation class• Can vary depending upon deployme...
Interceptors – Business Method    (Transaction)@InterceptorBinding               @Transactional@Retention(RUNTIME)        ...
Servlets in Java EE 5   At least 2 files<!--Deployment descriptor      /* Code in Java Class */  web.xml --><web-app>     ...
Servlets 3.0 (JSR 315)   Annotations-based @WebServletpackage com.sun;@WebServlet(name=”MyServlet”, urlPatterns={”/myApp/*...
Lab #3Servlets           22
Servlets 3.0• @WebServlet, @WebListener, @WebFilter, …• Asynchronous Servlets    • @WebServlet(asyncSupported=true)•   Plu...
Servlets 3.1 (JSR 340)  http://jcp.org/en/jsr/detail?id=340                                               NEW• Cloud suppo...
Java Persistence API 2 (JSR 317)• Improved O/R mapping• Type-safe Criteria API• Expanded and Richer JPQL• 2nd-level Cache•...
Lab #4Java Persistence API                       26
JPA 2.1 Candidate Features    http://jcp.org/en/jsr/detail?id=338                                            NEW●    Multi...
EJB 3.1 (JSR 318)Package & Deploy in a WAR    Java EE 5                                     Java EE 6                     ...
Lab #5EJB 3.1          29
EJB 3.1• No interface view – one source file per bean• Embeddable API• @Singleton  • Initialization in @PostContruct• Simp...
Contexts & Dependency Injection - CDI  (JSR 299)• Type-safe Dependency Injection • No String-based identifiers• Strong typ...
CDI Injection Points• Field, Method, Constructor• 0 or more qualifiers                         Which one ?• Type          ...
Lab #6CDI Qualifiers                 33
CDI Much more ...• Producer methods and fields• Bridging Java EE resources• Alternatives• Interceptors• Decorators• Stereo...
Java Server Faces 2.0 (JSR 314)• Facelets as “templating language” for the page   • Custom components much easier to devel...
Lab #7JSF 2.0          36
Bean Validation (JSR 303)• Tier-independent mechanism to define constraints for data validation  • Represented by annotati...
Lab #8Bean Validation                  38
JAX-RS 1.1• Java API for building RESTful Web Services• POJO based• Annotation-driven• Server-side API• HTTP-centric      ...
JAX-RS 1.1Code Sample - Simple@Path("helloworld")public class HelloWorldResource {    @Context UriInfo ui;    @GET    @Pro...
JAX-RS 1.1Code Sample – Specifying Output MIME type@Path("/helloworld")@Produces("text/plain")public class HelloWorldResou...
Lab #9JAX-RS         42
JAX-RS 1.1Code Sampleimport javax.inject.Inject;import javax.enterprise.context.RequestScoped;@RequestScopedpublic class A...
JAX-RS 1.1Code Sampleimport   javax.ws.rs.GET;import   javax.ws.rs.Path;import   javax.ws.rs.Produces;import   javax.ws.rs...
JAX-RS 2.0    http://jcp.org/en/jsr/detail?id=339                                                         NEW●    Client A...
http://blogs.sun.com/arungupta/entry/java_ee_6_twitter_demo                                                              46
Lab #10Twitter App              47
48
IDE Support for Java EE 6                            49
From the real users ...                                  Jigsaw puzzle, Modular,                                          ...
Avoid “framework explosion”  In selecting an application server our main goal  was to avoid the framework explosion that  ...
52
GlassFish Server Chronology2006    2007    2008      2009      2010    2011              … GlassFish v1 Java EE 5, Single ...
GlassFish Server DistributionsDistribution                  License      Features                                         ...
GlassFish 3.1 Overview• Built on GlassFish 3• Modular and Extensible HK2 Kernel  • ~262 modules• Clustering and High Avail...
GlassFish 3.1: Fast and Furious ...• 29% better startup/deploy/re-deploy cycle  over 3.0.1• 33% better HA performance over...
Java EE 7 : JSR 342                                                        NEW• Theme: Cloud• More easily operate on priva...
Java EE 7 Schedule                               NEW• March 2011 Early EG Formed• Q3 2011 Early Draft• Q1 2012 Public Draf...
Java EE JSR Soup                                       NEW• Java EE 7 - JSR 342• Servlets 3.1 – JSR 340• Expression Langua...
Transparency Checklist                                     NEW• Names of the EG members• EG business reported on publicly ...
References• glassfish.org• blogs.sun.com/theaquarium• facebook.com/glassfish• oracle.com/goto/glassfish• youtube.com/Glass...
<Insert Picture Here>Understanding the Nuts & Bolts of Java EE 6Arun Gupta, Java EE & GlassFish Guyblogs.sun.com/arungupta...
Upcoming SlideShare
Loading in...5
×

Spark IT 2011 - Java EE 6 Workshop

2,455

Published on

Spark IT 2011 - Java EE 6 Workshop

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
2,455
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
89
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Spark IT 2011 - Java EE 6 Workshop"

  1. 1. <Insert Picture Here>Understanding the Nuts & Bolts of Java EE 6Arun Gupta, Java EE & GlassFish Guyblogs.sun.com/arungupta, @arungupta
  2. 2. The following/preceding is intended to outline ourgeneral product direction. It is intended forinformation purposes only, and may not beincorporated into any contract. It is not acommitment to deliver any material, code, orfunctionality, and should not be relied upon inmaking purchasing decisions.The development, release, and timing of anyfeatures or functionality described for Oracle’sproducts remains at the sole discretion of Oracle. 2
  3. 3. Are you tweeting ? #glassfish#sparkit2011 3
  4. 4. Java EE: Past, Present, Future Cloud NEW Flexible Ease of Java EE 7 Development Java EE 6 HTML 5 WebSocket Pruning Java EE 5 Extensibility JSON API Web Ease of JCache Services Profiles Multi-tenancy Development Annotations Ease-of-dev Elasticity J2EE 1.4 EJB 3.0 EJB Lite Tech Refresh Web Services, JPA RESTful WS ... Robustness Management, New and CDI Enterprise Deployment, Updated Java J2EE 1.3 Async. Web Services Platform CMP, Connector Connector Architecture Web Profile J2EE 1.2 Servlet, JSP, EJB, JMS JPE RMI/IIOP ManagedProject Bean 1.0May 1998 Dec 1999 Sep 2001 Nov 2003 May 2006 Dec 2009 Q3 2012 10 specs 13 specs 20 specs 23 specs 28 specs ?? specs 4
  5. 5. Compatible Java EE 6 ImplsToday: Web Profile OnlyAnnounced: 5
  6. 6. Light-weight• Java EE 6 Web Profile• Pruning • Pruned today, means • Optional in the next release • Deleted in the subsequent releases • Technologies marked in Javadocs • EJB 2.x Entity Beans, JAX-RPC, JAXR, JSR 88 6
  7. 7. • EJB-in-WAR• No-interface EJB• Optional “web.xml”/”faces- config.xml”• Annotation-driven • @Schedule • @Path • @Inject • ... 7
  8. 8. <web-fragment> <filter> <filter-name>wicket.helloworld</filter-name> <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class> <init-param> <param-name>applicationClassName</param-name> <param-value>...</param-value> </init-param> </filter> <filter-mapping> <filter-name>wicket.helloworld</filter-name> <url-pattern>/*</url-pattern> </filter-mapping></web-fragment> 8
  9. 9. Java EE 6 - Done 09• Specifications approved by the JCP 20• Reference Implementation is GlassFish h Server Open Source Edition 3• TCK 10 t ecD 9
  10. 10. Java EE 6 Web Profile 1.0 Servlets 3.0 JPA 2.0 EJB 3.1 JDBC StAX Interceptors JSF 2.0 JAX-RS JNDI JavaMail 1.1 Bean EJB 3.1 Lite JAXB JMS JACC Validation1.0 JSP 2.2 CDI 1.0 JAX-WS JAXP SAAJ Managed JTA 1.1 JASPIC JAX-RPC ... Beans 1.0 Contributed by RedHat New Updated 10
  11. 11. Managed Beans 1.0 EJB CDI JSF JAX-WS JAX-RS JPA ...@Stateful @Managed @Web@Stateless @Named @Path @Entity ... Bean Service@Singleton @javax.annotation.ManagedBean 11
  12. 12. Managed Beans 1.0• POJO as managed component for the Java EE container • JavaBeans component model for Java EE • Simple and Universally useful • Advanced concepts in companion specs• Basic Services • Resource Injection, Lifecycle Callbacks, Interceptors• Available as • @Resource / @Inject • java:app/<module-name>/<bean-name> • java:module/<bean-name> 12
  13. 13. Lab #1Managed Beans 13
  14. 14. Managed Beans 1.0 - Sample@javax.annotation.ManagedBean @Resourcepublic class MyManagedBean { MyManagedBean bean; @PostConstruct public void setupResources() { // setup your resources } @Inject @PreDestroy MyManagedBean bean; public void cleanupResources() { // collect them back here } public String sayHello(String name) { return "Hello " + name; }}http://blogs.sun.com/arungupta/entry/totd_129_managed_beans_1 14
  15. 15. Interceptors 1.1• Interpose on invocations and lifecycle events on a target class• Defined • Using annotations or DD • Default Interceptors (only in DD)• Class & Method Interceptors • In the same transaction & security context• Cross-cutting concerns: logging, auditing, profiling 15
  16. 16. Lab #2Interceptors 16
  17. 17. Interceptors – Business Method (Logging)@InterceptorBinding @LoggingInterceptorBinding@Retention(RUNTIME) public class MyManagedBean {@Target({METHOD,TYPE}) . . .public @interface }LoggingInterceptorBinding {}@Interceptor@LoggingInterceptorBindingpublic class @LogInterceptor { @AroundInvoke public Object log(InvocationContext context) { System.out.println(context.getMethod().getName()); System.out.println(context.getParameters()); return context.proceed(); }} 17
  18. 18. Why Interceptor Bindings ?• Remove dependency from the interceptor implementation class• Can vary depending upon deployment environment• Allows central ordering of interceptors 18
  19. 19. Interceptors – Business Method (Transaction)@InterceptorBinding @Transactional@Retention(RUNTIME) public class ShoppingCart { . . . }@Target({METHOD,TYPE})public @interface Transactional { public class ShoppingCart {} @Transactional public void checkOut() { . . . }@Interceptor@Transactionalpublic class TransactionInterceptor { @Resource UserTransaction tx; @AroundInvoke public Object manageTransaction(InvocationContext context) { tx.begin() context.proceed(); tx.commit(); }} http://blogs.sun.com/arungupta/entry/totd_151_transactional_interceptors_using 19
  20. 20. Servlets in Java EE 5 At least 2 files<!--Deployment descriptor /* Code in Java Class */ web.xml --><web-app> package com.sun; <servlet> public class MyServlet extends <servlet-name>MyServlet HttpServlet { </servlet-name> public void <servlet-class> doGet(HttpServletRequest com.sun.MyServlet req,HttpServletResponse res) </servlet-class> { </servlet> ... <servlet-mapping> <servlet-name>MyServlet } </servlet-name> ... <url-pattern>/myApp/* } </url-pattern> </servlet-mapping> ...</web-app> 20
  21. 21. Servlets 3.0 (JSR 315) Annotations-based @WebServletpackage com.sun;@WebServlet(name=”MyServlet”, urlPatterns={”/myApp/*”})public class MyServlet extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse res) { <!--Deployment descriptor web.xml --> <web-app> ... <servlet> <servlet-name>MyServlet</servlet-name> } <servlet-class> com.sun.MyServlet </servlet-class> </servlet> <servlet-mapping> <servlet-name>MyServlet</servlet-name> <url-pattern>/myApp/*</url-pattern> </servlet-mapping> ... </web-app>http://blogs.sun.com/arungupta/entry/screencast_37_java_ee_6 21
  22. 22. Lab #3Servlets 22
  23. 23. Servlets 3.0• @WebServlet, @WebListener, @WebFilter, …• Asynchronous Servlets • @WebServlet(asyncSupported=true)• Plugin libraries using web fragments• Dynamic registration of Servlets• WEB-INF/lib/[*.jar]/META-INF/resources accessible in the root• Programmatic authentication login/logout• Default Error Page• ... 23
  24. 24. Servlets 3.1 (JSR 340) http://jcp.org/en/jsr/detail?id=340 NEW• Cloud support• Multi-tenancy • Security / Session state / Resources isolation• Asynchronous IO based on NIO2• Utilize Java EE concurrency utilities• Enable support for Web Sockets 24
  25. 25. Java Persistence API 2 (JSR 317)• Improved O/R mapping• Type-safe Criteria API• Expanded and Richer JPQL• 2nd-level Cache• New locking modes • PESSIMISTIC_READ – grab shared lock • PESSIMISTIC_WRITE – grab exclusive lock • PESSIMISTIC_FORCE_INCREMENT – update version• Standard configuration options • javax.persistence.jdbc.[driver | url | user | password] 25
  26. 26. Lab #4Java Persistence API 26
  27. 27. JPA 2.1 Candidate Features http://jcp.org/en/jsr/detail?id=338 NEW● Multi-tenancy● Support for stored procedures, vendor function● Update and Delete Criteria queries, JPQL ↔ Criteria● Query by Example● Support for schema generation● UUID generator type● Persistence Context synchronization control● Dynamic definition of PU● Additional event listeners 27
  28. 28. EJB 3.1 (JSR 318)Package & Deploy in a WAR Java EE 5 Java EE 6 myApp.warmyApp.ear WEB-INF/classes myWeb.war com.sun.FooServlet com.sun.TickTock WEB-INF/web.xml com.sun.FooBean WEB-INF/classes com.sun.FooHelper com.sun.FooServlet com.sun.TickTock myBeans.jar com.sun.FooBean web.xml ? com.sun.FooHelper http://blogs.sun.com/arungupta/entry/screencast_37_java_ee_6 28
  29. 29. Lab #5EJB 3.1 29
  30. 30. EJB 3.1• No interface view – one source file per bean• Embeddable API• @Singleton • Initialization in @PostContruct• Simplified Cron-like syntax for Timer• Asynchronous Session Bean• Portable Global JNDI Name 30
  31. 31. Contexts & Dependency Injection - CDI (JSR 299)• Type-safe Dependency Injection • No String-based identifiers• Strong typing, Loose coupling • Events, Interceptors, Decorators• Context & Scope management – extensible• Portable Extensions• Bridge EJB and JSF in the platform• Works with Java EE modular and component architecture • Integration with Unified Expression Language (UEL) 31
  32. 32. CDI Injection Points• Field, Method, Constructor• 0 or more qualifiers Which one ?• Type (Qualifier) @Inject @LoggedIn User userRequest What ?Injection (Type) 32
  33. 33. Lab #6CDI Qualifiers 33
  34. 34. CDI Much more ...• Producer methods and fields• Bridging Java EE resources• Alternatives• Interceptors• Decorators• Stereotypes 34
  35. 35. Java Server Faces 2.0 (JSR 314)• Facelets as “templating language” for the page • Custom components much easier to develop• Integrated Ajax• “faces-config.xml” optional in common cases• Default navigation rules• Much more … • Runs on Servlet 2.5+ • Bookmarkable URLs • Conditional navigation • ... 35
  36. 36. Lab #7JSF 2.0 36
  37. 37. Bean Validation (JSR 303)• Tier-independent mechanism to define constraints for data validation • Represented by annotations • javax.validation.* package• Integrated with JSF and JPA • JSF: f:validateRequired, f:validateRegexp • JPA: pre-persist, pre-update, and pre-remove• @NotNull(message=”...”), @Max, @Min, @Size• Fully Extensible • @Email String recipient; 37
  38. 38. Lab #8Bean Validation 38
  39. 39. JAX-RS 1.1• Java API for building RESTful Web Services• POJO based• Annotation-driven• Server-side API• HTTP-centric 39
  40. 40. JAX-RS 1.1Code Sample - Simple@Path("helloworld")public class HelloWorldResource { @Context UriInfo ui; @GET @Produces("text/plain") public String sayHello() { return "Hello World"; } @GET @Path("morning") public String morning() { return “Good Morning!”; }} 40
  41. 41. JAX-RS 1.1Code Sample – Specifying Output MIME type@Path("/helloworld")@Produces("text/plain")public class HelloWorldResource { @GET public String doGetAsPlainText() { . . . } @GET @Produces("text/html") public String doGetAsHtml() { . . . } @GET} @Produces({ "application/xml", "application/json"}) public String doGetAsXmlOrJson() { . . . } 41
  42. 42. Lab #9JAX-RS 42
  43. 43. JAX-RS 1.1Code Sampleimport javax.inject.Inject;import javax.enterprise.context.RequestScoped;@RequestScopedpublic class ActorResource { @Inject DatbaseBean db; public Actor getActor(int id) { return db.findActorById(id); }} 43
  44. 44. JAX-RS 1.1Code Sampleimport javax.ws.rs.GET;import javax.ws.rs.Path;import javax.ws.rs.Produces;import javax.ws.rs.PathParam;import javax.inject.Inject;import javax.enterprise.context.RequestScoped;@Path("/actor/{id}")@RequestScopedpublic class ActorResource { @Inject DatbaseBean db; @GET @Produces("application/json") public Actor getActor(@PathParam("id") int id) { return db.findActorById(id); }} http://blogs.sun.com/arungupta/entry/totd_124_using_cdi_jpa 44
  45. 45. JAX-RS 2.0 http://jcp.org/en/jsr/detail?id=339 NEW● Client API ● Low level using Builder pattern, Higher-level● Hypermedia● MVC Pattern ● Resource controllers, Pluggable viewing technology● Bean Validation ● Form or Query parameter validation● Closer integration with @Inject, etc.● Server-side asynchronous request processing● Server-side content negotiation 45
  46. 46. http://blogs.sun.com/arungupta/entry/java_ee_6_twitter_demo 46
  47. 47. Lab #10Twitter App 47
  48. 48. 48
  49. 49. IDE Support for Java EE 6 49
  50. 50. From the real users ... Jigsaw puzzle, Modular, standard, less xml, easy, easy, have I said easy?Developers can concentrateon business logic, Java EE 6 isproviding a standard forthe infrastructure. Standards compliance, vendor independence, milliseconds and kilobyte deployment Faster development, less frameworks/complexity, Higher integrated specs, more great code shipped simple and annotation driven, single-classloader WARs, next level of industry standard Not your fat grandfathers enterprise Java anymore, Definite excuse to avoid Enterprise Java Renaissance Spring forever http://blogs.sun.com/arungupta/tags/community+feedback 50
  51. 51. Avoid “framework explosion” In selecting an application server our main goal was to avoid the framework explosion that happens when you use a "custom" Enterprise stack like Tomcat + Spring + Hibernate + Myfaces +... Java EE 6 had 80% of what we needed out of the box: strong persistence support ( JPA ), inversion of control ( CDI ), and a lightweight component model ( EJB 3.1 )http://blogs.sun.com/stories/entry/egesa_engineering_avoids_framework_explosion 51
  52. 52. 52
  53. 53. GlassFish Server Chronology2006 2007 2008 2009 2010 2011 … GlassFish v1 Java EE 5, Single Instance GlassFish v2 Java EE 5, High Availability GlassFish Server 3 Java EE 6, Single Instance GlassFish Server 3.1 Java EE 6, High Availability GlassFish Server 3.2 Virtualization, PaaS 53
  54. 54. GlassFish Server DistributionsDistribution License Features • Java EE 6 compatibilityGlassFish Server Open CDDL & • Web Profile supportSource Edition 3.1 GPLv2 • In-memory replication / clusteringWeb Profile • Centralized Administration • Java EE 6 compatibilityGlassFish Open Source CDDL & • Full Java EE distributionEdition 3.1 GPLv2 • In-memory replication / clustering • Centralized Administration • AddsOracle GlassFish Server 3.1 Commercial • Oracle GlassFish Server ControlWeb Profile • Patches, support, knowledge base • AddsOracle GlassFish Server 3.1 Commercial • Oracle GlassFish Server Control • Patches, support, knowledge base
  55. 55. GlassFish 3.1 Overview• Built on GlassFish 3• Modular and Extensible HK2 Kernel • ~262 modules• Clustering and High Availability • HTTP, EJB, IIOP, SSO, Metro• Dynamic Invocation of Services• End-to-end extensibility 55
  56. 56. GlassFish 3.1: Fast and Furious ...• 29% better startup/deploy/re-deploy cycle over 3.0.1• 33% better HA performance over 2.1.1 • Scalable Grizzly Adapter based on Java NIO • Full-session and Modified-attribute* scope• Multiple clusters per domain, multiple instances per cluster, up to 100 instances per domain http://weblogs.java.net/blog/sdo/archive/2011/03/01/whats-new-glassfish-v31-performance 56
  57. 57. Java EE 7 : JSR 342 NEW• Theme: Cloud• More easily operate on private or public clouds• Deliver functionality as a service with support for features such as multi-tenancy and elasticity• Technology refresh: JMS 2.0, CDI 1.1, ...• Latest web standards: HTML 5 and Web Sockets• Possible JSRs inclusion • Concurrency Utilities for Java EE (JSR 236) • JCache (JSR 107)• New JSRs: Web Sockets, Java JSON API• Modularity and Versioning 57
  58. 58. Java EE 7 Schedule NEW• March 2011 Early EG Formed• Q3 2011 Early Draft• Q1 2012 Public Draft• Q3 2012 Final Release 58
  59. 59. Java EE JSR Soup NEW• Java EE 7 - JSR 342• Servlets 3.1 – JSR 340• Expression Language 3.0 – JSR 341• Java Message Service 2.0 – JSR 343• Java Server Faces 2.2 – JSR 344• Java Persistence API 2.1 – JSR 338• JAX-RS 2.0 – JSR 339 59
  60. 60. Transparency Checklist NEW• Names of the EG members• EG business reported on publicly readable alias• Schedule is public, current and updated regularly• Public can read/write to a wiki• Discussion board on jcp.org• Public read-only issue tracker 60
  61. 61. References• glassfish.org• blogs.sun.com/theaquarium• facebook.com/glassfish• oracle.com/goto/glassfish• youtube.com/GlassFishVideos• Follow @glassfish 61
  62. 62. <Insert Picture Here>Understanding the Nuts & Bolts of Java EE 6Arun Gupta, Java EE & GlassFish Guyblogs.sun.com/arungupta, @arungupta
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×