Skip to main content

Web services programming tips and tricks: Roundtrip issues, an introduction

Maintaining data integrity across JAX-RPC

Russell Butek (butek@us.ibm.com), Software Engineer, IBM
Russell Butek is one of the developers of the IBM WebSphere Web services engine. He is also an IBM representative on the JAX-RPC Java Specification Request (JSR) expert group. He was involved in the implementation of Apache's AXIS SOAP engine, driving AXIS 1.0 to comply with JAX-RPC 1.0. Previously, he was a developer of the IBM CORBA ORB and an IBM representative on a number of OMG task forces: the portable interceptor task force (of which he was chair), the core task force, and the interoperability task force.
Richard Scheuerle (scheu@us.ibm.com), Software Engineer, IBM
Richard Scheuerle is one of the developers of the IBM WebSphere Web Services engine. He was involved in the implementation of Apache's AXIS SOAP engine. Richard has 10 years of development experience with compiler/language design. Currently he is concentrating on the Web service engine performance and API design. Richard has also worked on the development of CORBA tooling and chip validation software.

Summary:  This tip introduces roundtripping, its definition, and its use. It begins to point out some roundtripping issues with the JAX-RPC specification. Subsequent tips will cover more issues in greater detail.

Date:  18 Mar 2004
Level:  Intermediate
Activity:  2213 views

This is the first of a series of tips on the topic of roundtripping. This tip introduces the notion of roundtripping and begins to hint at some problems with the existing JAX-RPC mapping rules. Once you understand what roundtripping is good for, subsequent tips will go into greater detail with issues.

Roundtripping is the process of mapping from one representation to another and back again. In the normal course of events, you would like to end up with what you started. For instance, take a number from the Arabic numeral system, such as 9. Map this number to the Roman numeral system. You end up with IX. Now map that back to the Arabic numeral system and you end up with, no surprise, 9.

But why is this no surprise? It is no surprise because the mapping from Arabic to Roman numerals, and back again, is what is mathematically known as one-to-one and onto. In short, for each Arabic numeral, there is one, and only one, Roman numeral which maps to it. The same is true for the mapping of Arabic to Roman numerals.

Or is it? What about the Arabic numeral 0? There is no mapping of Arabic 0 to a Roman numeral. So while it seems that there are no surprises, there really are.

Before I proceed, let me answer a question you might be asking: why do we care about roundtripping? I'll tell you. A typical Web services scenario is to take an existing application and expose it as a Web service. To do this in the Java world, first you generate a WSDL file from existing Java code (Java-to-WSDL). Then, from this WSDL file, you generate the Web services files (Java helper classes, deployment descriptors, etc.) for this service (WSDL-to-Java). Bundle all this stuff into an EAR file and you've got yourself a Web service of the original application. You started with a Java file, mapped it to WSDL, then mapped the WSDL back again to a Java file.

The above paragraph discusses the server side. Note that you do the WSDL-to-Java step on the client side as well, but that's not particularly interesting from a roundtrip point-of-view. You don't have Java code to start with on the client, so you didn't do the Java-to-WSDL step. It doesn't really matter if the client-side Java code is completely different from the server-side Java code. All that matters is that the messages which the client sends are acceptable to the server, and vice versa. So these roundtripping issues really only concern themselves with the server.

Note that so far I've discussed Java-to-WSDL-to-Java roundtripping. You could also consider WSDL-to-Java-to-WSDL roundtripping (which actually has many more problems). But you will seldom run across a use case for roundtripping beginning with WSDL. So I will stick with Java-to-WSDL-to-Java which, as shown in the previous paragraph, is a very common use case.

Things like zero

The Arabic numeral zero cannot map to the Roman numeral system. There are also things in Java language which do not map to WSDL, like objects which have behavior; for instance: InputStream, OutputStream, Class, Thread, etc. Keep in mind that Web services sends data across the wire, not Java objects -- after all, the receiver of a SOAP message might not be Java-based, and might not even be object-oriented.

The set of Java objects that cannot map to WSDL obviously cannot roundtrip back to Java types; so by their nature, there are no roundtrip issues with them. So I will not discuss them in this tip.


Things like nine

Java-to-WSDL/XML

When I'm talking about Java types mapping to WSDL, I really mean Java types mapping to XML schema which will be referenced by the WSDL. But it's easier to simply talk about the general case of WSDL, particularly when I discuss mapping things other than types. I refer to the whole set of issues as Java-to-WSDL-to-Java issues.

