What's new in Java EE 6 ? by  a ntonio  g oncalves
Focuses on news features of Java EE 6 You must know Java EE 5 28 specifications Thousands of pages Tough presentation
Agenda <ul><li>Quick overview
New concepts
New features on existing specifications
New specifications
Summary </li></ul>
Antonio Goncalves <ul><li>Freelance software architect
Author (Java EE 5 and Java EE 6)
JCP expert member (Java EE 6, Java EE 7)
Co-leader of the Paris JUG
Les Cast Codeurs podcast
Java Champion </li></ul>
Quick overview
A brief history
Zooming in Java EE 6 Web Services JAX-RPC 1.1 JAXM 1.0 JAX-RS 1.1 JAXR 1.0 Web Services 1.3 WS Metadata  2.0 Web JSF 2.0 S...
New concepts
Pruning (Soon less specs) <ul><li>Marks specifications optional in next version
Pruned in Java EE 6 </li><ul><li>Entity CMP 2.x
JAX-RPC
JAX-R
JSR 88 (Java EE Application Deployment) </li></ul><li>Might disappear from Java EE 7 </li><ul><li>Vendors may decide to ke...
…  or offer the delta as a set of modules </li></ul></ul>
Profiles
Web Profile 1.0 <ul><li>Subset of full platform
For web development </li><ul><li>Packages in a war </li></ul><li>Separate specification
Evolves at its own pace
Others will come </li><ul><li>Minimal (Servlet/JSP)
Portal.... </li></ul></ul>JSF 2.0 Servlet 3.0 JSP 2.2 EL 2.2 JSTL 1.2 EJB  Lite 3.1 Managed Beans 1.0 Interceptors 1.1 JTA...
EJB Lite <ul><li>Subset of the EJB 3.1 API
Used in Web profile
Packaged in a war </li></ul>Local Session Bean Injection CMT / BMT Interceptors Security Message Driven Beans EJB Web Serv...
Portable JNDI names <ul><li>Client inside a container (use DI) </li></ul>@EJB Hello h; <ul><li>Client outside a container ...
Portable JNDI names <ul><li>OrderBean  implements  Order  packaged in  orderejb.jar  within  orderapp.ear
java: global /orderapp/orderejb/OrderBean java: global /orderapp/orderejb/OrderBean!org.foo.Order </li></ul><ul><li>java: ...
Managed Beans 1.0 <ul><li>Separate spec shipped with Java EE 6
Container-managed POJOs
Support a small set of basic services </li><ul><li>Injection ( @Resource ...)
Life-cycle ( @PostConstruct ,  @PreDestroy )
Interceptor ( @Interceptor ,  @AroundInvoke ) </li></ul><li>Lightweight component model </li></ul>
Managed Beans 1.0 @javax.annotation.ManagedBean public class MyPojo { @Resource private Datasource ds; @PostConstruct priv...
Interceptors 1.1 <ul><li>Address cross-cutting concerns in Java EE
Were part of the EJB 3.0 spec
Now a seperate spec shipped with EJB 3.1
Can be uses in EJBs...
…  as well as ManagedBeans
@AroundInvoke
@AroundTimeout  for EJB timers </li></ul>
JPA 2.0
JPA 2.0 <ul><li>Evolves separately from EJB now </li><ul><li>JSR 317 </li></ul><li>Richer mappings
Richer JPQL
Standard config options
Criteria API
... </li></ul>
Richer mapping <ul><li>Collection of embeddables and basic types </li><ul><li>Not just collection of JPA entities
Multiple levels of embeddables </li></ul><li>More flexible support for Maps </li><ul><li>Keys, values can be one of : enti...
Collections of Embeddable Types @Embeddable  public class BookReference {   String title;   Float price;   String descript...
Richer JPQL <ul><li>Added entity type to support non-polymorphic queries
Allow joins in subquery FROM clause
Added new reserved words </li><ul><li>ABS, BOTH, CONCAT, ELSE, END, ESCAPE, LEADING, LENGTH, LOCATE, SET, SIZE, SQRT, SUBS...
Criteria API <ul><li>Strongly typed criteria API
Object-based query definition objects </li><ul><li>(Rather than JPQL string-based) </li></ul><li>Operates on the meta-mode...
Dynamically:  EntityManager.getMetamodel()
Statically:  Each entity  X  has a metamodel class  X_ </li></ul><li>CriteriaQuery  as a query graph </li></ul>
Criteria API EntityManager em = ...; CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Book> query =   cb.create...
Criteria API (Type-safe) EntityManager em = ...; CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Book> query =...
Criteria API (Builder pattern) EntityManager em = ...; CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Book> q...
Standard properties <ul><li>In  persistence.xml  : </li><ul><li>javax.persistence.jdbc.driver
javax.persistence.jdbc.url
javax.persistence.jdbc.user
javax.persistence.jdbc.password
javax.persistence.lock.scope
javax.persistence.lock.timeout </li></ul></ul>
And more... <ul><li>detach()
Join<X,Y> ,  ListJoin ,  MapJoin
Orphan removal functionality </li><ul><li>@OneToMany(orphanRemoval=true) </li></ul><li>BeanValidation integration on lifec...
Second-level cache API </li><ul><li>@Cacheable  annotation on entities
contain(Class,PK) ,  evict(Class,PK) , ... </li></ul><li>Pessimistic locking </li></ul>
Servlet 3.0
Ease of development <ul><li>Annotations based programming model </li><ul><li>@WebServlet
@WebFilter
Upcoming SlideShare
Loading in...5
×

What's new in Java EE 6

6,299

Published on

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

No Downloads
Views
Total Views
6,299
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
184
Comments
0
Likes
8
Embeds 0
No embeds

No notes for slide

What's new in Java EE 6

  1. 1. What's new in Java EE 6 ? by a ntonio g oncalves
  2. 2. Focuses on news features of Java EE 6 You must know Java EE 5 28 specifications Thousands of pages Tough presentation
  3. 3. Agenda <ul><li>Quick overview
  4. 4. New concepts
  5. 5. New features on existing specifications
  6. 6. New specifications
  7. 7. Summary </li></ul>
  8. 8. Antonio Goncalves <ul><li>Freelance software architect
  9. 9. Author (Java EE 5 and Java EE 6)
  10. 10. JCP expert member (Java EE 6, Java EE 7)
  11. 11. Co-leader of the Paris JUG
  12. 12. Les Cast Codeurs podcast
  13. 13. Java Champion </li></ul>
  14. 14. Quick overview
  15. 15. A brief history
  16. 16. Zooming in Java EE 6 Web Services JAX-RPC 1.1 JAXM 1.0 JAX-RS 1.1 JAXR 1.0 Web Services 1.3 WS Metadata 2.0 Web JSF 2.0 Servlet 3.0 JSP 2.2 EL 2.2 JSTL 1.2 Debugging 1.0 Support Enterprise EJB 3.1 JAF 1.1 JavaMail 1.4 JCA 1.6 JMS 1.1 JPA 2.0 JTA 1.1 Management, Security, Common CDI (JSR 299) 1.0 @Inject (JSR 330) 1.0 Bean Validation 1.0 Interceptors 1.1 Managed Beans 1.0 JACC 1.4 Java EE Application Deployment 1.2 Java EE Management 1.1 JASPIC 1.0 + Java SE 6 JAX-WS 2.2 JAXB 2.2 JDBC 4.0 JNDI 1.5 SAAJ 1.3 Common 1.1 Annotations RMI Java IDL JMX JAAS JAXP StAX ...
  17. 17. New concepts
  18. 18. Pruning (Soon less specs) <ul><li>Marks specifications optional in next version
  19. 19. Pruned in Java EE 6 </li><ul><li>Entity CMP 2.x
  20. 20. JAX-RPC
  21. 21. JAX-R
  22. 22. JSR 88 (Java EE Application Deployment) </li></ul><li>Might disappear from Java EE 7 </li><ul><li>Vendors may decide to keeps them...
  23. 23. … or offer the delta as a set of modules </li></ul></ul>
  24. 24. Profiles
  25. 25. Web Profile 1.0 <ul><li>Subset of full platform
  26. 26. For web development </li><ul><li>Packages in a war </li></ul><li>Separate specification
  27. 27. Evolves at its own pace
  28. 28. Others will come </li><ul><li>Minimal (Servlet/JSP)
  29. 29. Portal.... </li></ul></ul>JSF 2.0 Servlet 3.0 JSP 2.2 EL 2.2 JSTL 1.2 EJB Lite 3.1 Managed Beans 1.0 Interceptors 1.1 JTA 1.1 JPA 2.0 Bean Validation 1.0 CDI 1.0 @Inject 1.0
  30. 30. EJB Lite <ul><li>Subset of the EJB 3.1 API
  31. 31. Used in Web profile
  32. 32. Packaged in a war </li></ul>Local Session Bean Injection CMT / BMT Interceptors Security Message Driven Beans EJB Web Service Endpoint RMI/IIOP Interoperability Remote interface EJB 2.x Timer service CMP / BMP
  33. 33. Portable JNDI names <ul><li>Client inside a container (use DI) </li></ul>@EJB Hello h; <ul><li>Client outside a container </li></ul>Context ctx = new InitialContext(); Hello h = (Hello) ctx.lookup(xyz); <ul><li>Portable JNDI name is specified </li></ul>java:global/foo/bar/HelloEJB
  34. 34. Portable JNDI names <ul><li>OrderBean implements Order packaged in orderejb.jar within orderapp.ear
  35. 35. java: global /orderapp/orderejb/OrderBean java: global /orderapp/orderejb/OrderBean!org.foo.Order </li></ul><ul><li>java: app /orderejb/OrderBean java: app /orderejb/OrderBean!com.acme.Order </li></ul><ul><li>java: module /OrderBean java: module /OrderBean!org.foo.Order </li></ul>Fully-qualified interface name Usable from any application in the container
  36. 36. Managed Beans 1.0 <ul><li>Separate spec shipped with Java EE 6
  37. 37. Container-managed POJOs
  38. 38. Support a small set of basic services </li><ul><li>Injection ( @Resource ...)
  39. 39. Life-cycle ( @PostConstruct , @PreDestroy )
  40. 40. Interceptor ( @Interceptor , @AroundInvoke ) </li></ul><li>Lightweight component model </li></ul>
  41. 41. Managed Beans 1.0 @javax.annotation.ManagedBean public class MyPojo { @Resource private Datasource ds; @PostConstruct private void init() { .... } @Interceptors(LoggingInterceptor.class) public void myMethod() {...} }
  42. 42. Interceptors 1.1 <ul><li>Address cross-cutting concerns in Java EE
  43. 43. Were part of the EJB 3.0 spec
  44. 44. Now a seperate spec shipped with EJB 3.1
  45. 45. Can be uses in EJBs...
  46. 46. … as well as ManagedBeans
  47. 47. @AroundInvoke
  48. 48. @AroundTimeout for EJB timers </li></ul>
  49. 49. JPA 2.0
  50. 50. JPA 2.0 <ul><li>Evolves separately from EJB now </li><ul><li>JSR 317 </li></ul><li>Richer mappings
  51. 51. Richer JPQL
  52. 52. Standard config options
  53. 53. Criteria API
  54. 54. ... </li></ul>
  55. 55. Richer mapping <ul><li>Collection of embeddables and basic types </li><ul><li>Not just collection of JPA entities
  56. 56. Multiple levels of embeddables </li></ul><li>More flexible support for Maps </li><ul><li>Keys, values can be one of : entities, embeddables or basic types </li></ul><li>More relationship mapping options </li><ul><li>Unidirectional 1-many foreign key mappings </li></ul></ul>
  57. 57. Collections of Embeddable Types @Embeddable public class BookReference { String title; Float price; String description; String isbn; Integer nbOfPage; ... } @Entity public class ListOfGreatBooks { @ElementCollection protected Set<BookReference> javaBooks; @ElementCollection protected Set<String> tags; ... }
  58. 58. Richer JPQL <ul><li>Added entity type to support non-polymorphic queries
  59. 59. Allow joins in subquery FROM clause
  60. 60. Added new reserved words </li><ul><li>ABS, BOTH, CONCAT, ELSE, END, ESCAPE, LEADING, LENGTH, LOCATE, SET, SIZE, SQRT, SUBSTRING, TRAILING </li></ul></ul>
  61. 61. Criteria API <ul><li>Strongly typed criteria API
  62. 62. Object-based query definition objects </li><ul><li>(Rather than JPQL string-based) </li></ul><li>Operates on the meta-model </li><ul><li>Browse the structure of a Persistence Unit
  63. 63. Dynamically: EntityManager.getMetamodel()
  64. 64. Statically: Each entity X has a metamodel class X_ </li></ul><li>CriteriaQuery as a query graph </li></ul>
  65. 65. Criteria API EntityManager em = ...; CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Book> query = cb.createQuery(Book.class); Root<Book> book = query. from (Book.class); query. select (book) .where (cb.equal(book. get(&quot;description&quot;) , &quot;&quot;)); SELECT b FROM Book b WHERE b.description IS EMPTY
  66. 66. Criteria API (Type-safe) EntityManager em = ...; CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Book> query = cb.createQuery(Book.class); Root<Book> book = query. from (Book.class); query. select (book) . where (cb.isEmpty(book.get( Book_ .description))); Statically generated JPA 2.0 MetaModel
  67. 67. Criteria API (Builder pattern) EntityManager em = ...; CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Book> query = cb.createQuery(Book.class); Root<Book> book = query. from (Book.class); query. select (book) . where (cb.isEmpty(book.get( Book_ .description))) .orderBy (...) .distinct(true) .having (...) .groupBy (...); List<Book> books = em.createQuery (query).getResultList();
  68. 68. Standard properties <ul><li>In persistence.xml : </li><ul><li>javax.persistence.jdbc.driver
  69. 69. javax.persistence.jdbc.url
  70. 70. javax.persistence.jdbc.user
  71. 71. javax.persistence.jdbc.password
  72. 72. javax.persistence.lock.scope
  73. 73. javax.persistence.lock.timeout </li></ul></ul>
  74. 74. And more... <ul><li>detach()
  75. 75. Join<X,Y> , ListJoin , MapJoin
  76. 76. Orphan removal functionality </li><ul><li>@OneToMany(orphanRemoval=true) </li></ul><li>BeanValidation integration on lifecycle
  77. 77. Second-level cache API </li><ul><li>@Cacheable annotation on entities
  78. 78. contain(Class,PK) , evict(Class,PK) , ... </li></ul><li>Pessimistic locking </li></ul>
  79. 79. Servlet 3.0
  80. 80. Ease of development <ul><li>Annotations based programming model </li><ul><li>@WebServlet
  81. 81. @WebFilter
  82. 82. @WebListener
  83. 83. @WebInitParam </li></ul><li>Optional web.xml
  84. 84. Better defaults and CoC </li></ul>
  85. 85. A servlet 3.0 example @WebServlet (urlPatterns={&quot; /MyApp &quot;}) public class MyServlet extends HttpServlet { public void doGet (HttpServletRequest req, HttpServletResponse res){ .... } } <ul><li>Same for @WebFilter a nd @WebListener </li></ul>web.xml is optional
  86. 86. Pluggability <ul><li>Fragments are similar to web.xml
  87. 87. <web-fragment> instead of <web-app> </li><ul><li>Declare their own servlets, listeners and filters </li></ul><li>Annotations and web fragments are merged following a configurable order
  88. 88. JARs need to be placed in WEB-INF/lib
  89. 89. and use /META-INF/web-fragment.xml
  90. 90. Overridden by main web.xml </li></ul>
  91. 91. And more... <ul><li>Async support (Comet-style)
  92. 92. Static resources in META-INF/resources
  93. 93. Configuration API </li><ul><li>Add and configure Servlet, Filters, Listeners
  94. 94. Add security constraints
  95. 95. Using ServletContext API </li></ul><li>File upload (similar to Apache File Upload)
  96. 96. Configure cookie session name
  97. 97. Security with @ServletSecurity </li></ul>
  98. 98. EJB 3.1
  99. 99. Optional Local Interface <ul><li>@Local , @Remote
  100. 100. Interfaces are not always needed </li><ul><li>Only for local interfaces
  101. 101. Remote interfaces are now optional ! </li></ul></ul>@Stateless public class HelloBean { public String sayHello() { return &quot;Hello world!&quot;; } }
  102. 102. Packaging in a war foo.ear lib/foo_common.jar foo_web.war foo_ejb.jar foo.war WEB-INF/classes com/acme/ Foo .class com/acme/ FooServlet .class com/acme/ FooEJB .class
  103. 103. Asynchronous calls <ul><li>How to have asynchronous call in EJBs ? </li><ul><li>JMS is more about sending messages
  104. 104. Threads and EJB's don't integrate well </li></ul><li>@Asynchronous </li><ul><li>Applicable to any EJB type
  105. 105. Best effort, no delivery guarantee </li></ul><li>Method returns void or Future<T> </li><ul><li>javax.ejb.AsyncResult helper class : return new AsyncResult<int>(result) </li></ul></ul>
  106. 106. Asynchronous calls @Stateless public class OrderBean { public void createOrder() { Order order = persistOrder(); sendEmail(order); // fire and forget } public Order persistOrder() {...} @Asynchronous public void sendEmail(Order order) {...} }
  107. 107. Timer Service <ul><li>Programmatic and Calendar based scheduling </li><ul><li>« Last day of the month »
  108. 108. « Every five minutes on Monday and Friday » </li></ul><li>Cron-like syntax </li><ul><li>second [0..59], minute [0..59], hour [0..23]...
  109. 109. dayOfMonth [1..31]
  110. 110. dayOfWeek [0..7] or [sun, mon, tue..]
  111. 111. Month [0..12] or [jan,feb..] </li></ul></ul>
  112. 112. Timer Service @Stateless public class WakeUpBean { @Schedule(dayOfWeek=&quot;Mon-Fri&quot;, hour=&quot;9&quot;) void wakeUp() { ... } }
  113. 113. Singleton <ul><li>New component </li><ul><li>No/local/remote interface </li></ul><li>Follows the Singleton pattern </li><ul><li>One single EJB per application per JVM </li></ul><li>Used to share state in the entire application </li><ul><li>State not preserved after container shutdown </li></ul><li>Added concurrency management </li><ul><li>Default is single-threaded
  114. 114. @ConcurrencyManagement </li></ul></ul>
  115. 115. Singleton @Singleton public class CachingBean { private Map cache; @PostConstruct void init() { cache = ...; } public Map getCache() { return cache; } public void addToCache(Object key, Object val) { cache.put(key, val); } }
  116. 116. Embeddable Container <ul><li>API allowing to : </li><ul><li>Initialize a container
  117. 117. Get container ctx
  118. 118. … </li></ul><li>Can run in any Java SE environment </li><ul><li>Batch processing
  119. 119. Simplifies testing
  120. 120. Just a jar file in your classpath </li></ul></ul>Java SE Transaction manager Security system Messaging engine EJB 3.1 Embedded container
  121. 121. Embeddable Container public static void main(String[] args){ EJBContainer container = EJBContainer.createEJBContainer(); Context context = container.getContext(); Hello h = (Hello) context .lookup(&quot; Global_JNDI_Name &quot;); h .sayHello(); container.close(); }
  122. 122. And more... <ul><li>Interceptors and InterceptorBinding
  123. 123. Singletons can be chained
  124. 124. Non persistent timer
  125. 125. @StatefulTimeout
  126. 126. ... </li></ul>
  127. 127. JSF 2.0
  128. 128. Facelets now preferred VDL <ul><li>Facelets (XHTML) as alternative to JSP </li><ul><li>Based on a generic View Description Language (VDL)
  129. 129. Can't add Java code to XHTML page (and “that's a good thing!” ™ ) </li></ul><li>Pages are usable from basic editors
  130. 130. IDEs offer traditional value-add: </li><ul><li>Auto-completion (EL)
  131. 131. (Composite) Component management
  132. 132. Project management, testing, etc... </li></ul></ul>
  133. 133. Setup, configuration <ul><li>JSF 2.0 does not mandate Servlet 3.0 </li><ul><li>Servlet 2.5 containers will run JSF 2.0
  134. 134. web.xml may be optional depending on runtime </li></ul><li>faces-config.xml now optional </li><ul><li>@javax.faces.bean.ManagedBean
  135. 135. Not required with JSR 299
  136. 136. Navigation can now belong to the page ( <navigation-rules> become optional) </li></ul></ul>
  137. 137. JSF Composite Component <ul><li>Using JSF 1.x </li><ul><li>Implement UIComponent , markup in renderer, register in faces-config.xml , add tld , ... </li></ul><li>With JSF 2.0 </li><ul><li>Single file, no Java code needed
  138. 138. Use XHTML and JSF tags to create components </li></ul></ul><html xmlns:cc=&quot; http://java.sun.com/jsf/composite &quot;> <cc: interface > <cc: attribute ...> <cc: implementation > <ul><ul><li>Everything else is auto-wired </li></ul></ul>
  139. 139. <!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;> <html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xmlns:h=&quot;http://java.sun.com/jsf/html&quot; xmlns:composite=&quot;http://java.sun.com/jsf/composite&quot; > <!-- INTERFACE --> <composite:interface> <composite:attribute name=&quot;param&quot;/> </composite:interface> <!-- IMPLEMENTATION --> <composite:implementation> <h:outputText value=&quot;Hello there, #{cc.attrs.param} &quot;/> </composite:implementation> </html> /resources/ezcomp/mycomponent.xhtml Defining the component Naming the component <?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;> <html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xmlns:h=&quot;http://java.sun.com/jsf/html&quot; xmlns:custom=&quot;http://java.sun.com/jsf/composite/ezcomp&quot; > <h:body> <custom:mycomponent param=&quot;Java EE 6 attendees&quot;/> </h:body> </html> Using the component Implicit EL object
  140. 140. Ajax support <ul><li>Inspired by RichFaces, IceFaces, DynaFaces, ...
  141. 141. Common JavaScript library ( jsf.js ) </li><ul><li>request JavaScript functions captured by PartialViewContext for sub-tree processing
  142. 142. Client JavaScript updates the DOM </li></ul></ul><h:commandButton onclick=&quot; jsf.ajax.request (this,event,{render:' foo '}); return false;&quot;/> <ul><li><f:ajax> tag to ajaxify existing pages </li></ul>xmlns: f =&quot; http://java.sun.com/jsf/core &quot; <h:commandButton> <f:ajax event=&quot;change&quot; execute=&quot;myForm&quot; render=&quot; foo &quot; / > </h:commandButton>
  143. 143. And more... <ul><li>Validation delegated to BeanValidation
  144. 144. Easier resources management
  145. 145. Better error reporting
  146. 146. New managed bean scope (View)
  147. 147. Groovy support (Mojarra)
  148. 148. Bookmarkable URLs
  149. 149. Templating : define and apply layouts
  150. 150. Project stages (dev vs. test vs. production)
  151. 151. ... </li></ul>
  152. 152. Bean Validation 1.0
  153. 153. Bean Validation 1.0 <ul><li>Enable declarative validation in your applications
  154. 154. Constrain Once, Validate Anywhere </li><ul><li>restriction on a bean, field or property
  155. 155. not null, size between 1 and 7, valid email... </li></ul><li>Standard way to validate constraints
  156. 156. Integration with JPA 2.0 & JSF 2.0 </li></ul>
  157. 157. Bean Validation 1.0 public class Address { @NotNull @Size (max=30, message=&quot;longer than {max} characters&quot;) private String street1; ... @NotNull @Valid private Country country; } public class Country { @NotNull @Size(max=20) private String name; ... } request recursive object graph validation
  158. 158. Build your own! @Size(min=5, max=5) @ConstraintValidator(ZipcodeValidator.class) @Documented @Target({ANNOTATION_TYPE, METHOD, FIELD}) @Retention(RUNTIME) public @interface ZipCode { String message() default &quot;Wrong zipcode&quot;; String[] groups() default {}; }
  159. 159. Integration with JPA 2.0 and JSF 2.0 <ul><li>Automatic
  160. 160. No extra code
  161. 161. Happens during @PrePersist, @PreUpdate, @PreRemove
  162. 162. Shows how well integrated EE can be </li></ul>
  163. 163. JAX-RS 1.1 <ul><li>High-level HTTP API for RESTful Services
  164. 164. POJO and Annotations Based </li><ul><li>API also available </li></ul><li>Maps HTTP verbs (Get, Post, Put, Delete...)
  165. 165. JAX-RS 1.0 has been released in 2008
  166. 166. JAX-RS 1.1 integrates with EJBs (and more generally with Java EE 6) </li></ul>
  167. 167. Hello World @Path(&quot;/helloworld&quot;) public class HelloWorldResource { @GET @Produces(&quot;text/plain&quot;) public String sayHello() { return &quot;Hello World&quot;; } } GET http://example.com/helloworld
  168. 168. Hello World GET /helloworld HTTP/1.1 Host: example.com Accept: text/plain HTTP/1.1 200 OK Date: Wed, 12 Nov 2008 16:41:58 GMT Server: GlassFish v3 Content-Type: text/plain ; charset=UTF-8 Hello World Request Response
  169. 169. Different Mime Types @Path(&quot;/helloworld&quot;) public class HelloWorldResource { @GET @Produces(&quot;image/jpeg&quot;) public byte[] paintHello() { ... @GET @Produces(&quot;text/plain&quot;) public String displayHello() { ... @POST @Consumes(&quot;text/xml&quot;) public void updateHello(String xml) { ... }
  170. 170. Parameters & EJBs @Path(&quot;/users/ {userId} &quot;) @Stateless public class UserResource { @PersistenceContext EntityManage em; @GET @Produces(&quot;text/xml&quot;) public String getUser( @PathParam(&quot;userId&quot; ) String id){ User u = em.find(User.class, id) ... } }
  171. 171. And more... <ul><li>Different parameters ( @MatrixParam , @QueryParam , @CookieParam ...)
  172. 172. Support for @Head and @Option
  173. 173. Inject UriInfo using @Context
  174. 174. JAX-RS servlet mapping with @ApplicationPath(&quot;rs&quot;)
  175. 175. ... </li></ul>
  176. 176. DI 1.0 & CDI 1.0
  177. 177. Injection in Java EE 5 <ul><li>Common Annotation </li><ul><li>@Resource </li></ul><li>Specialized cases </li><ul><li>@EJB , @WebServicesRef , @PersistenceUnit … </li></ul><li>Requires managed objects </li><ul><li>EJB, Servlet and JSF Managed Bean in EE 5
  178. 178. Also in any Java EE 6's javax.annotation.ManagedBean </li></ul></ul>
  179. 179. Injection in Java EE 6 CDI (JSR 299) & @Inject (JSR 330) Inject just about anything anywhere... ...yet with strong typing
  180. 180. The tale of 2 dependency JSRs <ul><li>Context & Dependency Injection for Java EE </li><ul><li>Born as WebBeans, unification of JSF and EJB
  181. 181. “ Loose coupling, strong typing&quot;
  182. 182. Weld as the reference implementation </li></ul><li>Dependency Injection for Java (JSR 330) </li><ul><li>Lead by Google and SpringSource
  183. 183. Minimalistic dependency injection, @Inject
  184. 184. Applies to Java SE, Guice as the reference impl. </li></ul><li>Both aligned and part of Java EE 6 Web Profile
  185. 185. But that's another story </li></ul>
  186. 186. @Inject <ul><li>javax.inject package
  187. 187. @Inject : Identifies injectable constructors, methods, and fields
  188. 188. @Named : String-based qualifier (for EL)
  189. 189. @Qualifier : Identifies qualifier
  190. 190. @Scope : Identifies scope annotations
  191. 191. @Singleton : Instantiates once </li></ul>
  192. 192. Injection @Inject Customer cust; type injection point
  193. 193. Qualifier Annotation @Target({TYPE,METHOD,PARAMETER,FIELD}) @Retention(RUNTIME) @Documented @Qualifier public @interface Premium {…} @Premium // my own qualifier (see above) public class SpecialCustomer implements Customer { public void buy() {…} }
  194. 194. Injection with qualifier @Inject @Premium Customer cust; qualifier (user-defined label) i.e. « which one? » type injection point
  195. 195. Contexts (The 'C' in CDI) <ul><li>Built-in “Web” Scopes : </li><ul><li>@RequestScoped
  196. 196. @SessionScoped*
  197. 197. @ApplicationScoped*
  198. 198. @ConversationScoped* </li></ul><li>Other Scopes </li><ul><li>@Dependent is the default pseudo-scope for un-scoped beans (same as Managed Beans)
  199. 199. Build your own @ScopeType </li></ul><li>Clients need not be scope-aware </li></ul>* : requires Serializable fields to enable passivation
  200. 200. @ConversationScoped <ul><li>A conversation is : </li><ul><li>explicitly demarcated
  201. 201. associated with individual browser tabs
  202. 202. accessible from any JSF request </li></ul></ul>@Named @ConversationScoped public class ItemFacade implements Serializable { @Inject Conversation conversation; ... conversation.begin(); // long-running ... conversation.end(); // schedule for destruction
  203. 203. And more... <ul><li>Alternatives </li><ul><li>@Alternative annotation on various impl. </li></ul><li>Interceptors & Decorators </li><ul><li>Loosely-coupled orthogonal (technical) interceptors
  204. 204. @Decorator bound to given interface </li></ul><li>Stereotypes ( @Stereotype ) </li><ul><li>Captures any of the above common patterns </li></ul><li>Events </li><ul><li>Loosely-coupled (conditional) @Observable events </li></ul></ul>
  205. 205. Summary
  206. 206. Java EE 6 is... Richer Ligther Simpler
  207. 207. Application servers are... Less monolithic More OSGi based Ready for other profiles
  208. 208. Time is changing
  209. 209. Want to know more <ul><li>A book </li><ul><li>450 pages about Java EE 6
  210. 210. Second edition
  211. 211. Covers most specs </li></ul><li>A training </li><ul><li>3 days
  212. 212. Most specs
  213. 213. Hands on labs
  214. 214. Contact me </li></ul></ul>
  215. 215. Thanks www.antoniogoncalves.org [email_address] @agoncal @lescastcodeurs
  216. 216. Creative Commons <ul><li>Attribution — You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).
  217. 217. Noncommercial — You may not use this work for commercial purposes.
  218. 218. Share Alike — If you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar license to this one. </li></ul>
  1. A particular slide catching your eye?

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

×