artur
artur

Reputation: 1760

getting raw payload from JAX-WS service

Having a SOAP based web service with XML payload, how can I grab the XML payload of the service response in JAX-WS >2.0 client?

I can see how this question will be marked as duplicate, but bear with me.

It seems that the options are:

  1. Use Dispatch API. However this would require me to go low(er) level and create the request payload manually, which I want to avoid.

  2. Use handler infrastructure of the JAX-WS to grab the payload and possibly pass it via MessageContext property back to the client, but this will still unmarshall the XML into JAXB Object tree, which I want to avoid.

So, how can I:

  1. Call a web service using SEI - no messing with creating XML request from scratch
  2. Grab the 'RAW' XML response without the JAXB unmarshalling happening

Sounds simple enough, right?

Upvotes: 2

Views: 1917

Answers (1)

francesco foresti
francesco foresti

Reputation: 2043

Among the non-goals the JAX-WS 2 specification says that 'Pluggable data binding JAX-WS 2.0 will defer data binding to JAXB[10]; it is not a goal to provide a plug-in API to allow other types of data binding technologies to be used in place of JAXB. However, JAX-WS 2.0 will maintain the capability to selectively disable data binding to provide an XML based fragment suitable for use as input to alternative data binding technologies.'

So, you should be able to have access to the raw payload.

The following example is also in the specification :

4.3.5.5 Asynchronous, Callback, Payload-Oriented

class MyHandler implements AsyncHandler<Source> {

...
public void handleResponse(Response<Source> res) {
Source resMsg = res.get();
// do something with the results
}
}
Source reqMsg = ...;
Service service = ...;
Dispatch<Source> disp = service.createDispatch(portName,
Source.class, PAYLOAD);
MyHandler handler = new MyHandler();
disp.invokeAsync(reqMsg, handler);

Since the specification also states that a Binding has its own HandlerChain (see chapter 9) you should be able to remove the JAXB handler from the chain, so that JAXB marshalling/unmarshalling doesn't get involved.

Upvotes: 1

Related Questions