4

Can I use JAXB to intercept XML parsing to inspect a payload?

I have generated code bindings for a SharePoint WSDL using java's wsimport tool. I'm calling a SOAP method called GetListItems in SharePoint, the generated code is doing the XML parsing for me that comes back from the server.

That parse is failing; it's a known issue in SharePoint that it's possible for users to put special characters in some things that breaks the XML that SharePoint is generating.

This stack trace gives the hint Character reference "&#]) (notice the lack of closing double quote there) - my best guess right now is there's a non-printable character or something funky in the XML that is busting the parse. Fixing it begins with knowing more about how it's happening. Suggestions?

com.sun.xml.internal.ws.encoding.soap.DeserializationException: [failed to localize] Failed to deserialize the response.(javax.xml.bind.UnmarshalException
 - with linked exception:
[javax.xml.stream.XMLStreamException: ParseError at [row,col]:[2399,354]
Message: Character reference "&#])
        at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:111)
        at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:77)
        at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:147)
        at com.sun.proxy.$Proxy45.getListItems(Unknown Source)
        at 
        (Snipped bits of my code's stack trace)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:483)
        at com.simontuffs.onejar.Boot.run(Boot.java:340)
        at com.simontuffs.onejar.Boot.main(Boot.java:166)
Caused by: javax.xml.bind.UnmarshalException
 - with linked exception:
[javax.xml.stream.XMLStreamException: ParseError at [row,col]:[2399,354]
Message: Character reference "&#]
        at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamException(UnmarshallerImpl.java:470)
        at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:402)
        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.db.glassfish.BridgeWrapper.unmarshal(BridgeWrapper.java:257)
        at com.sun.xml.internal.ws.client.sei.ResponseBuilder$DocLit.readResponse(ResponseBuilder.java:635)
        at com.sun.xml.internal.ws.client.sei.StubHandler.readResponse(StubHandler.java:243)
        at com.sun.xml.internal.ws.db.DatabindingImpl.deserializeResponse(DatabindingImpl.java:189)
        at com.sun.xml.internal.ws.db.DatabindingImpl.deserializeResponse(DatabindingImpl.java:276)
        at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:104)
        ... 14 more

2 Answers 2

1

You could turn on logging of SOAP messages in your client. See for instance Tracing XML request/responses with JAX-WS to log to the console.

0

You could use a packet analyzer like WireShark to see what's in the XML. Add a filter like 'host www.whatever.com' and you'll be able to see the XML payload. It will be in the same message as the HTTP code.

4
  • This doesn't really answer the question. This would tell me exactly what's wrong with the XML but I'd still be stuck. Jun 20, 2015 at 14:11
  • From the article you linked, The resolution was to change the Title field and remove the offending character. So if you know what's breaking the XML you could change the content that is causing it (and theoretically do input validation on new content before it's saved there).
    – Chris
    Jun 22, 2015 at 13:20
  • This would fix one point issue, if I'm willing to do the work to find the point issue. There's no guarantee that it's only one point issue, the SharePoint library is very large (thousands of items) and changes regularly. Users lazy copy/paste from other apps, which is likely a source of bad unicode characters creeping in. This approach does let me fix errors, but only after my code breaks, one at a time, and manually. Would much rather intercept these and handle it differently. Jun 22, 2015 at 13:23
  • Well, it's one way you could do it. It sounds like your situation couldn't benefit from it (maybe you don't control when the data is entered into SharePoint), or you just prefer another way. That's fine.
    – Chris
    Jun 22, 2015 at 13:33

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.