Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are date and datetime supposed to be serialized SOAP (xml) messages

We are working on a building a java client with a third party SOAP Webservice, that is I have not access or control off server side code. We are just provided with the WSDL description file of the service. We are using Axis 1 (version 1.4 ).

We have run into following issue related to date vs datetime serialization and deserialization. The said wsdl defines two types DateTime and DateRange

<xs:element minOccurs="0" name="DateTime" type="xs:dateTime"/>
<xs:element minOccurs="0" name="DateRange">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="Start" type="xs:date"/>
      <xs:element name="End" type="xs:date"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

Where xs prefix denotes XML Schema, that is following is present

xmlns:xs="http://www.w3.org/2001/XMLSchema" 

The axis wsdl2java generates Java Objects whre datetime field is type to Calendar, and start, end fields are typed to java.util.Date

When serialization happens the start and end fields are serialized to yyyy-mm-dd format , for example 2014-02-01 But when the actual call is made to server side we recieve following response

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header/>
   <SOAP-ENV:Body>
      <SOAP-ENV:Fault>
         <faultcode>SOAP-ENV:Server</faultcode>
         <faultstring xml:lang="en">JiBX unmarshalling exception; nested exception is org.jibx.runtime.JiBXException: Missing 'T' separator in dateTime</faultstring>
      </SOAP-ENV:Fault>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

We used SOAP UI to build the request xml payload directly and observed if we pass just the date portion in start and end fields we get exact same response, while if we pass those two fields with time portion like a dateTime field it works, gives no fault message.

This when taken together with what I could gleam from XMLSchema documentation for xs:date and xs:dateTime , in particular lexical and canonical representation section, seems to imply that

  1. Axis based serialization of start and end field to just yyyy-mm-dd and ignoring the time portion is correct. And client side code generated conforms to WSDL provided to us.

  2. Server side code does not conform to WSDL provided to us, it expects a dateTime field rather than a date field.

  3. Since date and dateTime field are required to be serialized in different formats by the schema definition. The result it failure at server side when it attempts to de-serialize the message

To validate our hypothesis 1. we used Python's ZSI library to generate python stub and resulting xml from it.
Even that serializes start and end in yyyy-mm-dd format , with an additional 'Z' at the end. This again fails to get deserialized at server side, even though this serialization format conforms to xs:date as defined by XML Schema

<ns1:Start>2014-02-05Z</ns1:Start>

Can somebody confirm if hypothesis formed by us, based on observed behaviour, documentation and experiment with Python's ZSI is correct. Or if we are missing some detail

like image 688
Himanshu Avatar asked Mar 21 '23 16:03

Himanshu


1 Answers

Hm, you reason about your DateRange fields start and end, but the message is clearly about your DateTime field which requires (as XML schema says) a T-separator between date portion and time portion, not a space or any other char.

Please check how you serialize your DateTime field (not the start or end fields!). It must be in format "yyyy-MM-dd'T'HH:mm:ss".

like image 150
Meno Hochschild Avatar answered Apr 06 '23 03:04

Meno Hochschild