Welcome!

Java IoT Authors: Pat Romanski, Elizabeth White, Liz McMillan, Yeshim Deniz, Mehdi Daoudi

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
SYS-CON Events announced today that Datera 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. Datera offers a radically new approach to data management, where innovative software makes data infrastructure invisible, elastic and able to perform at the highest level. It eliminates hardware lock-in and gives IT organizations the choice to source x86 server nodes, with business model option...
21st International Cloud Expo, taking place October 31 - November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA, will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud strategy. Me...
SYS-CON Events announced today that DXWorldExpo has been named “Global 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. Digital Transformation is the key issue driving the global enterprise IT business. Digital Transformation is most prominent among Global 2000 enterprises and government institutions.
SYS-CON Events announced today that Massive Networks 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. Massive Networks mission is simple. To help your business operate seamlessly with fast, reliable, and secure internet and network solutions. Improve your customer's experience with outstanding connections to your cloud.
When shopping for a new data processing platform for IoT solutions, many development teams want to be able to test-drive options before making a choice. Yet when evaluating an IoT solution, it’s simply not feasible to do so at scale with physical devices. Building a sensor simulator is the next best choice; however, generating a realistic simulation at very high TPS with ease of configurability is a formidable challenge. When dealing with multiple application or transport protocols, you would be...
SYS-CON Events announced today that Akvelon 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. Akvelon is a business and technology consulting firm that specializes in applying cutting-edge technology to problems in fields as diverse as mobile technology, sports technology, finance, and healthcare.
SYS-CON Events announced today that Secure Channels, a cybersecurity firm, 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. Secure Channels, Inc. offers several products and solutions to its many clients, helping them protect critical data from being compromised and access to computer networks from the unauthorized. The company develops comprehensive data encryption security strategie...
SYS-CON Events announced today that WineSOFT 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. Based in Seoul and Irvine, WineSOFT is an innovative software house focusing on internet infrastructure solutions. The venture started as a bootstrap start-up in 2010 by focusing on making the internet faster and more powerful. WineSOFT’s knowledge is based on the expertise of TCP/IP, VPN, SS...
WebRTC is the future of browser-to-browser communications, and continues to make inroads into the traditional, difficult, plug-in web communications world. The 6th WebRTC Summit continues our tradition of delivering the latest and greatest presentations within the world of WebRTC. Topics include voice calling, video chat, P2P file sharing, and use cases that have already leveraged the power and convenience of WebRTC.
SYS-CON Events announced today that App2Cloud 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. App2Cloud is an online Platform, specializing in migrating legacy applications to any Cloud Providers (AWS, Azure, Google Cloud).
When shopping for a new data processing platform for IoT solutions, many development teams want to be able to test-drive options before making a choice. Yet when evaluating an IoT solution, it’s simply not feasible to do so at scale with physical devices. Building a sensor simulator is the next best choice; however, generating a realistic simulation at very high TPS with ease of configurability is a formidable challenge. When dealing with multiple application or transport protocols, you would be...
An increasing number of companies are creating products that combine data with analytical capabilities. Running interactive queries on Big Data requires complex architectures to store and query data effectively, typically involving data streams, an choosing efficient file format/database and multiple independent systems that are tied together through custom-engineered pipelines. In his session at @BigDataExpo at @ThingsExpo, Tomer Levi, a senior software engineer at Intel’s Advanced Analytics ...
Internet-of-Things discussions can end up either going down the consumer gadget rabbit hole or focused on the sort of data logging that industrial manufacturers have been doing forever. However, in fact, companies today are already using IoT data both to optimize their operational technology and to improve the experience of customer interactions in novel ways. In his session at @ThingsExpo, Gordon Haff, Red Hat Technology Evangelist, shared examples from a wide range of industries – including en...
Detecting internal user threats in the Big Data eco-system is challenging and cumbersome. Many organizations monitor internal usage of the Big Data eco-system using a set of alerts. This is not a scalable process given the increase in the number of alerts with the accelerating growth in data volume and user base. Organizations are increasingly leveraging machine learning to monitor only those data elements that are sensitive and critical, autonomously establish monitoring policies, and to detect...
"We're a cybersecurity firm that specializes in engineering security solutions both at the software and hardware level. Security cannot be an after-the-fact afterthought, which is what it's become," stated Richard Blech, Chief Executive Officer at Secure Channels, in this SYS-CON.tv interview at @ThingsExpo, held November 1-3, 2016, at the Santa Clara Convention Center in Santa Clara, CA.
To get the most out of their data, successful companies are not focusing on queries and data lakes, they are actively integrating analytics into their operations with a data-first application development approach. Real-time adjustments to improve revenues, reduce costs, or mitigate risk rely on applications that minimize latency on a variety of data sources. Jack Norris reviews best practices to show how companies develop, deploy, and dynamically update these applications and how this data-first...
Intelligent Automation is now one of the key business imperatives for CIOs and CISOs impacting all areas of business today. In his session at 21st Cloud Expo, Brian Boeggeman, VP Alliances & Partnerships at Ayehu, will talk about how business value is created and delivered through intelligent automation to today’s enterprises. The open ecosystem platform approach toward Intelligent Automation that Ayehu delivers to the market is core to enabling the creation of the self-driving enterprise.
The question before companies today is not whether to become intelligent, it’s a question of how and how fast. The key is to adopt and deploy an intelligent application strategy while simultaneously preparing to scale that intelligence. In her session at 21st Cloud Expo, Sangeeta Chakraborty, Chief Customer Officer at Ayasdi, will provide a tactical framework to become a truly intelligent enterprise, including how to identify the right applications for AI, how to build a Center of Excellence to ...
SYS-CON Events announced today that Massive Networks 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. Massive Networks mission is simple. To help your business operate seamlessly with fast, reliable, and secure internet and network solutions. Improve your customer's experience with outstanding connections to your cloud.
Because IoT devices are deployed in mission-critical environments more than ever before, it’s increasingly imperative they be truly smart. IoT sensors simply stockpiling data isn’t useful. IoT must be artificially and naturally intelligent in order to provide more value In his session at @ThingsExpo, John Crupi, Vice President and Engineering System Architect at Greenwave Systems, will discuss how IoT artificial intelligence (AI) can be carried out via edge analytics and machine learning techn...