忽略Apache Axis 1.4中的意外元素的任何解决方法?

编程入门 行业动态 更新时间:2024-10-22 15:21:47
本文介绍了忽略Apache Axis 1.4中的意外元素的任何解决方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在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:

  • 替换 xs:sequence with xs:all 。这允许以任何顺序返回元素,并且有助于修复很多情况,以及生成的存根代码,这使得步骤更容易
  • 对不起,但是对于每个响应bean,你从生成的代码(例如ResponseGetCustomerInfo.java)进入它的类,而不是这个:
  • Replace xs:sequence with xs:all. This allows elements to be returned in any order, and helps fix a lot of cases, as well as generated stub code which makes it easier for step
  • Sorry, but you for each response bean, you go into its class from the generated code (such as ResponseGetCustomerInfo.java), and instead of this:
  • 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中的意外元素的任何解决方法?

    本文发布于:2023-05-28 12:31:46,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/320966.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:词库加载错误:Could not find file &#039;D:\淘小白 高铁采集器win10\Configuration\Dict_Sto

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!