Welcome!

Java IoT Authors: Yeshim Deniz, Liz McMillan, Elizabeth White, Pat Romanski, Frank Lupo

Related Topics: Java IoT, Microservices Expo

Java IoT: Article

Moving to SOA in J2EE 1.4

How to take an existing J2EE 1.3 bean and convert it into a Web service endpoint with almost no changes to its business interfac

This past year the J2EE 1.4 specification enjoyed increased adoption by the industry, with most major application server vendors having released their J2EE 1.4 products and more and more enterprises upgrading their application servers and production applications to comply with it.

Apart from merely upgrading, there's a natural desire to leverage the primary focus of J2EE 1.4 - its support for service oriented architectures and Web services - and make it benefit the business by exposing the business logic of J2EE applications in a way that makes them portably accessible from the various heterogeneous environments that are around today.

Here at Compuware (the company I work for) we chose to make the ability to generate J2EE 1.4 applications one of the top requirements of the upcoming version of our OptimalJ product, an MDA-based development product that enables you to generate (from user-defined models) complex, standards-compliant J2EE 1.3 and J2EE 1.4 applications that run on JBoss, WebSphere, and WebLogic. To do this, we were faced with the formidable task of ensuring that the user-modeled enterprise beans or Stateless Session Beans (SLSBs) that used to be translated into EJB 2.0 code can now be translated into EJB 2.1 Beans with Web Service endpoints with a minimum of changes to the signatures of their business methods. The same was accomplished for Java components running in the Web container.

Essentially what we learned is how to take an existing J2EE 1.3 bean (a SLSB or a Java component running in the Web container) and convert it into a Web Service endpoint with almost no changes to its business interface by craftily applying Java-to-WSDL/XML mapping to its business interface.

What makes this difficult is that when a bean is exposed and accessed as a Web Service endpoint, parameter passing is subject to SOAP serialization rules, which are far more restrictive than RMI-IIOP serialization semantics.

What we did was stress the ASs' compliance to J2EE 1.4 to its limits and gained firsthand knowledge of what works and what doesn't. We found numerous problems in the application services that we targeted - JBoss 4.0.x and WebSphere 6.0.x, which we addressed in cooperation with the respective vendors. In this article I will share the valuable knowledge that we learned on this project, show portable solutions, and draw attention to common pitfalls.

Service Endpoints in J2EE 1.4
Web Service endpoint is a term used in J2EE to describe Web Service components deployed in a J2EE container. A service endpoint can be implemented using a stateless session bean, in which case it runs in the EJB container, or as a Java class that is registered as a servlet, in which case it runs in the Web container and is termed a JAX-RPC endpoint.

Associated with each service endpoint is its service endpoint interface (SEI for brevity). Given that the Web Service endpoint is implemented by a J2EE component, it's sometimes called a service implementation bean.

Conceptually and visually the SEI is very similar to the remote component interface of Enterprise JavaBeans. It too extends java.rmi.Remote, its methods must declare java.rmi.RemoteException in their throws clauses, and looking at the code of a SEI and a remote component interface alone is often impossible to tell the two apart. This similarity is delusive since, in the case of the SEI, parameter and return value passing is subject to the restrictive SOAP serialization rules, while for the remote component interface the more liberal Java serialization semantics apply (let alone communication via local component interfaces where no extra restrictions apply).

SOAP serialization rules only permit argument and return values of the following types:

  1. The primitive Java types (with the exception of char) and their wrapper counterparts
  2. The standard JDK classes java.lang.String, java.util.Date, java.util.Calendar, java.math.BigInteger, java.math.BigDecimal, javax.xml.namespace.QName, and java.net.URI
  3. JavaBeans with default constructors whose properties and public fields types are, in turn, allowed SOAP serialization types
  4. Java arrays whose underlying types are, in turn, permitted SOAP serialization types. An important special case is that arrays of type Object aren't supported because java.lang.Object is not enumerated as a supported type. Even though not explicitly mentioned in the specification, multidimensional arrays also pose problems and should be avoided to achieve compliancy with the WS-I Basic Profile.
