SOA Support in Java
SOA Support in Java
The Java 2 Platform Enterprise Edition (J2EE) is one of the two primary
platforms currently being used to develop enterprise solutions using Web
services. This section briefly introduces parts of the J2EE platform relevant to
SOA. We then proceed to revisit the service-orientation principles and primary
primitive and contemporary SOA characteristics established earlier in this book to
discuss how these potentially can be realized using the previously explained
parts of J2EE.
It is important to note that this section does not provide an in-depth explanation
of the J2EE platform, nor do we get into how to program Web services using
Java. There are already many comprehensive books that cover this vast subject
area (see www.serviceoriented.ws for recommended reading). The purpose of this
section is simply to continue our exploration of SOA realization. In doing so, we
highlight some of the main areas of interest within the J2EE platform.
The Java 2 Platform is divided into three major development and runtime
platforms, each addressing a different type of solution. The Java 2 Platform
Standard Edition (J2SE) is designed to support the creation of desktop
applications, while the Micro Edition (J2ME) is geared toward applications that
run on mobile devices. The Java 2 Platform Enterprise Edition (J2EE) is built to
support large-scale, distributed solutions. J2EE has been in existence for over
five years and has been used extensively to build traditional n-tier applications
with and without Web technologies.
Figure 18.13 does not illustrate the relationship between J2EE platform
components. It only shows the underlying layers provided by the J2EE platform
that support a J2EE service-oriented solution.
Figure 18.13. Relevant layers of the J2EE platform as they relate to SOA.
The Servlets + EJBs and Web + EJB Container layers (as well as the JAX-RPC
Runtime) relate to the Web and Component Technology layers established
earlier in the SOA platform basics section. They do not map cleanly to these
layers because to what extent component and Web technology is incorporated is
largely dependent on how a vendor chooses to implement this part of a J2EE
architecture.
The components shown in Figure 18.13 inter-relate with other parts of the overall
J2EE environment (as shown in Figure 18.14) to provide a platform capable of
realizing SOA.
Architecture components
While the first two components are of more relevance to establishing the
presentation layer of a service-oriented solution, the latter two commonly are
used to realize Web services.
Runtime environments
The J2EE environment relies on a foundation Java runtime to process the core
Java parts of any J2EE solution. In support of Web services, J2EE provides
additional runtime layers that, in turn, supply additional Web services specific
APIs (explained later). Most notable is the JAX-RPC runtime, which establishes
fundamental services, including support for SOAP communication and WSDL
processing.
Additionally, implementations of J2EE supply two types of component containers
that provide hosting environments geared toward Web services-centric
applications that are generally EJB or servlet-based.
As explained in the Service providers section, EJB and Web containers can host
EJB-based or servlet-based J2EE Web services. Web service execution on both
containers is supported by JAX-RPC runtime services. However, it is the vendor-
specific container logic that generally determines the shape and form of the
system-level message processing logic provided in support of Web services.
Note
Programming languages
As its name implies, the Java 2 Platform Enterprise Edition is centered around
the Java programming language. Different vendors offer proprietary development
products that provide an environment in which the standard Java language can
be used to build Web services.
Note
APIs
o Java API for XML Processing (JAXP) This API is used to process XML
document content using a number of available parsers. Both Document
Object Model (DOM) and Simple API for XML (SAX) compliant models are
supported, as well as the ability to transform and validate XML documents
using XSLT stylesheets and XSD schemas. Example packages include:
o Java API for XML-based RPC (JAX-RPC) The most established and
popular SOAP processing API, supporting both RPC-literal and document-
literal request-response exchanges and one-way transmissions. Example
packages that support this API include:
o Java API for XML Registries (JAXR) An API that offers a standard
interface for accessing business and service registries. Originally
developed for ebXML directories, JAXR now includes support for UDDI.
~javax.xml.registryA series of registry access functions that support the JAXR API.
~javax.xml.registry.infomodelClasses that represent objects within a registry.
Of these APIs, the two most commonly used for SOA are JAX-RPC to govern
SOAP messaging and JAXP for XML document processing. The two other
packages relevant to building the business logic for J2EE Web services
are javax.ejb and javax.servlet, which provide fundamental APIs for the
development of EJBs and servlets.
Note that we do not discuss these APIs any further. They are mentioned here
only to demonstrate the grouping of API functions in J2EE packages.
Service providers
o JAX-RPC Service Endpoint When building Web services for use within a
Web container, a JAX-RPC Service Endpoint is developed that frequently
is implemented as a servlet by the underlying Web container logic.
Servlets are a common incarnation of Web services within J2EE and most
suitable for services not requiring the features of the EJB container.
o EJB Service Endpoint The alternative is to expose an EJB as a Web
service through an EJB Service Endpoint. This approach is appropriate
when wanting to encapsulate existing legacy logic or when runtime
features only available within an EJB container are required. To build an
EJB Service Endpoint requires that the underlying EJB component be a
specific type of EJB called a Stateless Session Bean.
Regardless of vendor platform, both types of J2EE Web services are dependent
on the JAX-RPC runtime and associated APIs.
Note
Also a key part of either service architecture is an underlying model that defines
its implementation, called the Port Component Model. As described in the Web
Services for J2EE specification, it establishes a series of components that
comprise the implementation of a J2EE service provider, including:
Figure 18.15 illustrates how the J2EE components fit into our familiar service
provider model.
Service requestors
The JAX-RPC API also can be used to develop service requestors. It provides
the ability to create three types of client proxies, as explained here:
o Generated stub The generated stub (or just "stub") is the most common
form of service client. It is auto-generated by the JAX-RPC compiler (at
design time) by consuming the service provider WSDL, and producing a
Java-equivalent proxy component. Specifically, the compiler creates a
Java remote interface for every WSDL portType which exposes methods
that mirror WSDL operations. It further creates a stub based on the
WSDL port and binding constructs. The result is a proxy component that
can be invoked as any other Java component. JAX-RPC takes care of
translating communication between the proxy and the requesting business
logic component into SOAP messages transmitted to and received from
the service provider represented by the WSDL.
o Dynamic proxy and dynamic invocation interface Two variations of the
generated stub are also supported. The dynamic proxy is similar in
concept, except that the actual stub is not created until its methods are
invoked at runtime. Secondly, the dynamic invocation interface bypasses
the need for a physical stub altogether and allows for fully dynamic
interaction between a Java component and a WSDL definition at runtime.
The latter options are more suited for environments in which service interfaces
are more likely to change or for which component interaction needs to be
dynamically determined. For example, because a generated stub produces a
static proxy interface, it can be rendered useless when the corresponding WSDL
definition changes. Dynamic proxy generation avoids this situation.
Figure 18.16 explains how J2EE technologies work together within the service
requestor model.
Service agents
To support SOAP header processing, the JAX-RPC API allows for the creation of
specialized service agents called handlers (Figure 18.17)runtime filters that exist
as extensions to the J2EE container environments. Handlers can process SOAP
header blocks for messages sent by J2EE service requestors or for messages
received by EJB Endpoints and JAX-RPC Service Endpoints.
Figure 18.17. J2EE handlers as service agents.
Multiple handlers can be used to process different header blocks in the same
SOAP message. In this case the handlers are chained in a predetermined
sequence (appropriately called a handler chain).
Platform extensions
Different vendors that implement and build around the J2EE platform offer
various platform extensions in the form of SDKs that extend their development
tool offering. The technologies supported by these toolkits, when sufficiently
mature, can further support contemporary SOA. Following are two examples of
currently available platform extensions.
Case Study
As explained throughout earlier chapters, RailCo originally delivered a set of Web services so t
online vendor for TLS's B2B solution. A recent change in strategy prompted RailCo to broaden
of their Web services so that they could achieve the following two goals:
The initial Web services-based application was developed using the .NET framework. At first R
this solution with a set of redesigned .NET services. However, a recent corporate reorganizatio
to such an extent that it was not able to renew the contracts of the four consultant project team
original .NET solution.
To continue with its plan, RailCo had to draw upon in-house resources. The small group of Jav
responsible for maintaining the Java-based accounting system were identified as potential can
Because they had not yet worked with any of the Web services-related APIs, they needed to u
to speed on JAX-RPC and JAXP.
Though this delayed the original plan, an SOA eventually was realized, hosting the new Invoice
Fulfillment applications, built as J2EE solutions consisting of a set of JAX-RPC Service Endpoi
Service encapsulation
The distributed nature of the J2EE platform allows for the creation of independent
units of processing logic through Enterprise Java Beans or servlets. EJBs or
servlets can contain small or large amounts of application logic and can be
composed so that individual units comprise the processing requirements of a
specific business task or an entire solution.
Both EJBs and servlets can be encapsulated using Web services. This turns
them into EJB and JAX-RPC Service Endpoints, respectively. The underlying
business logic of an endpoint can further compose and interact with non-endpoint
EJB and servlet components. As a result, well-defined services can be created in
support of SOA.
Loose coupling
The use of interfaces within the J2EE platform allows for the abstraction of
metadata from a component's actual logic. When complemented with an open or
proprietary messaging technology, loose coupling can be realized. EJB and JAX-
RPC Endpoints further establish a standard WSDL definition, supported by J2EE
HTTP and SOAP runtime services. Therefore, loose coupling is a characteristic
that can be achieved in support of SOA.
Messaging
Also worth noting is the availability of the SOAP over JMS extension, which
supports the delivery of SOAP messages via the JMS protocol as an alternative
to HTTP. The primary benefit here is that this approach to data exchange
leverages the reliability features provided by the JMS framework. Within SOA this
extension can be used by the business logic of a Web service, allowing SOAP
messages to be passed through from the message process logic (which
generally will rely on HTTP as the transport protocol). Either way, the J2EE
platform provides the required messaging support for primitive SOA.
We've established that the J2EE platform supports and implements the first-
generation Web services technology set. It is now time to revisit the four
principles of service-orientation not automatically provided by Web services and
briefly discuss how each can be realized through J2EE.
Autonomy
Reusability
The advent of Enterprise Java Beans during the rise of distributed solutions over
the past decade established a componentized application design model that,
along with the Java programming language, natively supports object-orientation.
As a result, reusability is achievable on a component level. Because service-
orientation encourages services to be reusable and because a service can
encapsulate one or more new or existing EJB components, reusability on a
service level comes down to the design of a service's business logic and
endpoint.
Statelessness
Discoverability
As with reuse, service discoverability requires deliberate design. To make a
service discoverable, the emphasis is on the endpoint design, in that it must be
as descriptive as possible.
The Web services subset of the J2EE platform supports industry standard Web
services specifications, including WSDL, SOAP, and UDDI. As explained later in
the Intrinsically interoperable section, support for the WS-I Basic Profile also has
been provided. Further, the API specifications that comprise the J2EE platform
are themselves open standards, which further promotes vendor diversity, as
described in the next section.
Note
It should also be mentioned that some J2EE vendors have provided significant
contributions to the actual creation of Web services specifications.
Intrinsically interoperable
As of version 1.1, the JAX-RPC API is fully capable of creating WS-I Basic
Profile-compliant Web services. This furthers the vision of producing services
that are intrinsically interoperable. Care must be taken, though, to prevent the
use of handlers from performing runtime processing actions that could jeopardize
this compliance.
Note
IBM's Rational Application Developer provides built-in support for building WS-I
compliant Web services. Further, the Wscompile tool, which is part of the J2EE
SDK from Sun Microsystems, allows for the auto-generation of WS-I Basic Profile
compliant WSDL definitions.
Promotes federation
Also worth taking into consideration is the J2EE Connector Architecture (JCA), a
structured, adapter-centric integration architecture through which resource
adapters are used to bridge gaps between J2EE platforms and other
environments. As with JMS, JCA is traditionally centered around the use of
proprietary messaging protocols and platform-specific adapters. Recently,
however, support for asynchronous and SOAP messaging has been introduced.
Further, service adapters have been made available to tie JCA environments into
service-oriented solutions.
Note
Architecturally composable
Given the modular nature of supporting API packages and classes and the
choice of service-specific containers, the J2EE platform is intrinsically
composable. This allows solution designers to use only the parts of the platform
required for a particular application. For example, a Web services solution that
only consists of JAX-RPC Service Endpoints will likely not have a need for the
JMS class packagesora J2EE SOA that does not require a service registry will
not implement any part of the JAXR API.
Extensibility
As with any service-oriented solution, those based on the J2EE platform can be
designed with services that support the notion of future extensibility. This comes
down to fundamental design characteristics that impose conventions and
structure on the service interface level.
This is primarily because the concept of orchestration is not a native part of the
J2EE platform. Instead, orchestration services and design tools are provided by
vendors to supplement the J2EE Web services development and runtime
environment. Service-oriented business modeling and the service layers we've
discussed in this book can therefore be created with the right vendor tools.
Logic-level abstraction
JAX-RPC Service Endpoints and EJB Service Endpoints can be designed into
service layers that abstract application-specific or reusable logic. Further, entire
J2EE solutions can be exposed through these types of services, when
appropriate.
For example, if a vendor server platform is not satisfying current business needs
and requires replacement, application, entity-centric, and task-centric services
likely will be sufficiently mobile so that they can be used in the replacement
environment. The orchestration logic may or may not be portable, depending on
whether a common orchestration language, such as WS-BPEL, was used to
express the process logic.