This simple client
application accepts command-line arguments for the vSphere server name (DNS
name or IP address), user name, and password.
To build a simple vSphere client application in
Java, use the following steps.
Procedure
-
Import the vSphere Web Services API
libraries:
import com.vmware.vim25.*;
-
Import the necessary Java (and JAX-WS
connection, bindings, and SOAP) libraries:
import java.util.*;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSession;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.soap.SOAPFaultException;
-
Create the
TestClient
class:
public class TestClient {
-
Include the class variable
declarations/definitions. Use a
TrustManager
class to accept all certificates, as
shown in
Accessing the vSphere Web Services HTTP Endpoint with JAX-WS
. This is not appropriate for a production environment. Production code should
implement certificate support.
-
Use the vSphere Web Services APIs to create
the connection, as shown in
Accessing the vSphere Server from a Web Services Client.
-
Retrieve data from the vSphere or vCenter
Server. In this example, we are just going to print out the product name,
server type, and product version to prove that the client is connected and
working correctly.
System.out.println(serviceContent.getAbout().getFullName());
System.out.println("Server type is " + serviceContent.getAbout().getApiType());
System.out.println("API version is " + serviceContent.getAbout().getVersion());
-
Use the
VimPort object to close
the connection, as shown in
Closing the Connection from a Web Services Client.
Always close your server connections to maintain security.