vey*_*kin 16 java axis soap web-services
在2012年为Apache Axis 2 "Apache AXIS忽略/跳过解析附加元素"之前询问了这个问题.对于Axis 1.4,还没有解决方法吗?
问题定义
例如;
1-在开发[使用Axis 1.4 ] 时,我们的wsdl中有一个soap响应定义('ResponseGetCustomerInfo'):
...
<xs:element name="ResponseGetCustomerInfo">
<xs:complexType>
<xs:sequence>
<xs:element ref="ns1:CustomerID"/>
<xs:element ref="ns1:CustomerUsername"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="CustomerID" type="xs:integer"/>
<xs:element name="CustomerUsername" type="xs:string"/>
...
Run Code Online (Sandbox Code Playgroud)
2-当我们得到这样的结果时,很高兴看到响应是可解析的:
<?xml version="1.0" encoding="utf-8" ?>
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<ResponseGetCustomerInfo xmlns="http://tempUri.org/">
<CustomerID>1</CustomerID>
<CustomerUsername>raki</CustomerUsername>
</ResponseGetCustomerInfo>
</soap:Body>
</soap:Envelope>
Run Code Online (Sandbox Code Playgroud)
3-一段时间后,我们的服务提供商更改了服务响应并将新的输出字段添加到响应中,我们不知道何时或为何 ;
<?xml version="1.0" encoding="utf-8" ?>
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<ResponseGetCustomerInfo xmlns="http://tempUri.org/">
<CustomerID>1</CustomerID>
<CustomerUsername>raki</CustomerUsername>
<CustomerName>Raki</CustomerName>
<CustomerSurname>Bandao</CustomerSurname>
</ResponseGetCustomerInfo>
</soap:Body>
</soap:Envelope>
Run Code Online (Sandbox Code Playgroud)
4-新的响应在理论上与旧版本兼容,因为没有字段既没有删除也没有改变.但Axis无法解析响应:
"SAXException: Invalid Element ... "
Run Code Online (Sandbox Code Playgroud)
我不想更新wsdl并再次重新生成Web服务客户端.那么,有没有办法在响应中跳过"意外的[新添加的]元素"?或任何解决方法?
我正在尝试很多方法,但还没有找到任何解决方案.
由于编写这些服务的不良供应商,我们总是经历这个地狱。
因此,不幸的是,没有办法使用WSDL2JAVA的参数,但是有一个解决方法,您将至少重新生成一次存根:
xs:sequence用。。。来代替xs:all。这允许以任何顺序返回元素,并有助于修复很多情况,以及生成的存根代码,这使得步骤更容易while(!reader.isStartElement() && !reader.isEndElement())
reader.next();
if(reader.isStartElement())
// A start element we are not expecting indicates a trailing invalid
// property
throw new org.apache.axis2.databinding.ADBException("Unexpected subelement " + reader.getLocalName());
Run Code Online (Sandbox Code Playgroud)
拥有这个:
while(!reader.isStartElement() && !reader.isEndElement())
reader.next();
// if(reader.isStartElement())
// A start element we are not expecting indicates a trailing invalid
// property
// The below is commented, to prevent unexpected result parameters from causing an exception
// (As well as the condition above is removed)
// throw new org.apache.axis2.databinding.ADBException("Unexpected subelement " + reader.getLocalName());
Run Code Online (Sandbox Code Playgroud)
它经过测试,效果至少比没有解决方案要好。
| 归档时间: |
|
| 查看次数: |
7232 次 |
| 最近记录: |