Welcome!

Java IoT Authors: Liz McMillan, Pat Romanski, Yeshim Deniz, Elizabeth White, Kong Yang

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
The current age of digital transformation means that IT organizations must adapt their toolset to cover all digital experiences, beyond just the end users’. Today’s businesses can no longer focus solely on the digital interactions they manage with employees or customers; they must now contend with non-traditional factors. Whether it's the power of brand to make or break a company, the need to monitor across all locations 24/7, or the ability to proactively resolve issues, companies must adapt to...
Artificial intelligence, machine learning, neural networks. We’re in the midst of a wave of excitement around AI such as hasn’t been seen for a few decades. But those previous periods of inflated expectations led to troughs of disappointment. Will this time be different? Most likely. Applications of AI such as predictive analytics are already decreasing costs and improving reliability of industrial machinery. Furthermore, the funding and research going into AI now comes from a wide range of com...
In this presentation, Striim CTO and founder Steve Wilkes will discuss practical strategies for counteracting fraud and cyberattacks by leveraging real-time streaming analytics. In his session at @ThingsExpo, Steve Wilkes, Founder and Chief Technology Officer at Striim, will provide a detailed look into leveraging streaming data management to correlate events in real time, and identify potential breaches across IoT and non-IoT systems throughout the enterprise. Strategies for processing massive ...
SYS-CON Events announced today that GrapeUp, the leading provider of rapid product development at the speed of business, will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place October 31-November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Grape Up is a software company, specialized in cloud native application development and professional services related to Cloud Foundry PaaS. With five expert teams that operate in various sectors of the market acr...
Internet of @ThingsExpo, taking place October 31 - November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with 21st Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The Internet of Things (IoT) is the most profound change in personal and enterprise IT since the creation of the Worldwide Web more than 20 years ago. All major researchers estimate there will be tens of billions devic...
SYS-CON Events announced today that Ayehu will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on October 31 - November 2, 2017 at the Santa Clara Convention Center in Santa Clara California. Ayehu provides IT Process Automation & Orchestration solutions for IT and Security professionals to identify and resolve critical incidents and enable rapid containment, eradication, and recovery from cyber security breaches. Ayehu provides customers greater control over IT infras...
SYS-CON Events announced today that MobiDev, a client-oriented software development company, will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place October 31-November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. MobiDev is a software company that develops and delivers turn-key mobile apps, websites, web services, and complex software systems for startups and enterprises. Since 2009 it has grown from a small group of passionate engineers and business...
SYS-CON Events announced today that Cloud Academy named "Bronze Sponsor" of 21st International Cloud Expo which will take place October 31 - November 2, 2017 at the Santa Clara Convention Center in Santa Clara, CA. 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 com...
The current age of digital transformation means that IT organizations must adapt their toolset to cover all digital experiences, beyond just the end users’. Today’s businesses can no longer focus solely on the digital interactions they manage with employees or customers; they must now contend with non-traditional factors. Whether it's the power of brand to make or break a company, the need to monitor across all locations 24/7, or the ability to proactively resolve issues, companies must adapt to...
SYS-CON Events announced today that CA Technologies has been named "Platinum Sponsor" of SYS-CON's 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 planning to development to management to security, CA creates software that fuels transformation for companies in the applic...
We build IoT infrastructure products - when you have to integrate different devices, different systems and cloud you have to build an application to do that but we eliminate the need to build an application. Our products can integrate any device, any system, any cloud regardless of protocol," explained Peter Jung, Chief Product Officer at Pulzze Systems, in this SYS-CON.tv interview at @ThingsExpo, held November 1-3, 2016, at the Santa Clara Convention Center in Santa Clara, CA
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.
Amazon started as an online bookseller 20 years ago. Since then, it has evolved into a technology juggernaut that has disrupted multiple markets and industries and touches many aspects of our lives. It is a relentless technology and business model innovator driving disruption throughout numerous ecosystems. Amazon’s AWS revenues alone are approaching $16B a year making it one of the largest IT companies in the world. With dominant offerings in Cloud, IoT, eCommerce, Big Data, AI, Digital Assista...
SYS-CON Events announced today that Enzu will exhibit at SYS-CON's 21st Int\ernational Cloud Expo®, which will take place October 31-November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Enzu’s mission is to be the leading provider of enterprise cloud solutions worldwide. Enzu enables online businesses to use its IT infrastructure to their competitive advantage. By offering a suite of proven hosting and management services, Enzu wants companies to focus on the core of their ...
Multiple data types are pouring into IoT deployments. Data is coming in small packages as well as enormous files and data streams of many sizes. Widespread use of mobile devices adds to the total. In this power panel at @ThingsExpo, moderated by Conference Chair Roger Strukhoff, panelists looked at the tools and environments that are being put to use in IoT deployments, as well as the team skills a modern enterprise IT shop needs to keep things running, get a handle on all this data, and deliver...
In his session at @ThingsExpo, Eric Lachapelle, CEO of the Professional Evaluation and Certification Board (PECB), provided an overview of various initiatives to certify 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 worldwide re...
IoT solutions exploit operational data generated by Internet-connected smart “things” for the purpose of gaining operational insight and producing “better outcomes” (for example, create new business models, eliminate unscheduled maintenance, etc.). The explosive proliferation of IoT solutions will result in an exponential growth in the volume of IoT data, precipitating significant Information Governance issues: who owns the IoT data, what are the rights/duties of IoT solutions adopters towards t...
With the introduction of IoT and Smart Living in every aspect of our lives, one question has become relevant: What are the security implications? To answer this, first we have to look and explore the security models of the technologies that IoT is founded upon. In his session at @ThingsExpo, Nevi Kaja, a Research Engineer at Ford Motor Company, discussed some of the security challenges of the IoT infrastructure and related how these aspects impact Smart Living. The material was delivered interac...
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.
No hype cycles or predictions of zillions of things here. IoT is big. You get it. You know your business and have great ideas for a business transformation strategy. What comes next? Time to make it happen. In his session at @ThingsExpo, Jay Mason, Associate Partner at M&S Consulting, presented a step-by-step plan to develop your technology implementation strategy. He discussed the evaluation of communication standards and IoT messaging protocols, data analytics considerations, edge-to-cloud tec...