Java EE 6

17
Java EE 6 All Platform, no clutter @greyfairer

description

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

Transcript of Java EE 6

Page 1: Java EE 6

Java EE 6All Platform, no clutter

@greyfairer

Page 2: Java EE 6

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

Page 3: Java EE 6

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 {

...

Page 4: Java EE 6

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

Page 5: Java EE 6

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

Page 6: Java EE 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();

});

Page 7: Java EE 6

Demo: Chat servlet● Glassfish: asynch-request-war sample

Page 8: Java EE 6

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

Page 9: Java EE 6

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

Page 10: Java EE 6

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

Page 11: Java EE 6

JSF 2.0 in Java EE 6● Supports javax.validation● All @Named CDI beans are accessible● Custom Components will use JAX-RS

Page 12: Java EE 6

Demo: novashop 2● From Adam Bien hacks● http://kenai.com/projects/javaee-patterns/sources/hg/show/hacks/NovaShop

● Index.xhtml, registered.xhtml

Page 13: Java EE 6

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

Page 14: Java EE 6

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

Page 15: Java EE 6

Demo: novashop 3● Configurator for maxNumberOfRegistrations

Page 16: Java EE 6

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.

Page 17: Java EE 6

Q & A