3

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?

user691154
  • 192
  • 2
  • 9

1 Answers1

2

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:

-Dcom.sun.xml.ws.transport.http.client.HttpTransportPipe.dump=true
Helter Scelter
  • 715
  • 4
  • 12
  • That is also a good way to solve the problem -- though it does assume that you can exactly re-create the request that your code is sending.. if you don't have a log of what your code is actually producing somewhere then you will have a hard time reproducing issues caused by bad input from your app. – Helter Scelter Dec 13 '11 at 17:20
  • That works in my case since there exists some 'default query' I can easily use to see if the remote end is working correctly. – user691154 Jan 17 '12 at 09:29
  • If you use the internal JAX-WS, i.e. the one provided with the JRE in rt.jar, you must use com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.dump=true (note the extra 'internal') as mentioned [in the answer to this question](http://stackoverflow.com/questions/5350476/tracing-xml-request-responses-with-jax-ws-when-error-occurs) . – Hok Feb 20 '14 at 09:23