I'm using Spring Boot and Spring WS to authenticate into a SOAP service. The SOAP response includes a JSESSIONID cookie in the headers. I need to retrieve the value of that JSESSIONID from the server response HTTP headers, and then send it as a "Cookie" header in each my subsequent SOAP request.

I understand there is an answer to this at JSESSIONID and setting cookie for WebServiceTemplate, but that link is broken.

Any help you can provide would be greatly appreciated!

UPDATE: I've written this code:

public class MyHttpComponentsMessageSender extends HttpComponentsMessageSender {

    private final Logger log = LoggerFactory.getLogger(this.getClass());

    public WebServiceConnection createConnection(URI uri) throws IOException  {
        HttpComponentsConnection conn = (HttpComponentsConnection) super.createConnection(uri) ;

        HttpPost httpPost = conn.getHttpPost();

        Header[] headers = httpPost.getAllHeaders();

        for (Header header : headers)  {
            log.debug("header = {}", header);
        }

        HttpResponse httpResponse = conn.getHttpResponse();

        log.debug("httpResponse =  {}", httpResponse);

        return conn;
    }

}

and this:

        WebServiceTemplate webServiceTemplate = getWebServiceTemplate();

        webServiceTemplate.setMessageSender(new MyHttpComponentsMessageSender());

        response = 
            webServiceTemplate
            .marshalSendAndReceive("http://www.foo.com/endpoint?wsdl", request, new SoapActionCallback("http://www.foo.com/endpoint?wsdl"));

And I'm not seeing any headers in the response from which I can get the JSESSIONID cookie:

2019-05-05 07:24:22:213 DEBUG [main] MyHttpComponentsMessageSender - header = Accept-Encoding: gzip

2019-05-05 07:24:22:213 DEBUG [main] MyHttpComponentsMessageSender - httpResponse = null

How can I get the "Set-Cookie" header, or better yet, the Cookie[] from HttpClient from the server response?

0 Answers