Results 1 to 3 of 3
  1. #1
    CoAstroGeek is offline Member
    Join Date
    Sep 2008
    Posts
    1
    Rep Power
    0

    Arrow 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:

    Java Code:
     <xsd:element name="LaunchDate" type="xsd:date"/>
    Netbeans generates a class wrapping this XSD with all the needed getters & setters. With lots of extra stuff removed, it looks something like this...

    SatcatRecord.java
    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;
        }
    }
    I then implement the guts of the function which involves retrieving the data from the database and populating the SatcatRecord object.

    First question ... how do you declare/instantiate the XMLGregorianCalendar object??
    I have something like this:

    Java Code:
    XMLGregorianCalendar gregDate;
    gregDate = DatatypeFactory.newInstance().newXMLGregorianCalendar();
    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.

    Now I populate the gregDate object. Just take this simple example:

    Java Code:
    gregDate.setYear(1969);
    gregDate.setMonth(7);
    gregDate.setDay(16);
    I then use this value to populate the LaunchDate member of SatcatRecord as such:

    Java Code:
    org.netbeans.xml.schema.satcat.SatcatRecord record;
    record = new org.netbeans.xml.schema.satcat.SatcatRecord();
    record.setLaunchDate(gregDate);
    When I go to test the service, I end up with the following in the output record:

    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:

    Java Code:
                     record.setCountry(gregDate.toString());
    or
                     record.setCountry(gregDate.toXMLFormat());
    I get the expected output:

    Java Code:
    <ns3:Country>1969-07-16T00:00:00</ns3:Country>
    So ... why isn't my XMLGregorianDate object being properly translated into the date field in the returned XML?

    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.

  2. #2
    ian_scho is offline Member
    Join Date
    Dec 2009
    Posts
    1
    Rep Power
    0

    Default

    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)

  3. #3
    RogerP is offline Member
    Join Date
    Jan 2010
    Location
    UK
    Posts
    9
    Rep Power
    0

    Default

    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

  1. serialize to web service?
    By theartz in forum Advanced Java
    Replies: 2
    Last Post: 08-16-2008, 01:39 AM
  2. Setup RMI service on Ant
    By vaskarbasak in forum Advanced Java
    Replies: 0
    Last Post: 07-24-2008, 02:25 PM
  3. Web Service from JSP
    By Eric in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 07-02-2007, 05:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •