Creating a Custom Java Service
You can extend the vSphere Web Client service layer with your own Java services. Typically, you create a Java service if your user interface extensions add actions to the vSphere Web Client, where the Java service performs the action operation on the virtual infrastructure. You can also add a Java service to perform a complex calculation, retrieve data from an external source, or perform other miscellaneous tasks.
To add a Java service, you must provide a Java Archive (JAR) bundle that contains the classes in the service. Inside the JAR bundle, you must add an XML configuration file that declares all of the Java objects that the service adds to the vSphere Web Client Virgo server framework. The Virgo server uses Spring as the application server framework.
Making Java Services Available to User Interface Components in the vSphere Web Client
To make a custom Java service available to your extension Flex components in the vSphere Web Client, complete the following steps.
1
2
3
4
5
Using ActionScript, create a proxy class in your extension Flex component. The proxy class is used to communicate between the user interface plug-in module and the service.
Creating the Java Interface and Classes
To integrate with the Virgo server Spring framework, the Java service you create must provide separate interface and implementation classes. Example: Basic Java Service Interface and Implementation shows a basic example of an interface class and an implementation class.
Example: Basic Java Service Interface and Implementation
package com.vmware.myService;
 
public interface MyService {
String echo (String message);
}
 
public class MyServiceImpl implements MyService {
public String echo (String message) {
return message;
}
}
 
Packaging and Exposing the Service
To make your Java service available for use with the vSphere Web Client, you must export the service and add it to the Spring configuration on the Virgo server.
Exporting the Service
You must locate the /src/main/resources/META-INF/MANIFEST.MF file in your service JAR bundle and ensure that the Java service package is exported. To export the package, the following line must appear in the MANIFEST.MF file:
Export-Package: com.vmware.myService
where com.vmware.myService is the name of the service package you have created.
Adding the Service to the Spring Configuration
You add your service to the Spring configuration on the Virgo server by creating a <bean> element in the Spring configuration file. In the JAR bundle, locate the /src/main/resources/META-INF/spring/bundle-context.xml file. The file contains a <beans> XML element containing services in the configuration. Add your service as a new <bean> as follows:
<bean name=”myServiceImpl” class=”com.vmware.myService.MyServiceImpl”/>
where the name attribute is the name of your service implementation, and the class attribute contains the class you have created that implements the service interface.
You must also expose the service interface as an OSGI bundle in the Spring framework. In the JAR bundle, locate the /src/main/resources/META-INF/spring/bundle-context-osgi.xml file. This file also contains a <beans> XML element. Add your service using the following line:
<osgi:service id=”myService” ref=”myServiceImpl” interface=”com.vmware.myService.MyService”/>
where the id attribute is the name of your service, the ref element specifies the service implementation you have added to the bundle-context.xml file, and the interface element contains the class that defines the service interface.