Importing a Service in a User Interface Plug-In Module
To use a Java service you have created and exposed in the vSphere Web Client 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.
Within 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
where com.vmware.myService is the name of the service package you have created.
Within 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.
Creating a Proxy Class Using ActionScript
Using a proxy class within 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 on proxy classes and their role in the user interface layer, see Architecting Data Views.
Example: Example ActionScript Proxy Class presents a sample ActionScript proxy class implementation. The sample proxy class extends the com.vmware.flexutil.proxies.BaseProxy class provided by the vSphere Web Client.
Example: Example ActionScript Proxy Class
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 = "EchoService";
 
// 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 =
"/" + GlobalviewModule.contextPath + "/messagebroker/amfsecure";
 
/**
* 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 have imported in your plug-in module configuration files. In Example: Example ActionScript Proxy Class, the proxy constructor sets the destination parameter to the service ID myService, as defined in the WAR bundle configuration file (/war/src/main/webapp/WEB-INF/spring/bundle-context.xml).
Within the proxy, you can call functions within the Java service by using the callService method. The callService method is included in the package com.vmware.flexutil.ServiceUtil. In Example: Example ActionScript Proxy Class, the proxy class uses the callService method to call the echo method in the Java service.