在Apache AXIS忽略/跳过其他元素之前询问了此问题在2012年为Apache Axis 2解析时,Axis 1.4还没有解决方法吗?
The problem was asked before "Apache AXIS Ignore/Skip additional element while parsing" in 2012 for Apache Axis 2. Is there no workaround yet for Axis 1.4?
问题定义
例如;
1 - 我们有一个soap响应定义('ResponseGetCustomerInfo')在我们的wsdl开发时[使用 Axis 1.4 ]:
1- We have a soap response definition('ResponseGetCustomerInfo') in our wsdl while development[with Axis 1.4]:
... <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"/> ...2 - 很高兴见到这一点当我们得到这样的结果时,响应是可解析的:
2- Is good to see that response is parsable when we get like this:
<?xml version="1.0" encoding="utf-8" ?> <soap:Envelope xmlns:soap="schemas.xmlsoap/soap/envelope/" xmlns:xsi="www.w3/2001/XMLSchema-instance" xmlns:xsd="www.w3/2001/XMLSchema"> <soap:Body> <ResponseGetCustomerInfo xmlns="tempUri/"> <CustomerID>1</CustomerID> <CustomerUsername>raki</CustomerUsername> </ResponseGetCustomerInfo> </soap:Body> </soap:Envelope>3 - 一段时间后,我们的服务提供商更改了服务响应,为响应添加新的输出字段,我们不知道何时或为何;
3- After some time, our service provider changed the service response and adds new output fields to response and we don't know when or why;
<?xml version="1.0" encoding="utf-8" ?> <soap:Envelope xmlns:soap="schemas.xmlsoap/soap/envelope/" xmlns:xsi="www.w3/2001/XMLSchema-instance" xmlns:xsd="www.w3/2001/XMLSchema"> <soap:Body> <ResponseGetCustomerInfo xmlns="tempUri/"> <CustomerID>1</CustomerID> <CustomerUsername>raki</CustomerUsername> <CustomerName>Raki</CustomerName> <CustomerSurname>Bandao</CustomerSurname> </ResponseGetCustomerInfo> </soap:Body> </soap:Envelope>4 - 新响应理论上与旧版本兼容,因为没有删除或更改的字段。但是Axis无法解析响应:
4- New response theoretically compatible with older version because of no field neither deleted nor changed. But Axis can not parse the response:
"SAXException: Invalid Element ... "我不想更新wsdl并再次重新生成Web服务客户端 。那么,有没有办法在响应中跳过意外的[新添加的]元素?或者任何解决方法?
I don't want to update wsdl and regenerate web service client again. So, Is there any way to skip "Unexpected[newly added] elements" in the response? or any workaround?
我正在尝试很多方法,但还找不到任何解决方案。
I am trying many ways, but could not find any solution yet.
推荐答案由于供应商写这些服务,我们总是经历这个地狱。
We always go through this hell due to bad vendors writing these services.
所以,不幸的是,没有办法使用 WSDL2JAVA ,但有一个解决方法,你至少会重新生成一次存根:
So, unfortunately, there's no way out using parameters for WSDL2JAVA, BUT there is a workaround, you'll to re-generate stubs at least once:
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());
有这个:
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());它已经过测试,至少比没有解决方案更好。
It's tested and works at least better than no solution.
更多推荐
忽略Apache Axis 1.4中的意外元素的任何解决方法?
发布评论