Developing a client for VMware vSphere Web Services SDK using Apache CXF

1. Generating the client code from the wsdl

The documentation for the WSDLToJava tool is available at the Apache CXF homepage. -p com.vmware.vim25 /home/<username>/SDK/wsdl/vim25/vimService.wsdl

2. Instantiate a client where you can call the operations

        JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
        VimPortType vimPort = (VimPortType) proxyFactory.create();

3. Enable session management
Because of the way you login to the VMware vSphere Web Services it is necessary to maintain a session. To enable session management for the CXF client you need to add the following code.

        ((BindingProvider) vimPort).getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);

4. The client should be able to follow redirects to support httpsWithRedirect
        Client client = ClientProxy.getClient(vimPort);

        HTTPConduit conduit = (HTTPConduit) client.getConduit();

5. Get SSL to work
First run it so that it just trusts everybody.

        TrustManager[] simpleTrustManager = new TrustManager[] { new X509TrustManager() {
            public[] getAcceptedIssuers() {
                return null;

            public void checkClientTrusted([] certs, String authType) {

            public void checkServerTrusted([] certs, String authType) {
        } };
        TLSClientParameters tlsParams = new TLSClientParameters();

Now we know the web service part works.
Replace the TrustManager with one that have access to the relevant keystore to be sure your keystore contains the right certificates:

        TLSClientParameters tlsParams = new TLSClientParameters();
        tlsParams.setTrustManagers(new TrustManager[] { getTrustManager() });


That is it. Now a client for the vSphere web service SDK is ready and can start querying and manipulating a vSphere environment.

On this blog it is explained that one should include the all important cxf.xml. I haven't seen any need for that for this client.


Send en kommentar

Populære indlæg fra denne blog

FreeOTP icon fix on Android

Podcasts in UE Smart Radio

Connect to postgresql 9.2 server in openSUSE 13.2