5

I am using Metro to invoke a SOAP web service. I am receiving a SOAP response with an invalid character reference in the body from a server I have no control over. I want to fix the XML before Metro unmarshals it and throws an exception to my client. Is this possible?

I've tried adding a LogicalHandler and a SOAPHandler but both of them throw the same unmarshal exception when I try to get the payload (failing in LogicalMessage.getPayload() and SOAPMessageContext.getMessage() respectively). The handlers work fine giving me access to the messages when the responses don't have invalid XML.

Here is what the exception looks like:

com.sun.xml.internal.ws.encoding.soap.DeserializationException: Failed to read a response: javax.xml.bind.UnmarshalException
 - with linked exception:
[javax.xml.stream.XMLStreamException: ParseError at [row,col]:[7,2653]
Message: Character reference "&#]
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamException(UnmarshallerImpl.java:421)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:357)
at com.sun.xml.internal.bind.v2.runtime.BridgeImpl.unmarshal(BridgeImpl.java:109)
at com.sun.xml.internal.bind.api.Bridge.unmarshal(Bridge.java:222)
at com.sun.xml.internal.ws.client.sei.ResponseBuilder$DocLit.readResponse(ResponseBuilder.java:539)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:110)
... 41 more
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[7,2653]
Message: Character reference "&#
at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:598)
at com.sun.xml.internal.ws.util.xml.XMLStreamReaderFilter.next(XMLStreamReaderFilter.java:81)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:182)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:355)

Is there a way I can get the raw payload, fix it and substitute it back and carry on?

2
  • Did the answer helped you? If so, consider to accept it, if not, leave a comment and I may try to help you further.
    – lpinto.eu
    Apr 17, 2015 at 16:20
  • Did you find the solution, I'm searching on it but didn't find anything yet however SOAPUI handle response and show data correctly. May 16, 2016 at 12:38

2 Answers 2

1

I think you can. Please see the folowwing links, for some related questions, it seems theres are some pointer there. If you can't fix the xml and carry on, you can always create a custom unmarshall.

Getting raw XML response from Java web service client

Is it possible to get the raw XML payload using Metro web services framework?

0

nope, your answer doesn't help. Both of them point to obtaining the raw XML AFTER it attemps deserialization, and that is where the problem lies. so no go.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.