javaweb-servicessoapwsdljava2wsdl

XmlAnyElement lax = true any object returns list in SOAP UI but when consuming the service in JAVA get only the last object


I expect a list in response but i am getting only the last item expected from the list. what could i be doing wrong?

Wsdl part:

<s:element name="delTrackLogsResponse">
    <s:complexType>
        <s:sequence>
            <s:element maxOccurs="1" minOccurs="1" name="returnDocument" type="tns:Element"/>
        </s:sequence>
   </s:complexType>
</s:element>
<s:complexType name="Element">
    <s:sequence>
        <s:any processContents="lax"/>
    </s:sequence>
</s:complexType>

Classes generated bu wsdl2java:

public class DelTrackLogsResponse {

    @XmlElement(required = true)
    protected Element returnDocument;
//followed by getters setters
}

public class Element {

    @XmlAnyElement(lax = true)
    protected Object any;
//followed by getters setters
}

My call to the service:

response.setReturnDocument(cdCommunicationLogSession().delTrackLogs(parameters);

I marshal the response object to view the response:

StringWriter stringWriter = new StringWriter();

JAXBContext jaxbContext = JAXBContext.newInstance(cd.communicationlog.Element.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();

// format the XML output
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

QName qName = new QName("cd.communicationlog", "trackLogsResponse");
JAXBElement<DelTrackLogsResponse> root = new JAXBElement<DelTrackLogsResponse>(qName,DelTrackLogsResponse.class, response);

jaxbMarshaller.marshal(root, stringWriter);

String result = stringWriter.toString();
log.debug("---- result xml: " + result);

The result xml i get:

<ns2:trackLogsResponse xmlns:ns2="com.sample.jaxb.model" xmlns="urn:cd:communicationLog">
    <returnDocument>
        <element clickFlag="0" deliveryDate="2017-02-23" deliveryLabel="xyz" deliveryType="Email" firstLogDate="N/A" openFlag="0"/>
    </returnDocument>
</ns2:trackLogsResponse>

Where as when i run the same thing in SOAP UI i get a list in response such as:

 <delTrackLogsResponse SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns="urn:cd:communicationLog">
         <returnDocument xsi:type="ns:Element" SOAP-ENV:encodingStyle="http://xml.apache.org/xml-soap/literalxml">
            <element deliveryLabel="abc" deliveryDate="2017-03-20" deliveryType="Email" firstLogDate="N/A" openFlag="0" clickFlag="0"/>
            <element deliveryLabel="abc" deliveryDate="2017-03-20" deliveryType="Email" firstLogDate="N/A" openFlag="0" clickFlag="0"/>
           .
           .
           .
           .
            <element deliveryLabel="xyz" deliveryDate="2017-02-23" deliveryType="Email" firstLogDate="N/A" openFlag="0" clickFlag="0"/>
            <element deliveryLabel="xyz" deliveryDate="2017-02-23" deliveryType="Email" firstLogDate="N/A" openFlag="0" clickFlag="0"/>
         </returnDocument>
 </delTrackLogsResponse>

Thanks in advance :)


Solution

  • Here is what I changed in the wsdl:

    <s:complexType name="Element">
           <s:sequence>
                 <s:any processContents="lax" maxOccurs="unbounded" minOccurs="1"/>
           </s:sequence>
    </s:complexType>
    

    Works fine now.