我可以使用JAXB拦截XML解析来检查有效负载吗?
我使用java的GetListItems
工具为SharePoint WSDL生成了代码绑定。我在SharePoint中调用名为Character reference "&#])
的SOAP方法,生成的代码正在为我从服务器返回的XML解析。
那个解析失败了;它是一个known issue in SharePoint,用户可以将特殊字符放在某些破坏SharePoint正在生成的XML的东西上。
这个堆栈跟踪给出了提示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
(注意那里没有关闭的双引号) - 我现在最好的猜测是那里有一个不可打印的字符或XML中的一些时髦的东西正在破坏解析。修复它首先要了解更多关于它是如何发生的。建议?
{{1}}
答案 0 :(得分:1)
您可以在客户端中打开SOAP消息的日志记录。例如,见 Tracing XML request/responses with JAX-WS登录控制台。
答案 1 :(得分:0)
您可以使用像WireShark这样的数据包分析器来查看XML中的内容。添加像'host www.whatever.com'这样的过滤器,您将能够看到XML有效负载。它将与HTTP代码在同一消息中。