How to use the VMware Java SDK in IBM WebSphere

IBM WebSphere is still underpinning an number of IBM software products that do not run in containers on Red Hat OpenShift. Myself and @hvanrun were working with IBM Cloud Orchestrator (ICO) last year, an enterprise orchestrator that is used by a major European client.

Although we have since migrated successfully to IBM Business Automation Workflow, we had a requirement at the time to make API calls from ICO to a VMware vSphere environment. ICO runs on IBM Business Process Manager 8.6, which in turn runs on IBM WebSphere Network Deployment 8.5.5. Since IBM WebSphere is a Java EE runtime, we decided to leverage the VMware Java SDK to make these API calls .

What are VMware vSphere and IBM Business Process Manager?

VMware vSphere is a popular commercial hypervisor for the x86-64 architecture to host VMs and manage them through a management plane called VMware vCenter.

IBM® Business Process Manager is a comprehensive business process management platform. It provides a robust set of tools to author, test, and deploy business processes, as well as full visibility and insight to managing those business processes.

IBM® Business Process Manager is now available as IBM Business Automation Workflow and is part of IBM Cloud Pak for Automation. IBM Cloud Pak for Automation offers design, build, run, and automation services to rapidly scale your programs and fully execute and operationalize an automation strategy.

Our Challenge and Solution

Initially we had some challenges to make this integration work. Although we followed the examples from the VMware Java SDK Samples (samples included in SDK), the sample code below did not work as expected.

vimService = new VimService(endpointURL);
vimPort = vimService.getVimPort();

Map<String, Object> ctxt = ((BindingProvider) vimPort).getRequestContext();
            
ctxt.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);

serviceContent = vimPort.retrieveServiceContent(servicesInstance);

In particular, on every call to <include method/line/etc> we received the following message in the WebSphere SystemErr.log:

[7/2/20 10:13:46:277 CEST] 000b140c SystemErr R Sample code failed
[7/2/20 10:13:46:278 CEST] 000b140c SystemErr R javax.xml.ws.WebServiceException: Error: Maintain Session is enabled but none of the session properties (Cookies, Over-written URL) are returned.
[7/2/20 10:13:46:278 CEST] 000b140c SystemErr R at org.apache.axis2.jaxws.ExceptionFactory.createWebServiceException(ExceptionFactory.java:173)
[7/2/20 10:13:46:278 CEST] 000b140c SystemErr R at org.apache.axis2.jaxws.ExceptionFactory.makeWebServiceException(ExceptionFactory.java:70)
[7/2/20 10:13:46:278 CEST] 000b140c SystemErr R at org.apache.axis2.jaxws.ExceptionFactory.makeWebServiceException(ExceptionFactory.java:118)
[7/2/20 10:13:46:278 CEST] 000b140c SystemErr R at org.apache.axis2.jaxws.BindingProvider.setupSessionContext(BindingProvider.java:355)
[7/2/20 10:13:46:278 CEST] 000b140c SystemErr R at org.apache.axis2.jaxws.BindingProvider.checkMaintainSessionState(BindingProvider.java:322)

We worked with IBM Support and ultimately found that this post on stackoverflow.com was the key to the solution of our problem. Using the Java code below, we were able to make calls using the VMware Java SDK from ICO without any issues!

vimService = new VimService(endpointURL);
vimPort = vimService.getVimPort();

Map<String, Object> ctxt = ((BindingProvider) vimPort).getRequestContext();
            
ctxt.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
            
String CUSTOM_COOKIE_ID = ""; 
ctxt.put(CUSTOM_COOKIE_ID, "vmware_soap_session");
ctxt.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
            
// Retrieve the ServiceContent object and login
// Second retrieve context provides cookies for next calls
VimService vimServiceRSC = new VimService(endpointURL);
VimPortType vimPortRSC = vimServiceRSC.getVimPort();

Map<String, Object> ctxtRSC = ((BindingProvider)vimPortRSC).getRequestContext();
            ctxtRSC.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url.toString());

serviceContent = vimPortRSC.retrieveServiceContent(servicesInstance);

2 thoughts on “How to use the VMware Java SDK in IBM WebSphere

  1. Hello, I was very glad to find your post about connecting to venter from Websphere. I’m doing something similar in BPM, related to ICO if I’m remembering correctly. Even using your code I seems to have the same problem when doing vimiportRSC.retrieveServiceContent(SVC_INST_REF). Exception:JavaException: javax.xml.ws.WebServiceException: Error: Maintain Session is enabled but none of the session properties (Cookies, Over-written URL) are returned. Maybe I’ve made a dumb mistake and just can’t it, Any help you can give would be great. Thanks
    I’ll try to leave my code as reference:
    try {
    String vimSdkUrlString = “https://” + server + VIM_PATH;

    this.vimService = new VimService();

    this.vimPort = vimService.getVimPort();

    Map context = ((BindingProvider) vimPort).getRequestContext();

    context.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, vimSdkUrlString);

    // Start of Cookie Code
    String CUSTOM_COOKIE_ID = “”;
    context.put(CUSTOM_COOKIE_ID, “vmware_soap_session”);
    context.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);

    VimService vimServiceRSC = new VimService();

    VimPortType vimPortRSC = vimServiceRSC.getVimPort();

    Map ctxtRSC = ((BindingProvider) vimPortRSC).getRequestContext();
    ctxtRSC.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, vimSdkUrlString);

    serviceContent = vimPortRSC.retrieveServiceContent(SVC_INST_REF);
    // End of Cookie Code

    UserSession sessionManager = this.vimPort.login(serviceContent.getSessionManager(), username, password, null);

    } catch (InvalidLocaleFaultMsg | InvalidLoginFaultMsg | RuntimeFaultFaultMsg e) {
    System.out.println(“Exception during login:” + e.getMessage());
    e.printStackTrace();
    }

    Like

    1. Hey Dennis,

      I see that you are creating URL that points to WSDL, however I do not see you using that URL when invoking vimService.

      in my case URL looked like this:

      String url = “https://” + serverName + “/sdk/vimService”; // ** check for bad serverName
      String tempUrl = url + “.wsdl”;

      URL endpointURL = new URL(tempUrl);

      and later I initialized new vimService using that endpointURL variable in both service contents:

      vimService = new VimService(endpointURL);
      vimPort = vimService.getVimPort();

      // Retrieve the ServiceContent object and login
      // Second retrieve context provides cookies for next calls
      VimService vimServiceRSC = new VimService(endpointURL);
      VimPortType vimPortRSC = vimServiceRSC.getVimPort();

      You can try this in your code and update here if it worked.

      Like

Leave a comment

Design a site like this with WordPress.com
Get started