?
Solved

Defining Timestamp for use in the WSDL

Posted on 2004-08-02
7
Medium Priority
?
2,524 Views
Last Modified: 2008-03-10
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
0
Comment
Question by:HycelTaylor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 11695710
Simplest would be to use xsd:long:

private long creationDate;


...

creationDate = System.currentTimeMillis();
0
 

Author Comment

by:HycelTaylor
ID: 11696041
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 11696420
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 11699765
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
 
LVL 92

Assisted Solution

by:objects
objects earned 2000 total points
ID: 11699775
0
 

Author Comment

by:HycelTaylor
ID: 11699887
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
 
LVL 92

Expert Comment

by:objects
ID: 11699916
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question