<Insert Picture Here>




Understanding the Nuts & Bolts of Java EE 6
Arun Gupta, Java EE & GlassFish Guy
blogs.sun.com/arungupta, @arungupta
The following/preceding 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.



                                                     2
Are you tweeting ?



 #glassfish
#sparkit2011


                     3
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                                                      Managed
Project                                                                  Bean 1.0


May 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
Compatible Java EE 6 Impls

Today:                       Web Profile Only




Announced:
                                                5
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
• EJB-in-WAR
• No-interface EJB
• Optional
  “web.xml”/”faces-
  config.xml”
• Annotation-driven
  •   @Schedule
  •   @Path
  •   @Inject
  •   ...




                      7
<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
Java EE 6 - Done




                09
• Specifications approved by the JCP




              20
• Reference Implementation is GlassFish




             h
  Server Open Source Edition 3
• TCK
         10 t
 ec
D


                                          9
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
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
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
Lab #1
Managed Beans


                13
Managed Beans 1.0 - Sample

@javax.annotation.ManagedBean                              @Resource
public 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
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
Lab #2
Interceptors


               16
Interceptors – Business Method
  (Logging)
@InterceptorBinding                    @LoggingInterceptorBinding
@Retention(RUNTIME)                    public class MyManagedBean {
@Target({METHOD,TYPE})                   . . .
public @interface                      }
LoggingInterceptorBinding {
}


@Interceptor
@LoggingInterceptorBinding
public class @LogInterceptor {
  @AroundInvoke
  public Object log(InvocationContext context) {
     System.out.println(context.getMethod().getName());
     System.out.println(context.getParameters());
     return context.proceed();
  }
}




                                                                 17
Why Interceptor Bindings ?
• Remove dependency from the interceptor
  implementation class
• Can vary depending upon deployment
  environment
• Allows central ordering of interceptors




                                            18
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
@Transactional
public 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
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
Servlets 3.0 (JSR 315)
   Annotations-based @WebServlet

package 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
Lab #3
Servlets


           22
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
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
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
Lab #4
Java Persistence API


                       26
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
EJB 3.1 (JSR 318)
Package & Deploy in a WAR

    Java EE 5                                     Java EE 6
                                            myApp.war
myApp.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
Lab #5
EJB 3.1


          29
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
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
CDI
 Injection Points

• Field, Method, Constructor
• 0 or more qualifiers
                         Which one ?
• Type                    (Qualifier)




            @Inject @LoggedIn User user
Request                            What ?
Injection                          (Type)

                                            32
Lab #6
CDI Qualifiers


                 33
CDI
 Much more ...

• Producer methods and fields
• Bridging Java EE resources
• Alternatives
• Interceptors
• Decorators
• Stereotypes




                                34
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
Lab #7
JSF 2.0


          36
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
Lab #8
Bean Validation


                  38
JAX-RS 1.1


• Java API for building RESTful Web Services
• POJO based
• Annotation-driven
• Server-side API
• HTTP-centric




                                           39
JAX-RS 1.1
Code 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
JAX-RS 1.1
Code 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
Lab #9
JAX-RS


         42
JAX-RS 1.1
Code Sample

import javax.inject.Inject;
import javax.enterprise.context.RequestScoped;

@RequestScoped
public class ActorResource {
    @Inject DatbaseBean db;

    public Actor getActor(int id) {
        return db.findActorById(id);
    }
}




                                                 43
JAX-RS 1.1
Code Sample
import   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}")
@RequestScoped
public 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
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
http://blogs.sun.com/arungupta/entry/java_ee_6_twitter_demo

                                                              46
Lab #10
Twitter App


              47
48
IDE Support for Java EE 6




                            49
From the real users ...                                  Jigsaw puzzle, Modular,
                                                               standard, less xml, easy,
                                                               easy, have I said easy?
Developers can concentrate
on business logic, Java EE 6 is
providing a standard for
the 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 grandfather's
                                                            enterprise Java anymore,
                     Definite excuse to avoid               Enterprise Java Renaissance
                     Spring forever

                http://blogs.sun.com/arungupta/tags/community+feedback


                                                                                             50
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
GlassFish Server Chronology

2006    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
GlassFish Server Distributions


Distribution                  License      Features

                                           • Java EE 6 compatibility
GlassFish Server Open         CDDL &       • Web Profile support
Source Edition 3.1            GPLv2        • In-memory replication / clustering
Web Profile
                                           • Centralized Administration
                                           • Java EE 6 compatibility
GlassFish Open Source         CDDL &       • Full Java EE distribution
Edition 3.1                   GPLv2        • In-memory replication / clustering
                                           • Centralized Administration
                                           • Adds
Oracle GlassFish Server 3.1   Commercial        • Oracle GlassFish Server Control
Web Profile                                     • Patches, support, knowledge
                                                base
                                           • Adds
Oracle GlassFish Server 3.1   Commercial        • Oracle GlassFish Server Control
                                                • Patches, support, knowledge
                                                base
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
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
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
Java EE 7 Schedule
                               NEW

• March 2011 Early EG Formed
• Q3 2011 Early Draft
• Q1 2012 Public Draft
• Q3 2012 Final Release




                                     58
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
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
References


• glassfish.org
• blogs.sun.com/theaquarium
• facebook.com/glassfish
• oracle.com/goto/glassfish
• youtube.com/GlassFishVideos
• Follow @glassfish




                                61
<Insert Picture Here>




Understanding the Nuts & Bolts of Java EE 6
Arun Gupta, Java EE & GlassFish Guy
blogs.sun.com/arungupta, @arungupta

