The Java Platform, Enterprise Edition (Java EE) provides a standards-based platform for developing web and enterprise applications. These applications are typically designed as multitier applications, with a frontend tier consisting of web frameworks, a middle tier providing security and transactions, and a backend tier providing connectivity to a database or a legacy system. The Java EE platform defines APIs for different components in each tier, and also provides some additional services such as naming, injection, and resource management that span across the platform. Each component is defined in a separate specification that also describes the API, javadocs, and expected behavior.
The Java Platform, Enterprise Edition 6 (Java EE 6) was released in December 2009 and provides a simple, easy-to-use, and complete stack for building such applications. The previous version of the platform, Java EE 5, took the first step in providing a simplified developer experience. The Java EE 6 platform further improves upon the developer productivity features and also adds a lot more functionality.
The three main goals of the platform are:
The Java EE 6 platform takes ease of use to new heights by
extensively using convention over configuration and heavy use of
annotations on a Plain Old Java Object (POJO). Adding
@Singleton to a POJO makes it an Enterprise JavaBean. Further, this could be easily
packaged in a WAR file instead of a special packaging of JAR or EAR.
Servlets are POJOs as well, annotated with
@WebServlet. Deployment descriptors like
faces-config.xml are optional
in most cases; the information typically specified in deployment
descriptors is now captured in annotations. There are default rules
of navigation from one page of JSF to another. Publishing a POJO as
a RESTful web service is equivalent to adding an
@Path annotation on a POJO.
Making deployment descriptors optional, using convention over configuration, and relying heavily on annotations makes the Java EE 6 platform easy to use and, above all, less verbose.
There are 31 component specifications in the Java EE 6 platform, as listed in Appendix EE.6 of the platform specification. These components include Enterprise JavaBeans (EJB), Servlets, JavaServer Faces (JSF), Java API for RESTful Web Services (JAX-RS), and many others. Building a typical enterprise application may not require all the components. Also, some of the technologies like Java API for XML Registries (JAXR) or Java API for XML-based RPC (JAX-RPC) were very relevant when introduced in the platform. Now they have either been replaced by better components, such as Java API for XML Web Services (JAX-WS), or are no longer used.
The Java SE Expert Group defined a two-step process for removing features from the platform. In this process, known as pruning, a feature is marked as optional (referred to as proposed optional) in one release, and then a subsequent release can decide to either remove the feature, retain it as a required component, or leave it in the proposed removal state. The Java EE Expert Group used that process and targeted some features for pruning. This is analogous to trimming rose bushes in the beginning of each year so that fresh blossoms can grow. Pruning unused features ensures that even with new feature additions, the platform will remain simple and lightweight.
The Java EE platform also introduces the notion of profiles. A profile represents a configuration of the platform suited to a particular class of applications. A profile may be a subset or superset of the technologies in the platform. The Java EE 6 Web Profile is defined as a separate specification in the platform, and is defined as a subset of technologies contained in the platform and targeted toward the developers of modern web applications. This breaks away from the “one size fits all” approach of previous releases. And although it’s a proper subset, it still offers a reasonably complete stack composed of standard APIs, and it’s capable out-of-the-box for addressing a wide variety of web applications. The web profile allows developers to build web applications quickly and prevents the proliferation of custom web stacks for easier maintainability. Additional profiles can be defined by following the rules of the Java Community Process (JCP).
Together, pruning and web profiles make the Java EE 6 platform lightweight and simple to maintain.
The platform provides a rich set of functionality to create
enterpise applications. However, it’s a common practice to include
third-party frameworks to supplement or complement functionality in
the platform. These frameworks require registration of a
ServletFilter, or similar
component so that they are recognized by the runtime. The Servlet
specification defines a web fragment
mechanism by which these entry points to the framework are defined
in the framework library. The Servlet containers then register the
framework, relieving the developer of the burden. This allows these
frameworks to be treated as first-class citizens of the
In addition, the Contexts and Dependency Injection (CDI) specification defines a portable extension mechanism that allows you to extend the capabilities of the platform in different ways, for example by providing certain predefined scopes. A new scope can be easily defined and included with any Java EE 6–compliant application server using the portable extensions method.
Specifications like CDI, JavaServer Faces 2, Java API for RESTful Services, Java Persistence API 2, and Servlets 3 make the Java EE 6 platform more powerful. This book will provide an overview of the main technologies included in the platform, and easy-to-understand code samples will be used throughout to demonstrate improvements in Java EE 6.
The Java EE 6 platform was developed as Java Specification Request 316 or JSR 316 (http://jcp.org/en/jsr/detail?id=316) following Java Community Process (JCP) 2.7. The JCP process defines three key deliverables for any JSR:
Binary implementation of the proposed specification. The RI helps to ensure that the proposed specifications can be implemented in a binary form and provides constant feedback to the specification process.
JSR 318: Interceptors 1.1
The different components work together to provide an integrated stack, as shown in Figure 1-1.
In Figure 1-1:
JPA, JTA, and JMS provide the basic services such as database access, transactions, and messaging.
Managed Beans and EJB provide a simplified programming model using POJOs to use the basic services.
CDI, Interceptors, and Common Annotations provide concepts that are applicable to a wide variety of components, such as type-safe dependency injection, addressing cross-cutting concerns using interceptors, and a common set of annotations.
CDI Extensions allow you to extend the platform beyond its existing capabilities in a standard way.
Web services using JAX-RS and JAX-WS, JSF, JSP, and EL define the programming model for web applications. Web Fragments allow automatic registration of third-party web frameworks in a very natural way.
Bean Validation provides a standard means to declare constraints and validate them across different technologies.
The RI of Java EE 6 is built in the GlassFish Community. The GlassFish Server Open Source Edition provides a full Java EE 6–compliant, free, and open source application server. It is also available in a Web Profile distribution and can be downloaded from http://glassfish.org. The application server is easy to use (zip installer and NetBeans/Eclipse/IntelliJ integration), lightweight (downloads starting at 30 MB, small disk/memory footprint), and modular (OSGi-based, containers start on demand). It also provides clustering with high availability and centralized administration using CLI, web-based administration console, and REST management/monitoring APIs. The Oracle GlassFish Server is Oracle’s commercially supported GlassFish server distribution and can be downloaded from http://oracle.com/goto/glassfish. As of this writing, there are 17 Java EE 6–compliant application servers. The complete list is available at http://www.oracle.com/technetwork/java/javaee/overview/compatibility-jsp-136984.html.
The main features of the key specifications are described.
EJBs can be packaged in a
.war for local
local and remote access.
EJBs can be accessed using a portable global JNDI name.
A method of a session bean may be marked to be invoked asynchronously. These methods allow the client to retrieve the result value later, or use the fire-and-forget pattern.
Time-based events can be scheduled using cron-like
syntax by specifying
@Schedule on bean
The Embeddable EJB API allows client code and its corresponding enterprise beans to run within the same JVM and the class loader.
Servlets, filters, and listeners can be programmatically
Asynchronous servlets allow the control (or thread) to return back to the container to perform other tasks while waiting for the long-running process to complete.
Framework libraries can be integrated in a modular way
Servlet security can be specified using
@HttpMethodConstraint in addition to
Standard set of HTTP protocol methods such as GET, POST, PUT, and DELETE are supported.
Each resource can be represented in multiple formats; custom types are supported as well.
Client-side content negotiation supported using HTTP
Client-side API to invoke a SOAP-based web service.
Well-defined extension points for pre/post processing of request/response messages on client and server.
Standard Java-to-WSDL and WSDL-to-Java mapping.
Most of the elements in
have an alternative annotation. Default navigation rules are
defined following convention-over-configuration.
HTTP GET support and bookmarkable URLs.
Integration with Bean Validation.
The Metamodel captures a metamodel of the persistent state and relationships of the managed classes of a persistence unit. This abstract persistence schema is then used to author the type-safe queries using Criteria API.
Pessimistic locking is supported in addition to optimistic locking by the addition of new locking modes.
Standard configuration options using
Provides strong typing by specifying all dependencies using Java type system. Provides loose coupling with Events, Interceptors, and Decorators.
Provides an integration with Expression Language.
Defines an extensible scope and context management mechanism.
Bridges transactional tier (EJB) and presentation tier (JSF) in the platform.