我有一个SOAP响应,我想将其解析为SOAPApplicationResult对象。我已成功从响应中获取类型NS1和NS2,但在从响应中解除部分NS3类型的同时遇到问题。 下面是我用来解除deseralize和SOAP响应的代码。
String fileName = "com/servicebus/thirdparty/response.xml";
String response = SystemUtil.loadFileAsString(fileName);
org.apache.axis.server.AxisServer server = new org.apache.axis.server.AxisServer();
MessageContext msgContext = new MessageContext(server);
registerMessage(msgContext);
java.io.Reader reader = new java.io.StringReader(response);
DeserializationContext dser = new DeserializationContext(new org.xml.sax.InputSource(reader), msgContext,
Message.RESPONSE);
dser.parse();
SOAPEnvelope env = dser.getEnvelope();
RPCElement rpcElem = (RPCElement) env.getFirstBody();
MessageElement struct = rpcElem.getRealElement();
Iterator childElements = struct.getChildElements();
while (childElements.hasNext())
{
org.apache.axis.description.ParameterDesc param;
MessageElement next = (MessageElement) childElements.next();
SOAPApplicationResult objectValue = (SOAPApplicationResult) next.getValueAsType(new javax.xml.namespace.QName(
"SOAPApplicationResult","http://soap.xxxx.yyyy.com"), SOAPApplicationResult.class);
String serializeAxisObject = AxisObjectUtil.serializeAxisObject(objectValue, true, true);
}
当我从响应中删除OccupationLoading和PersonObjectList类型时,它会被deseralized但是这两个不起作用。它给出了错误" org.xml.sax.SAXException:com.webservices.thirdparty.generated.infexpert.SOAPPersonResult中的无效元素 - PersonObjectList"。我正在为NS2提供QName(新的javax.xml.namespace.QName(" SOAPApplicationResult"," http://soap.xxxx.yyyyy.com"))。看来我必须将多个QNames映射到上下文,但不知道该怎么做。
这是SOAP响应:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:NS1="urn:ABCDSoapProviderIntf-IABCDSOAPProvider">
<NS1:calculateResponse xmlns:NS2="http://soap.xxxx.yyyyy.com"
xmlns:NS3="http://soap.xxxx.zzzz.com/">
<return xsi:type="NS2:SOAPApplicationResult">
<ErrorMessage xsi:type="xsd:string" />
<Result xsi:type="xsd:string" />
<PersonResults xsi:type="SOAP-ENC:Array"
SOAP-ENC:arrayType="NS2:SOAPPersonResult[1]">
<item xsi:type="NS3:ABCDSoapPersonResult">
<ID xsi:type="xsd:string">1245245</ID>
<Result xsi:type="xsd:string">Doc</Result>
<RuleResults xsi:type="SOAP-ENC:Array"
SOAP-ENC:arrayType="NS2:SOAPRuleResult[1]">
<item xsi:type="NS2:SOAPRuleResult">
<Result xsi:type="xsd:string">Doc</Result>
<Notice xsi:type="xsd:string">A Document is required</Notice>
</item>
</RuleResults>
<ProductResults xsi:type="SOAP-ENC:Array"
SOAP-ENC:arrayType="NS2:SOAPProductResult[1]">
<item xsi:type="NS3:ABCDSOAPProductResult">
<Result xsi:type="xsd:string">Offer</Result>
<ID xsi:type="xsd:string">Some Id</ID>
<RuleResults xsi:type="SOAP-ENC:Array"
SOAP-ENC:arrayType="NS2:SOAPRuleResult[1]">
<item xsi:type="NS2:SOAPRuleResult">
<Result xsi:type="xsd:string">Offer</Result>
<Notice xsi:type="xsd:string">Standard</Notice>
<Reasons xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="NS2:SOAPReason[0]" />
</item>
</RuleResults>
<OccupationLoading xsi:type="NS3:SOAPPermanentLoading">
<BeginAfter xsi:type="xsd:int">0</BeginAfter>
<BeginEnd xsi:type="xsd:int">0</BeginEnd>
</OccupationLoading>
</item>
</ProductResults>
<PersonObjectList xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="xsd:string[2]">
<item>Z001</item>
<item>E6679</item>
</PersonObjectList>
</item>
</PersonResults>
</return>
</NS1:calculateResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>