Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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 cookie in the HTTP header to every webservice in order to prove my identity.

I use one webservice named Utility to get my authorization. This sets a cookie which needs to be provided in all subsequent calls to any webservice.

This can be accomplished by setting javax.xml.ws.session.maintain to true on the BindingProvider of the port for the webservice. This works great for subsequent calls to the methods in the Utility webservice. The problem is that this only maintains the session/cookie for that single webservice. I need it across others as well.

I need the cookie passed in to a separate webservice named History How can I accomplish this? Is it feasible to have a super Service class which both Utility and History could extend and share the same session state with?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
343 views
Welcome To Ask or Share your Answers For Others

1 Answer

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)
            )
        );

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...