SlideShare a Scribd company logo
1 of 113
Download to read offline
<Insert Picture Here>




Java EE 6 & GlassFish v3: Paving the path for the future
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
 #uberconf


                     3
Java EE: Past & Present                                                       Flexible
                                                                 Ease of
                                                               Development       Java EE 6
                                                                                 Pruning
                                                               Java EE 5         Extensibility
                                                 Web           Ease of
                                               Services                          Prof les
                                                                                    i
                                                               Development
                                                               Annotations
                                                                                 Ease-of-dev
                                               J2EE 1.4        EJB 3.0           EJB Lite
                                               Web Services,   Persistence API   RESTful WS
                           Robustness          Management,     New and           CDI
           Enterprise                          Deployment,     Updated
             Java          J2EE 1.3            Async.          Web Services
           Platform            CMP,            Connector
                             Connector
                            Architecture   `                                     Java EE 6
           J2EE 1.2
           Servlet, JSP,                                                         Web Prof le
                                                                                         i
            EJB, JMS
 JPE        RMI/IIOP
Project
                                                                                  Managed
                                                                                  Bean 1.0

May 1998   Dec 1999        Sep 2001              Nov 2003        May 2006            Dec 2009
           10 specs        13 specs              20 specs        23 specs            28 specs

                                                                                                 4
Compatible Java EE 5 Impl




http://java.sun.com/javaee/overview/compatibility-javaee5.jsp


                                                                5
Compatible Java EE 6 Impls

Today:




Announced:
                             6
Goals for the Java EE 6 Platform


• Flexible & Light-weight
• Extensible
     • Embrace Open Source Frameworks
• Easier to use, develop on
     • Continue on path set by Java EE 5




                                           7
Java EE 6 is Flexible

• Decouple specs to allow more combinations
• Expands potential licensee ecosystem
• Profiles
  • Targeted bundle of technologies
  • Defined through the JCP
  • Web Profile Defined
     • Defined by the Java EE 6 Expert Group




                                               8
Java EE 6 Web Profile 1.0

• Fully functional mid-sized profile
  • Actively discussed in the Java EE 6 Expert
    Group and outside it
  • Technologies
    • Servlets 3.0, JSP 2.2, EL 2.2, Debugging Support for
      Other Languages 1.0, JSTL 1.2, JSF 2.0, Common
      Annotations 1.1, EJB 3.1 Lite, JTA 1.1, JPA 2.0, Bean
      Validation 1.0, Managed Beans 1.0, Interceptors 1.1,
      Context & Dependency Injection 1.0, Dependency
      Injection for Java 1.0




                                                              9
Java EE 6 is Lightweight

• Pruning
   • Make some technologies optional
• Pruned today, means
   • Optional in the next release
   • Deleted in the subsequent releases
• Technologies marked in Javadocs
   • JAX-RPC, EJB 2.x Entity Beans, JAXR, JSR 88




                                                   10
Java EE 6 - Done




                  09
• Specifications approved by the JCP
• Reference Implementation is GlassFish v3




               20
• TCK

       ec
      D

                                             11
Java EE 6 Specifications

• The Platform
• Java EE 6 Web Profile 1.0
• Managed Beans 1.0




                              12
Java EE 6 Specifications
  New

• Contexts and Dependency Injection for
  Java EE (JSR 299)
• Bean Validation 1.0 (JSR 303)
• Java API for RESTful Web Services (JSR 311)
• Dependency Injection for Java (JSR 330)




                                           13
Java EE 6 Specifications
  Extreme Makeover

• Java Server Faces 2.0 (JSR 314)
• Java Servlets 3.0 (JSR 315)
• Java Persistence 2.0 (JSR 317)
• Enterprise Java Beans 3.1 & Interceptors 1.1
  (JSR 318)
• Java EE Connector Architecture 1.6 (JSR 322)




                                             14
Java EE 6 Specifications
   Updates

• Java API for XML-based Web Services 2.2 (JSR 224)
• Java API for XML Binding 2.2 (JSR 222)
• Web Services Metadata MR3 (JSR 181)
• JSP 2.2/EL 2.2 (JSR 245)
• Web Services for Java EE 1.3 (JSR 109)
• Common Annotations 1.1 (JSR 250)
• Java Authorization Contract for Containers 1.3 (JSR 115)
• Java Authentication Service Provider Interface for
 Containers 1.0 (JSR 196)



                                                        15
Java EE 6 Specifications
       As is

•   JDBC 4.0 API
•   Java Naming and Directory Interface 1.2
•   Java Message Service 1.1
•   Java Transaction API 1.1
•   Java Transaction Service 1.0
•   JavaMail API Specification 1.4
•   JavaBeans Activation Framework 1.1
•   Java API for XML Processing 1.3
•   Java API for XML-based RPC 1.1
•   SOAP with Attachments API for Java 1.3
•   Java API for XML Registries 1.0
•   Java EE Management Specification 1.1 (JSR 77)
•   Java EE Deployment Specification 1.2 (JSR 88)
•   Java Management Extensions 1.2
•   Java Authentication and Authorization Service 1.0
•   Debugging Support for Other Languages (JSR 45)
•   Standard Tag Library for JSP 1.2 (JSR 52)
•   Streaming API for XML 1.0 (JSR 173)



                                                        16
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


                                                                    17
Managed Beans 1.0

• 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>
                                            18
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


                                                                                 19
Interceptors 1.1
• Interpose on invocations and lifecycle
  events on a target class
• Defined
 • Using annotations or DD
 • On target class or an interceptor class
   associated with the target class
• Default Interceptors (only in DD)
• Class & Method Interceptors




                                             20
Interceptors 1.1 - Code

@InterceptorBinding
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface MyInterceptorBinding {
}

@Interceptor
@MyInterceptorBinding
public class MyInterceptor {
  . . .
}




                                                  21
Interceptors 1.1 – Sample Code

@Interceptors(MyInterceptor.class)
public class MyManagedBean {
  . . .
}

@Inject / @Resource
MyManagedBean bean;

@Interceptors({MyInterceptor.class,
              MyInterceptor2.class})
public class MyManagedBean {
  . . .
}



http://blogs.sun.com/arungupta/entry/totd_134_interceptors_1_1


                                                                 22
Java EE 6 & Ease-of-development

• Continue advancements of Java EE 5
• Primary focus: Web Tier
• General principles
  • Annotation-based programming model
  • Reduce or eliminate need for DD
  • Traditional API for advanced users




                                         23
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>



                                                            24
Servlets 3.0 (JSR 315)
   Annotations-based @WebServlet

package com.sun;
@WebServlet(name=”MyServlet”, urlPattern=”/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/totd_81_getting_started_with


                                                                                            25
Servlets 3.0
 Annotations-based @WebServlet

@WebServlet(name="mytest",
     urlPatterns={"/myurl"},
     initParams={
       @InitParam(name="n1", value="v1"),
       @InitParam(name="n2", value="v2")
     }
)
public class TestServlet extends
       javax.servlet.http.HttpServlet {
        ....
}



                                            26
Servlets 3.0
Annotations-based @WebListeners
<listener>
   <listener-class>
      server.LoginServletListener
   </listener-class>
</listener>



package server;

. . .

@WebListener()
public class LoginServletListener implements
ServletContextListener {


                                               27
Servlets 3.0
     Annotations-based @WebFilter
                                <filter>
                                    <filter-name>PaymentFilter</filter-name>
                                    <filter-class>server.PaymentFilter</filter-class>
                                    <init-param>
                                         <param-name>param1</param-name>
                                         <param-value>value1</param-value>
package server;                     </init-param>
. . .                           </filter>
@WebFilter(                     <filter-mapping>
                                    <filter-name>PaymentFilter</filter-name>
  filterName="PaymentFilter",       <url-pattern>/*</url-pattern>
  InitParams={                  </filter-mapping>
    @WebInitParam(              <filter-mapping>
                                    <filter-name>PaymentFilter</filter-name>
       name="param1",               <servlet-name>PaymentServlet</servlet-name>
       value="value1")              <dispatcher>REQUEST</dispatcher>
    }                           </filter-mapping>
  urlPatterns={"/*"},
  servletNames={"PaymentServlet"},
  dispatcherTypes={DispatcherType.REQUEST}
)
public class PaymentFilter implements Filter {
. . .



                                                                                28
Servlets 3.0
  Asynchronous Servlets


• Useful for Comet, long waits
• Must declare
 @WebServlet(asyncSupported=true)
AsyncContext context = request.startAsync();
context.addListener(new AsyncListener() { … });
context.dispatch(“/request.jsp”);
//context.start(Runnable action);
. . .
context.complete();



                                                  29
Servlets 3.0
 Extensibility

• Plugin libraries using web fragments
 • Modular web.xml
• Bundled in framework JAR file in META-INF
  directory
• Zero-configuration, drag-and-drop for web
  frameworks
 • Servlets, servlet filters, context listeners for a framework
   get discovered and registered by the container
• Only JAR files in WEB-INF/lib are used


                                                                  30
Servlets 3.0
      Extensibility


<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>
http://blogs.sun.com/arungupta/entry/totd_91_applying_java_ee


                                                                                31
Servlets 3.0
     Extensibility



<web-fragment>
  <filter>
     <filter-name>LiftFilter</filter-name>
      <display-name>Lift Filter</display-name>
      <description>The Filter that intercepts lift calls</description>
      <filter-class>net.liftweb.http.LiftFilter</filter-class>
   </filter>
   <filter-mapping>
     <filter-name>LiftFilter</filter-name>
     <url-pattern>/*</url-pattern>
   </filter-mapping>
</web-fragment>


 http://blogs.sun.com/arungupta/entry/totd_101_applying_servlet_3


                                                                         32
Servlets 3.0
  Resource Sharing

• Static and JSP no longer confined to
  document root of the web application
• May be placed in WEB-INF/lib/
  [*.jar]/META-INF/resources
• Resources in document root take
  precedence over those in bundled JAR
 myapp.war
   WEB-INF/lib/catalog.jar
              /META-INF/resources/catalog/books.html

 http://localhost:8080/myapp/catalog/books.html

                                                       33
Servlets 3.0
  Much more ...

• Programmatic authentication, login, logout
   > HttpServletRequest.authenticate
   > HttpServletRequest.login
   > HttpServletRequest.logout
• File upload support
• Servlet Security  <error-page>
                       <error-code>...</error-code>
   > @ServletSecurity        <exception-type>...</exception-type>
                             <location>/404.html</location>
• Default Error Page      </error-page>

   > Any HTTP status code
   > http://blogs.sun.com/arungupta/entry/
     totd_136_default_error_page
                                                              34
EJB 3.1 (JSR 318)
   Package & Deploy in a WAR

          Java EE 5                                        Java EE 6
                                                       foo.war
    foo.ear
                                                       WEB-INF/classes
      foo_web.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

      foo_ejb.jar
      com.sun.FooBean                                      web.xml ?
      com.sun.FooHelper


http://blogs.sun.com/arungupta/entry/totd_95_ejb_3_1


                                                                             35
EJB 3.1

• No interface view – one source file per bean
 • Only for Local and within WAR
 • Required for Remote
 • No location transparency
• Component initialization in @PostConstruct
 • No assumptions on no-arg ctor




                                               36
EJB 3.1
  Portable Global JNDI Name Syntax

• Portable
• Global
• Application/Module-scoped
• Derived from metadata such as name,
  component name etc.




                                        37
EJB 3.1
   Portable Global JNDI Name Syntax
                                                  Base name of ejb-jar/WAR
  Only within EAR                                  (or ejb-jar.xml/web.xml)
 Base name of EAR
 (or application.xml)



  java:global[/<app-name>]/<module-name>/<bean-name>
  [!<fully-qualified-interface-name>]



                                  Unqualified name of the bean class
• Until now, only java:comp          Annotation/name attribute
                                             Or ejb-jar.xml
• Local & Remote business
• No-interface
• Also in java:app, java:module

                                                                          38
EJB 3.1
 Embeddable API – Simple Bean



@Stateless
public class App {
    public String sayHello(String name) {
        return "Hello " + name;
    }
}




                                            39
EJB 3.1
       Embeddable API – Deploy the Bean


     public void testEJB() throws NamingException {
             EJBContainer ejbC =
                  EJBContainer.createEJBContainer();
             Context ctx = ejbC.getContext();
             App app = (App)
                  ctx.lookup("java:global/classes/App");
             assertNotNull(app);
             String NAME = "Duke";
             String greeting = app.sayHello(NAME);
             assertNotNull(greeting);
             assertTrue(greeting.equals("Hello " + NAME));
             ejbC.close();
         }

http://blogs.sun.com/arungupta/entry/totd_128_ejbcontainer_createejbcontainer_embedded


                                                                                         40
EJB 3.1
  Singleton Beans
• One instance per app/VM, not pooled
  • Useful for caching state
  • CMT/BMT
  • Access to container services for injection, resource
    manager, timers, startup/shutdown callbacks, etc.
  • Enable eager initialization using @Startup
  • Always supports concurrent access
  • Define initialization ordering using @Depends
  @Singleton
  public class MyEJB {
    . . .
  }

                                                           41
EJB 3.1
  Asynchronous Session Beans
• Light-weight JMS
• Control returns to the client before the
   container dispatches the invocation to a
   bean instance
• @Asynchronous – method or class
• Return type – void or Future<V>
• Transaction context does not propagate
 • REQUIRED → REQUIRED_NEW
• Security principal propagates


                                              42
EJB 3.1
 Asynchronous Session Beans – Code Sample
@Stateless
@Asynchronous
public class SimpleAsyncEJB {
    public Future<Integer> addNumbers(int n1, int n2) {
        Integer result;

            result = n1 + n2;
            try {
                // simulate JPA queries + reading file system
                Thread.currentThread().sleep(2000);
            } catch (InterruptedException ex) {
                ex.printStackTrace();
            }
            return new AsyncResult(result);
      }
}




http://blogs.sun.com/arungupta/entry/totd_137_asynchronous_ejb_a


                                                                   43
EJB 3.1
  Timers
• Automatically created EJB Timers
• Calendar-based Timers – cron like semantics
 • @Schedule(dayOfWeek=”Mon,Wed”)
 • (hour=”14”, dayOfMonth=”Last Thu”,
   month=”Nov”)
 • (minute=”*/5”, hour=”*”)
• Automatically created EJB Timers
 • Based upon @Schedule
• Non-persistent timer, e.g. Cache



                                           44
EJB 3.1
 EJB 3.1 Lite

A proper subset of the full EJB 3.1 API that
includes a small, powerful selection of EJB
features suitable for writing portable
transactional business logic
...
suitable for inclusion in a wider range
of Java products, many of which have much
smaller installation and runtime footprints
than a typical full Java EE implementation

                                               45
EJB 3.1
EJB 3.1 Lite – Feature Comparison




                                    46
Contexts & Dependency Injection
 (JSR 299)
• Type-safe Dependency Injection
 • Builds on @Inject API
• Context/Scope management
• Works with multiple bean types
• Includes ELResolver




                                   47
CDI
 Injection Points

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




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

                                            48
CDI
 Basics

• Separate from @Resource but can co-
 exist
 • @Resource for container managed DI
 • @Inject for application managed DI
• Strong typing, loose coupling
 • Clients only declare dependencies via injection
   points
 • Bean selection is done by CDI




                                                     49
CDI – Sample Client Code
    Field and Method Injection

public class CheckoutHandler {

    @Inject @LoggedIn User user;

    @Inject PaymentProcessor processor;

    @Inject void setShoppingCart(@Default Cart cart) {
       …
    }

}




                                                         50
CDI – Sample Client Code
Constructor Injection

public class CheckoutHandler {

    @Inject
    CheckoutHandler(@LoggedIn User user,
                    PaymentProcessor processor,
                    @Default Cart cart) {
      ...
    }

}




                                                  51
CDI - Sample Client Code
Multiple Qualifiers and Qualifiers with Arguments

public class CheckoutHandler {

    @Inject
    CheckoutHandler(@LoggedIn User user,
                    @Reliable
                    @PayBy(CREDIT_CARD)
                    PaymentProcessor processor,
                    @Default Cart cart) {
      ...
    }

}




                                                    52
CDI - How to configure ?
 There is none!

• Discovers bean in all modules in which CDI
  is enabled
• Beans are automatically selected for
  injection
• Possible to enable groups of bean
  selectively via a descriptor




                                               53
CDI - Scopes

• Beans can be declared in a scope
 • Everywhere: @ApplicationScoped,
   @RequestScoped
 • Web app: @SessionScoped
 • JSF app: @ConversarionScoped
 • Pseudo-scope (default): @Dependent
• CDI runtime will make sure the right
  bean is created at the right time
• Client do NOT have to be scope-aware



                                         54
CDI - Named Beans
  Built-in support for the Unified EL

• Beans give themselves a name with
 @Named(“cart”)
• Then refer to it from a JSF or JSP page
 using the EL:
    <h:commandButton
             value=”Checkout”
             action=“#{cart.checkout}”/>




                                            55
CDI
 Much more ...

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




                                56
Java Server Faces 2.0 (JSR 314)

• Facelets as “templating language” for the page
  • Custom components much easier to develop
     <html xmlns="http://www.w3.org/1999/xhtml"
     xmlns:ui="http://java.sun.com/jsf/facelets"
     xmlns:h="http://java.sun.com/jsf/html">
     <h:head>
       <title>Enter Name &amp; Password</title>
     </h:head>
     <h:body>
       <h1>Enter Name &amp; Password</h1>
       <h:form>
         <h:panelGrid columns="2">
           <h:outputText value="Name:"/>
           <h:inputText value="#{simplebean.name}" title="name"
                        id="name" required="true"/>
           <h:outputText value="Password:"/>
           <h:inputText value="#{simplebean.password}" title="password"
                        id="password" required="true"/>
         </h:panelGrid>
         <h:commandButton action="show" value="submit"/>
       </h:form>
     </h:body>
   </html>


                                                                          57
JSF 2 Composite Components




                             58
JSF 2 Composite Components
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:ez="http://java.sun.com/jsf/composite/ezcomp">
  <h:head>
    <title>Enter Name &amp; Password</title>
  </h:head>
  <h:body>
    <h1>Enter Name &amp; Password</h1>
    <h:form>
      <ez:username-password/>
      <h:commandButton action="show" value="submit"/>
    </h:form>
                                     . . .
  </h:body>
                                     WEB-INF
</html>
                                     index.xhtml
                                     resources/
                                       ezcomp/
                                         username-password.xhtml

http://blogs.sun.com/arungupta/entry/totd_135_jsf2_custom_components

                                                                       59
Java Server Faces 2.0
  Integrated Ajax Support

• f:ajax


 <h:commandButton
       actionListener="#{sakilabean.findActors}"
       value="submit">
       <f:ajax execute="length"
           render="actorTable totalActors"/>
     </h:commandButton>



  http://blogs.sun.com/arungupta/entry/totd_123_f_ajax_bean


                                                              60
Java Server Faces 2.0

• “faces-config.xml” optional in common cases
 • <managed-bean> → @ManagedBean or @Named
 • Validator, Renderer, Listener, ...
 • Default navigation rules – match a view on the disk



 @Named(“simplebean”)
 public class SimpleBean {
 . . .
 }
 <h:commandButton action="show" value="submit"/>

                                                         61
Java Server Faces 2.0
 Much more ...
                                    <navigation-case>
                                      <from-outcome>success</from-outcome>
• Runs on Servlet 2.5+                <to-view-id>/page2.xhtml</to-view-id>
                                      <!-- Only accept if the following condition

• Conditional navigation
                                    is true -->
                                      <if>#{foo.someCondition}</if>
                                    </navigation-case>

• Project Stages
 • Development, UnitTest, SystemTest, Production
• Custom Scopes for Managed Beans
• Bookmarkable URLs
 • h:link, h:button    <h:link outcome="viewEntry" value="Link">
                          <f:param name="entry" value="#{aBean.entry}"/>
                       </h:link>


                       <a href="http://localhost:8080/myapp/viewEntry.xhtml?
                       entry=entry1">Link</a>




                                                                               62
Java Persistence API 2 (JSR 317)
 Sophisticated mapping/modeling options

• Collection of basic types


@Entity
public class Person {
    @Id protected String ssn;
    protected String name;
    protected Date birthDate;
    . . .
    @ElementCollection
    @CollectionTable(name=”ALIAS”)
    protected Set<String> nickNames;
}



                                          63
Java Persistence API 2
 Sophisticated mapping/modeling options

• Collection of embeddables

@Embeddable public class Address {
    String street;
    String city;
    String state;
    . . .
}

@Entity public class RichPerson extends Person {
    . . .
    @ElementCollection
    protected Set<Address> vacationHomes;
    . . .
}


                                                   64
Java Persistence API 2
 Sophisticated mapping/modeling options

• Multiple levels of embedding


@Embeddable public class ContactInfo {
    @Embedded Address address;
    . . .
}

@Entity public class Employee {
    @Id int empId;
    String name;
    ContactInfo contactInfo;
    . . .
}


                                          65
Java Persistence API 2
 Sophisticated mapping/modeling options

• Improved Map support

@Entity public class VideoStore {
    @Id Integer storeId;
    Address location;
    . . .
    @ElementCollection
    Map<Movie, Integer> inventory;
}

@Entity public class Movie {
    @Id String title;
    @String director;
    . . .
}

                                          66
Java Persistence API 2
  Expanded JPQL

• Support for all new modeling/mapping
  features
• Operators and functions in select list
• INDEX, KEY/VALUE ENTRY
// Inventory is Map<Movie, Integer>

SELECT v.location.street, KEY(i).title, VALUE(i),
FROM VideoStore v JOIN v.inventory i
WHERE KEY(i).director LIKE '%Hitchcock%'
    AND VALUE(i) > 0



                                                    67
Java Persistence API 2
Expaded JPQL – CASE Expression



UPDATE Employee e
SET e.salary =
    CASE e.rating
        WHEN 1 THEN e.salary * 1.05
        WHEN 2 THEN e.salary * 1.02
        ELSE e.salary * 0.95
    END




                                      68
Java Persistence API 2
Type-safe Criteria API

EntityManager em = …;
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<ResultType> cquery =
    cb.createQuery(ResultType.class);
Root<MyEntity> e = cquery.from(MyEntity.class);
Join<MyEntity, RelatedEntity> j = e.join(…);
…
cquery.select(…)
      .where(…)
      .orderBy(…)
      .groupBy(…);

TypedQuery<ResultType> tq = em.createQuery(cquery);
List<ResultType> result = tq.getResultList();



                                                      69
Java Persistence API 2
 Much more ...

• 2nd-level Cache
  • @Cacheable on entities
  • contain, evict ...
• 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]


                                                             70
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;


                                                   71
Bean Validation
 Integration with JPA
• Managed classes may be configured
 • Entities, Mapped superclasses, Embeddable classes
• Applied during pre-persist, pre-update, pre-
  remove lifecycle events
• How to enable ?
 • “validation-mode” in persistence.xml
 • “javax.persistence.validation.mode” key in
   Persistence.createEntityManagerFactory
• Specific set of classes can be targeted
 • javax.persistence.validation.group.pre-[persist|update|
   remove]

                                                             72
Bean Validation
 Integration with JSF

• Individual validators not required
• Integration with EL
  • f:validateBean, f:validateRequired
   <h:form>
     <f:validateBean>
       <h:inputText value=”#{model.property}” />
       <h:selectOneRadio value=”#{model.radioProperty}” > …
       </h:selectOneRadio>
       <!-- other input components here -->
     </f:validateBean>
   </h:form>




                                                              73
JAX-RS 1.1


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




                                           74
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";
    }

    @Path("morning")
    public String morning() {
        return “Good Morning!”;
    }
}




                                    75
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() {
                                  . . .
                                }


                                                               76
JAX-RS 1.1
Code Sample – Specifying Input MIME type

@POST
@Consumes("text/plain")
public String saveMessage() {
    . . .
}




                                           77
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);
    }
}




                                                 78
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


                                                                                79
JAX-RS 1.1
  More Code Samples

• Processing POSTed HTML Form
@POST
@Consumes("application/x-www-form-urlencoded")
public void post(@FormParam("name") String name) {
     // Store the message
}

• Sub-Resources
@Singleton
@Path("/printers")
public class PrintersResource {

 @GET @Path("/list")
 @Produces({"application/json", "application/xml"})
 public WebResourceList getListOfPrinters() { ... }

 @GET @Path("/ids/{printerid}")
 @Produces({"application/json", "application/xml"})
 public Printer getPrinter(@PathParam("printerid") String printerId) { ... }



                                                                         80
JAX-RS 1.1
        Integration with Java EE 6 – Servlets 3.0

    • No or Portable “web.xml”
<web-app>                                              @ApplicationPath(“resources”)
  <servlet>
    <servlet-name>Jersey Web Application</servlet-name>public class MyApplication {
    <servlet-class>                                      @Override
      com.sun.jersey.spi.container.servlet.ServletContainer
    </servlet-class>
                                                         public Set<Class<?>> getClasses() {
    <init-param>                                           return new HashSet<Class<?>(
      <param-name>javax.ws.rs.Application</param-name>
                                                              Arrays.asList(
      <param-value>com.foo.MyApplication</param-value>
    </init-param>                                               AResource.class,
  </servlet>
                                                                AnotherResource.class));
  <servlet-mapping>
    <servlet-name>Jersey Web Application</servlet-name>  }
    <url-pattern>/resources/*</url-pattern>
                                                       }
  </servlet-mapping>
</web-app>




                                                                                        81
JAX-RS 1.1
    Integration with Java EE 6 – EJB 3.1

• Use stateless or singleton EJBs in the
    WAR as resource and provider classes
@Path(“stateless”)
@Stateless                                  @Singleton
public class MyStatelessRootResource {      public class MyStatelessResource {
    @Context UriInfo ui;                            @Context UriInfo ui;


    @GET                                        …
    public String get() { return “GET”; }   }

    @EJB MyStatelessResource subResource;


    @Path(“sub-resource”)
    public MyStatelessResource sub() {
      return subResource;
    }
}


                                                                            82
JAX-RS 1.1
 Jersey Client-side API

• Consume HTTP-based RESTful Services
• Easy-to-use
 • Better than HttpURLConnection!
• Reuses JAX-RS API
 • Resources and URI are first-class citizens
• Not part of JAX-RS yet
 • com.sun.jersey.api.client




                                                83
JAX-RS 1.1
   Jersey Client API – Code Sample

Client client = Client.create();

WebResource resource = client.resource(“...”);

//curl http://example.com/base
String s = resource.get(String.class);

//curl -HAccept:text/plain http://example.com/base
String s = resource.
        accept(“text/plain”).
        get(String.class);

http://blogs.sun.com/enterprisetechtips/entry/consuming_restful_web_services_with


                                                                                    84
JAX-RS 1.1
Jersey Client API – NetBeans Code Generation




                                               85
JAX-RS 1.1
  WADL Representation of Resources

• Machine processable description of
  HTTP-based Applications
• Generated OOTB for the application
<application xmlns="http://research.sun.com/wadl/2006/10">
  <doc xmlns:jersey="http://jersey.dev.java.net/"
       jersey:generatedBy="Jersey: 1.1.4.1 11/24/2009 01:37 AM"/>
  <resources base="http://localhost:8080/HelloWADL/resources/">
    <resource path="generic">
      <method id="getText" name="GET">
        <response>
          <representation mediaType="text/plain"/>
        </response>
      </method>
      <method id="putText" name="PUT">
        <request>
          <representation mediaType="text/plain"/>
        </request>
      </method>
    </resource>
  </resources>
</application>




                                                                    86
JAX-RS 1.1
 Much more ...

• Jersey is the Reference Implementation,
 included in GlassFish
 • RESTEasy, Restlet, CXF, Wink
• Hypermedia support (only in Jersey)
• Integration with Spring, Guice, Atom, …
• WADL representation
 • Complete, Per resource
• Jersey 1.2 modules are OSGi compliant


                                            87
IDE Support for Java EE 6




                            88
Books on Java EE




                   89
http://education.oracle.com/pls/web_prod-plq-dad/db_pages.getlppage?page_id=212&path=SADJ


                                                                                            90
What is GlassFish ?

• A community
  • Users, Partners, Testers, Developers, ...
  • Started in 2005 on java.net
• Application Server
  • Open Source (CDDL & GPL v2)
  • Java EE Reference Implementation




                                                91
GlassFish Distributions
Distribution                  License      Features

GlassFish Open Source         CDDL &       • Java EE 6 Compatibility
Edition 3.0                   GPLv2        • No Clustering
                                           • Clustering planned in 3.1
                                           • mod_jk for load balancing

GlassFish Open Source         CDDL &       • Java EE 5 Compatibility
Edition 2.1.1                 GPLv2        • In memory replication
                                           • mod_loadbalancer
Oracle GlassFish Server 3.0   Commercial   • GlassFish Open Source Edition 3.0
                                           • GlassFish Server Control            Clustering
                                           • Clustering planned in 3.1            Coming
                                                                                   Soon!
Oracle GlassFish Server       Commercial   • GlassFish Open Source Edition
2.1.1                                        2.1.1
                                           • Enterprise Manager
                                           • HADB




                                                                                         92
GlassFish 3

 • Modular
   • Maven 2 – Build & Module description
   • Felix – OSGi runtime (200+ bundles)
   • Allow any type of Container to be plugged
         • Start Container and Services on demand

 • Embeddable: runs in-VM
 • Extensible
   • Rails, Grails, Django, ...
   • Administration, Monitoring, Logging, Deployment, ...

http://blogs.sun.com/dochez/entry/glassfish_v3_extensions_part_5


                                                                   93
GlassFish 3 & OSGi
• No OSGi APIs are used in GlassFish
  • HK2 provides abstraction layer
• All GlassFish modules are OSGi bundles
• Felix is default, also runs on Knopflerfish & Equinox
   • Can run in an existing shell




  http://blogs.sun.com/arungupta/entry/totd_103_glassfish_v3_with


                                                                    94
Dynamic Languages & Frameworks




http://glassfish-scripting.dev.java.net


                                          95
Demo
     NetBeans / Eclipse & Java EE 6



http://blogs.sun.com/arungupta/entry/screencast_27_simple_web_application
http://blogs.sun.com/arungupta/entry/screencast_28_simple_web_application
http://blogs.sun.com/arungupta/entry/screencast_26_develop_run_debug/
http://blogs.sun.com/arungupta/entry/totd_93_getting_started_with/
http://blogs.sun.com/arungupta/entry/totd_94_a_simple_java
http://blogs.sun.com/arungupta/entry/totd_95_ejb_3_1
http://blogs.sun.com/arungupta/entry/totd_102_java_ee_6
http://blogs.sun.com/arungupta/entry/totd_99_creating_a_java



                                                                            96
97
Demo
GlassFish 3 Administration




                             98
Light Weight & On-demand Monitoring

• Event-driven light-weight and non-intrusive
  monitoring
• Modules provide domain specific probes
  (monitoring events)
  • EJB, Web, Connector, JPA, Jersey, Orb, Ruby
• End-to-end monitoring on Solaris using
  DTrace
• 3rd party scripting clients
  • JavaScript to begin with



                                                  99
Demo
 GlassFish 3 Monitoring




http://blogs.sun.com/arungupta/entry/totd_104_glassfish_v3_monitoring


                                                                        100
REST Interface

• REST interface to management and
monitoring data
 • Configuration data, commands invocation,
  (start/stop instance, deploy, undeploy, ...), CRUD
  resources (JMS, JDBC, ...)
  •localhost:4848/management/domain
  •localhost:4848/monitoring/domain
• GET, POST, DELETE methods
• XML, JSON, HTML reps



                                                       101
Demo
 GlassFish 3 REST Interface




http://blogs.sun.com/arungupta/entry/totd_113_javafx_front_end
http://blogs.sun.com/arungupta/entry/totd_116_glassfish_v3_administration


                                                                       102
Boost your productivity
   Retain session across deployment
asadmin redeploy –properties keepSessions=true helloworld.war




                                                                103
Boost your productivity
Deploy-on-Save




                          104
Books on GlassFish




                     105
GlassFish 3 Performance




   http://weblogs.java.net/blog/sdo/archive/2009/12/08/first-look-v3-performance


                                                                                   106
GlassFish 3 Performance




  http://weblogs.java.net/blog/sdo/archive/2009/12/08/first-look-v3-performance


                                                                                  107
GlassFish 3.1
• Main Features
  • Clustering and Centralized Administration
  • High Availability
• Other ...
  • Application Versioning
  • Embedded (extensive)
  • Admin Console based on RESTful API




                                                108
GlassFish Roadmap

 • Oracle committed to GlassFish community
 • No changes to the operation of GlassFish OSS
 • Remains transparent and participatory
 • GlassFish strengthened by Oracle stewardship
   • Oracle wants to grow the community
 • Customer and community driven roadmap




http://glassfish.org/roadmap



                                            109
GlassFish Roadmap Detail




  110
©2010 Oracle Corporation
Fusion Middleware Integration Strategy
• Commercial version will have
  integrations with Fusion Middleware
  • Certification on JRockit
  • Integration with Coherence and TopLink
• Fusion Middleware and Fusion
  Applications currently not planned to be
  certified on GlassFish
• Initial integrations will be interoperability
  • Web services, Web services policy, Identity
    Management (OAM)

                                                  111
References


• glassfish.org
• blogs.sun.com/theaquarium
• oracle.com/goto/glassfish
• glassfish.org/roadmap
• Follow @glassfish




                              112
<Insert Picture Here>




Java EE 6 & GlassFish v3: Paving the path for the future
Arun Gupta, Java EE & GlassFish Guy
blogs.sun.com/arungupta, @arungupta

More Related Content

What's hot

Understanding the nuts & bolts of Java EE 6
Understanding the nuts & bolts of Java EE 6Understanding the nuts & bolts of Java EE 6
Understanding the nuts & bolts of Java EE 6
Arun Gupta
 
Andrei Niculae - JavaEE6 - 24mai2011
Andrei Niculae - JavaEE6 - 24mai2011Andrei Niculae - JavaEE6 - 24mai2011
Andrei Niculae - JavaEE6 - 24mai2011
Agora Group
 

What's hot (19)

OSGi-enabled Java EE Applications using GlassFish at JCertif 2011
OSGi-enabled Java EE Applications using GlassFish at JCertif 2011OSGi-enabled Java EE Applications using GlassFish at JCertif 2011
OSGi-enabled Java EE Applications using GlassFish at JCertif 2011
 
Java EE 6 & GlassFish v3 @ DevNexus
Java EE 6 & GlassFish v3 @ DevNexusJava EE 6 & GlassFish v3 @ DevNexus
Java EE 6 & GlassFish v3 @ DevNexus
 
Running your Java EE applications in the Cloud
Running your Java EE applications in the CloudRunning your Java EE applications in the Cloud
Running your Java EE applications in the Cloud
 
Understanding the nuts & bolts of Java EE 6
Understanding the nuts & bolts of Java EE 6Understanding the nuts & bolts of Java EE 6
Understanding the nuts & bolts of Java EE 6
 
Java EE 6 & GlassFish v3: Paving the path for the future - Tech Days 2010 India
Java EE 6 & GlassFish v3: Paving the path for the future - Tech Days 2010 IndiaJava EE 6 & GlassFish v3: Paving the path for the future - Tech Days 2010 India
Java EE 6 & GlassFish v3: Paving the path for the future - Tech Days 2010 India
 
Java EE 6 & GlassFish v3: Paving the path for the future - Spark IT 2010
Java EE 6 & GlassFish v3: Paving the path for the future - Spark IT 2010Java EE 6 & GlassFish v3: Paving the path for the future - Spark IT 2010
Java EE 6 & GlassFish v3: Paving the path for the future - Spark IT 2010
 
Tools Coverage for the Java EE Platform @ Silicon Valley Code Camp 2010
Tools Coverage for the Java EE Platform @ Silicon Valley Code Camp 2010Tools Coverage for the Java EE Platform @ Silicon Valley Code Camp 2010
Tools Coverage for the Java EE Platform @ Silicon Valley Code Camp 2010
 
Java EE 6 & GlassFish v3 at Vancouver JUG, Jan 26, 2010
Java EE 6 & GlassFish v3 at Vancouver JUG, Jan 26, 2010Java EE 6 & GlassFish v3 at Vancouver JUG, Jan 26, 2010
Java EE 6 & GlassFish v3 at Vancouver JUG, Jan 26, 2010
 
Java EE6 Overview
Java EE6 OverviewJava EE6 Overview
Java EE6 Overview
 
The State of Java under Oracle at JCertif 2011
The State of Java under Oracle at JCertif 2011The State of Java under Oracle at JCertif 2011
The State of Java under Oracle at JCertif 2011
 
TDC 2011: The Java EE 7 Platform: Developing for the Cloud
TDC 2011: The Java EE 7 Platform: Developing for the CloudTDC 2011: The Java EE 7 Platform: Developing for the Cloud
TDC 2011: The Java EE 7 Platform: Developing for the Cloud
 
Glass Fishv3 March2010
Glass Fishv3 March2010Glass Fishv3 March2010
Glass Fishv3 March2010
 
Andrei Niculae - JavaEE6 - 24mai2011
Andrei Niculae - JavaEE6 - 24mai2011Andrei Niculae - JavaEE6 - 24mai2011
Andrei Niculae - JavaEE6 - 24mai2011
 
Java EE 6 and GlassFish v3: Paving the path for future
Java EE 6 and GlassFish v3: Paving the path for futureJava EE 6 and GlassFish v3: Paving the path for future
Java EE 6 and GlassFish v3: Paving the path for future
 
Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...
Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...
Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...
 
Java EE 6 : Paving The Path For The Future
Java EE 6 : Paving The Path For The FutureJava EE 6 : Paving The Path For The Future
Java EE 6 : Paving The Path For The Future
 
Arun Gupta: London Java Community: Java EE 6 and GlassFish 3
Arun Gupta: London Java Community: Java EE 6 and GlassFish 3 Arun Gupta: London Java Community: Java EE 6 and GlassFish 3
Arun Gupta: London Java Community: Java EE 6 and GlassFish 3
 
Glassfish Overview Fontys 20090520
Glassfish Overview Fontys 20090520Glassfish Overview Fontys 20090520
Glassfish Overview Fontys 20090520
 
GIDS 2012: Java Message Service 2.0
GIDS 2012: Java Message Service 2.0GIDS 2012: Java Message Service 2.0
GIDS 2012: Java Message Service 2.0
 

Viewers also liked

Java EE 7 (Hamed Hatami)
Java EE 7 (Hamed Hatami)Java EE 7 (Hamed Hatami)
Java EE 7 (Hamed Hatami)
Hamed Hatami
 
Fifty Features of Java EE 7 in 50 Minutes
Fifty Features of Java EE 7 in 50 MinutesFifty Features of Java EE 7 in 50 Minutes
Fifty Features of Java EE 7 in 50 Minutes
glassfish
 

Viewers also liked (18)

Second Level Cache in JPA Explained
Second Level Cache in JPA ExplainedSecond Level Cache in JPA Explained
Second Level Cache in JPA Explained
 
Java EE Revisits Design Patterns
Java EE Revisits Design PatternsJava EE Revisits Design Patterns
Java EE Revisits Design Patterns
 
ESB
ESBESB
ESB
 
Java EE 8 - An instant snapshot
Java EE 8 - An instant snapshot Java EE 8 - An instant snapshot
Java EE 8 - An instant snapshot
 
Java EE 7 (Hamed Hatami)
Java EE 7 (Hamed Hatami)Java EE 7 (Hamed Hatami)
Java EE 7 (Hamed Hatami)
 
Wprowadzenie do C# i platformy .NET
Wprowadzenie do C# i platformy .NETWprowadzenie do C# i platformy .NET
Wprowadzenie do C# i platformy .NET
 
Refaktoryzacja kodu w języku PHP
Refaktoryzacja kodu w języku PHPRefaktoryzacja kodu w języku PHP
Refaktoryzacja kodu w języku PHP
 
Java EE vs Spring Framework
Java  EE vs Spring Framework Java  EE vs Spring Framework
Java EE vs Spring Framework
 
AngularJS for Java Developers
AngularJS for Java DevelopersAngularJS for Java Developers
AngularJS for Java Developers
 
Java EE 7 for Real Enterprise Systems
Java EE 7 for Real Enterprise SystemsJava EE 7 for Real Enterprise Systems
Java EE 7 for Real Enterprise Systems
 
Java EE Revisits GoF Design Patterns
Java EE Revisits GoF Design PatternsJava EE Revisits GoF Design Patterns
Java EE Revisits GoF Design Patterns
 
Java EE 7 Recipes
Java EE 7 RecipesJava EE 7 Recipes
Java EE 7 Recipes
 
Software Architecture for DevOps and Continuous Delivery
Software Architecture for DevOps and Continuous DeliverySoftware Architecture for DevOps and Continuous Delivery
Software Architecture for DevOps and Continuous Delivery
 
Java EE 7 - Overview and Status
Java EE 7  - Overview and StatusJava EE 7  - Overview and Status
Java EE 7 - Overview and Status
 
Java EE Introduction
Java EE IntroductionJava EE Introduction
Java EE Introduction
 
Developing Modern Java Web Applications with Java EE 7 and AngularJS
Developing Modern Java Web Applications with Java EE 7 and AngularJSDeveloping Modern Java Web Applications with Java EE 7 and AngularJS
Developing Modern Java Web Applications with Java EE 7 and AngularJS
 
SE2016 Java Alex Theedom "Java EE revisits design patterns"
SE2016 Java Alex Theedom "Java EE revisits design patterns"SE2016 Java Alex Theedom "Java EE revisits design patterns"
SE2016 Java Alex Theedom "Java EE revisits design patterns"
 
Fifty Features of Java EE 7 in 50 Minutes
Fifty Features of Java EE 7 in 50 MinutesFifty Features of Java EE 7 in 50 Minutes
Fifty Features of Java EE 7 in 50 Minutes
 

Similar to Java EE 6 & GlassFish 3

Similar to Java EE 6 & GlassFish 3 (20)

Java E
Java EJava E
Java E
 
Spark IT 2011 - Java EE 6 Workshop
Spark IT 2011 - Java EE 6 WorkshopSpark IT 2011 - Java EE 6 Workshop
Spark IT 2011 - Java EE 6 Workshop
 
Java EE 6 and GlassFish portfolio
Java EE 6 and GlassFish portfolioJava EE 6 and GlassFish portfolio
Java EE 6 and GlassFish portfolio
 
Java EE 6 Aquarium Paris
Java EE 6 Aquarium ParisJava EE 6 Aquarium Paris
Java EE 6 Aquarium Paris
 
Java EE 6
Java EE 6Java EE 6
Java EE 6
 
Deep Dive Hands-on in Java EE 6 - Oredev 2010
Deep Dive Hands-on in Java EE 6 - Oredev 2010Deep Dive Hands-on in Java EE 6 - Oredev 2010
Deep Dive Hands-on in Java EE 6 - Oredev 2010
 
Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ JAX London ...
Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ JAX London ...Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ JAX London ...
Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ JAX London ...
 
Java Enterprise Edition 6 Overview
Java Enterprise Edition 6 OverviewJava Enterprise Edition 6 Overview
Java Enterprise Edition 6 Overview
 
The Java Ee 6 Platform Normandy Jug
The Java Ee 6 Platform Normandy JugThe Java Ee 6 Platform Normandy Jug
The Java Ee 6 Platform Normandy Jug
 
Java EE 6 & GlassFish = Less Code + More Power @ DevIgnition
Java EE 6 & GlassFish = Less Code + More Power @ DevIgnitionJava EE 6 & GlassFish = Less Code + More Power @ DevIgnition
Java EE 6 & GlassFish = Less Code + More Power @ DevIgnition
 
Java EE 6 = Less Code + More Power
Java EE 6 = Less Code + More PowerJava EE 6 = Less Code + More Power
Java EE 6 = Less Code + More Power
 
Java EE 6 & GlassFish = Less Code + More Power at CEJUG
Java EE 6 & GlassFish = Less Code + More Power at CEJUGJava EE 6 & GlassFish = Less Code + More Power at CEJUG
Java EE 6 & GlassFish = Less Code + More Power at CEJUG
 
Java EE 6 and GlassFish v3: Paving the path for future
Java EE 6 and GlassFish v3: Paving the path for futureJava EE 6 and GlassFish v3: Paving the path for future
Java EE 6 and GlassFish v3: Paving the path for future
 
Java EE / GlassFish Strategy & Roadmap @ JavaOne 2011
Java EE / GlassFish Strategy & Roadmap @ JavaOne 2011Java EE / GlassFish Strategy & Roadmap @ JavaOne 2011
Java EE / GlassFish Strategy & Roadmap @ JavaOne 2011
 
Boston 2011 OTN Developer Days - Java EE 6
Boston 2011 OTN Developer Days - Java EE 6Boston 2011 OTN Developer Days - Java EE 6
Boston 2011 OTN Developer Days - Java EE 6
 
Java EE 7: the Voyage of the Cloud Treader
Java EE 7: the Voyage of the Cloud TreaderJava EE 7: the Voyage of the Cloud Treader
Java EE 7: the Voyage of the Cloud Treader
 
The Java EE 7 Platform: Developing for the Cloud (FISL 12)
The Java EE 7 Platform: Developing for the Cloud  (FISL 12)The Java EE 7 Platform: Developing for the Cloud  (FISL 12)
The Java EE 7 Platform: Developing for the Cloud (FISL 12)
 
OTN Developer Days - Java EE 6
OTN Developer Days - Java EE 6OTN Developer Days - Java EE 6
OTN Developer Days - Java EE 6
 
Java EE 7 - Into the Cloud
Java EE 7 - Into the CloudJava EE 7 - Into the Cloud
Java EE 7 - Into the Cloud
 
Whats Cool in Java E 6
Whats Cool in Java E 6Whats Cool in Java E 6
Whats Cool in Java E 6
 

More from Arun Gupta

More from Arun Gupta (20)

5 Skills To Force Multiply Technical Talents.pdf
5 Skills To Force Multiply Technical Talents.pdf5 Skills To Force Multiply Technical Talents.pdf
5 Skills To Force Multiply Technical Talents.pdf
 
Machine Learning using Kubernetes - AI Conclave 2019
Machine Learning using Kubernetes - AI Conclave 2019Machine Learning using Kubernetes - AI Conclave 2019
Machine Learning using Kubernetes - AI Conclave 2019
 
Machine Learning using Kubeflow and Kubernetes
Machine Learning using Kubeflow and KubernetesMachine Learning using Kubeflow and Kubernetes
Machine Learning using Kubeflow and Kubernetes
 
Secure and Fast microVM for Serverless Computing using Firecracker
Secure and Fast microVM for Serverless Computing using FirecrackerSecure and Fast microVM for Serverless Computing using Firecracker
Secure and Fast microVM for Serverless Computing using Firecracker
 
Building Java in the Open - j.Day at OSCON 2019
Building Java in the Open - j.Day at OSCON 2019Building Java in the Open - j.Day at OSCON 2019
Building Java in the Open - j.Day at OSCON 2019
 
Why Amazon Cares about Open Source
Why Amazon Cares about Open SourceWhy Amazon Cares about Open Source
Why Amazon Cares about Open Source
 
Machine learning using Kubernetes
Machine learning using KubernetesMachine learning using Kubernetes
Machine learning using Kubernetes
 
Building Cloud Native Applications
Building Cloud Native ApplicationsBuilding Cloud Native Applications
Building Cloud Native Applications
 
Chaos Engineering with Kubernetes
Chaos Engineering with KubernetesChaos Engineering with Kubernetes
Chaos Engineering with Kubernetes
 
How to be a mentor to bring more girls to STEAM
How to be a mentor to bring more girls to STEAMHow to be a mentor to bring more girls to STEAM
How to be a mentor to bring more girls to STEAM
 
Java in a World of Containers - DockerCon 2018
Java in a World of Containers - DockerCon 2018Java in a World of Containers - DockerCon 2018
Java in a World of Containers - DockerCon 2018
 
The Serverless Tidal Wave - SwampUP 2018 Keynote
The Serverless Tidal Wave - SwampUP 2018 KeynoteThe Serverless Tidal Wave - SwampUP 2018 Keynote
The Serverless Tidal Wave - SwampUP 2018 Keynote
 
Introduction to Amazon EKS - KubeCon 2018
Introduction to Amazon EKS - KubeCon 2018Introduction to Amazon EKS - KubeCon 2018
Introduction to Amazon EKS - KubeCon 2018
 
Mastering Kubernetes on AWS - Tel Aviv Summit
Mastering Kubernetes on AWS - Tel Aviv SummitMastering Kubernetes on AWS - Tel Aviv Summit
Mastering Kubernetes on AWS - Tel Aviv Summit
 
Top 10 Technology Trends Changing Developer's Landscape
Top 10 Technology Trends Changing Developer's LandscapeTop 10 Technology Trends Changing Developer's Landscape
Top 10 Technology Trends Changing Developer's Landscape
 
Container Landscape in 2017
Container Landscape in 2017Container Landscape in 2017
Container Landscape in 2017
 
Java EE and NoSQL using JBoss EAP 7 and OpenShift
Java EE and NoSQL using JBoss EAP 7 and OpenShiftJava EE and NoSQL using JBoss EAP 7 and OpenShift
Java EE and NoSQL using JBoss EAP 7 and OpenShift
 
Docker, Kubernetes, and Mesos recipes for Java developers
Docker, Kubernetes, and Mesos recipes for Java developersDocker, Kubernetes, and Mesos recipes for Java developers
Docker, Kubernetes, and Mesos recipes for Java developers
 
Thanks Managers!
Thanks Managers!Thanks Managers!
Thanks Managers!
 
Migrate your traditional VM-based Clusters to Containers
Migrate your traditional VM-based Clusters to ContainersMigrate your traditional VM-based Clusters to Containers
Migrate your traditional VM-based Clusters to Containers
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Recently uploaded (20)

EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 

Java EE 6 & GlassFish 3

  • 1. <Insert Picture Here> Java EE 6 & GlassFish v3: Paving the path for the future Arun Gupta, Java EE & GlassFish Guy blogs.sun.com/arungupta, @arungupta
  • 2. 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
  • 3. Are you tweeting ? #glassfish #uberconf 3
  • 4. Java EE: Past & Present Flexible Ease of Development Java EE 6 Pruning Java EE 5 Extensibility Web Ease of Services Prof les i Development Annotations Ease-of-dev J2EE 1.4 EJB 3.0 EJB Lite Web Services, Persistence API RESTful WS Robustness Management, New and CDI Enterprise Deployment, Updated Java J2EE 1.3 Async. Web Services Platform CMP, Connector Connector Architecture ` Java EE 6 J2EE 1.2 Servlet, JSP, Web Prof le i EJB, JMS JPE RMI/IIOP Project Managed Bean 1.0 May 1998 Dec 1999 Sep 2001 Nov 2003 May 2006 Dec 2009 10 specs 13 specs 20 specs 23 specs 28 specs 4
  • 5. Compatible Java EE 5 Impl http://java.sun.com/javaee/overview/compatibility-javaee5.jsp 5
  • 6. Compatible Java EE 6 Impls Today: Announced: 6
  • 7. Goals for the Java EE 6 Platform • Flexible & Light-weight • Extensible • Embrace Open Source Frameworks • Easier to use, develop on • Continue on path set by Java EE 5 7
  • 8. Java EE 6 is Flexible • Decouple specs to allow more combinations • Expands potential licensee ecosystem • Profiles • Targeted bundle of technologies • Defined through the JCP • Web Profile Defined • Defined by the Java EE 6 Expert Group 8
  • 9. Java EE 6 Web Profile 1.0 • Fully functional mid-sized profile • Actively discussed in the Java EE 6 Expert Group and outside it • Technologies • Servlets 3.0, JSP 2.2, EL 2.2, Debugging Support for Other Languages 1.0, JSTL 1.2, JSF 2.0, Common Annotations 1.1, EJB 3.1 Lite, JTA 1.1, JPA 2.0, Bean Validation 1.0, Managed Beans 1.0, Interceptors 1.1, Context & Dependency Injection 1.0, Dependency Injection for Java 1.0 9
  • 10. Java EE 6 is Lightweight • Pruning • Make some technologies optional • Pruned today, means • Optional in the next release • Deleted in the subsequent releases • Technologies marked in Javadocs • JAX-RPC, EJB 2.x Entity Beans, JAXR, JSR 88 10
  • 11. Java EE 6 - Done 09 • Specifications approved by the JCP • Reference Implementation is GlassFish v3 20 • TCK ec D 11
  • 12. Java EE 6 Specifications • The Platform • Java EE 6 Web Profile 1.0 • Managed Beans 1.0 12
  • 13. Java EE 6 Specifications New • Contexts and Dependency Injection for Java EE (JSR 299) • Bean Validation 1.0 (JSR 303) • Java API for RESTful Web Services (JSR 311) • Dependency Injection for Java (JSR 330) 13
  • 14. Java EE 6 Specifications Extreme Makeover • Java Server Faces 2.0 (JSR 314) • Java Servlets 3.0 (JSR 315) • Java Persistence 2.0 (JSR 317) • Enterprise Java Beans 3.1 & Interceptors 1.1 (JSR 318) • Java EE Connector Architecture 1.6 (JSR 322) 14
  • 15. Java EE 6 Specifications Updates • Java API for XML-based Web Services 2.2 (JSR 224) • Java API for XML Binding 2.2 (JSR 222) • Web Services Metadata MR3 (JSR 181) • JSP 2.2/EL 2.2 (JSR 245) • Web Services for Java EE 1.3 (JSR 109) • Common Annotations 1.1 (JSR 250) • Java Authorization Contract for Containers 1.3 (JSR 115) • Java Authentication Service Provider Interface for Containers 1.0 (JSR 196) 15
  • 16. Java EE 6 Specifications As is • JDBC 4.0 API • Java Naming and Directory Interface 1.2 • Java Message Service 1.1 • Java Transaction API 1.1 • Java Transaction Service 1.0 • JavaMail API Specification 1.4 • JavaBeans Activation Framework 1.1 • Java API for XML Processing 1.3 • Java API for XML-based RPC 1.1 • SOAP with Attachments API for Java 1.3 • Java API for XML Registries 1.0 • Java EE Management Specification 1.1 (JSR 77) • Java EE Deployment Specification 1.2 (JSR 88) • Java Management Extensions 1.2 • Java Authentication and Authorization Service 1.0 • Debugging Support for Other Languages (JSR 45) • Standard Tag Library for JSP 1.2 (JSR 52) • Streaming API for XML 1.0 (JSR 173) 16
  • 17. 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 17
  • 18. Managed Beans 1.0 • 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> 18
  • 19. 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 19
  • 20. Interceptors 1.1 • Interpose on invocations and lifecycle events on a target class • Defined • Using annotations or DD • On target class or an interceptor class associated with the target class • Default Interceptors (only in DD) • Class & Method Interceptors 20
  • 21. Interceptors 1.1 - Code @InterceptorBinding @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD, ElementType.TYPE}) public @interface MyInterceptorBinding { } @Interceptor @MyInterceptorBinding public class MyInterceptor { . . . } 21
  • 22. Interceptors 1.1 – Sample Code @Interceptors(MyInterceptor.class) public class MyManagedBean { . . . } @Inject / @Resource MyManagedBean bean; @Interceptors({MyInterceptor.class, MyInterceptor2.class}) public class MyManagedBean { . . . } http://blogs.sun.com/arungupta/entry/totd_134_interceptors_1_1 22
  • 23. Java EE 6 & Ease-of-development • Continue advancements of Java EE 5 • Primary focus: Web Tier • General principles • Annotation-based programming model • Reduce or eliminate need for DD • Traditional API for advanced users 23
  • 24. 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> 24
  • 25. Servlets 3.0 (JSR 315) Annotations-based @WebServlet package com.sun; @WebServlet(name=”MyServlet”, urlPattern=”/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/totd_81_getting_started_with 25
  • 26. Servlets 3.0 Annotations-based @WebServlet @WebServlet(name="mytest", urlPatterns={"/myurl"}, initParams={ @InitParam(name="n1", value="v1"), @InitParam(name="n2", value="v2") } ) public class TestServlet extends javax.servlet.http.HttpServlet { .... } 26
  • 27. Servlets 3.0 Annotations-based @WebListeners <listener> <listener-class> server.LoginServletListener </listener-class> </listener> package server; . . . @WebListener() public class LoginServletListener implements ServletContextListener { 27
  • 28. Servlets 3.0 Annotations-based @WebFilter <filter> <filter-name>PaymentFilter</filter-name> <filter-class>server.PaymentFilter</filter-class> <init-param> <param-name>param1</param-name> <param-value>value1</param-value> package server; </init-param> . . . </filter> @WebFilter( <filter-mapping> <filter-name>PaymentFilter</filter-name> filterName="PaymentFilter", <url-pattern>/*</url-pattern> InitParams={ </filter-mapping> @WebInitParam( <filter-mapping> <filter-name>PaymentFilter</filter-name> name="param1", <servlet-name>PaymentServlet</servlet-name> value="value1") <dispatcher>REQUEST</dispatcher> } </filter-mapping> urlPatterns={"/*"}, servletNames={"PaymentServlet"}, dispatcherTypes={DispatcherType.REQUEST} ) public class PaymentFilter implements Filter { . . . 28
  • 29. Servlets 3.0 Asynchronous Servlets • Useful for Comet, long waits • Must declare @WebServlet(asyncSupported=true) AsyncContext context = request.startAsync(); context.addListener(new AsyncListener() { … }); context.dispatch(“/request.jsp”); //context.start(Runnable action); . . . context.complete(); 29
  • 30. Servlets 3.0 Extensibility • Plugin libraries using web fragments • Modular web.xml • Bundled in framework JAR file in META-INF directory • Zero-configuration, drag-and-drop for web frameworks • Servlets, servlet filters, context listeners for a framework get discovered and registered by the container • Only JAR files in WEB-INF/lib are used 30
  • 31. Servlets 3.0 Extensibility <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> http://blogs.sun.com/arungupta/entry/totd_91_applying_java_ee 31
  • 32. Servlets 3.0 Extensibility <web-fragment> <filter> <filter-name>LiftFilter</filter-name> <display-name>Lift Filter</display-name> <description>The Filter that intercepts lift calls</description> <filter-class>net.liftweb.http.LiftFilter</filter-class> </filter> <filter-mapping> <filter-name>LiftFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-fragment> http://blogs.sun.com/arungupta/entry/totd_101_applying_servlet_3 32
  • 33. Servlets 3.0 Resource Sharing • Static and JSP no longer confined to document root of the web application • May be placed in WEB-INF/lib/ [*.jar]/META-INF/resources • Resources in document root take precedence over those in bundled JAR myapp.war WEB-INF/lib/catalog.jar /META-INF/resources/catalog/books.html http://localhost:8080/myapp/catalog/books.html 33
  • 34. Servlets 3.0 Much more ... • Programmatic authentication, login, logout > HttpServletRequest.authenticate > HttpServletRequest.login > HttpServletRequest.logout • File upload support • Servlet Security <error-page> <error-code>...</error-code> > @ServletSecurity <exception-type>...</exception-type> <location>/404.html</location> • Default Error Page </error-page> > Any HTTP status code > http://blogs.sun.com/arungupta/entry/ totd_136_default_error_page 34
  • 35. EJB 3.1 (JSR 318) Package & Deploy in a WAR Java EE 5 Java EE 6 foo.war foo.ear WEB-INF/classes foo_web.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 foo_ejb.jar com.sun.FooBean web.xml ? com.sun.FooHelper http://blogs.sun.com/arungupta/entry/totd_95_ejb_3_1 35
  • 36. EJB 3.1 • No interface view – one source file per bean • Only for Local and within WAR • Required for Remote • No location transparency • Component initialization in @PostConstruct • No assumptions on no-arg ctor 36
  • 37. EJB 3.1 Portable Global JNDI Name Syntax • Portable • Global • Application/Module-scoped • Derived from metadata such as name, component name etc. 37
  • 38. EJB 3.1 Portable Global JNDI Name Syntax Base name of ejb-jar/WAR Only within EAR (or ejb-jar.xml/web.xml) Base name of EAR (or application.xml) java:global[/<app-name>]/<module-name>/<bean-name> [!<fully-qualified-interface-name>] Unqualified name of the bean class • Until now, only java:comp Annotation/name attribute Or ejb-jar.xml • Local & Remote business • No-interface • Also in java:app, java:module 38
  • 39. EJB 3.1 Embeddable API – Simple Bean @Stateless public class App { public String sayHello(String name) { return "Hello " + name; } } 39
  • 40. EJB 3.1 Embeddable API – Deploy the Bean public void testEJB() throws NamingException { EJBContainer ejbC = EJBContainer.createEJBContainer(); Context ctx = ejbC.getContext(); App app = (App) ctx.lookup("java:global/classes/App"); assertNotNull(app); String NAME = "Duke"; String greeting = app.sayHello(NAME); assertNotNull(greeting); assertTrue(greeting.equals("Hello " + NAME)); ejbC.close(); } http://blogs.sun.com/arungupta/entry/totd_128_ejbcontainer_createejbcontainer_embedded 40
  • 41. EJB 3.1 Singleton Beans • One instance per app/VM, not pooled • Useful for caching state • CMT/BMT • Access to container services for injection, resource manager, timers, startup/shutdown callbacks, etc. • Enable eager initialization using @Startup • Always supports concurrent access • Define initialization ordering using @Depends @Singleton public class MyEJB { . . . } 41
  • 42. EJB 3.1 Asynchronous Session Beans • Light-weight JMS • Control returns to the client before the container dispatches the invocation to a bean instance • @Asynchronous – method or class • Return type – void or Future<V> • Transaction context does not propagate • REQUIRED → REQUIRED_NEW • Security principal propagates 42
  • 43. EJB 3.1 Asynchronous Session Beans – Code Sample @Stateless @Asynchronous public class SimpleAsyncEJB { public Future<Integer> addNumbers(int n1, int n2) { Integer result; result = n1 + n2; try { // simulate JPA queries + reading file system Thread.currentThread().sleep(2000); } catch (InterruptedException ex) { ex.printStackTrace(); } return new AsyncResult(result); } } http://blogs.sun.com/arungupta/entry/totd_137_asynchronous_ejb_a 43
  • 44. EJB 3.1 Timers • Automatically created EJB Timers • Calendar-based Timers – cron like semantics • @Schedule(dayOfWeek=”Mon,Wed”) • (hour=”14”, dayOfMonth=”Last Thu”, month=”Nov”) • (minute=”*/5”, hour=”*”) • Automatically created EJB Timers • Based upon @Schedule • Non-persistent timer, e.g. Cache 44
  • 45. EJB 3.1 EJB 3.1 Lite A proper subset of the full EJB 3.1 API that includes a small, powerful selection of EJB features suitable for writing portable transactional business logic ... suitable for inclusion in a wider range of Java products, many of which have much smaller installation and runtime footprints than a typical full Java EE implementation 45
  • 46. EJB 3.1 EJB 3.1 Lite – Feature Comparison 46
  • 47. Contexts & Dependency Injection (JSR 299) • Type-safe Dependency Injection • Builds on @Inject API • Context/Scope management • Works with multiple bean types • Includes ELResolver 47
  • 48. CDI Injection Points • Field, Method, Constructor • 0 or more qualifiers Which one ? • Type (Qualifier) @Inject @LoggedIn User user Request What ? Injection (Type) 48
  • 49. CDI Basics • Separate from @Resource but can co- exist • @Resource for container managed DI • @Inject for application managed DI • Strong typing, loose coupling • Clients only declare dependencies via injection points • Bean selection is done by CDI 49
  • 50. CDI – Sample Client Code Field and Method Injection public class CheckoutHandler { @Inject @LoggedIn User user; @Inject PaymentProcessor processor; @Inject void setShoppingCart(@Default Cart cart) { … } } 50
  • 51. CDI – Sample Client Code Constructor Injection public class CheckoutHandler { @Inject CheckoutHandler(@LoggedIn User user, PaymentProcessor processor, @Default Cart cart) { ... } } 51
  • 52. CDI - Sample Client Code Multiple Qualifiers and Qualifiers with Arguments public class CheckoutHandler { @Inject CheckoutHandler(@LoggedIn User user, @Reliable @PayBy(CREDIT_CARD) PaymentProcessor processor, @Default Cart cart) { ... } } 52
  • 53. CDI - How to configure ? There is none! • Discovers bean in all modules in which CDI is enabled • Beans are automatically selected for injection • Possible to enable groups of bean selectively via a descriptor 53
  • 54. CDI - Scopes • Beans can be declared in a scope • Everywhere: @ApplicationScoped, @RequestScoped • Web app: @SessionScoped • JSF app: @ConversarionScoped • Pseudo-scope (default): @Dependent • CDI runtime will make sure the right bean is created at the right time • Client do NOT have to be scope-aware 54
  • 55. CDI - Named Beans Built-in support for the Unified EL • Beans give themselves a name with @Named(“cart”) • Then refer to it from a JSF or JSP page using the EL: <h:commandButton value=”Checkout” action=“#{cart.checkout}”/> 55
  • 56. CDI Much more ... • Producer methods and fields • Bridging Java EE resources • Alternatives • Interceptors • Decorators • Stereotypes 56
  • 57. Java Server Faces 2.0 (JSR 314) • Facelets as “templating language” for the page • Custom components much easier to develop <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html"> <h:head> <title>Enter Name &amp; Password</title> </h:head> <h:body> <h1>Enter Name &amp; Password</h1> <h:form> <h:panelGrid columns="2"> <h:outputText value="Name:"/> <h:inputText value="#{simplebean.name}" title="name" id="name" required="true"/> <h:outputText value="Password:"/> <h:inputText value="#{simplebean.password}" title="password" id="password" required="true"/> </h:panelGrid> <h:commandButton action="show" value="submit"/> </h:form> </h:body> </html> 57
  • 58. JSF 2 Composite Components 58
  • 59. JSF 2 Composite Components <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:ez="http://java.sun.com/jsf/composite/ezcomp"> <h:head> <title>Enter Name &amp; Password</title> </h:head> <h:body> <h1>Enter Name &amp; Password</h1> <h:form> <ez:username-password/> <h:commandButton action="show" value="submit"/> </h:form> . . . </h:body> WEB-INF </html> index.xhtml resources/ ezcomp/ username-password.xhtml http://blogs.sun.com/arungupta/entry/totd_135_jsf2_custom_components 59
  • 60. Java Server Faces 2.0 Integrated Ajax Support • f:ajax <h:commandButton actionListener="#{sakilabean.findActors}" value="submit"> <f:ajax execute="length" render="actorTable totalActors"/> </h:commandButton> http://blogs.sun.com/arungupta/entry/totd_123_f_ajax_bean 60
  • 61. Java Server Faces 2.0 • “faces-config.xml” optional in common cases • <managed-bean> → @ManagedBean or @Named • Validator, Renderer, Listener, ... • Default navigation rules – match a view on the disk @Named(“simplebean”) public class SimpleBean { . . . } <h:commandButton action="show" value="submit"/> 61
  • 62. Java Server Faces 2.0 Much more ... <navigation-case> <from-outcome>success</from-outcome> • Runs on Servlet 2.5+ <to-view-id>/page2.xhtml</to-view-id> <!-- Only accept if the following condition • Conditional navigation is true --> <if>#{foo.someCondition}</if> </navigation-case> • Project Stages • Development, UnitTest, SystemTest, Production • Custom Scopes for Managed Beans • Bookmarkable URLs • h:link, h:button <h:link outcome="viewEntry" value="Link"> <f:param name="entry" value="#{aBean.entry}"/> </h:link> <a href="http://localhost:8080/myapp/viewEntry.xhtml? entry=entry1">Link</a> 62
  • 63. Java Persistence API 2 (JSR 317) Sophisticated mapping/modeling options • Collection of basic types @Entity public class Person { @Id protected String ssn; protected String name; protected Date birthDate; . . . @ElementCollection @CollectionTable(name=”ALIAS”) protected Set<String> nickNames; } 63
  • 64. Java Persistence API 2 Sophisticated mapping/modeling options • Collection of embeddables @Embeddable public class Address { String street; String city; String state; . . . } @Entity public class RichPerson extends Person { . . . @ElementCollection protected Set<Address> vacationHomes; . . . } 64
  • 65. Java Persistence API 2 Sophisticated mapping/modeling options • Multiple levels of embedding @Embeddable public class ContactInfo { @Embedded Address address; . . . } @Entity public class Employee { @Id int empId; String name; ContactInfo contactInfo; . . . } 65
  • 66. Java Persistence API 2 Sophisticated mapping/modeling options • Improved Map support @Entity public class VideoStore { @Id Integer storeId; Address location; . . . @ElementCollection Map<Movie, Integer> inventory; } @Entity public class Movie { @Id String title; @String director; . . . } 66
  • 67. Java Persistence API 2 Expanded JPQL • Support for all new modeling/mapping features • Operators and functions in select list • INDEX, KEY/VALUE ENTRY // Inventory is Map<Movie, Integer> SELECT v.location.street, KEY(i).title, VALUE(i), FROM VideoStore v JOIN v.inventory i WHERE KEY(i).director LIKE '%Hitchcock%' AND VALUE(i) > 0 67
  • 68. Java Persistence API 2 Expaded JPQL – CASE Expression UPDATE Employee e SET e.salary = CASE e.rating WHEN 1 THEN e.salary * 1.05 WHEN 2 THEN e.salary * 1.02 ELSE e.salary * 0.95 END 68
  • 69. Java Persistence API 2 Type-safe Criteria API EntityManager em = …; CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<ResultType> cquery = cb.createQuery(ResultType.class); Root<MyEntity> e = cquery.from(MyEntity.class); Join<MyEntity, RelatedEntity> j = e.join(…); … cquery.select(…) .where(…) .orderBy(…) .groupBy(…); TypedQuery<ResultType> tq = em.createQuery(cquery); List<ResultType> result = tq.getResultList(); 69
  • 70. Java Persistence API 2 Much more ... • 2nd-level Cache • @Cacheable on entities • contain, evict ... • 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] 70
  • 71. 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; 71
  • 72. Bean Validation Integration with JPA • Managed classes may be configured • Entities, Mapped superclasses, Embeddable classes • Applied during pre-persist, pre-update, pre- remove lifecycle events • How to enable ? • “validation-mode” in persistence.xml • “javax.persistence.validation.mode” key in Persistence.createEntityManagerFactory • Specific set of classes can be targeted • javax.persistence.validation.group.pre-[persist|update| remove] 72
  • 73. Bean Validation Integration with JSF • Individual validators not required • Integration with EL • f:validateBean, f:validateRequired <h:form> <f:validateBean> <h:inputText value=”#{model.property}” /> <h:selectOneRadio value=”#{model.radioProperty}” > … </h:selectOneRadio> <!-- other input components here --> </f:validateBean> </h:form> 73
  • 74. JAX-RS 1.1 • Java API for building RESTful Web Services • POJO based • Annotation-driven • Server-side API • HTTP-centric 74
  • 75. 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"; } @Path("morning") public String morning() { return “Good Morning!”; } } 75
  • 76. 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() { . . . } 76
  • 77. JAX-RS 1.1 Code Sample – Specifying Input MIME type @POST @Consumes("text/plain") public String saveMessage() { . . . } 77
  • 78. 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); } } 78
  • 79. 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 79
  • 80. JAX-RS 1.1 More Code Samples • Processing POSTed HTML Form @POST @Consumes("application/x-www-form-urlencoded") public void post(@FormParam("name") String name) { // Store the message } • Sub-Resources @Singleton @Path("/printers") public class PrintersResource { @GET @Path("/list") @Produces({"application/json", "application/xml"}) public WebResourceList getListOfPrinters() { ... } @GET @Path("/ids/{printerid}") @Produces({"application/json", "application/xml"}) public Printer getPrinter(@PathParam("printerid") String printerId) { ... } 80
  • 81. JAX-RS 1.1 Integration with Java EE 6 – Servlets 3.0 • No or Portable “web.xml” <web-app> @ApplicationPath(“resources”) <servlet> <servlet-name>Jersey Web Application</servlet-name>public class MyApplication { <servlet-class> @Override com.sun.jersey.spi.container.servlet.ServletContainer </servlet-class> public Set<Class<?>> getClasses() { <init-param> return new HashSet<Class<?>( <param-name>javax.ws.rs.Application</param-name> Arrays.asList( <param-value>com.foo.MyApplication</param-value> </init-param> AResource.class, </servlet> AnotherResource.class)); <servlet-mapping> <servlet-name>Jersey Web Application</servlet-name> } <url-pattern>/resources/*</url-pattern> } </servlet-mapping> </web-app> 81
  • 82. JAX-RS 1.1 Integration with Java EE 6 – EJB 3.1 • Use stateless or singleton EJBs in the WAR as resource and provider classes @Path(“stateless”) @Stateless @Singleton public class MyStatelessRootResource { public class MyStatelessResource { @Context UriInfo ui; @Context UriInfo ui; @GET … public String get() { return “GET”; } } @EJB MyStatelessResource subResource; @Path(“sub-resource”) public MyStatelessResource sub() { return subResource; } } 82
  • 83. JAX-RS 1.1 Jersey Client-side API • Consume HTTP-based RESTful Services • Easy-to-use • Better than HttpURLConnection! • Reuses JAX-RS API • Resources and URI are first-class citizens • Not part of JAX-RS yet • com.sun.jersey.api.client 83
  • 84. JAX-RS 1.1 Jersey Client API – Code Sample Client client = Client.create(); WebResource resource = client.resource(“...”); //curl http://example.com/base String s = resource.get(String.class); //curl -HAccept:text/plain http://example.com/base String s = resource. accept(“text/plain”). get(String.class); http://blogs.sun.com/enterprisetechtips/entry/consuming_restful_web_services_with 84
  • 85. JAX-RS 1.1 Jersey Client API – NetBeans Code Generation 85
  • 86. JAX-RS 1.1 WADL Representation of Resources • Machine processable description of HTTP-based Applications • Generated OOTB for the application <application xmlns="http://research.sun.com/wadl/2006/10"> <doc xmlns:jersey="http://jersey.dev.java.net/" jersey:generatedBy="Jersey: 1.1.4.1 11/24/2009 01:37 AM"/> <resources base="http://localhost:8080/HelloWADL/resources/"> <resource path="generic"> <method id="getText" name="GET"> <response> <representation mediaType="text/plain"/> </response> </method> <method id="putText" name="PUT"> <request> <representation mediaType="text/plain"/> </request> </method> </resource> </resources> </application> 86
  • 87. JAX-RS 1.1 Much more ... • Jersey is the Reference Implementation, included in GlassFish • RESTEasy, Restlet, CXF, Wink • Hypermedia support (only in Jersey) • Integration with Spring, Guice, Atom, … • WADL representation • Complete, Per resource • Jersey 1.2 modules are OSGi compliant 87
  • 88. IDE Support for Java EE 6 88
  • 89. Books on Java EE 89
  • 91. What is GlassFish ? • A community • Users, Partners, Testers, Developers, ... • Started in 2005 on java.net • Application Server • Open Source (CDDL & GPL v2) • Java EE Reference Implementation 91
  • 92. GlassFish Distributions Distribution License Features GlassFish Open Source CDDL & • Java EE 6 Compatibility Edition 3.0 GPLv2 • No Clustering • Clustering planned in 3.1 • mod_jk for load balancing GlassFish Open Source CDDL & • Java EE 5 Compatibility Edition 2.1.1 GPLv2 • In memory replication • mod_loadbalancer Oracle GlassFish Server 3.0 Commercial • GlassFish Open Source Edition 3.0 • GlassFish Server Control Clustering • Clustering planned in 3.1 Coming Soon! Oracle GlassFish Server Commercial • GlassFish Open Source Edition 2.1.1 2.1.1 • Enterprise Manager • HADB 92
  • 93. GlassFish 3 • Modular • Maven 2 – Build & Module description • Felix – OSGi runtime (200+ bundles) • Allow any type of Container to be plugged • Start Container and Services on demand • Embeddable: runs in-VM • Extensible • Rails, Grails, Django, ... • Administration, Monitoring, Logging, Deployment, ... http://blogs.sun.com/dochez/entry/glassfish_v3_extensions_part_5 93
  • 94. GlassFish 3 & OSGi • No OSGi APIs are used in GlassFish • HK2 provides abstraction layer • All GlassFish modules are OSGi bundles • Felix is default, also runs on Knopflerfish & Equinox • Can run in an existing shell http://blogs.sun.com/arungupta/entry/totd_103_glassfish_v3_with 94
  • 95. Dynamic Languages & Frameworks http://glassfish-scripting.dev.java.net 95
  • 96. Demo NetBeans / Eclipse & Java EE 6 http://blogs.sun.com/arungupta/entry/screencast_27_simple_web_application http://blogs.sun.com/arungupta/entry/screencast_28_simple_web_application http://blogs.sun.com/arungupta/entry/screencast_26_develop_run_debug/ http://blogs.sun.com/arungupta/entry/totd_93_getting_started_with/ http://blogs.sun.com/arungupta/entry/totd_94_a_simple_java http://blogs.sun.com/arungupta/entry/totd_95_ejb_3_1 http://blogs.sun.com/arungupta/entry/totd_102_java_ee_6 http://blogs.sun.com/arungupta/entry/totd_99_creating_a_java 96
  • 97. 97
  • 99. Light Weight & On-demand Monitoring • Event-driven light-weight and non-intrusive monitoring • Modules provide domain specific probes (monitoring events) • EJB, Web, Connector, JPA, Jersey, Orb, Ruby • End-to-end monitoring on Solaris using DTrace • 3rd party scripting clients • JavaScript to begin with 99
  • 100. Demo GlassFish 3 Monitoring http://blogs.sun.com/arungupta/entry/totd_104_glassfish_v3_monitoring 100
  • 101. REST Interface • REST interface to management and monitoring data • Configuration data, commands invocation, (start/stop instance, deploy, undeploy, ...), CRUD resources (JMS, JDBC, ...) •localhost:4848/management/domain •localhost:4848/monitoring/domain • GET, POST, DELETE methods • XML, JSON, HTML reps 101
  • 102. Demo GlassFish 3 REST Interface http://blogs.sun.com/arungupta/entry/totd_113_javafx_front_end http://blogs.sun.com/arungupta/entry/totd_116_glassfish_v3_administration 102
  • 103. Boost your productivity Retain session across deployment asadmin redeploy –properties keepSessions=true helloworld.war 103
  • 106. GlassFish 3 Performance http://weblogs.java.net/blog/sdo/archive/2009/12/08/first-look-v3-performance 106
  • 107. GlassFish 3 Performance http://weblogs.java.net/blog/sdo/archive/2009/12/08/first-look-v3-performance 107
  • 108. GlassFish 3.1 • Main Features • Clustering and Centralized Administration • High Availability • Other ... • Application Versioning • Embedded (extensive) • Admin Console based on RESTful API 108
  • 109. GlassFish Roadmap • Oracle committed to GlassFish community • No changes to the operation of GlassFish OSS • Remains transparent and participatory • GlassFish strengthened by Oracle stewardship • Oracle wants to grow the community • Customer and community driven roadmap http://glassfish.org/roadmap 109
  • 110. GlassFish Roadmap Detail 110 ©2010 Oracle Corporation
  • 111. Fusion Middleware Integration Strategy • Commercial version will have integrations with Fusion Middleware • Certification on JRockit • Integration with Coherence and TopLink • Fusion Middleware and Fusion Applications currently not planned to be certified on GlassFish • Initial integrations will be interoperability • Web services, Web services policy, Identity Management (OAM) 111
  • 112. References • glassfish.org • blogs.sun.com/theaquarium • oracle.com/goto/glassfish • glassfish.org/roadmap • Follow @glassfish 112
  • 113. <Insert Picture Here> Java EE 6 & GlassFish v3: Paving the path for the future Arun Gupta, Java EE & GlassFish Guy blogs.sun.com/arungupta, @arungupta