Harry Potel
Harry Potel

Reputation: 83

Add SOAP Header to spring-ws 2.2.0 endpoint response

I need to build a webservice that includes a SOAP Header in the response with spring-ws.

My endpoint processes the request header, then returns the Element that will be the SOAP Body response.

What I need to do is to add a SOAP Header to that response, using the information from the request header.

The only way that I know how to do that is using an interceptor, but that way I don't know how to obtain the header object that I've unmarshalled from the request.

I'm using this way to write my endpoint, as I want to unmarshall and validate the header in my code:

public void handle(@RequestPayload DOMSource domSource, SoapHeader header)

However, the documentation also has this alternative

public void handle(@RequestPayload MyJaxb2Object requestObject, @RequestPayload Element element, Message messageContext)

But that doesn't work for me because I don't want to unmarshall the payload, only the header.

I'm using Spring-ws 2.2.0. http://docs.spring.io/spring-ws/docs/2.2.0.RELEASE/reference/htmlsingle/

Thanks a lot Regards

Upvotes: 0

Views: 1262

Answers (1)

Harry Potel
Harry Potel

Reputation: 83

Ok, so I found the solution to this problem.

Spring-WS will accept any arguments to your endpoint handling method that can resolve. There are many resolvers and you can create your own, however the one I needed existed already (MessageContextMethodArgumentResolver), I saw the code for this one and it was only checking by parameter class. My issue, was that I was using Message when I should be using org.springframework.ws.context.MessageContext instead.

Once I fixed that I was able to have the three parameters that I needed, the payload annotated with @RequestPayload, the SoapHeader and the MessageContext.

With all those things, I was able to set objects in the message context as properties. Then, I wrote an EndpointInterceptor and in the "handleResponse" method I've generated the SOAP Header using the information in my object.

Upvotes: 1

Related Questions