Search code examples
javaweb-servicessoapwsdlwsdl2java

XMLGregorianCalendar hours maximum negative integer on conversion to xs:date


I used cxf's wsdl2java to create the java stubs to use an external webservice and it uses dates as XMLGregorianCalendar, where in the wsdl they are xs:date. Having looked it up this does seem correct.

I am able to call the web service with no problems, but when I send a date, the copy of my request that comes with the response always has -2,147,483,648 in the hours, minutes, seconds and timezone fields, making my date very wrong! As the webservice is meant to be responding with data that matches my request, it is of course giving me the wrong information.

I am working on viewing what I actually send out (see Viewing SOAP request from Java client) but can't download any extra software and am having trouble with handlers. As far as debugging the java goes, I am not sending out these values from java, but I can't tell if it is a conversion issue in my generated java to soap request conversion or if it is at the external service.

Does anyone have any advice for debugging this problem, or has anyone seen this before with wsdl2java and XMLGregorianCalendar to xs:date?


Solution

  • Solved my own problem -

    The value -2,147,483,648 is also the value used by the constant DatatypeConstants.FIELD_UNDEFINED so in order to make my date match with the date used by the web service I had to set my time field in the XMLGregorianCalendar like so

    GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTime(date);
    XMLGregorianCalendar xmlDate =  DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar);   
    xmlDate.setMillisecond(DatatypeConstants.FIELD_UNDEFINED);  
    

    I was assuming that 0 would be equivalent to undefined, but that is not the case.