title: How to intercept XML parsing errors in JAXB processing of SOAP messages?
body: <p>Can I use JAXB to intercept XML parsing to inspect a payload?  </p>
  
  <p>I have generated code bindings for a SharePoint WSDL using java's <code>wsimport</code> tool.  I'm calling a SOAP method called <code>GetListItems</code> in SharePoint, the generated code is doing the XML parsing for me that comes back from the server.</p>
  
  <p>That parse is failing; it's a <a href="https://devspoint.wordpress.com/2011/03/28/ms-word-special-characters-may-break-sharepoint-web-services/" rel="nofollow">known issue in SharePoint</a> that it's possible for users to put special characters in some things that breaks the XML that SharePoint is generating. </p>
  
  <p>This stack trace gives the hint <code>Character reference "&amp;#])</code> (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?</p>
  
  <pre><code>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 "&amp;#])
          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 "&amp;#]
          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
  </code></pre>