Java2WDSL & WSDL2Java - java.util.Date not handled consistently - Digizol6

Post Top Ad

Responsive Ads Here

Post Top Ad

Responsive Ads Here

Wednesday, July 16, 2008

Java2WDSL & WSDL2Java - java.util.Date not handled consistently

Java2WSDL and WSDL2Java tools in Axis (1.4) are pretty handy tools. Those help you to generate a WSDL from a java class as well as generating stubs/skeletons from a WSDL. But if you are dealing with java.util.Date fields in your code, you must pay some attention.

Java2WSDL

Consider the following java interface which uses java.util.Date as a return type as well as a method parameter.

public interface MyService {
public java.util.Date getNextDate();
public void updateLastRun(java.util.Date date);
}
When the Java2WDSL tool generates a WSDL for a class with a Date field, it will represent java.util.Date fields as dateTime fields in WSDL. The generated WSDL file would look as follows.

<?xml version="1.0" encoding="UTF-8" ?>
<wsdl:definitions targetNamespace="http://service"
xmlns:apachesoap="http://xml.apache.org/xml-soap"
xmlns:impl="http://service" xmlns:intf="http://service"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<!--WSDL created by Apache Axis version: 1.4-->
<wsdl:message name="setOpeningDateResponse">
</wsdl:message>
<wsdl:message name="setOpeningDateRequest">
<wsdl:part name="in0" type="xsd:dateTime" />
</wsdl:message>

<wsdl:message name="getOpenningDateResponse">
<wsdl:part name="getOpenningDateReturn" type="xsd:dateTime" />
</wsdl:message>
<wsdl:message name="getOpenningDateRequest">
</wsdl:message>

<!--rest of the content removed-->
</wsdl:definitions>
I have posted only a part of the WSDL which contains the messages. If you go through the above WSDL, you will see that both java.util.Date fields are represented as "dateTime" fields (type="xsd:dateTime").

WSDL2Java

Now we can generate the Java classes using our WSDL file. WSDL2Java tool will use the WSDL file and generate a set of classes for us. Following is the generated MyService class.

package service;

public interface MyService extends java.rmi.Remote {
public java.util.Calendar getOpenningDate()
throws java.rmi.RemoteException;
public void setOpeningDate(java.util.Calendar in0)
throws java.rmi.RemoteException;
}
See the difference? The generated MyService interface has java.util.Calendar fields instead of java.util.Date.

Since your binding implementation class implements this new interface, you will have some hard time in dealing with this data type changes. May be there's a quick fix which we don't see from here.

We tried this on Axis1.4 and did not try with Axis2.

Related Articles

No comments:

Post a Comment

Post Top Ad

Responsive Ads Here