Guideline for the creation of MBeans based on Web services.
Knowledge of Java and Web services is required in order to be able to fully understand this guideline.
AE provides support neither for Web services nor for MBeans.
The Automation Engine supports Web services through the usage of MBeans in combination with the JMX agent. Many vendors offer Web services rather than MBeans as interfaces that provide access to their applications. This guideline describes step by step how an MBean is generated from an existing Web service. The Web service "CurrencyConvertor" which is provided by Generic Objects Technologies Ltd serves as an example. It supplies currency exchange rates.
Requirements:
MBeans can only be created for synchronous Web services. Using asynchronous Web services is much more difficult and must be handled individually.
Thoroughly test the generated MBean.
1. |
Setting up Apache Axis |
---|
2. |
Generating Java classes for calling the Web service |
---|
3. |
Creating an MBean for using the Java classes |
---|
ConverterMBean.java:
package com.uc4.ws;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
public interface ConverterMBean {
double convertCurrency(String fromCurrency, String toCurrency)
throws ServiceException, RemoteException, IllegalArgumentException;
}
Converter.java:
package com.uc4.ws;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import NET.webserviceX.www.Currency;
import NET.webserviceX.www.CurrencyConvertorLocator;
import NET.webserviceX.www.CurrencyConvertorSoap;
public class Converter implements ConverterMBean {
public double convertCurrency(String fromCurrency, String toCurrency)
throws ServiceException, RemoteException, IllegalArgumentException {
CurrencyConvertorLocator locator = new CurrencyConvertorLocator();
CurrencyConvertorSoap soap = locator.getCurrencyConvertorSoap();
return soap.conversionRate(
Currency.fromString(fromCurrency),
Currency.fromString(toCurrency));
}
}
The method "convertCurrency" contains the Web service call. Therefore, it uses the generated Java classes. It creates a service-locator instance and calls the method "getCurrencyConvertorSoap" in order to obtain a SOAP stub. This pattern (locator-stub) is described in the Apache Axis documentation.
The stub calls the Web service. The parameters are converted from "java.lang.String" to "NET.webserviceX.www.Currency" objects because only simple data types can be used in MBeans. The supplied result is the current currency conversion rate.
4. |
Creating the MBean's JAR file and the Java classes |
---|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project name="uc4" default="exampleMBean.jar">
<property name="classes_dir" value="bin" />
<target name="exampleMBean.jar" description="Web Service MBean">
<jar jarfile="exampleMBean.jar" basedir="${classes_dir}"/>
</target>
</project>
No ant script is required in development environments such as Eclipse. Here you can generate the JAR file via menu command.
5. |
Starting the JMX Agent using an MBean |
---|
Java -cp axis.jar;commons-discovery-0.2.jar;commons-logging-1.0.4.jar;
wsdl4j-1.5.1.jar;saaj.jar;exampleMBean.jar;ucxjjmx.jar;jaxrpc.jar com/uc4/ex/jmx/UCXJMX
UNIX: use a colon (":") instead of a semicolon (";").
The JMX agent does not require an application server but can run independently. It is sufficient to install the Java version 5 as it contains the required JMX packages of version 1.2.
1. |
Creating a JMX job |
---|
The function JMX_CREATE_MBEAN creates an MBean instance and registers it on the local MBean Server.
The domain name must not include the characters ":", "*" and "?". In order to avoid collisions between the MBeans of different vendors, Automic recommends using the DNS name of your company backwards as the domain name.
The key properties assign a unique name to the MBeans within the domain. They are separated by commas ",". A key property is structured as follows: Properties=Value. The property must not correspond to an attribute of the MBean. The number of key properties is not limited and the order is irrelevant. A key property must not contain inverted commas, commas or ":", "=", "*" and "?". Specify at least one key property.
2. |
Using the MBean |
---|
The function JMX_INVOKE calls an operation of an MBean.
Read the report using the script function PREP_PROCESS_REPORT so that the values supplied by the MBeans can be used for further processing. The Sample Collection contains a description of the required steps.