Before the web service call I can bind the current cookie value to a Thread Local:
Code:
CookieHolder.setCookieValue("JSESSIONID=1234;");
(obviously I would get this ID from the HttpServletRequest)
and the call the webservice template
Code:
getWebServiceTemplate().sendSourceAndReceiveToResult . . .
and add an interceptor which does the following:
Code:
public class AddCookieHeaderInterceptor implements ClientInterceptor {
public boolean handleFault(MessageContext messageContext)
throws WebServiceClientException {
return true;
}
public boolean handleRequest(MessageContext messageContext)
throws WebServiceClientException {
TransportContext context = TransportContextHolder.getTransportContext();
CommonsHttpConnection connection = (CommonsHttpConnection )context.getConnection();
String cookieValue = CookieHolder.getCookieValue();
if(cookieValue!=null){
connection.getPostMethod().addRequestHeader("Cookie", cookieValue);
}
return true;
}
public boolean handleResponse(MessageContext messageContext)
throws WebServiceClientException {
return true;
}
}
This works but I can't help feeling there is a better way!!