Issath Khan
Issath Khan

Reputation: 11

Set HTTP Servlet Cookie from web service client

I want to set an http servlet cookie from a web service client and I want to check it on the server side for security purpose. I am using JAX-WS web service. I have tried the following code from client side. But it is not working for me. So please any one help me to solve this problem. Thank you.

((BindingProvider)webservicePort).getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY,true);
Map<String, Object> req_ctx = ((BindingProvider)webservicePort).getRequestContext();
Map<String, List<String>> headers = new HashMap<String, List<String>>();
headers.put("Cookie", Collections.singletonList("SAMPLE_COOKIE"));
req_ctx.put(MessageContext.SERVLET_REQUEST, headers);

Upvotes: 1

Views: 1714

Answers (1)

megala
megala

Reputation: 21

The Following code working fine. This will gives cookies on server side.

BindingProvider bindingProvider = (BindingProvider) Port;
        Map<String,Object> requestContext = bindingProvider.getRequestContext();
        Map<String, List<String>> requestHeaders = new HashMap<String, List<String>>();
        List<String> cookies = new ArrayList<String>();
        cookies.add("SMSESSION=testCookie");
        requestHeaders.put("Cookie", cookies);
        requestContext.put(MessageContext.HTTP_REQUEST_HEADERS, requestHeaders);

Upvotes: 1

Related Questions