この例ではMDB (メッセージ駆動型Bean)ベースのNovell exteNd WSSDK Serviceの開発および展開方法について説明します。 スケルトンクラスの実装は、スケルトンがServletベースの場合と同様に実行しますが、パッケージおよび展開は異なります。 通常のWAR (Web Application Archive)の代わりにEAR (Enterprise Application Archive)を展開します。1 Remoteインタフェース
この例では、java2rmi ウィザードを使用してjava.lang.Mathクラスに基づくRemoteインタフェースを作成します。
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 コンパイルフラグ
MDBベースのスケルトンを生成するには、-mdbフラグをwsdl2javaまたはrmi2soapコンパイラに渡す必要があります。 一般的なServletベースのスケルトンと同様、rmi2soapコンパイラはサブクラスを提供する必要のあるMath_ServiceSkeleton
クラスを生成します。 実装クラスは、Servletベースのスケルトンの場合と同様に書き込まれます。この場合の書き込みは、単にjava.lang.Math
クラスのスタティックメソッドに委任しているだけです。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.abs(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 パッケージおよび展開
MDBを展開するには、適切なEARファイルを作成する必要があります。 Novell exteNd WSSDK jarファイルを生成されたservices.ear
ファイルに含める場合は、ビルドスクリプトを変更する必要があります。 詳細については、ejb-jar.xmlファイルおよびapplication.xmlファイルを参照してください。HTTP経由でMDBにアクセスする場合、JMSルータを展開する必要があります。
router.war
インクルードファイルを使用できます。展開先のコンテナによっては、このファイルを修正する必要がある可能性もあります。 コンテナのCLASSPATHにwssdk.jar
ファイルが存在しない限り、このファイルはWEB-INF/lib
ディレクトリに含める必要があります。 ルータをTomcatに展開し、jBroker MQに対して実行する場合、WARファイルのjBroker MQおよびjBroker ORBライブラリも含める必要があります。4 SOAP/HTTPクライアント
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 Hello | 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クライアント
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 Hello | 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.