Inject the Session Cookie
Back Into the Request in Java
Before making another call to the server, inject
the session cookie back into the request as shown in the following example.
Inject the Session Cookie Back Into the
Request
// Step 5 Inject the session cookie back into the request once before // making another call to the server. JAXWS will maintain that cookie // for all subsequent requests. Map<String, Object> ctxt3 = ((BindingProvider) vimPort).getRequestContext(); ctxt3.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, vcServerUrl); ctxt3.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true); // One time setting of the cookie @SuppressWarnings("unchecked") Map<String, List<String>> headers = (Map<String, List<String>>) ctxt3.get(MessageContext.HTTP_REQUEST_HEADERS); if (headers == null) { headers = new HashMap<String, List<String>>(); } headers.put("Cookie", Arrays.asList(cookie)); ctxt3.put(MessageContext.HTTP_REQUEST_HEADERS, headers); // Authentication complete. Proceed with rest of the API calls // that are required for your functionality. return cookie; } }