Yusuf
Yusuf

Reputation: 119

Get custom HTTP header (Cookie) using SOAP web service client in Netbeans

I am using the standard web service client in Netbeans. The SOAP server includes a Cookie as a HTTP header. How do I access this header/cookie from the client code?

I assume one method involves using a MessageHandler. I have added a Web Service Message Handler, and I have tried modifying the public boolean handleMessage(SOAPMessageContext messageContext) method, but I cant figure how to grab an HTTP header, and not a SOAPMessage.

I know how to add a custom header in the web service client, e.g. for Authentication, but I just dont know how to get a custom header in the client:

Authenticator.setDefault(new Authenticator() {
        @Override
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication("username", "Password".toCharArray());
        }

Upvotes: 1

Views: 2094

Answers (2)

Yusuf
Yusuf

Reputation: 119

The solution that I used was by using getResponseContext() to get a custom HTTP header:

 Map<String, Object> responseHeaders;
 responseHeaders = sourceDispatch.getResponseContext();
 Object cookie = responseHeaders.get("javax.xml.ws.http.response.headers");

This is nice and familiar because I had used getRequestContext to set a custom HTTP header.

Upvotes: 1

DmitryKanunnikoff
DmitryKanunnikoff

Reputation: 2266

Try to use:

SOAPConnection connection = IpspSOAPConnectionFactory.newInstance().createConnection();
SOAPMessage responseSoap = connection.call(requestSoap, webServiceUrl);
String[] someHeader = responseSoap.getMimeHeaders().getHeader(someHeaderName);

Upvotes: 0

Related Questions