jaxws 处理程序对错误响应的行为
我已经设置了一个 JAXWS 客户端并向其 Binding handlerChain 添加了 SoapHandler 实现。所有这一切都是为了在未按预期运行时查看原始服务响应。
当一切正常时,我的 handler.handleMessage() 被调用两次,一次用于请求,一次用于响应。
但是,当服务的响应是一些乱码的 XML 或更糟的情况时,我希望调用 handler.handleFault,但什么也没有发生。
以下是本例中相关堆栈跟踪的一部分:
com.sun.xml.internal.ws.streaming.XMLStreamReaderException: XML reader error: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1]
Message: Premature end of file.
com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.wrapException(XMLStreamReaderUtil.java:256)
com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.next(XMLStreamReaderUtil.java:84)
com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.nextContent(XMLStreamReaderUtil.java:99)
com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.nextElementContent(XMLStreamReaderUtil.java:89)
com.sun.xml.internal.ws.encoding.StreamSOAPCodec.decode(StreamSOAPCodec.java:164)
com.sun.xml.internal.ws.encoding.StreamSOAPCodec.decode(StreamSOAPCodec.java:292)
com.sun.xml.internal.ws.encoding.StreamSOAPCodec.decode(StreamSOAPCodec.java:118)
com.sun.xml.internal.ws.encoding.SOAPBindingCodec.decode(SOAPBindingCodec.java:278)
com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:180)
com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:83)
com.sun.xml.internal.ws.transport.DeferredTransportPipe.processRequest(DeferredTransportPipe.java:105)
com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fiber.java:587)
com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Fiber.java:546)
com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber.java:531)
com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Fiber.java:428)
com.sun.xml.internal.ws.client.Stub.process(Stub.java:211)
com.sun.xml.internal.ws.client.sei.SEIStub.doProcess(SEIStub.java:124)
com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:98)
com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:78)
com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:107)
我想获取交换的原始数据,该数据可能不是 XML,因为我的处理程序已经期望在其 context.getMessage().getSOAPPart() 中有一个很好的 XML,所以我不这样做认为这是要走的路。
我很想绕过 SOAP 堆栈并直接通过 HTTP 运行我的请求来获取数据,但发现这有点难看
我真的应该这样做吗?
I've setup a JAXWS client and added a SoapHandler implementation to its Binding handlerChain. All this in the hope of viewing the raw service response when it's not running as it should.
When everything is fine my handler.handleMessage() get called twice, once for the request and once for the response.
But when the service's response is some garbled XML or worse I would have hoped the handler.handleFault to be called but nothing happens.
Here is part of the relevant stacktrace in this case :
com.sun.xml.internal.ws.streaming.XMLStreamReaderException: XML reader error: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1]
Message: Premature end of file.
com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.wrapException(XMLStreamReaderUtil.java:256)
com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.next(XMLStreamReaderUtil.java:84)
com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.nextContent(XMLStreamReaderUtil.java:99)
com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.nextElementContent(XMLStreamReaderUtil.java:89)
com.sun.xml.internal.ws.encoding.StreamSOAPCodec.decode(StreamSOAPCodec.java:164)
com.sun.xml.internal.ws.encoding.StreamSOAPCodec.decode(StreamSOAPCodec.java:292)
com.sun.xml.internal.ws.encoding.StreamSOAPCodec.decode(StreamSOAPCodec.java:118)
com.sun.xml.internal.ws.encoding.SOAPBindingCodec.decode(SOAPBindingCodec.java:278)
com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:180)
com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:83)
com.sun.xml.internal.ws.transport.DeferredTransportPipe.processRequest(DeferredTransportPipe.java:105)
com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fiber.java:587)
com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Fiber.java:546)
com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber.java:531)
com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Fiber.java:428)
com.sun.xml.internal.ws.client.Stub.process(Stub.java:211)
com.sun.xml.internal.ws.client.sei.SEIStub.doProcess(SEIStub.java:124)
com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:98)
com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:78)
com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:107)
I would like to get the RAW data that's exchanged which might not be XML and since my handler already expect a nice XML in its context.getMessage().getSOAPPart() I don't think this is the way to go.
I'm tempted of bypassing the SOAP stack and running my request directly over HTTP to get the data, but find this a tiny-bit ugly
Should I really go that way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
AFAIK,无法以编程方式获取 JAX-WS 服务的原始数据流。
为了获取数据流,您需要将某种处理程序插入 HTTP(或其他)协议管道中。我确信有一些方法可以完成此任务,具体取决于您的 JAX-WS 实现和版本,但没有一个方法是 JAX-WS 标准的一部分。 (再次,AFAIK..)
如果您只是需要解决问题并且实际上只想记录来自 HTTP 管道的请求和响应,您可以使用此系统属性使 HTTP 传输管道记录流经它的所有内容:
AFAIK, there is no way to programmatically get the raw data stream for a JAX-WS service.
in order to get the data stream you would need to insert some kind of handler into the HTTP (or whatever) protocol pipe line. I'm sure there are ways to accomplish this depending on your JAX-WS implementation and version, but none are part of the JAX-WS standard. (again, AFAIK..)
if you are just needing to troubleshoot a problem and really just want to log the request and response from the HTTP pipeline, you can use this system property to cause the HTTP transport pipe to log everything that flows through it: