XmlAnyElement lax = true SOAP UI 中的任何对象 returns 列表但是当使用 JAVA 中的服务时仅获取最后一个对象
XmlAnyElement lax = true any object returns list in SOAP UI but when consuming the service in JAVA get only the last object
我希望得到一个响应列表,但我只得到列表中预期的最后一项。我可能做错了什么?
Wsdl 部分:
<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>
类 生成了 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
}
我对服务的调用:
response.setReturnDocument(cdCommunicationLogSession().delTrackLogs(parameters);
我编组响应对象以查看响应:
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);
我得到的结果xml:
<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>
当我 运行 在 SOAP UI 中做同样的事情时,我得到一个响应列表,例如:
<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>
提前致谢:)
这是我在 wsdl 中所做的更改:
<s:complexType name="Element">
<s:sequence>
<s:any processContents="lax" maxOccurs="unbounded" minOccurs="1"/>
</s:sequence>
</s:complexType>
现在工作正常。
我希望得到一个响应列表,但我只得到列表中预期的最后一项。我可能做错了什么?
Wsdl 部分:
<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>
类 生成了 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
}
我对服务的调用:
response.setReturnDocument(cdCommunicationLogSession().delTrackLogs(parameters);
我编组响应对象以查看响应:
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);
我得到的结果xml:
<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>
当我 运行 在 SOAP UI 中做同样的事情时,我得到一个响应列表,例如:
<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>
提前致谢:)
这是我在 wsdl 中所做的更改:
<s:complexType name="Element">
<s:sequence>
<s:any processContents="lax" maxOccurs="unbounded" minOccurs="1"/>
</s:sequence>
</s:complexType>
现在工作正常。