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:
- Ease of use
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
@Stateless
,@Stateful
, or@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 likeweb.xml
andfaces-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.
- Lightweight
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.
- Extensibility
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
ServletListener
,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 platform.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:
- Specification
A formal document that describes the proposed component and its features.
- Reference Implementation (RI)
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.
- Technology Compliance Kit (TCK)
A set of tests that verify that the RI is in compliance with the specification. This allows multiple vendors to provide compliant implementations.
Java EE 6 consists of the platform specification that defines requirements across the platform. It also consists of the following component specifications:
- Web Technologies
- Enterprise Technologies
- Web Service Technologies
- Management and Security Technologies
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.
JAX-RPC (JSR 101), JAXR (JSR 93), EJB Entity Beans (part of JSR 153), and Java EE Application Deployment (JSR 88) are marked for pruning in this version of the platform.
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 TCK is available to all Java EE licensees for testing their respective implementations.
Some new specifications have been added to improve the functionality and richness of the platform. Several existing component specifications were revised to make them simple and easy to use.
The main features of the key specifications are described.
- Managed Beans
- Enterprise JavaBeans
An EJB can be created with a single source file per bean and annotated with
@Stateless
,@Stateful
, or@Singleton
.EJBs can be packaged in a
.war
for local access using@Local
andejb-jar
for 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 methods.The Embeddable EJB API allows client code and its corresponding enterprise beans to run within the same JVM and the class loader.
- Servlets
Annotation-driven Servlet (
@WebServlet
), Filter (@WebFilter
), and Listener (@WebListener
). Theweb.xml
descriptor becomes optional in most of the common cases.Servlets, filters, and listeners can be programmatically registered using
ServletContext
.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 using
web-fragment.xml
.Servlet security can be specified using
@Servlet
Security
,@HttpConstraint
, and@HttpMethodConstraint
in addition to<security-constraint>
.
- Java API for RESTful Web Services
POJO-based and annotation-driven way of publishing RESTful web services.
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
Accept:
header.
- SOAP-Based Web Services
Publish SOAP-based web services using a POJO and annotations. Finer grained control over the messages using
Source
,DataSource
, andSOAPMessage
.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.
- JavaServer Faces
Facelets is defined as the preferred templating language for the page. This allows composite components to be easily defined, enabling true abstraction.
Support for Ajax using JavaScript APIs and declarative Ajax using
f:ajax
.Most of the elements in
faces-config.xml
have an alternative annotation. Default navigation rules are defined following convention-over-configuration.HTTP GET support and bookmarkable URLs.
Integration with Bean Validation.
- Java Persistence API
An improved object/relational mapping to provide more intuitive Java mapping. An expanded and richer JPQL to support the improved mapping and some new functionality.
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
javax.persistence
properties.
- Interceptors
- Contexts and Dependency Injection
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.
- Bean Validation
Get Java EE 6 Pocket Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.