And that's all - no Java collections, even if a JavaBean class implements java.io.Serializable, it doesn't imply its eligibility for SOAP serialization! Even though there's a concept of custom serializers/deserializers for Web Service endpoints, such serializers aren't portable across Web Services for J2EE providers and, as a result, aren't supported in J2EE 1.4. Yet, despite the apparent restrictions, we found out that in many situations it's still possible to devise portable ways of exposing your business interfaces as SEIs without changing them much.

An SEI can coexist with the remote/local component interfaces of a SLSB or the business interface of a Web component in which case it may have a different number of business methods than the accompanying component interface(s). Like its remote/local counterparts, a SEI can feature overloaded methods that should be mapped to wsdl:operations with distinct names (more on that can be found in the Pullout on WS-I Basic Profile). We observed that JBoss didn't support overloaded methods in SEIs prior to version 4.0.4. (See http://jira.jboss.com/jira/browse/JBWS-463.)

Another important difference between the remote or local component interface and the SEI is that the latter must be accompanied by a WSDL definition that provides a canonical description of its Web Service endpoint that can be published to third parties (which may not necessarily be using a Java environment).

This essentially brings in an additional dimension because the SEI's WSDL definition influences how method invocations are serialized into XML. One way to influence the serialization of method invocations is the binding that the WSDL definition has assigned to the SEI. J2EE 1.4 supports two portable bindings - document-literal and rpc-literal, whose details can be found in [1, 2, and 3]. Thus in J2EE 1.4 a Web Service endpoint is fully described by the pair { SEI, WSDL } and the same SEI accompanied by different WSDL definitions leads to different XML messages on the wire.

The fact that a J2EE Web service endpoint is defined by the { SEI, WSDL } pair entails two different ways of developing one:

  • Start from a SEI. The rules of this approach are defined in the Java-to-XML/WSDL mapping whose definition can be found in the JAX-RPC 1.1 specification.
  • Start from a WSDL definition. This development approach is governed by the WSDL/XML-to-Java mapping.
The two mappings aren't symmetrical. Moreover each allows variations. That is, the transformation SEI1 -> WSDL -> SEI2 need not imply that SEI1 = SEI2. When dealing with an existing stateless session bean or existing business logic component running in the Web container, it is of course the Java-to-XML/WSDL mapping that's applicable. This mapping is also prevalent in new projects and the rest of the article will concentrate on it. (The WSDL/XML-to-Java mapping is typically turned to only when one needs to develop a Web Service endpoint that conforms to the interface and binding information provided by a given WSDL document.)

Java-to-XML/WSDL Mapping
When using the development approach based on the Java-to-XML/WSDL mapping, what you do first is define the SEI for the component you want to expose as a Web Service. You typically do so by copying the signatures of an existing component's business methods from its remote component interface (for EJBs) or business interface (for components running in the Web container). Sometimes you may have to change the signature slightly and I will explain later when that is necessary.

When mapping Java types to XML Schema definitions all non-standard types are regarded as JavaBeans. An essential and little considered aspect of this mapping is that only public non-final non-transient fields and read/write properties as defined by the java.beans.Introspector class are taken into account. Java exceptions are treated slightly differently; in their case read properties are also counted in. Each read property must be accompanied by a corresponding parameter in the constructor; otherwise it wouldn't be possible to assign the property a value. We found out that some application servers (e.g., JBoss 4.0.x - cf. http://jira.jboss.com/jira/browse/JBAS-2139) have problems with read-only properties in exceptions when a property's type is an array.

The fact that 1) public non-final fields are very uncommon and their use is discouraged and that 2) properties are queried for by using java.beans.Introspector means that we can accompany "problematic" Java types - that in themselves don't qualify for SOAP serialization rules - with BeanInfo counterparts that present explicit information of what the properties of a given Java type are. Listing 1 offers an example of a "problematic" Java type that was used as a superclass for all application exceptions in our project.

The problem with this class is that it features two properties that don't qualify for SOAP serialization - cause of type Throwable and values of type Object[]. No matter how you map this class to an XML Schema complex type (even if you exclude the problematic properties from the complex type's content model), you're bound to run into problems during your application's execution. Listing 2 shows an accompanying BeanInfo class that makes AlturaException a legitimate type for SOAP serialization.

