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.
Obtaining a Session Token - Code Fragments from VMPromoteDisks.java
.
.
.
private static String cookieValue = "";
private static Map headers = new HashMap();
.
.
.
private static void trustAllHttpsCertificates()
throws Exception {
javax.net.ssl.TrustManager[] trustAllCerts = new javax.net.ssl.TrustManager[1];
javax.net.ssl.TrustManager tm = new TrustAllTrustManager();
trustAllCerts[0] = tm;
javax.net.ssl.SSLContext sc = javax.net.ssl.SSLContext.getInstance("SSL");
javax.net.ssl.SSLSessionContext sslsc = sc.getServerSessionContext();
sslsc.setSessionTimeout(0);
sc.init(null, trustAllCerts, null);
javax.net.ssl.HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
}
...
private static void connect()
throws Exception {
HostnameVerifier hv = new HostnameVerifier() {
public boolean verify(String urlHostName, SSLSession session) {
return true;
}
};
trustAllHttpsCertificates();
HttpsURLConnection.setDefaultHostnameVerifier(hv);
SVC_INST_REF.setType(SVC_INST_NAME);
SVC_INST_REF.setValue(SVC_INST_NAME);
vimService = new VimService();
vimPort = vimService.getVimPort();
Map<String, Object> ctxt =
((BindingProvider) vimPort).getRequestContext();
ctxt.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
ctxt.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
serviceContent = vimPort.retrieveServiceContent(SVC_INST_REF);
headers =
(Map) ((BindingProvider) vimPort).getResponseContext().get(
MessageContext.HTTP_RESPONSE_HEADERS);
vimPort.login(serviceContent.getSessionManager(),
userName,
password, null);
isConnected = true;
propCollectorRef = serviceContent.getPropertyCollector();
rootRef = serviceContent.getRootFolder();
}
...