Skip to main content

jaxws 2.1.3 - jaxb error when unmarshalling ws response

6 replies [Last post]
exgorth
Offline
Joined: 2007-09-05

Hello!!

I'm using jaxws 2.1.3 to generate and run as web service consumer.
I have a wsdl published by the 3rd party.
I've generated stubs and they are working: "simple" operations are invoked on service, consumer receive responses.

But when i'm receiving a certain response i'm getting an exception:
Caused by: java.lang.ArrayIndexOutOfBoundsException: -2
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startPrefixMapping(UnmarshallingContext.java:767)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at com.sun.xml.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startPrefixMapping(InterningXmlVisitor.java:81)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.handleStartElement(StAXStreamConnector.java:265)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:209)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:358)
at org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:213)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:138)
at com.sun.xml.bind.v2.runtime.BridgeImpl.unmarshal(BridgeImpl.java:120)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:125)
at com.sun.xml.bind.api.Bridge.unmarshal(Bridge.java:233)
at com.sun.xml.ws.client.sei.ResponseBuilder$DocLit.readResponse(ResponseBuilder.java:515)
at org.apache.maven.surefire.Surefire.run(Surefire.java:132)
at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:121)
at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:89)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:118)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:290)
at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:818)
at $Proxy41.getStopsAndQuotas(Unknown Source)
at ru.invito.ws.client.bronni.LoaderSoapAdapter$4.defineOperation(LoaderSoapAdapter.java:144)
at ru.invito.ws.client.bronni.LoaderSoapAdapter$4.defineOperation(LoaderSoapAdapter.java:142)
at ru.invito.ws.client.bronni.AbstractServiceOperation.service(LoaderSoapAdapter.java:356)

The message that jaxws tried to unmarshal is valid xml, but it does not get unmarshalled!

The strange thing that previously this client was implemented with xfire 1.2.4, that uses jaxb-api-2.0.jar, jaxb-impl-2.0.1.jar, jaxws-api-2.0.jar - and it unmarshalls this message without a problem.

I can use neither xfire-1.2.4, nor jaxws-2.0 because i cannot work with them in maven.

How to resolve this?
Please help!!

i'm using jaxws 2.1.3, java 1.5.0_12, maven-2.0.7

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
exgorth
Offline
Joined: 2007-09-05

anyone?

aldana
Offline
Joined: 2007-01-23

hi,

i've got the same problem. have you found a solution, yet?

thanks.

exgorth
Offline
Joined: 2007-09-05

Actually, i've found that usage of DefaultValidationEventHandler is deprecated for JAXB2.

As with the code..i've switched off this project, continue using xfire's wsgen and client classes to do work.

But i'm interested in subj, so if you post your problem code here, i'll try to resolve your problem.

kolmis
Offline
Joined: 2006-12-07
exgorth
Offline
Joined: 2007-09-05

Thanx, Kolmis. I'll pay an attention to this issue.

exgorth
Offline
Joined: 2007-09-05

I'm back with the details.

Actually i've found that it is a JAXB (as part of jaxws-2.1.3) error.
i've downloaded the xml myself, saved it to file "stopsResponse.xml",then constructed JAXBcontext, and invoked Unmarshaller and Marshaller back to anoter file.
The source was:


..othe child elements..
..othe child elements..

The resulting file was:


Then i've added a validator to the unmarsheller:
unmarshaller.setEventHandler(new javax.xml.bind.helpers.DefaultValidationEventHandler()); as suggested at https://jaxb.dev.java.net/guide/Unmarshalling_is_not_working__Help_.html

After that the stacktrace appeared:
[INFO] Surefire report directory: D:\home\invito\tasks\maven\invito\bronni\jax-ws\jax-ws-client\target\surefire-reports

-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running ru.invito.ws.client.bronni.JaxbTest
DefaultValidationEventHandler: [ERROR]: unexpected element (uri:"http://tourml.ru/products/2004-04-19", local:"header"). Expected elements are <{}sources>,<{}header>,<{}r
eferences>
Location: line 3
javax.xml.bind.UnmarshalException: unexpected element (uri:"http://tourml.ru/products/2004-04-19", local:"header"). Expected elements are <{}sources>,<{}header>,<{}refere
nces>
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:603)
at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:244)
at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:239)
at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportUnexpectedChildElement(Loader.java:116)
at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.childElement(Loader.java:101)
at com.sun.xml.bind.v2.runtime.unmarshaller.StructureLoader.childElement(StructureLoader.java:245)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:446)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:427)
at com.sun.xml.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:137)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:211)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:184)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:137)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:184)
at ru.invito.ws.client.bronni.JaxbTest.testGetStopsAndQuotasResponse(JaxbTest.java:43)

So it says that the expected order of child elements is:
<{}sources>,<{}header>,<{}references>

But when looking at schema i see:









The file that i've tried to unmarshall is valid instance of that schema.

Why does JAXB expectations are differ from schema?

PS. the full schema is here: http://touralliance.bronni.ru/Loader.asmx?WSDL