Message Driven Bean Example

This example shows how to develop and deploy a Message Driven Bean (MDB) based Novell exteNd WSSDK Service. The implementation of the skeleton class is done in exactly the same was as if the skeleton was Servlet based, but the packaging and deployment is different. You will deploy a Enterprise Application Archive (EAR) instead of the regular Web Application Archive (WAR).

1 Remote Interface

In this example, we have created a remote interface based on the java.lang.Math class using the java2rmi wizards:
package mdb;
                                                                           
public interface Math extends java.rmi.Remote
{
    double IEEEremainder(double p0, double p1) throws java.rmi.RemoteException;
    double abs(double p0) throws java.rmi.RemoteException;
    double acos(double p0) throws java.rmi.RemoteException;
    double asin(double p0) throws java.rmi.RemoteException;
    double atan(double p0) throws java.rmi.RemoteException;
    double atan2(double p0, double p1) throws java.rmi.RemoteException;
    double ceil(double p0) throws java.rmi.RemoteException;
    double cos(double p0) throws java.rmi.RemoteException;
    double exp(double p0) throws java.rmi.RemoteException;
    double floor(double p0) throws java.rmi.RemoteException;
    double log(double p0) throws java.rmi.RemoteException;
    double max(double p0, double p1) throws java.rmi.RemoteException;
    double min(double p0, double p1) throws java.rmi.RemoteException;
    double pow(double p0, double p1) throws java.rmi.RemoteException;
    double random() throws java.rmi.RemoteException;
    double rint(double p0) throws java.rmi.RemoteException;
    long round(double p0) throws java.rmi.RemoteException;
    double sin(double p0) throws java.rmi.RemoteException;
    double sqrt(double p0) throws java.rmi.RemoteException;
    double tan(double p0) throws java.rmi.RemoteException;
    double toDegrees(double p0) throws java.rmi.RemoteException;
    double toRadians(double p0) throws java.rmi.RemoteException;
}

2 Compile Flags

In order to generate an MDB based skeleton, you need to pass the -mdb flag to the wsdl2java or rmi2soap compiler. As with the familiar Servlet based skeleton, the rmi2soap compiler generates the Math_ServiceSkeleton class, which you must provide a sub class for. The implementation class is written as for a Servlet based skeleton; in this case we merely delegate to the static methods in the java.lang.Math class:
package mdb;
                                                                           
import java.lang.Math;
import java.rmi.RemoteException;
                                                                           
public class MathImpl extends Math_ServiceSkeleton
{
    public double IEEEremainder(double p0, double p1) throws RemoteException
    {
    |   return Math.IEEEremainder(p0, p1);
    }
                                                                           
    public double abs(double p0) throws RemoteException
    {
    |   return Math.abs(p0);
    }
                                                                           
    public double acos(double p0) throws RemoteException
    {
    |   return Math.acos(p0);
    }
                                                                           
    public double asin(double p0) throws RemoteException
    {
    |   return Math.asin(p0);
    }
                                                                           
    public double atan(double p0) throws RemoteException
    {
    |   return Math.atan(p0);
    }
                                                                           
    public double atan2(double p0, double p1) throws RemoteException
    {
    |   return Math.atan2(p0, p1);
    }
                                                                           
    public double ceil(double p0) throws RemoteException
    {
    |   return Math.ceil(p0);
    }
                                                                           
    public double cos(double p0) throws RemoteException
    {
    |   return Math.cos(p0);
    }
                                                                           
    public double exp(double p0) throws RemoteException
    {
    |   return Math.exp(p0);
    }
                                                                           
    public double floor(double p0) throws RemoteException
    {
    |   return Math.floor(p0);
    }
                                                                           
    public double log(double p0) throws RemoteException
    {
    |   return Math.log(p0);
    }
                                                                           
    public double max(double p0, double p1) throws RemoteException
    {
    |   return Math.max(p0, p1);
    }
                                                                           
    public double min(double p0, double p1) throws RemoteException
    {
    |   return Math.min(p0, p1);
    }
                                                                           
    public double pow(double p0, double p1) throws RemoteException
    {
    |   return Math.pow(p0, p1);
    }
                                                                           
