Welcome!

Java IoT Authors: Yeshim Deniz, Elizabeth White, Liz McMillan, Jyoti Bansal, Jason Bloomberg

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
Your homes and cars can be automated and self-serviced. Why can't your storage? From simply asking questions to analyze and troubleshoot your infrastructure, to provisioning storage with snapshots, recovery and replication, your wildest sci-fi dream has come true. In his session at @DevOpsSummit at 20th Cloud Expo, Dan Florea, Director of Product Management at Tintri, will provide a ChatOps demo where you can talk to your storage and manage it from anywhere, through Slack and similar services ...
In his session at @ThingsExpo, Eric Lachapelle, CEO of the Professional Evaluation and Certification Board (PECB), will provide an overview of various initiatives to certifiy the security of connected devices and future trends in ensuring public trust of IoT. Eric Lachapelle is the Chief Executive Officer of the Professional Evaluation and Certification Board (PECB), an international certification body. His role is to help companies and individuals to achieve professional, accredited and worldw...
SYS-CON Events announced today that Linux Academy, the foremost online Linux and cloud training platform and community, will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Linux Academy was founded on the belief that providing high-quality, in-depth training should be available at an affordable price. Industry leaders in quality training, provided services, and student certification passes, its goal is to c...
"delaPlex is a software development company. We do team-based outsourcing development," explained Mark Rivers, COO and Co-founder of delaPlex Software, in this SYS-CON.tv interview at 18th Cloud Expo, held June 7-9, 2016, at the Javits Center in New York City, NY.
SYS-CON Events announced today that SoftLayer, an IBM Company, has been named “Gold Sponsor” of SYS-CON's 18th Cloud Expo, which will take place on June 7-9, 2016, at the Javits Center in New York, New York. SoftLayer, an IBM Company, provides cloud infrastructure as a service from a growing number of data centers and network points of presence around the world. SoftLayer’s customers range from Web startups to global enterprises.
SYS-CON Events announced today that CA Technologies has been named “Platinum Sponsor” of SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY, and the 21st International Cloud Expo®, which will take place October 31-November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. CA Technologies helps customers succeed in a future where every business – from apparel to energy – is being rewritten by software. From ...
SYS-CON Events announced today that Technologic Systems Inc., an embedded systems solutions company, will exhibit at SYS-CON's @ThingsExpo, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Technologic Systems is an embedded systems company with headquarters in Fountain Hills, Arizona. They have been in business for 32 years, helping more than 8,000 OEM customers and building over a hundred COTS products that have never been discontinued. Technologic Systems’ pr...
In his keynote at @ThingsExpo, Chris Matthieu, Director of IoT Engineering at Citrix and co-founder and CTO of Octoblu, focused on building an IoT platform and company. He provided a behind-the-scenes look at Octoblu’s platform, business, and pivots along the way (including the Citrix acquisition of Octoblu).
SYS-CON Events announced today that Loom Systems will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Founded in 2015, Loom Systems delivers an advanced AI solution to predict and prevent problems in the digital business. Loom stands alone in the industry as an AI analysis platform requiring no prior math knowledge from operators, leveraging the existing staff to succeed in the digital era. With offices in S...
SYS-CON Events announced today that HTBase will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. HTBase (Gartner 2016 Cool Vendor) delivers a Composable IT infrastructure solution architected for agility and increased efficiency. It turns compute, storage, and fabric into fluid pools of resources that are easily composed and re-composed to meet each application’s needs. With HTBase, companies can quickly prov...
SYS-CON Events announced today that T-Mobile will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. As America's Un-carrier, T-Mobile US, Inc., is redefining the way consumers and businesses buy wireless services through leading product and service innovation. The Company's advanced nationwide 4G LTE network delivers outstanding wireless experiences to 67.4 million customers who are unwilling to compromise on ...
SYS-CON Events announced today that Cloud Academy will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Cloud Academy is the industry’s most innovative, vendor-neutral cloud technology training platform. Cloud Academy provides continuous learning solutions for individuals and enterprise teams for Amazon Web Services, Microsoft Azure, Google Cloud Platform, and the most popular cloud computing technologies. Ge...
SYS-CON Events announced today that CrowdReviews.com has been named “Media Sponsor” of SYS-CON's 20th International Cloud Expo, which will take place on June 6–8, 2017, at the Javits Center in New York City, NY. CrowdReviews.com is a transparent online platform for determining which products and services are the best based on the opinion of the crowd. The crowd consists of Internet users that have experienced products and services first-hand and have an interest in letting other potential buyers...
SYS-CON Events announced today that Infranics will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Since 2000, Infranics has developed SysMaster Suite, which is required for the stable and efficient management of ICT infrastructure. The ICT management solution developed and provided by Infranics continues to add intelligence to the ICT infrastructure through the IMC (Infra Management Cycle) based on mathemat...
SYS-CON Events announced today that Interoute, owner-operator of one of Europe's largest networks and a global cloud services platform, has been named “Bronze Sponsor” of SYS-CON's 20th Cloud Expo, which will take place on June 6-8, 2017 at the Javits Center in New York, New York. Interoute is the owner-operator of one of Europe's largest networks and a global cloud services platform which encompasses 12 data centers, 14 virtual data centers and 31 colocation centers, with connections to 195 add...
SYS-CON Events announced today that SD Times | BZ Media has been named “Media Sponsor” of SYS-CON's 20th International Cloud Expo, which will take place on June 6–8, 2017, at the Javits Center in New York City, NY. BZ Media LLC is a high-tech media company that produces technical conferences and expositions, and publishes a magazine, newsletters and websites in the software development, SharePoint, mobile development and commercial UAV markets.
SYS-CON Events announced today that Cloudistics, an on-premises cloud computing company, has been named “Bronze Sponsor” of SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Cloudistics delivers a complete public cloud experience with composable on-premises infrastructures to medium and large enterprises. Its software-defined technology natively converges network, storage, compute, virtualization, and management into a ...
Now that the world has connected “things,” we need to build these devices as truly intelligent in order to create instantaneous and precise results. This means you have to do as much of the processing at the point of entry as you can: at the edge. The killer use cases for IoT are becoming manifest through AI engines on edge devices. An autonomous car has this dual edge/cloud analytics model, producing precise, real-time results. In his session at @ThingsExpo, John Crupi, Vice President and Eng...
There are 66 million network cameras capturing terabytes of data. How did factories in Japan improve physical security at the facilities and improve employee productivity? Edge Computing reduces possible kilobytes of data collected per second to only a few kilobytes of data transmitted to the public cloud every day. Data is aggregated and analyzed close to sensors so only intelligent results need to be transmitted to the cloud. Non-essential data is recycled to optimize storage.
"I think that everyone recognizes that for IoT to really realize its full potential and value that it is about creating ecosystems and marketplaces and that no single vendor is able to support what is required," explained Esmeralda Swartz, VP, Marketing Enterprise and Cloud at Ericsson, in this SYS-CON.tv interview at @ThingsExpo, held June 7-9, 2016, at the Javits Center in New York City, NY.