It has been a long awaited metamorphosis closely watched by millions of java ee enthusiasts!  Finally Java EE survived in the era of osgi-driven virtualized server space. Thanks to a stiff competition offered by the VMWare-SpringSource conglomeration.

Java Gurus did tremendous soul searching to figure out what went wrong over the years !  The result is a simplistic view of a complex world !

Select your Pizza

In its latest incarnation, the most striking change is – rightsizing the platform ! It makes lot of sense to be able to select desired platform profile. That is a company specialized in web-based products can choose a ‘web profile’.
GlassFish v3 Web Profile starts small, then one can add features like RESTful admin as needed.
You can limit the footprint of the web-container by choosing only what you need (servlet 3 or ejb 3.1 or both).
A close contest with spring-source indeed!

Healing Touch

To make life simpler, java ee 6 offers the perfect healing touch by just pruning jax-rpc, ejb 2.x entity beans, jaxr .. (no need to mention how painful they were !)

More good news ! The platform is truly extensible now with goal of zero-configuration.

Zero-Configuration – emergence of Java Contexts

Core container can simply be bootstrapped. Then container-initializers, servlets, servlet-filters, fwk-context-listensers can be discovered and registered during runtime through the JSR-299: Java Contexts and Dependency Injection. (Java Contexts – a best of breed of seam and spring beans).  This specification enhances the EJB component model with contextual lifecycle management.

Web Fragments

Just like bundles in osgi, developers can now create modular ‘plugin library jars’ using the concept of ‘web fragments’.

Actually, Glassfish has embraced open-source library ‘HK2’ to implement osgi-like module architecture.

If we can drag-n-drop web frameworks , wouldn’t that make web.xml obsolete ?  Of course, yes !  just annotate the servlet to deploy servlet … @WebServlet (name urlpattern)

No need to mention in web.xml.
Obviously one can use the descriptor to override the url pattern. You don’t need to recompile the whole application.  With modularity and flexible pluggability comes ‘simplified packaging’ !

That means ejbs can be directly added to web app. No need for classic ejb.jar !  Finally, EJB mandates one source file per bean.

Inject whatever whenever

Custom fwks can directly be plugged into container. That is ‘JRuby on Rails’ can run natively inside GlassFish v3.

 Actually It is now possible to inject Java EE resources, remote EJB references, web service references, persistence contexts and persistence units using typesafe 299-style injection. For example, we can inject a persistence context like this:
@UserDatabase EntityManager entityManager;
Where @UserDatabase is a binding type.

Any session bean instance obtained via the dependency injection service is a contextual instance. It is bound to a lifecycle context and is available to other objects that execute in that context. The container automatically creates the instance when it is needed by a client.

<h:inputText id=”username” value=”#{credentials.username}”/>

The Credentials bean has a lifecycle that is bound to the JSF request:

@Model
public class Credentials {
private String username;

<h:commandButton value=”Login” action=”#{login.login}”

The Login bean has a lifecycle that is bound to the HTTP session:
@SessionScoped @Model
public class Login {
@Current Credentials credentials;
@Users EntityManager userDatabase;

Support for activities

It’s now possible for a third-party framework, especially an orchestration engine, to register beans that apply only within the scope of a certain activity, for example, a workflow task, business process or web interaction.
This feature has tremendous impact as all verticals merging fast into a single server space. That is a BPM Process published as a service in an app server can talk to the SCA Process deplyed as another service and also requiring prediction support from a Rule Engine service.

Now JEE 6 will help realize such complex golas of technology integration.

Asynchronity and amzing annotations

Event observers may now receive event notifications asynchronously

 Make a process aynchronous — @WebServlet (asyncSupport=true)
 then call AyncContext ctx = ServletRequest.startAsync(..)
 finally  ctx.dispatch(..)

As per Gavin King –

“JSR-299 The spec now features by far the most sophisticated annotation and XML based metadata reuse and overriding scheme ever devised”

@Singleton – enables sharing state amongst all beans

@ConcurrencyManagement – container managed security

@Asynch – Lightwt asynchronicity for businessmethods

@Schedule(dayOfWeek=”Mon/Wed – for timer sevice    … and so on.

There is a metadata-complete flag in the descriptors that turns annotation processing off.

Conversation Scope

Both JSR 311 for Restful Service and JSR 299 for Conversation Scope now part of Servlet Spec. The conversation context is provided by a built-in context object for the built-in passivating scope type
@ConversationScoped. The conversation scope is active:
• during all standard lifecycle phases of any JSF faces or non-faces request.
The conversation context provides access to state associated with a particular conversation. Every JSF request has an associated conversation. This association is managed automatically by the container according to the following rules:
• Any JSF request has exactly one associated conversation.
• The conversation associated with a JSF request is determined at the beginning of the restore view phase and does not change during the request.
Any conversation is in one of two states: transient or long-running.
• By default, a conversation is transient
• A transient conversation may be marked long-running by calling Conversation.begin()

One should read the whole spec to learn the interesting flow of COnversation Scope.

 In a nutshell, Sun’s JEE Survival mantra :

“The whole GlassFish v3 EJB 3.1 container is smaller than one megabyte, can be dynamically installed and uninstalled, and is surprisingly “elastic.” You can develop and deploy an application with only a few annotations.”

References :

http://in.relation.to/Bloggers/RevisedPublicDraftOfJSR299JavaContextsAndDependencyInjection

http://www.java.net/blogs/robc/

http://www.javabeat.net/articles/99-new-features-in-java-ee-60-3.html

http://www.infoq.com/news/2009/01/java-ee6-draft

http://blogs.sun.com/carolmcdonald/entry/jpa_performance_don_t_ignore