Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any workaround for ignoring unexpected elements in Apache 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?

Problem Definition

For instance;

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- Is good to see that response is parsable when we get like this:

<?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>

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="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>

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 ... "

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.

like image 570
veysiertekin Avatar asked Nov 13 '14 11:11

veysiertekin


People also ask

What is WSDD file in Web services?

wsdd file. The wsdd stands for Web service description file. It is an XML file used by the Axis engine. It contains definitions of the Web services that Axis deploys from your Web application.

What is the use of Apache Axis in Web services?

Apache Axis2/C can be used to provide and consume WebServices. It has been implemented with portability and ability to embed in mind, hence could be used as a Web services enabler in other software. Rampart is the security module of Axis2.

What is Axis SOAP?

Introduction. Apache Axis is an implementation of the SOAP ("Simple Object Access Protocol") submission to W3C. From the draft W3C specification: SOAP is a lightweight protocol for exchanging structured information in a decentralized, distributed environment.


Video Answer


1 Answers

We always go through this hell due to bad vendors writing these services.

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:

  1. 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
  2. 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());

Have this:

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.

like image 93
abdelrahman-sinno Avatar answered Oct 26 '22 01:10

abdelrahman-sinno