To use a Java service you created and exposed in the service layer, a user interface plug-in module must import the service. You import the service by updating two metadata configuration files within your user interface plug-in module Web Archive (WAR) bundle.

In your user interface plug-in module WAR bundle, locate the /war/src/main/webapp/META-INF/MANIFEST.MF file and add the following lines.

Import-Package: com.vmware.myService

com.vmware.myService is the name of the service package you created.

If you are adding a Flex extension, you need to specify the parameters for the Flex-to-Java framework. In the WAR bundle, locate the /war/src/main/webapp/WEB-INF/spring/bundle-context.xml file. This file specifies the necessary service parameters for the Flex-to-Java framework on the vSphere Web Client application server. Inside the <beans> element of the bundle-context.xml file, create the service references as follows.

<flex:message-broker id="myService-ui-broker"
  services-config-path="/WEB-INF/flex/services-config.xml"/>
<osgi:reference id="myService" interface="com.vmware.myService.MyService"/>
<flex:remoting-destination ref="myService" message-broker="myService-ui-broker"/>

The <flex:message broker> and <flex:remoting-destination> elements declare your service as a destination for Flex remote object invocation.

Using a proxy class in your extension Flex component is the recommended way to manage communication between a custom Java service and your Flex data views. The vSphere Web Client includes a Flex utility library that includes a base proxy class. You can use this base proxy class to implement the proxy class that communicates with your service.

For more information about proxy classes and their role in the user interface layer, see Creating Data View Extensions.

The following example presents a sample ActionScript proxy class implementation. The sample proxy class extends the com.vmware.flexutil.proxies.BaseProxy class that the vSphere Web Client provides.

package com.vmware.samples.globalview {
  import com.vmware.flexutil.proxies.BaseProxy;
 
  /**
  * Proxy class for the EchoService java service
  */
  public class EchoServiceProxy extends BaseProxy {
    // Service name matching the flex:remoting-destination declared in
    // main/webapp/WEB-INF/spring/bundle-context.xml
    private static const SERVICE_NAME:String = "myService";
 
    // channelUri uses the Web-ContextPath define in MANIFEST.MF (globalview-ui)
    // A secure AMF channel is required because vSphere Web Client uses https
    private static const CHANNEL_URI:String =
       ServiceUtil.getDefaultChannelUri(GlobalviewModule.contextPath);
 
    /**
    * Create a EchoServiceProxy with a secure channel.
    */
    public function EchoServiceProxy() {
      super(SERVICE_NAME, CHANNEL_URI);
    }
 
    /**
    * Call the "echo" method of the EchoService java service.
    *
    * @param message Single argument to the echo method
    * @param callback Callback in the form <code>function(result:Object,
    * error:Error, callContext:Object)</code>
    * @param context Optional context object passed back with the result
    */
    public function echo(message:String,
                         callback:Function = null,
                         context:Object = null):void {
      // "echo" takes a single message argument but callService still requires an array.
      callService("echo", [message], callback, context);
    }
  }
}

You must set the Proxy constructor destination argument to the service ID that you imported in your plug-in module configuration files. The proxy constructor sets the destination parameter to the service ID myService, as defined in the /war/src/main/webapp/WEB-INF/spring/bundle-context.xml WAR bundle configuration file.

In the proxy, you can call functions of the Java service by using the callService method. The callService method is included in the package com.vmware.flexutil.ServiceUtil. The proxy class uses the callService method to call the echo method in the Java service.