6

We consume the web service of third party. Whenever they update the XML schema like add the new element we got the following error message.

"SAXException: Invalid Element ... "

Is there any way in AXIS to ask skip the additional element received on XML while parsing it?

I have generated web service client using AXIS earlier i used to receive XML as below

<Flight>
   <AirlineCode>AB</AirlineCode> 
</Flight>

and everything was working fine. But now i am getting an additional tag in response.

<Flight>
   <AirlineCode>AB</AirlineCode> 
   <OtherCode>XX</OtherCode> 
</Flight>

And for that i am getting "Invalid Element" Exception.

Thanks

Machavity
  • 30,841
  • 27
  • 92
  • 100
Ankur Raiyani
  • 1,509
  • 5
  • 21
  • 49
  • Share snapshot of your code and response XML you receive. – Rahul Agrawal Sep 26 '12 at 08:30
  • You can always use the WSDL provided and regenarate your classes based on the new WSDL or even better maintain a "backwards compatibility" scheme based on the delivered WSDL version (for this to work there should be a relevant tag in the response indicating the server's version. – pankar Sep 26 '12 at 08:35
  • @Rahul: I have included my question. – Ankur Raiyani Sep 26 '12 at 12:17

2 Answers2

3

Apache Axis2 version 1.7.0-SNAPSHOT has the ability to ignore unexpected elements by compiling with the -Eiu switch.

Downloads for 1.7.0-SNAPSHOT

IvanRF
  • 7,115
  • 5
  • 47
  • 71
Daniel
  • 855
  • 10
  • 21
0

Daniel's answer should help, but be aware that the output you get from Axis2 is very different from what you get from Axis so you will probably have to rewrite your integration somewhat. Also, the link he provided is for a subset of Axis2.

You're going to need the whole shebang for it to work and that's available here since, as of this writing, I couldn't find this release managed on any maven repositories: https://repository.apache.org/content/groups/snapshots/org/apache/axis2/axis2/1.7.0-SNAPSHOT/

Because this version is not managed in maven right now figuring out the dependencies is a big pain. Here's a snapshot of the gradle dependencies I used:

compile 'org.apache.ws.commons.schema:XmlSchema:1.4.7'
compile 'org.apache.ws.commons.axiom:axiom-api:1.2.15'
compile 'org.apache.neethi:neethi:3.0.1'
compile 'axis:axis-wsdl4j:1.6.3'
compile 'commons-logging:commons-logging:1.1.1'
compile files('C:\\temp\\wsdl\\axis2-1.7.0-SNAPSHOT.jar', 'C:\\temp\\wsdl\\axiom.jar')
compile group: 'commons-collections', name: 'commons-collections', version: '3.2'

The axiom dependency was something I had to download manually because trying to use the repository managed version was not working for reasons that aren't clear to me.

All this aside, if you're not married to the Axis technology stack I would recommend avoiding it and instead integrating with a dynamic WSDL to Java framework that can accommodate WebServices whose Schema structure could change.

IcedDante
  • 6,145
  • 12
  • 57
  • 100
  • "I couldn't find this release managed on any maven repositories" Well, the link actually points to a Maven repository. Probably you mean that you didn't find it in the Maven central repository. That's excpected, since it's not a release, but a snapshot, as implied by the "-SNAPSHOT" in the version number... – Andreas Veithen Aug 31 '15 at 17:58
  • "The axiom dependency was something I had to download manually because trying to use the repository managed version was not working for reasons that aren't clear to me." That's because you only added "axiom-api", and not "axiom-impl" (The latter should be added as a dependency in scope "runtime"). – Andreas Veithen Aug 31 '15 at 18:00
  • I did mean the maven central repository. But that also doesn't change the fact that the link you provided is only part of the Axis library. I don't know what these ridiculous downvotes are all about – IcedDante Aug 31 '15 at 18:19
  • I didn't provide any link. I was referring to the link you posted in your answer. That link actually points to an uber-JAR which is a partial aggregation of various Axis2 components, but if you take a closer look, you will see that the repository of course contains all artifacts. – Andreas Veithen Aug 31 '15 at 22:15
  • Sorry, by link "you" provided I was referring to the link posted in the accepted answer. Yes, the repository contains a jar for all the artifacts but you have to search for it. I linked to it directly. Again- I don't know why this was downvoted. I spent a long time trying to get this version running on my system and the documentation here will hopefully spare anyone else doing the same thing the headache of getting it setup – IcedDante Sep 06 '15 at 17:19
  • You spent a lot of time because you took the wrong approach. Just add https://repository.apache.org/content/groups/snapshots as a snapshot repository to your build and all dependencies will be downloaded automatically. – Andreas Veithen Sep 06 '15 at 21:48