There is a large set of Java types which behave like the Arabic numeral nine, types which do map to WSDL. But even this set of Java-to-WSDL-mappable data types is not fully roundtrippable.

Most Java types in the Java-to-WSDL-mappable set map back to Java types just fine. For instance, Java code's int maps to the XML type xsd:int, and this maps back to Java code's int. Since most things roundtrip just fine, it is easy to fall into the trap of assuming that all things roundtrip just fine. But there is one problem type: java.util.Date.

java.util.Date

Java code's java.util.Date maps to XML schema's xsd:datetime. But then xsd:datetime maps back to Java code as java.util.Calendar. Why couldn't JAX-RPC map Date to xsd:date and then back to Date? And Calendar to datetime and back to Calendar? That would have cleared up this roundtrip issue, but there are two very good reasons this could not be done.

  1. Maintaining roundtrippability was not a goal of JAX-RPC.
  2. java.util.Date has more info than can be contained within an xsd:date type (time, for instance), so JAX-RPC uses an XML schema type that can hold all of the info: xsd:datetime.

How to deal with Date

Just say "no"

The easiest way around the issue of Date not roundtripping is simply to avoid it. Use java.util.Calendar instead because it does roundtrip. Besides, many of the Date methods have been deprecated in favor of Calendar methods, so you probably want a Calendar object anyway.

Write wrappers

Perhaps you cannot change the original API. Another alternative is to write wrapper code around the APIs that use Date. The wrapper code would be the Web service, and it would delegate all invocations to the real implementation. They are fairly simple to write. For example, given the original, unchangeable interface in Listing 1, you could write for it the wrapper in Listing 2.


Listing 1. Legacy API
package com.ibm.developerWorks.roundtrip;

public class Legacy {
    public void setDate(java.util.Date date) {...};
}



Listing 2. Web service wrapper around the original legacy application
package com.ibm.developerWorks.roundtrip;
public class Wrapper {
    private Legacy legacy = new Legacy();
    public void setDate(java.util.Calendar calendar) {
        legacy.setDate(calendar.getTime());
    }
}

Modify the mapping metadata file

Web services for J2EE (commonly referred to as JSR-109) defines a mapping metadata file which allows you to bypass some of the JAX-RPC mapping rules. Stay tuned for a future tip which will give some hints about modifying this mapping metadata file to get around roundtripping issues.

There are other roundtrip issues besides java.util.Date which I will cover in more detail in subsequent tips. Stay tuned for further roundtripping tips which will go into more details.


Summary

A typical Web services scenario is to take an existing application and expose it as a Web service. To do so, you will have to round trip from Java types to WSDL and back to Java types. In this roundtripping, the original constructs are not necessarily preserved. This tip showed that, if the original Java API contained java.util.Date, then the roundtrip resulting API will not match the original.

There are a number of ways to work around roundtrip issues: you could avoid them altogether; you could write Web service wrappers around the original implementation, or you could modify the mapping metadata file (though this tip did not go into details on the mapping metadata file).


Resources

About the authors

Russell Butek is one of the developers of the IBM WebSphere Web services engine. He is also an IBM representative on the JAX-RPC Java Specification Request (JSR) expert group. He was involved in the implementation of Apache's AXIS SOAP engine, driving AXIS 1.0 to comply with JAX-RPC 1.0. Previously, he was a developer of the IBM CORBA ORB and an IBM representative on a number of OMG task forces: the portable interceptor task force (of which he was chair), the core task force, and the interoperability task force.

Richard Scheuerle is one of the developers of the IBM WebSphere Web Services engine. He was involved in the implementation of Apache's AXIS SOAP engine. Richard has 10 years of development experience with compiler/language design. Currently he is concentrating on the Web service engine performance and API design. Richard has also worked on the development of CORBA tooling and chip validation software.

Comments (Undergoing maintenance)



Trademarks  |  My developerWorks terms and conditions

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=SOA and Web services, XML
ArticleID=11890
ArticleTitle=Web services programming tips and tricks: Roundtrip issues, an introduction
publish-date=03182004
author1-email=butek@us.ibm.com
author1-email-cc=
author2-email=scheu@us.ibm.com
author2-email-cc=

My developerWorks community

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Rate a product. Write a review.

Special offers