    public double random() throws RemoteException
    {
    |   return Math.random();
    }
                                                                           
    public double rint(double p0) throws RemoteException
    {
    |   return Math.rint(p0);
    }
                                                                           
    public long round(double p0) throws RemoteException
    {
    |   return Math.round(p0);
    }
                                                                           
    public double sin(double p0) throws RemoteException
    {
    |   return Math.sin(p0);
    }
                                                                           
    public double sqrt(double p0) throws RemoteException
    {
    |   return Math.sqrt(p0);
    }
                                                                           
    public double tan(double p0) throws RemoteException
    {
    |   return Math.tan(p0);
    }
                                                                           
    public double toDegrees(double p0) throws RemoteException
    {
    |   return Math.toDegrees(p0);
    }
                                                                           
    public double toRadians(double p0) throws RemoteException
    {
    |   return Math.toRadians(p0);
    }
}

3 Packaging and Deployment

In order to deploy a MDB, you'll need to create the appropriate EAR file. You may need to modify the build script if you wish to include the Novell exteNd WSSDK jar files into the generated services.ear file. Please consult the ejb-jar.xml and application.xml files for additional detail.

If you want to access the MDB via HTTP you also need to deploy the JMS router. You can use the included router.war file, which you may need to modify depending on the container you're deploying to. Unless you have the wssdk.jar file in your container's CLASSPATH, you will need to include it into the WEB-INF/lib directory. If you're deploying the router to Tomcat and run against jBroker MQ, you will also need to include the jBroker MQ and jBroker ORB libraries in the WAR file.

4 SOAP/HTTP Client

package mdb;
                                                                           
import javax.xml.rpc.Stub;
import javax.naming.InitialContext;
                                                                           
public class Client
{
    public static void main(String[] args) throws Exception
    {
    |   // get the initial context
    |   InitialContext ctx = new InitialContext();
    |                                                                      
    |   // lookup the service for Math
    |   MathService svc = (MathService)
    |       ctx.lookup("xmlrpc:soap:mdb.MathService");
    |                                                                      
    |   // get the math stub
    |   Math math = (Math) svc.getMathPort();
    |                                                                      
    |   // set the end point address
    |   ((Stub)math)._setProperty("javax.xml.rpc.service.endpoint.address",
    |       args.length > 0 ? args[0] : "http://localhost:9090/math");
    |                                                                      
    |   // invoke the service's methods
    |   System.out.println("IEEEremainder = " + math.IEEEremainder(4.44, 3.33));
    |   System.out.println("abs = " + math.abs(4.44));
    |   System.out.println("acos = " + math.acos(2.22));
    |   System.out.println("asin = " + math.asin(1.11));
    |   System.out.println("atan = " + math.atan(4.44));
    |   System.out.println("atan2 = " + math.atan2(2.22, 3.33));
    |   System.out.println("ceil = " + math.ceil(2.22));
    |   System.out.println("cos = " + math.cos(2.22));
    |   System.out.println("exp = " + math.exp(1.33));
    |   System.out.println("floor = " + math.floor(1.44));
    |   System.out.println("log = " + math.log(2.22));
    |   System.out.println("max = " + math.max(3.33, 4.44));
    |   System.out.println("min = " + math.min(3.33, 4.44));
    |   System.out.println("pow = " + math.pow(2.22, 3.33));
    |   System.out.println("random = " + math.random());
    |   System.out.println("rint = " + math.rint(3.33));
    |   System.out.println("round = " + math.round(4.44));
    |   System.out.println("sin = " + math.sin(2.22));
    |   System.out.println("sqrt = " + math.sqrt(5.55));
    |   System.out.println("tan = " + math.tan(4.44));
    |   System.out.println("toDegrees = " + math.toDegrees(1.11));
    |   System.out.println("toRadians = " + math.toRadians(45.45));
    }
}

5 SOAP/JMS Client

package mdb;
                                                                           
import java.util.Hashtable;
import java.util.Properties;
                                                                           
import javax.naming.InitialContext;
                                                                           
import com.sssw.jbroker.web.portable.Stub;
                                                                           
