Java Example of Connecting to the Lookup Service and Retrieving the Service Registration Object

The example is based on the code in the
LookupServiceHelper.java
sample file.
This example uses the steps that are described in the Connect to the Lookup Service and Retrieve the Service Registration Object procedure.
For a complete and up-to-date version of the sample code, see the vSphere Automation SDK Java samples at GitHub.
The connection code in the example disables certificate and host name checking for the connection for simplicity. For a production deployment, supply appropriate handlers. See the SDK sample file for a more detailed example of connection code.
... String lookupServiceUrl; LsService lookupService; LsPortType lsPort; ManagedObjectReference serviceInstanceRef; LookupServiceContent lookupServiceContent; ManagedObjectReference serviceRegistration; //1 - Configure Lookup Service stub. HostnameVerifier hostVerifier = new HostnameVerifier (){ public boolean verify(String urlHostName, SSLSession session){ return true; } }; HttpsURLConnection.setDefaultHostnameVerifier(hostVerifier); SslUtil.trustAllHttpsCertificates(); //2 - Create the Lookup Service stub. lookupService = new LsService(); lsPort = new LsPorType.getLsPort(); ((BindingProvider)lsProvider).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, lookupServiceUrl); //4 - Create a predetermined management object. serviceInstanceRef = new ManagedObjectReference(); serviceInstanceRef.setType("LookupServiceInstance"); serviceInsanceRefl.setValue("ServiceInstance"); //5 - Retrieve the ServiceContent object. lookupServiceContent = lsPort.retrieveServiceContent(serviceInstanceRef); //6 - Retrieve the service registration serviceRegistration = lookupServiceContent.getServiceRegistration(); ...