Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Java EE 6

442 views

Published on

Short presentation showing highlights of Java EE 6, inspired by Adam Bien's hacks.

Published in: Software, Technology, Education
  • Be the first to comment

  • Be the first to like this

Java EE 6

  1. 1. Java EE 6 All Platform, no clutter @greyfairer
  2. 2. Agenda Servlet 3.0, JAX-RS 1.1, JSF 2.0 JSR-330 a.k.a. javax.inject JSR-299 a.k.a. CDI Arquillian CDI Extensions
  3. 3. Servlets 3.0 @WebServlet(name=”MyServlet”, urlPatterns={”/myApp/*”}) public class MyServlet extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse res) { ... @WebFilter( filterName="PaymentFilter", urlPatterns={"/*"}, servletNames={"PaymentServlet"}, ) public class PaymentFilter implements Filter { ...
  4. 4. Modular war's ● Jar's in WEB-INF/lib can also contain annotated servlet/filter/listener classes ● Jar's can also contribute META-INF/web.xml ● <web-fragment>...</web-fragment> ● Jar's can also contribute jsp's, static html ● In META-INF/resources
  5. 5. Servlet 3.0 and CDI ● If you have a WEB-INF/beans.xml, Web archives will be scanned for Managed Beans ● Can be injected in servlets, JAX-RS, JSF beans EJB CDI JPAJSF ... @Stateful @Stateless @Singleton @Produces @Named @Entity @Managed Bean ... EJB
  6. 6. Asynch Servlets @WebServlet(name="AsyncServlet", asyncSupported=true) public class AsyncServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) { final AsyncContext ac = request.startAsync(); ac.setTimeout(...) ac.start( new Runnable(){ ac.getResponse().getWriter()...; ac.complete(); });
  7. 7. Demo: Chat servlet ● Glassfish: asynch-request-war sample
  8. 8. JAX-RS 1.1 ● RESTfull Web Services ● Typical use: javascript clients ● GET/POST/PUT/DELETE resources ● URL encodes resource identification ● Encoding defined by MIME headers ● Class and/or method annotated with @Path ● Automatic JSON/XML encoding using JAXB
  9. 9. Demo: novashop ● From Adam Bien hacks ● http://kenai.com/projects/javaee-patterns/sources/hg/show/hacks/NovaShop ● @Path, @PathParam, @Produces, @Consumes annotation on WorkshopRegistration ● Use Chrome Advanced Rest Client
  10. 10. JSF 2.0 ● .xhtml view technology ● Uses JEE6 managed POJO’s ● @RequestScoped, @ConversationScoped, @Named ● New: call any method, even with parameters. ● Controllers: method calls on managed beans ● Bind form fields to bean properties – Typically @RequestScoped beans ● Implicit navigation using method’s returned value ● Redirect after post: ?faces-redirect=true
  11. 11. JSF 2.0 in Java EE 6 ● Supports javax.validation ● All @Named CDI beans are accessible ● Custom Components will use JAX-RS
  12. 12. Demo: novashop 2 ● From Adam Bien hacks ● http://kenai.com/projects/javaee-patterns/sources/hg/show/hacks/NovaShop ● Index.xhtml, registered.xhtml
  13. 13. JSR-330 a.k.a. javax.inject ● @Inject, @Qualifier, @Scope, etc. ● Standardized Dependency Injection API ● Reference Implementation: Google Guice 2.0 ● Also supported by Spring since 3.0 ● Defines API, not injector implementation or configuration
  14. 14. JSR-299 a.k.a. CDI ● Standardized dependency injection behaviour and configuration ● Required feature of any Java EE 6 container, including Web profile ● javax.enterprise.* package ● @Produces (evt. with InjectionPoint) ● Instance<> and @Alternative ● Event<> and @Observes
  15. 15. Demo: novashop 3 ● Configurator for maxNumberOfRegistrations
  16. 16. CDI Extensions ● CDI has Service Provider Interfaces ● Allows extensions drop-in ● http://groups.diigo.com/group/cdi-extensions ● Seam 3 and others ● https://github.com/CDISource/cdisource ● @Spring Spring to CDI bridge ● CDI to Spring: use JNDI Lookup.
  17. 17. Q & A

×