public class JmsClient
{
    public static void main(String[] args) throws Exception
    {
    |   // get the initial context
    |   InitialContext ctx = new InitialContext();
    |                                                                      
    |   // lookup the service for Math
    |   MathService svc = (MathService)
    |       ctx.lookup("xmlrpc:soap:mdb.MathService");
    |                                                                      
    |   // get the math stub
    |   Math math = (Math) svc.getMathPort();
    |                                                                      
    |   // set the end point address
    |   ((Stub)math)._setProperty("javax.xml.rpc.service.endpoint.address",
    |       args.length > 0 ? args[0] : "jms://queue/queue0");
    |                                                                      
    |   // instruct jms transport to use requestor
    |   ((Stub)math)._setProperty(Stub.JMS_USE_REQUESTOR, Boolean.TRUE);
    |                                                                      
    |   Properties props = new Properties();
    |   props.put("org.omg.CORBA.ORBClass", "com.sssw.jbroker.ORBLite");
    |   props.put("org.omg.CORBA.ORBSingletonClass", "com.sssw.jbroker.orb.SingletonORB");
    |   props.put("javax.rmi.CORBA.StubClass", "com.sssw.jbroker.rmi.StubDelegate");
    |   props.put("javax.rmi.CORBA.UtilClass", "com.sssw.jbroker.rmi.UtilDelegate");
    |   props.put("javax.rmi.CORBA.PortableRemoteObjectClass",
    |       "com.sssw.jbroker.rmi.PortableRemoteObjectDelegate");
    |   props.put("ORBDefaultInitRef", "iioploc://localhost:3506");
    |   org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init((String[])null, props);
    |   Hashtable env = new Hashtable();
    |   env.put("java.naming.corba.orb", orb);
    |   env.put("java.naming.factory.object", "com.sssw.jms.naming.JMQObjectFactory");
    |   env.put("java.naming.factory.initial", "com.sun.jndi.cosnaming.CNCtxFactory");
    |                                                                      
    |   // set the JNDI environment
    |   ((Stub)math)._setProperty(Stub.JMS_JNDI_ENVIRONMENT, env);
    |                                                                      
    |   // set the JNDI lookup string for connection factory
    |   ((Stub)math)._setProperty(Stub.JMS_QUEUE_FACTORY_JNDI, "queue/connectionFactory");
    |                                                                      
    |   // set the JNDI lookup string for queue
    |   ((Stub)math)._setProperty(Stub.JMS_QUEUE_JNDI, "queue/queue0");
    |                                                                      
    |   // set timeout for reply message
    |   ((Stub)math)._setProperty(Stub.JMS_REPLY_TIMEOUT, new Integer(10000));
    |                                                                      
    |   // invoke the service's methods
    |   System.out.println("IEEEremainder = " + math.IEEEremainder(4.44, 3.33));
    |   System.out.println("abs = " + math.abs(4.44));
    |   System.out.println("acos = " + math.acos(2.22));
    |   System.out.println("asin = " + math.asin(1.11));
    |   System.out.println("atan = " + math.atan(-1.11));
    |   System.out.println("atan2 = " + math.atan2(2.22, 3.33));
    |   System.out.println("ceil = " + math.ceil(2.22));
    |   System.out.println("cos = " + math.cos(2.22));
    |   System.out.println("exp = " + math.exp(1.33));
    |   System.out.println("floor = " + math.floor(1.44));
    |   System.out.println("log = " + math.log(2.22));
    |   System.out.println("max = " + math.max(3.33, 4.44));
    |   System.out.println("min = " + math.min(3.33, 4.44));
    |   System.out.println("pow = " + math.pow(2.22, 3.33));
    |   System.out.println("random = " + math.random());
    |   System.out.println("rint = " + math.rint(3.33));
    |   System.out.println("round = " + math.round(4.44));
    |   System.out.println("sin = " + math.sin(2.22));
    |   System.out.println("sqrt = " + math.sqrt(5.55));
    |   System.out.println("tan = " + math.tan(4.44));
    |   System.out.println("toDegrees = " + math.toDegrees(1.11));
    |   System.out.println("toRadians = " + math.toRadians(45.45));
    }
}
Copyright © 2000-2003, Novell, Inc. All rights reserved.