As you can see the BeanInfo class simply excluded the cause property from the serialized state. It also redirected the values property to a new getter and setter - getStringValues and setStringValues (the setter is required to cater to those ASs that don't yet adequately support read-only properties of array types in exceptions). The new getter and setter are shown below:

/** Returns a String representation of this object's arguments. */
public String[] getStringValues() {
   return getValues() == null
       || getValues().getClass() != String[].class
     ? null : (String[]) getValues();
}
public void setStringValues(String values[]) {
   args = values;
}

When dealing with abstract Java classes, some application servers (e.g., WebSphere 6.0.x) require that they be mapped to abstract complex types, which is a sensible requirement that should be followed not only for portability but also to support polymorphism in the SEI methods.

With our changes to the serialized state of AlturaException, we can now portably map it to an XML Schema complex type:

<xsd:complexType name="AlturaException" abstract="true">
   <xsd:sequence>
     <xsd:element name="key" type="xsd:string"/>
     <xsd:element name="values" type="xsd:string" nillable="true"
     minOccurs="0" maxOccurs="unbounded"/>
   </xsd:sequence>
</xsd:complexType>

More Stories By Andrei Iltchenko

Andrei Iltchenko is a development lead at Compuware Corporation where he works on the MDA product OptimalJ and is responsible for the business logic area of OptimalJ-generated J2EE applications. He is also a Sun certified Java developer for Java Web Services, a Sun Certified Business Component Developer, a Sun Certified Developer, and a Sun Certified Programmer.

Comments (1) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
SYS-CON Belgium News Desk 02/17/06 07:11:44 PM EST

This past year the J2EE 1.4 specification enjoyed increased adoption by the industry, with most major application server vendors having released their J2EE 1.4 products and more and more enterprises upgrading their application servers and production applications to comply with it.

@ThingsExpo Stories
Amazon is pursuing new markets and disrupting industries at an incredible pace. Almost every industry seems to be in its crosshairs. Companies and industries that once thought they were safe are now worried about being “Amazoned.”. The new watch word should be “Be afraid. Be very afraid.” In his session 21st Cloud Expo, Chris Kocher, a co-founder of Grey Heron, will address questions such as: What new areas is Amazon disrupting? How are they doing this? Where are they likely to go? What are th...
SYS-CON Events announced today that IBM has been named “Diamond Sponsor” of SYS-CON's 21st Cloud Expo, which will take place on October 31 through November 2nd 2017 at the Santa Clara Convention Center in Santa Clara, California.
Infoblox delivers Actionable Network Intelligence to enterprise, government, and service provider customers around the world. They are the industry leader in DNS, DHCP, and IP address management, the category known as DDI. We empower thousands of organizations to control and secure their networks from the core-enabling them to increase efficiency and visibility, improve customer service, and meet compliance requirements.
Join IBM November 1 at 21st Cloud Expo at the Santa Clara Convention Center in Santa Clara, CA, and learn how IBM Watson can bring cognitive services and AI to intelligent, unmanned systems. Cognitive analysis impacts today’s systems with unparalleled ability that were previously available only to manned, back-end operations. Thanks to cloud processing, IBM Watson can bring cognitive services and AI to intelligent, unmanned systems. Imagine a robot vacuum that becomes your personal assistant tha...
SYS-CON Events announced today that IBM has been named “Diamond Sponsor” of SYS-CON's 21st Cloud Expo, which will take place on October 31 through November 2nd 2017 at the Santa Clara Convention Center in Santa Clara, California.
In his Opening Keynote at 21st Cloud Expo, John Considine, General Manager of IBM Cloud Infrastructure, will lead you through the exciting evolution of the cloud. He'll look at this major disruption from the perspective of technology, business models, and what this means for enterprises of all sizes. John Considine is General Manager of Cloud Infrastructure Services at IBM. In that role he is responsible for leading IBM’s public cloud infrastructure including strategy, development, and offering ...
SYS-CON Events announced today that N3N will exhibit at SYS-CON's @ThingsExpo, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. N3N’s solutions increase the effectiveness of operations and control centers, increase the value of IoT investments, and facilitate real-time operational decision making. N3N enables operations teams with a four dimensional digital “big board” that consolidates real-time live video feeds alongside IoT sensor data a...
In a recent survey, Sumo Logic surveyed 1,500 customers who employ cloud services such as Amazon Web Services (AWS), Microsoft Azure, and Google Cloud Platform (GCP). According to the survey, a quarter of the respondents have already deployed Docker containers and nearly as many (23 percent) are employing the AWS Lambda serverless computing framework. It’s clear: serverless is here to stay. The adoption does come with some needed changes, within both application development and operations. Tha...
With major technology companies and startups seriously embracing Cloud strategies, now is the perfect time to attend 21st Cloud Expo October 31 - November 2, 2017, at the Santa Clara Convention Center, CA, and June 12-14, 2018, at the Javits Center in New York City, NY, and learn what is going on, contribute to the discussions, and ensure that your enterprise is on the right path to Digital Transformation.
SYS-CON Events announced today that Avere Systems, a leading provider of enterprise storage for the hybrid cloud, will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Avere delivers a more modern architectural approach to storage that doesn't require the overprovisioning of storage capacity to achieve performance, overspending on expensive storage media for inactive data or the overbui...
Digital transformation is changing the face of business. The IDC predicts that enterprises will commit to a massive new scale of digital transformation, to stake out leadership positions in the "digital transformation economy." Accordingly, attendees at the upcoming Cloud Expo | @ThingsExpo at the Santa Clara Convention Center in Santa Clara, CA, Oct 31-Nov 2, will find fresh new content in a new track called Enterprise Cloud & Digital Transformation.
Most technology leaders, contemporary and from the hardware era, are reshaping their businesses to do software. They hope to capture value from emerging technologies such as IoT, SDN, and AI. Ultimately, irrespective of the vertical, it is about deriving value from independent software applications participating in an ecosystem as one comprehensive solution. In his session at @ThingsExpo, Kausik Sridhar, founder and CTO of Pulzze Systems, will discuss how given the magnitude of today's applicati...
Smart cities have the potential to change our lives at so many levels for citizens: less pollution, reduced parking obstacles, better health, education and more energy savings. Real-time data streaming and the Internet of Things (IoT) possess the power to turn this vision into a reality. However, most organizations today are building their data infrastructure to focus solely on addressing immediate business needs vs. a platform capable of quickly adapting emerging technologies to address future ...
SYS-CON Events announced today that NetApp has been named “Bronze Sponsor” of SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. NetApp is the data authority for hybrid cloud. NetApp provides a full range of hybrid cloud data services that simplify management of applications and data across cloud and on-premises environments to accelerate digital transformation. Together with their partners, NetApp emp...
As popularity of the smart home is growing and continues to go mainstream, technological factors play a greater role. The IoT protocol houses the interoperability battery consumption, security, and configuration of a smart home device, and it can be difficult for companies to choose the right kind for their product. For both DIY and professionally installed smart homes, developers need to consider each of these elements for their product to be successful in the market and current smart homes.
Widespread fragmentation is stalling the growth of the IIoT and making it difficult for partners to work together. The number of software platforms, apps, hardware and connectivity standards is creating paralysis among businesses that are afraid of being locked into a solution. EdgeX Foundry is unifying the community around a common IoT edge framework and an ecosystem of interoperable components.
Join IBM November 1 at 21st Cloud Expo at the Santa Clara Convention Center in Santa Clara, CA, and learn how IBM Watson can bring cognitive services and AI to intelligent, unmanned systems. Cognitive analysis impacts today’s systems with unparalleled ability that were previously available only to manned, back-end operations. Thanks to cloud processing, IBM Watson can bring cognitive services and AI to intelligent, unmanned systems. Imagine a robot vacuum that becomes your personal assistant th...
SYS-CON Events announced today that Avere Systems, a leading provider of hybrid cloud enablement solutions, will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Avere Systems was created by file systems experts determined to reinvent storage by changing the way enterprises thought about and bought storage resources. With decades of experience behind the company’s founders, Avere got its ...
SYS-CON Events announced today that Golden Gate University will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Since 1901, non-profit Golden Gate University (GGU) has been helping adults achieve their professional goals by providing high quality, practice-based undergraduate and graduate educational programs in law, taxation, business and related professions. Many of its courses are taug...
SYS-CON Events announced today that SIGMA Corporation will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. uLaser flow inspection device from the Japanese top share to Global Standard! Then, make the best use of data to flip to next page. For more information, visit http://www.sigma-k.co.jp/en/.