This example is based on the code in the ServiceManager and the SSOConnection Java classes from the com.vmware.vcloud.suite.samples.common package. The source files are located in the following vCloud Suite SDK for Java directory: VMware-vCloud-Suite-SDK-Java/client/samples/java.

This example uses the steps that are described in the Create a Web Services Session procedure.

import com.vmware.vim25.VimPortType;
import com.vmware.vim25.VimService;
import com.vmware.vsphere.samples.LoginByTokenSample;
import com.vmware.vim25.ServiceContent;
import com.vmware.vcloud.suite.samples.vim.helpers.VimUtil;

...

// Log in to the vSphere Web Services Endpoint and retrieve a session identifier.
SamlTokenElement tokenElement = ssoConnection.getSamlBearerTokenElement();
String sessionId = LoginByTokenSample.LoginUsingSAMLToken(tokenElement, vimUrl, null, null);
 
// Use the VimPortType and VimService objects from
// the vSphere Web Services API for accessing Web Services and  
// retrieve the request context.
VimService vimService = new VimService();
vimPortType vimPort = vimService.getVimPort();
 
// Add the retrieved session ID to the request context.
Map<String, Object> ctxt = ((BindingProvider) vimPort).getRequestContext();
ctxt.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, vimUrl);
ctxt.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
Map<String, List<String>> headers =
            (Map<String, List<String>>) ctxt.getMessageContext.HTTP_REQUEST_HEADERS);
  if (headers == null) {
     headers = new HashMap<String, List<String>>();
  }
headers.put(“Cookie”, Arrays.asList(vcSessionId);
ctxt.put(MessageContext.HTTP_REQUEST_HEADERS, headers);
 
// Use the session ID context when retrieving the ServiceContent object. 
// The ServiceContent object gives you access to a number of 
// server-side managed objects that represent vSphere services and components.
// For more information about the vSphere Web Services, 
// see the vSphere Web Services SDK Programming Guide documentation.
ServiceContent serviceContent = VimUtil.getServiceContent(vimPort);