Apache AXIS Ignore/Skip additional element while parsing
Asked Answered
P

2

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

Phytogeography answered 26/9, 2012 at 8:27 Comment(3)
Share snapshot of your code and response XML you receive.Dorathydorca
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.Nellenelli
@Rahul: I have included my question.Phytogeography
P
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

Pox answered 2/12, 2013 at 17:28 Comment(0)
P
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.

Pine answered 28/8, 2015 at 20:59 Comment(6)
"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...Bollinger
"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").Bollinger
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 aboutPine
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.Bollinger
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 setupPine
You spent a lot of time because you took the wrong approach. Just add repository.apache.org/content/groups/snapshots as a snapshot repository to your build and all dependencies will be downloaded automatically.Bollinger

© 2022 - 2024 — McMap. All rights reserved.