As with other Web services, the vSphere Web service maintains session state for each client connection by using a token in the HTTP header to identify the session. The vSphere server returns a session token to the client in its response to the client connection request. Subsequent messages between client and server automatically include the token.Each of the stand-alone samples in the SDK\vsphere-ws\java\JAX-WS\samples\com\vmware\ uses the JAX-WS TrustAllTrustCertificates class, as discussed in Example: Obtaining a Session Token - Code Fragments from VMPromoteDisks.java to ignore certificates, obtain a session token, and then connect to the server.
Caution We do not recommend that you trust all certificates in a production environment. Instead, you can look at the sample code to see how the JAX-WS libraries are used when making the connection, but set up an SSL policy that allows connection only with trusted certificates.The steps for accessing any HTTP endpoint with JAX-WS bindings are listed at the beginning of Example: Obtaining a Session Token - Code Fragments from VMPromoteDisks.java. These steps include the vSphere Web Services SDK Server URL, vSphere server object, and variables.
1 In this example we use a TrustManager class to accept all certificates. This is not appropriate for a production environment. Production code should implement certificate support.
■ ManagedObjectReference for the ServiceInstance.
■ VimService object for access to the Web service.
■ VimPortType object for access to all of the methods defined in the vSphere API.
■ ServiceContent for access to the managed object services on the server.
4 Declare a host name verifier that will automatically enable the connection. The host name verifier is invoked during the SSL handshake.
1 Create a managed object reference for the ServiceInstance object on the server.
2 Create a VimService object to obtain a VimPort binding provider. The BindingProvider object provides access to the protocol fields in request/response messages. Retrieve the request context which will be used for processing message requests.The VimServiceLocator and VimPortType objects provide access to vSphere servers. The getVimPort method returns a VimPortType object that provides access to the vSphere API methods.
3 Store the Server URL in the request context and specify true to maintain the connection between the client and server. The client API will include the Server's HTTP cookie in its requests to maintain the session. If you do not set this to true, the Server will start a new session with each request.
4 The following code fragment from the SDK\vsphere-ws\java\JAX-WS\samples\com\vmware\vm\
VMPromoteDisks.java sample shows another implementation of the server connection. Review the stand-alone Java samples that are shipped with your vSphere Web Services SDK, and use similar code to get a session token for your client application.