Custom css

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.

org.apache.cxf.tools.wsdlto.WSDLToJava -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();
        proxyFactory.setServiceClass(VimPortType.class);
        proxyFactory.setAddress(url);
        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();
        conduit.getClient().setAutoRedirect(true);

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

        TrustManager[] simpleTrustManager = new TrustManager[] { new X509TrustManager() {
            public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                return null;
            }

            public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) {
            }

            public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) {
            }
        } };
        TLSClientParameters tlsParams = new TLSClientParameters();
        tlsParams.setTrustManagers(simpleTrustManager);
        tlsParams.setDisableCNCheck(true);
        conduit.setTlsClientParameters(tlsParams);

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() });
        tlsParams.setDisableCNCheck(true);
 

        conduit.setTlsClientParameters(tlsParams); 

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.

1 kommentar:

Install AWS VPN Client for openSUSE Tumbleweed

Code: curl https://d20adtppz83p9s.cloudfront.net/GTK/latest/awsvpnclient_amd64.deb -o awsvpnclient_amd64.deb sudo zypper in alien alien --t...