JAX-WS client: maintain session/cookies across multiple services

前端 未结 2 2062
渐次进展
渐次进展 2020-12-05 16:08

I\'m using Netbeans to automatically create webservice clients based off WSDL files. This works well, except the webservices I\'m using require that I pass in a custom cooki

2条回答
  •  死守一世寂寞
    2020-12-05 16:35

    I've found a solution.

    You can get response headers using this after you've made the call:

    ((BindingProvider)port).getResponseContext().get(MessageContext.HTTP_RESPONSE_HEADERS);
    

    Find the Set-Cookie header and store its value.

    Then before your next request (in any webservice) you can set the Cookie header:

    ((BindingProvider)port).getRequestContext().put(
                MessageContext.HTTP_REQUEST_HEADERS,
                    Collections.singletonMap("Cookie", Collections.singletonList(cookieValue)
                )
            );
    

提交回复
热议问题