<Insert Picture Here>




An Overview of the Java EE 6 Platform
Roberto Chinnici
Java EE Platform Lead
The following is intended to outline our general
product direction. It is intended for information
purposes only, and may not be incorporated into any
contract. It is not a commitment to deliver any
material, code, or functionality, and should not be
relied upon in making purchasing decisions.
The development, release, and timing of any
features or functionality described for Oracle’s
products remains at the sole discretion of Oracle.
Agenda


•   What's new in Java EE 6?
•   Web Profile
•   Extensibility
•   Highlights from some of the new APIs
<Insert Picture Here>



Java EE 6 Platform
JAVA EE 6
  FINAL RELEASE
DECEMBER 10, 2009
What's New?


•   Several new APIs
•   Web Profile
•   Pluggability/extensibility
•   Dependency injection
•   Lots of improvements to existing APIs
New and updated components


•   EJB 3.1               •   Managed Beans 1.0
•   JPA 2.0               •   Interceptors 1.1
•   Servlet 3.0           •   JAX-WS 2.2
•   JSF 2.0               •   JSR-109 1.3
•   JAX-RS 1.1            •   JSP 2.2
•   Connectors 1.6        •   EL 2.2
•   Bean Validation 1.0   •   JSR-250 1.1
•   DI 1.0                •   JASPIC 1.1
•   CDI 1.0               •   JACC 1.5
Web Profile


• First Java EE profile to be defined
• A fully-functional, mid-size stack for modern web
  application development
• Complete, but not the kitchen sink
Java EE 6 Web Profile Contents


                      JSF 2.0

     JSP 2.2 · EL 2.2 · JSTL 1.2 · JSR-45 1.0

                    Servlet 3.0

EJB 3.1 Lite · DI 1.0 · CDI 1.0 · Managed Beans 1.0

Bean Validation 1.0 · Interceptors 1.1 · JSR-250 1.1

                 JPA 2.0 · JTA 1.1
Java EE 6 Web Profile Extension Points


                       JSF 2.0

      JSP 2.2 · EL 2.2 · JSTL 1.2 · JSR-45 1.0

                     Servlet 3.0

EJB 3.1 Lite · DI 1.0 · CDI 1.0 · Managed Beans 1.0

 Bean Validation 1.0 · Interceptors 1.1 · JSR-250 1.1

                  JPA 2.0 · JTA 1.1
Pluggability/Extensibility


• Focus on the web tier in this release
• Create a level playing field for third-party frameworks
• Simplify packaging of web applications
Modular Web Applications


•   Libraries can contain /META-INF/web-fragment.xml
•   web.xml is optional
•   @WebServlet, @WebFilter annotations
•   ServletContainerInitializer interface
•   Programmatic registration of components
•   Resource jars containing /META-INF/resources

      /WEB-INF/lib/catalog.jar
         /META-INF/resources/catalog/books.html
→    http://myserver:8080/myapp/catalog/books.html
Sample Servlet

import javax.servlet.annotation.WebServlet;

@WebServlet(urlPatterns=”/contents”)
public class MyServlet extends HttpServlet {
  public void doGet(HttpServletRequest request,
                    HttpServletResponse response) {
    // ...
  }

}



    No deployment descriptor needed
Sample Web Fragment Descriptor

<web-fragment
     version=”3.0”
     xmlns="http://java.sun.com/xml/ns/javaee">
  <servlet>
    <servlet-name>welcome</servlet-name>
    <servlet-class>WelcomeServlet</servlet-class>
  </servlet>
  <listener>
    <listener-class>RequestListener</listener-class>
  </listener>
</web-fragment>
Strategy for Evolving the APIs


•   Capture common patterns
•   Fix inconsistencies
•   Adopt what works
•   Make APIs work better together
•   Reducing boilerplate/packaging
•   Be transparent
JAX-RS 1.1


•   RESTful web services API
•   Already widely adopted
•   Really a general, high-level HTTP API
•   Annotation-based programming model
•   Programmatic API when needed
JAX-RS Sample

@Path(“widgets/{id}”)
@Consumes(“application/widgets+xml”)
@Produces(“application/widgets+xml”)
public class WidgetResource {
    public WidgetResource(@PathParam(“id”)
                          String id) {…}

    @GET
    public Widget getWidget() {…}

    @PUT
    public void putWidget(Widget widget){…}
}
Building HTTP Responses



return Response.created(createdUri)
               .entity(createdContent)
               .build();

return Response.status(404)
        .entity(message)
        .type("text/plain")
        .build();




Similarly, use UriBuilder to build URIs
EJB 3.1


• @Singleton beans
• @Startup beans
• Declarative timers
• Asynchronous method calls
   @Asynchronous public Future<Integer> compute();
• Define EJBs directly inside a web application
• EJBContainer API works on Java SE
EJB 3.1 Code Snippets
@Singleton @Startup
public class StartupBean {
  @PostConstruct
  public void doAtStartup() { … }
}

@Stateless public class BackupBean {
  @Schedule(dayOfWeek=”Fri”, hour=”3”, minute=”15”)
  public void performBackup() { … }
}

@Stateless public class CacheRefreshingBean {
  @Schedule(minute=”*/5”, persistent=false)
  public void refreshCache() { … }
}
EJB 3.1 Lite


•   A subset of EJB 3.1
•   All types of session beans (stateful, stateless, singletons)
•   Local access only
•   Declarative transactions and security
•   Interceptors
•   ejb-jar.xml descriptor optional
Java EE 6 Web Profile Core Component Model


                      JSF 2.0

      JSP 2.2 · EL 2.2 · JSTL 1.2 · JSR-45 1.0

                    Servlet 3.0

EJB 3.1 Lite · DI 1.0 · CDI 1.0 · Managed Beans 1.0

Bean Validation 1.0 · Interceptors 1.1 · JSR-250 1.1

                 JPA 2.0 · JTA 1.1
Dependency Injection


• DI + CDI (JSR-330 + JSR-299)
• @Resource still around for container resources
  @Resource DataSource myDB;
• Added @Inject annotation for type-safe injection
  @Inject @LoggedIn User user;
• Automatic scope management (request, session, etc.)
• No configuration: beans discovered at startup
• Extensible via the BeanManager API
Scoped Bean with Constructor Injection


@ApplicationScoped
public class CheckoutHandler {
  @Inject
  public CheckoutHandler(
          @LoggedIn User user,
          @Reliable @PayBy(CREDIT_CARD)
          PaymentProcessor processor,
          @Default ShoppingCart cart) {…}
}


Injection points identified by Qualifier + Type
@Default qualifier can be omitted
Why Use CDI?


• Structure the application as a set of beans
• Injection and events enable decoupling
  – No direct dependency between beans
  – Freedom to refactor the code, change implementations
• Automatic state management base on scope
• Support EJB components and plain “managed beans”
• Beans discovered automatically - no configuration
  needed
• Extensible notion of bean
  – Can incorporate components from external frameworks
Java EE 6 Platform


•   More powerful
•   More flexible
•   More extensible
•   Easier to use




      http://www.oracle.com/javaee
Overview of Java EE 6 by Roberto Chinnici at SFJUG

Overview of Java EE 6 by Roberto Chinnici at SFJUG

  • 1.
    <Insert Picture Here> AnOverview of the Java EE 6 Platform Roberto Chinnici Java EE Platform Lead
  • 2.
    The following isintended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.
  • 3.
    Agenda • What's new in Java EE 6? • Web Profile • Extensibility • Highlights from some of the new APIs
  • 4.
  • 5.
    JAVA EE 6 FINAL RELEASE DECEMBER 10, 2009
  • 6.
    What's New? • Several new APIs • Web Profile • Pluggability/extensibility • Dependency injection • Lots of improvements to existing APIs
  • 7.
    New and updatedcomponents • EJB 3.1 • Managed Beans 1.0 • JPA 2.0 • Interceptors 1.1 • Servlet 3.0 • JAX-WS 2.2 • JSF 2.0 • JSR-109 1.3 • JAX-RS 1.1 • JSP 2.2 • Connectors 1.6 • EL 2.2 • Bean Validation 1.0 • JSR-250 1.1 • DI 1.0 • JASPIC 1.1 • CDI 1.0 • JACC 1.5
  • 8.
    Web Profile • FirstJava EE profile to be defined • A fully-functional, mid-size stack for modern web application development • Complete, but not the kitchen sink
  • 9.
    Java EE 6Web Profile Contents JSF 2.0 JSP 2.2 · EL 2.2 · JSTL 1.2 · JSR-45 1.0 Servlet 3.0 EJB 3.1 Lite · DI 1.0 · CDI 1.0 · Managed Beans 1.0 Bean Validation 1.0 · Interceptors 1.1 · JSR-250 1.1 JPA 2.0 · JTA 1.1
  • 10.
    Java EE 6Web Profile Extension Points JSF 2.0 JSP 2.2 · EL 2.2 · JSTL 1.2 · JSR-45 1.0 Servlet 3.0 EJB 3.1 Lite · DI 1.0 · CDI 1.0 · Managed Beans 1.0 Bean Validation 1.0 · Interceptors 1.1 · JSR-250 1.1 JPA 2.0 · JTA 1.1
  • 11.
    Pluggability/Extensibility • Focus onthe web tier in this release • Create a level playing field for third-party frameworks • Simplify packaging of web applications
  • 12.
    Modular Web Applications • Libraries can contain /META-INF/web-fragment.xml • web.xml is optional • @WebServlet, @WebFilter annotations • ServletContainerInitializer interface • Programmatic registration of components • Resource jars containing /META-INF/resources /WEB-INF/lib/catalog.jar /META-INF/resources/catalog/books.html → http://myserver:8080/myapp/catalog/books.html
  • 13.
    Sample Servlet import javax.servlet.annotation.WebServlet; @WebServlet(urlPatterns=”/contents”) publicclass MyServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) { // ... } } No deployment descriptor needed
  • 14.
    Sample Web FragmentDescriptor <web-fragment version=”3.0” xmlns="http://java.sun.com/xml/ns/javaee"> <servlet> <servlet-name>welcome</servlet-name> <servlet-class>WelcomeServlet</servlet-class> </servlet> <listener> <listener-class>RequestListener</listener-class> </listener> </web-fragment>
  • 15.
    Strategy for Evolvingthe APIs • Capture common patterns • Fix inconsistencies • Adopt what works • Make APIs work better together • Reducing boilerplate/packaging • Be transparent
  • 16.
    JAX-RS 1.1 • RESTful web services API • Already widely adopted • Really a general, high-level HTTP API • Annotation-based programming model • Programmatic API when needed
  • 17.
    JAX-RS Sample @Path(“widgets/{id}”) @Consumes(“application/widgets+xml”) @Produces(“application/widgets+xml”) public classWidgetResource { public WidgetResource(@PathParam(“id”) String id) {…} @GET public Widget getWidget() {…} @PUT public void putWidget(Widget widget){…} }
  • 18.
    Building HTTP Responses returnResponse.created(createdUri) .entity(createdContent) .build(); return Response.status(404) .entity(message) .type("text/plain") .build(); Similarly, use UriBuilder to build URIs
  • 19.
    EJB 3.1 • @Singletonbeans • @Startup beans • Declarative timers • Asynchronous method calls @Asynchronous public Future<Integer> compute(); • Define EJBs directly inside a web application • EJBContainer API works on Java SE
  • 20.
    EJB 3.1 CodeSnippets @Singleton @Startup public class StartupBean { @PostConstruct public void doAtStartup() { … } } @Stateless public class BackupBean { @Schedule(dayOfWeek=”Fri”, hour=”3”, minute=”15”) public void performBackup() { … } } @Stateless public class CacheRefreshingBean { @Schedule(minute=”*/5”, persistent=false) public void refreshCache() { … } }
  • 21.
    EJB 3.1 Lite • A subset of EJB 3.1 • All types of session beans (stateful, stateless, singletons) • Local access only • Declarative transactions and security • Interceptors • ejb-jar.xml descriptor optional
  • 22.
    Java EE 6Web Profile Core Component Model JSF 2.0 JSP 2.2 · EL 2.2 · JSTL 1.2 · JSR-45 1.0 Servlet 3.0 EJB 3.1 Lite · DI 1.0 · CDI 1.0 · Managed Beans 1.0 Bean Validation 1.0 · Interceptors 1.1 · JSR-250 1.1 JPA 2.0 · JTA 1.1
  • 23.
    Dependency Injection • DI+ CDI (JSR-330 + JSR-299) • @Resource still around for container resources @Resource DataSource myDB; • Added @Inject annotation for type-safe injection @Inject @LoggedIn User user; • Automatic scope management (request, session, etc.) • No configuration: beans discovered at startup • Extensible via the BeanManager API
  • 24.
    Scoped Bean withConstructor Injection @ApplicationScoped public class CheckoutHandler { @Inject public CheckoutHandler( @LoggedIn User user, @Reliable @PayBy(CREDIT_CARD) PaymentProcessor processor, @Default ShoppingCart cart) {…} } Injection points identified by Qualifier + Type @Default qualifier can be omitted
  • 25.
    Why Use CDI? •Structure the application as a set of beans • Injection and events enable decoupling – No direct dependency between beans – Freedom to refactor the code, change implementations • Automatic state management base on scope • Support EJB components and plain “managed beans” • Beans discovered automatically - no configuration needed • Extensible notion of bean – Can incorporate components from external frameworks
  • 26.
    Java EE 6Platform • More powerful • More flexible • More extensible • Easier to use http://www.oracle.com/javaee