VMware {code} Community
jguereca
Contributor
Contributor

Session not Authenticated - Client received SOAP Fault from server

Hello, 

I am attempting to retrieve HostSystem and VirtualMachine data with the web services API after using the vimport.login() method. I seem to be logging in just fine and retrieving the ServiceContent without error but when I make my API call to retrieve data, I receive the following error

Client received SOAP Fault from server: The session is not authenticated. Please see the server log to find more detail regarding the exact cause of the failure. 

I tried looking through the logs but did not find anything associated with that error. I was initially suspecting that I needed to add a cookie. I found an example in the web services guide for retrieving a cookie from the response headers from the RequestContext as shown below but no "Set-cookie" header exists

requestContext = ((BindingProvider) vimPort).getResponseContext();
headers = (Map<String, Object>) requestContext.get(MessageContext.HTTP_RESPONSE_HEADERS);
List cookies = (List) headers.get("Set-cookie");

Any help would be great!

Reply
0 Kudos
1 Reply
jguereca
Contributor
Contributor

UPDATE

I was able to retrieve the "Set-cookie" from the responseContext after using the _vimport.login() method and not before as the example code suggests.

I am using the following code to add the cookie to the requestContext headers but I am still receiving the same SOAP Fault error

Map<String, Object> responseContext = ((BindingProvider) _vimPort).getResponseContext();

headers = (Map<String, Object>) responseContext.get(MessageContext.HTTP_RESPONSE_HEADERS);

List cookies = (List) headers.get("Set-cookie");

String cookieValue = (String) cookies.get(0);

StringTokenizer tokenizer = new StringTokenizer(cookieValue, ";");

cookieValue = tokenizer.nextToken(); String path = "$" + tokenizer.nextToken();

String cookie = "$Version=\"1\"; " + cookieValue + "; " + path;

// set the cookie in the new request header Map<String, List> reqHeadrs = new HashMap<>();

reqHeadrs.put("Cookie", Collections.singletonList(cookie));

// Add session cookie back into the request context Map<String, Object> reqContext =  ((BindingProvider) _vimPort).getRequestContext(); reqContext.put(MessageContext.HTTP_REQUEST_HEADERS, reqHeadrs);

Reply
0 Kudos