Results 1 to 3 of 3
- 09-18-2008, 12:00 AM #1
Member
- Join Date
- Sep 2008
- Posts
- 1
- Rep Power
- 0
Web Service from WSDL & XMLGregorianCalendar Issues
Hi folks,
Java newbie here, so don't discount the obvious answers!
I'm trying to create a web service to expose some orf our data. I wrote an XML schema & WSDL using the NetBeans tools, and then generated a web service from them. It's working well - except for an issue on the dates.
The XML schema (SatcatRecord.xsd) returned by the service includes several dates, which I cleverly chose to represent with the xsd:date type, as such:
Netbeans generates a class wrapping this XSD with all the needed getters & setters. With lots of extra stuff removed, it looks something like this...Java Code:<xsd:element name="LaunchDate" type="xsd:date"/>
SatcatRecord.java
I then implement the guts of the function which involves retrieving the data from the database and populating the SatcatRecord object.Java Code:public class SatcatRecord { @XmlElement(name = "LaunchDate", required = true) @XmlSchemaType(name = "date") protected XMLGregorianCalendar launchDate; public XMLGregorianCalendar getLaunchDate() { return launchDate; } public void setLaunchDate(XMLGregorianCalendar value) { this.launchDate = value; } }
First question ... how do you declare/instantiate the XMLGregorianCalendar object??
I have something like this:
I really don't know that that 2nd line is doing - I found it via a code search on google, but it seems to do the job.Java Code:XMLGregorianCalendar gregDate; gregDate = DatatypeFactory.newInstance().newXMLGregorianCalendar();
Now I populate the gregDate object. Just take this simple example:
I then use this value to populate the LaunchDate member of SatcatRecord as such:Java Code:gregDate.setYear(1969); gregDate.setMonth(7); gregDate.setDay(16);
When I go to test the service, I end up with the following in the output record:Java Code:org.netbeans.xml.schema.satcat.SatcatRecord record; record = new org.netbeans.xml.schema.satcat.SatcatRecord(); record.setLaunchDate(gregDate);
???Java Code:<ns3:LaunchDate>0001-02-05</ns3:LaunchDate>
But the gregDate object seems to be populated correctly - if I instead stuff the string representation into a string field in the same structure:
I get the expected output:Java Code:record.setCountry(gregDate.toString()); or record.setCountry(gregDate.toXMLFormat());
So ... why isn't my XMLGregorianDate object being properly translated into the date field in the returned XML?Java Code:<ns3:Country>1969-07-16T00:00:00</ns3:Country>
A few things I've tried...
Tried making the LaunchDate field in the XML schema a dateTime type instead of just date - same result.
Checked the XMLGregorianDate copy-constructor ... seems to be behaving properly.
Not sure where to go from here - any suggestions are welcome!
Oh ... FWIW:
Netbeans IDE 6.1
Sun Java Applications Server 9.1_02
All running on a 32bit Fedora Core 5 system.
- 12-18-2009, 10:45 AM #2
Member
- Join Date
- Dec 2009
- Posts
- 1
- Rep Power
- 0
It's not something to do with the fact that it's before 1970, is it? You'll get a negative long value for 1969.
http-->//java.sun.com/j2se/1.4.2/docs/api/java/util/Date.html#Date(long)
- 01-23-2010, 04:23 PM #3
Member
- Join Date
- Jan 2010
- Location
- UK
- Posts
- 9
- Rep Power
- 0
Probably you solved it by now. If not, is this what you want?
Java Code:/* * DateConverter.java * * Created on 30 March 2007, 17:02 * * To change this template, choose Tools | Template Manager * and open the template in the editor. */ package xyz; import java.util.Date; import java.util.GregorianCalendar; import javax.xml.datatype.XMLGregorianCalendar; /** * * @author RogerP */ public class DateConverter { protected Date date; /** Creates a new instance of DateConverter */ public DateConverter() { } public DateConverter(XMLGregorianCalendar xmlGregorianCalendar) { GregorianCalendar dateGreg = xmlGregorianCalendar.toGregorianCalendar(); this.date = dateGreg.getTime(); } }
Similar Threads
-
serialize to web service?
By theartz in forum Advanced JavaReplies: 2Last Post: 08-16-2008, 01:39 AM -
Setup RMI service on Ant
By vaskarbasak in forum Advanced JavaReplies: 0Last Post: 07-24-2008, 02:25 PM -
Web Service from JSP
By Eric in forum JavaServer Pages (JSP) and JSTLReplies: 2Last Post: 07-02-2007, 05:00 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks