Defining Timestamp for use in the WSDL

Hello,

I've created a simple java value object to test the different primary attributes that I will be using throughout my application which will be using web services.  This value object will also be used in an interface to pass data to the client in a web service.  
 
The value object is as follows:
 
public class InformationVO {
  private String name;
  private Integer Id;
  private Float price;
  private Timestamp creationDate;
  private Boolean inStock;
 
  ....
}
 
The interface is as follows:
 
pubic interface Information {
  public InformationVO[] getInformationList();
  public InformationVO getInformation(Integer id);
}
 
Problem:
 
When I run the java org.apache.axis.wsdl.Java2WSDL program for the Information interface I get the following error:

"The class java.sql.Timestamp is defined in java or javax package and cannot be converted into an xml schema type.  an xml schema anyType will be used to define this class in wsdl file."
 
I looked on line at http://ws.apache.org/axis/java/user-guide.html, under the topic of "Standard mappings from WSDL to Java" and found that xsd:dateTime maps to java.util.Calendar.  
 
I'm not sure how this will work since java.util.Calendar is an abstract class.  I wouldn't want to use GregorianCalendar all over the place when Timestamp will do just fine.  I use Timestamp all over the place.  Thus, there must be a way to map Timestamp to xsd:dateTime or create a custom serializer and de-serializer in order to use Timestamp.
 
Has any one run in to this issue?  

If so, what was your solution?
 
Thanks,

Hycel
HycelTaylorAsked:
Who is Participating?
 
objectsConnect With a Mentor Commented:
you need to define a custom mapping, specifying serialer/deserializer classes. Something like:

<typeMapping qname="ns:local" xmlns:ns="someNamespace"
    languageSpecificType="java:java.util.Timestamp"
    serializer="au.com.objects.TimestampSerializer"
    deserializer="au.com.objects.TimestampDeserializer"
    encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
0
 
CEHJCommented:
Simplest would be to use xsd:long:

private long creationDate;


...

creationDate = System.currentTimeMillis();
0
 
HycelTaylorAuthor Commented:
CEHJ

That's actually not a bad solution.  Still it would mean that I would need to modify all of my value objects that use Timestamp as well as the data access objects that use those value object and all of the business logic that surounds them.  

Do you not think that perhaps someone else has run in to this same problem and found a solution where Timestamp can still be used?  I am a little confused as to why the experts that defined the java specification for web services chose to use the java.util.Calendar class as the standard mapping for WSDL.  Below is a list of there mappings:

Standard mappings from WSDL to Java

xsd:base64Binary byte[]
xsd:boolean boolean
xsd:byte byte
xsd:dateTime java.util.Calendar
xsd:decimal java.math.BigDecimal
xsd:double double
xsd:float float
xsd:hexBinary byte[]
xsd:int int
xsd:integer java.math.BigInteger
xsd:long long
xsd:QName javax.xml.namespace.QName
xsd:short short
xsd:string java.lang.String

I just don't get it.  The java.sql.Timestamp is used by so many java programmers in there VO's.  I'm still of the belief that there is a mapping solution.  I'm just not sure how to go about it.  The documentation at http://ws.apache.org/axis/java/user-guide.html, is vague on this area.

Any other suggestion?
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
CEHJCommented:
Since is suspect this is all about serialization ultimately, you could override read/writeObject


private void writeObject(ObjectOutputStream oos)
    throws IOException {
  oos.defaultWriteObject();
  // Write/save additional fields
  oos.writeLong(creationDate.getTime());
}

declaring

private transient Timestamp creationDate;

but this is 'educated guesswork' on my part ;-)
0
 
HycelTaylorAuthor Commented:
Objects,

You are correct.  I just got back for the book store.  I picked up a book called, Building Web Services with Java.  I found out two major points:

The temporary solution I found was to use java.util.Date  Unlike the Axis web site, it has a table describing all of the compatible mappings.  java.util.Date happens to be one of them.  It's not in the list on the Axis website (go figure).
 
The permanent fix would be to write a custom Serializer and Deserializer for Timestamp.  On page 285 the before mentioned book, it says the following:

"
1. Write a Serializer implementation that takes an object of your Java type and writes the XML the way you like it using a SerializationContext.

2. Make sure the serializer writes a correct schema for the generated XML.

3. Write a simple factory implementation so that the engine can create instances of you serializer.  Look at any of the seralizer factories in the org.apache.axis.encoding.ser package for examples.  The SerializerFactory you build will be the class you refer to as the serializer component in WSDD type mappings and in the Call.registerTypeMapping() client APIs.
"

The first alternative, using java.util.Date is not the end of the world.  I would simply have to make minor adjustments to my DAOs and VOs.  Conversion between Timestamp and java.util.Date is not that major.
 
For example:
 
java.util.Date dt;
java.sql.Timestamp ts;
 
ts = new Timestamp(dt.getTime());
dt = new java.util.Date(ts.getTime());
 
I think this should work.
 
This may be the best solution because it java.util.Date maps to dateTime, thus making it useable by other none java platforms.
 
Thanks for the confermation.
0
 
objectsCommented:
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.