Spark IT 2011 - Java EE 6 Workshop

  • 1.
    <Insert Picture Here> Understandingthe Nuts & Bolts of Java EE 6 Arun Gupta, Java EE & GlassFish Guy blogs.sun.com/arungupta, @arungupta
  • 2.
    The following/preceding 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. 2
  • 3.
    Are you tweeting? #glassfish #sparkit2011 3
  • 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 Managed Project Bean 1.0 May 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.
    Compatible Java EE6 Impls Today: Web Profile Only Announced: 5
  • 6.
    Light-weight • Java EE6 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.
    • EJB-in-WAR • No-interfaceEJB • Optional “web.xml”/”faces- config.xml” • Annotation-driven • @Schedule • @Path • @Inject • ... 7
  • 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.
    Java EE 6- Done 09 • Specifications approved by the JCP 20 • Reference Implementation is GlassFish h Server Open Source Edition 3 • TCK 10 t ec D 9
  • 10.
    Java EE 6Web 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.
    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.
    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.
  • 14.
    Managed Beans 1.0- Sample @javax.annotation.ManagedBean @Resource public 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.
    Interceptors 1.1 • Interposeon 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.
  • 17.
    Interceptors – BusinessMethod (Logging) @InterceptorBinding @LoggingInterceptorBinding @Retention(RUNTIME) public class MyManagedBean { @Target({METHOD,TYPE}) . . . public @interface } LoggingInterceptorBinding { } @Interceptor @LoggingInterceptorBinding public class @LogInterceptor { @AroundInvoke public Object log(InvocationContext context) { System.out.println(context.getMethod().getName()); System.out.println(context.getParameters()); return context.proceed(); } } 17
  • 18.
    Why Interceptor Bindings? • Remove dependency from the interceptor implementation class • Can vary depending upon deployment environment • Allows central ordering of interceptors 18
  • 19.
    Interceptors – BusinessMethod (Transaction) @InterceptorBinding @Transactional @Retention(RUNTIME) public class ShoppingCart { . . . } @Target({METHOD,TYPE}) public @interface Transactional { public class ShoppingCart { } @Transactional public void checkOut() { . . . } @Interceptor @Transactional public 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.
    Servlets in JavaEE 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.
    Servlets 3.0 (JSR315) Annotations-based @WebServlet package 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.
  • 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.
    Servlets 3.1 (JSR340) 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.
    Java Persistence API2 (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.
  • 27.
    JPA 2.1 CandidateFeatures 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.
    EJB 3.1 (JSR318) Package & Deploy in a WAR Java EE 5 Java EE 6 myApp.war myApp.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.
  • 30.
    EJB 3.1 • Nointerface 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.
    Contexts & DependencyInjection - 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.
    CDI Injection Points •Field, Method, Constructor • 0 or more qualifiers Which one ? • Type (Qualifier) @Inject @LoggedIn User user Request What ? Injection (Type) 32
  • 33.
  • 34.
    CDI Much more... • Producer methods and fields • Bridging Java EE resources • Alternatives • Interceptors • Decorators • Stereotypes 34
  • 35.
    Java Server Faces2.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.
  • 37.
    Bean Validation (JSR303) • 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.
  • 39.
    JAX-RS 1.1 • JavaAPI for building RESTful Web Services • POJO based • Annotation-driven • Server-side API • HTTP-centric 39
  • 40.
    JAX-RS 1.1 Code 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.
    JAX-RS 1.1 Code 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.
  • 43.
    JAX-RS 1.1 Code Sample importjavax.inject.Inject; import javax.enterprise.context.RequestScoped; @RequestScoped public class ActorResource { @Inject DatbaseBean db; public Actor getActor(int id) { return db.findActorById(id); } } 43
  • 44.
    JAX-RS 1.1 Code Sample import 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}") @RequestScoped public 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.
    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.
  • 47.
  • 48.
  • 49.
    IDE Support forJava EE 6 49
  • 50.
    From the realusers ... Jigsaw puzzle, Modular, standard, less xml, easy, easy, have I said easy? Developers can concentrate on business logic, Java EE 6 is providing a standard for the 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 grandfather's enterprise Java anymore, Definite excuse to avoid Enterprise Java Renaissance Spring forever http://blogs.sun.com/arungupta/tags/community+feedback 50
  • 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.
  • 53.
    GlassFish Server Chronology 2006 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.
    GlassFish Server Distributions Distribution License Features • Java EE 6 compatibility GlassFish Server Open CDDL & • Web Profile support Source Edition 3.1 GPLv2 • In-memory replication / clustering Web Profile • Centralized Administration • Java EE 6 compatibility GlassFish Open Source CDDL & • Full Java EE distribution Edition 3.1 GPLv2 • In-memory replication / clustering • Centralized Administration • Adds Oracle GlassFish Server 3.1 Commercial • Oracle GlassFish Server Control Web Profile • Patches, support, knowledge base • Adds Oracle GlassFish Server 3.1 Commercial • Oracle GlassFish Server Control • Patches, support, knowledge base
  • 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.
    GlassFish 3.1: Fastand 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.
    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.
    Java EE 7Schedule NEW • March 2011 Early EG Formed • Q3 2011 Early Draft • Q1 2012 Public Draft • Q3 2012 Final Release 58
  • 59.
    Java EE JSRSoup 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.
    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.
    References • glassfish.org • blogs.sun.com/theaquarium •facebook.com/glassfish • oracle.com/goto/glassfish • youtube.com/GlassFishVideos • Follow @glassfish 61
  • 62.
    <Insert Picture Here> Understandingthe Nuts & Bolts of Java EE 6 Arun Gupta, Java EE & GlassFish Guy blogs.sun.com/arungupta, @arungupta