ヘッダーをスキップ
Oracle® Fusion Middleware Oracle WebLogic Server Oracle WebLogic Tuxedo Connectorアプリケーションの開発
12c (12.1.2)
E48051-01
  ドキュメント・ライブラリへ移動
ライブラリ
製品リストへ移動
製品
目次へ移動
目次

前
 
次
 

4 RMI/IIOPおよびCORBAを相互に運用するOracle WebLogic Tuxedo Connectorの使用

この章では、Oracle WebLogic ServerとOracle Tuxedo CORBAオブジェクトの間の相互運用性をサポートするOracle WebLogic Tuxedo Connectorを使用するために、アプリケーションを変更する方法について説明します。

この章の内容は以下のとおりです。


注意:

CORBAを相互運用するOracle WebLogic Tuxedo Connectorを構成するには、いくつかの管理タスクを実行する必要があります。CORBAを相互運用するOracle WebLogic Tuxedo Connectorを管理する方法については、『Oracle WebLogic Server WebLogic Tuxedo Connectorの管理』のCorbaアプリケーションの管理に関する項を参照してください。

Oracle Tuxedo CORBAアプリケーションを開発する方法については、http://docs.oracle.com/cd/E13203_01/tuxedo/tux100/interm/corbaprog.htmlCORBAプログラミングを参照してください。


CORBA Java APIを用いてOracle WebLogic Tuxedo ConnectorクライアントBeanを
開発する方法

Oracle WebLogic Tuxedo Connectorを使うと、オブジェクト(たとえばEJBやRMIオブジェクト)は、CORBA Java API (発信)を用いて、Oracle TuxedoにデプロイされたCORBAオブジェクトを呼び出すことができます。Oracle WebLogic Tuxedo Connectorでは、Oracle WebLogic Server RMI-IIOP実行時環境を使用してCORBAをサポートするWTC ORBを実装しています。この拡張では次のような機能が提供されます。

CORBA Java APIを使用するには、WTC ORBを使用する必要があります。以下のいずれかのメソッドを使用して、BeanでORBを取得します。

Properties Prop;
Prop = new Properties();
Prop.put("org.omg.CORBA.ORBClass","weblogic.wtc.corba.ORB");
ORB orb = ORB.init(new String[0], Prop);

または

ORB orb = (ORB)(new InitialContext().lookup("java:comp/ORB"));

または

ORB orb = ORB.init();

Oracle Tuxedoにデプロイされているオブジェクトを参照するには、以下のいずれかの方法を使用できます。

CosNamingサービスの使用


注意:

オブジェクト参照の詳細は、「FederationURLフォーマットの使用方法」を参照してください。


  1. Oracle WebLogic Tuxedo Connectorは、リモートOracle Tuxedo CORBAドメインにあるオブジェクトへの参照を取得するために、CosNamingサービスを使用します。これは、corbaloc:tgiopまたはcorbaname:tgiopオブジェクト参照を使用して行います。次の文は、CosNamingサービスを使用してOracle Tuxedo CORBAオブジェクトへの参照を取得します。

    // Get the simple factory.
    org.omg.CORBA.Object simple_fact_oref =
         orb.string_to_object("corbaname:tgiop:simpapp#simple_factory");
    

説明:

  • simpappは、Oracle Tuxedo UBBに指定されたOracle TuxedoドメインのドメインID。

  • simple_factoryは、Oracle Tuxedo CORBA CosNamingサーバーにおいてオブジェクト参照がバインドされていた名前。

サンプルToupperCorbaBean.javaコード


注意:

発信Oracle Tuxedo CORBAオブジェクト用のクライアントBeanを開発する方法の例については、Oracle WebLogic Server配布キットのEXAMPLES_HOME\wl_server\examples\src\examples\wtc\corba\simpappcnsパッケージを参照してください。WebLogic Serverサンプル・コードの詳細は、『Oracle WebLogic Serverの理解』のサンプル・アプリケーションおよびサンプル・コードに関する項を参照してください。

次のToupperCorbaBean.javaコードは、WTC ORBを呼び出し、COSNamingサービスを使用してオブジェクト参照を取得する方法の例です。


例4-1 サンプル・サービス・アプリケーション

.
.
.
public String Toupper(String toConvert)
throws RemoteException
{
     log("toupper called, converting " + toConvert);

     try {
        // Initialize the ORB.
        String args[] = null;
         Properties Prop;
        Prop = new Properties();
        Prop.put("org.omg.CORBA.ORBClass",
                "weblogic.wtc.corba.ORB");

        ORB orb = (ORB) new InitialContext().lookup("java:comp/ORB");

        // Get the simple factory.
        org.omg.CORBA.Object simple_fact_oref =
        orb.string_to_object("corbaname:tgiop:simpapp#simple_factory");

        //Narrow the simple factory.
        SimpleFactory simple_factory_ref =
        SimpleFactoryHelper.narrow(simple_fact_oref);

        // Find the simple object.
        Simple simple = simple_factory_ref.find_simple();

        // Convert the string to upper case.
        org.omg.CORBA.StringHolder buf = 
          new org.omg.CORBA.StringHolder(toConvert);
        simple.to_upper(buf);
        return buf.value;
     }
     catch (Exception e) {
        throw new RemoteException("Can't call TUXEDO CORBA server: " +e);
     }
}
.
.
.

FactoryFinderの使用


注意:

オブジェクト参照の詳細は、「FederationURLフォーマットの使用方法」を参照してください。


Oracle WebLogic Tuxedo Connectorでは、find_one_factory_by_idメソッドを使用してFactoryFinderオブジェクトをサポートしています。これは、corbaloc:tgiopまたはcorbaname:tgiopオブジェクト参照を使用して行います。次のメソッドで、ORBを使用してFactoryFinderオブジェクトを取得します。

// String to Object.
org.omg.CORBA.Object fact_finder_oref = 
     orb.string_to_object("corbaloc:tgiop:simpapp/FactoryFinder");

// Narrow the factory finder.
FactoryFinder fact_finder_ref =
     FactoryFinderHelper.narrow(fact_finder_oref);

// Use the factory finder to find the simple factory.
org.omg.CORBA.Object simple_fact_oref =
     fact_finder_ref.find_one_factory_by_id(SimpleFactoryHelper.id());

説明:

  • simpappは、Oracle Tuxedo UBBに指定されたOracle TuxedoドメインのドメインID。

  • FactoryFinderは、Oracle Tuxedo CORBAサーバーにおいてオブジェクト参照がバインドされていた名前。

WLECからOracle WebLogic Tuxedo Connectorへの移行

WLECは、Oracle WebLogic Serverでは使用できなくなり、サポートされなくなりました。WLECユーザーはアプリケーションをOracle WebLogic Tuxedo Connectorに移行することをお薦めします。詳細は、『Oracle WebLogic Server WLECのためのWebLogic Tuxedo Connector移行ガイド』を参照してください。

サンプル・コード

次のコードは、WTC ORBを呼び出し、FactoryFinderを使用してオブジェクト参照を取得する方法の例です。

例4-2 サンプルFactoryFinderコード

.
.
.
public ConverterResult convert (String changeCase, String mixed) 
throws ProcessingErrorException
{
     String result;
     try {
     // Initialize the ORB.
     String args[] = null;
     Properties Prop;
     Prop = new Properties();
     Prop.put("org.omg.CORBA.ORBClass","weblogic.wtc.corba.ORB");
     ORB orb = (ORB)new InitialContext().lookup("java:comp/ORB");

     org.omg.CORBA.Object fact_finder_oref =
         orb.string_to_object("corbaloc:tgiop:simpapp/FactoryFinder");

     // Narrow the factory finder.
     FactoryFinder fact_finder_ref =
        FactoryFinderHelper.narrow(fact_finder_oref);

     // find_one_factory_by_id
     org.omg.CORBA.Object simple_fact_oref =
        fact_finder_ref.find_one_factory_by_id(FactoryFinderHelper.id());

     // Narrow the simple factory.
     SimpleFactory simple_factory_ref =
        SimpleFactoryHelper.narrow(simple_fact_oref);

     // Find the simple object.
     Simple simple = simple_factory_ref.find_simple();

     if (changeCase.equals("UPPER")) {
     // Invoke the to_upper opeation on M3 Simple object
     org.omg.CORBA.StringHolder buf = 
        new org.omg.CORBA.StringHolder(mixed);
     simple.to_upper(buf);
     result = buf.value;
     }
     else
     {
     result = simple.to_lower(mixed);
     }

     }
     catch (org.omg.CORBA.SystemException e) {e.printStackTrace();

     throw new ProcessingErrorException("Converter error: Corba system exception: " + e);
     }
     catch (Exception e) {
     e.printStackTrace();
     throw new ProcessingErrorException("Converter error: " + e);
     }
return new ConverterResult(result);
}
.
.
.

Oracle WebLogic Tuxedo Connector用のRMI/IIOPアプリケーションを開発する方法


注意:

RMI/IIOPアプリケーションの開発方法の詳細は、『Oracle WebLogic Server RMIアプリケーションの開発』を参照してください。


RMI over IIOP (Internet Inter-ORB Protocol)は、JavaプログラムがCORBA (Common Object Request Broker Architecture)クライアントと対話してCORBAオブジェクトを実行できるように、RMIを拡張しています。Oracle WebLogic Tuxedo Connectorは次のことを可能にします。

次の節では、Oracle Tuxedo CORBAアプリケーションと対話するOracle WebLogic Tuxedo Connectorを使用するために、RMI/IIOPアプリケーションを修正する方法に関する情報を提供します。

Oracle WebLogic Tuxedo Connectorを使用するために
着信RMI/IIOPアプリケーションを変更する方法

クライアントは、COSNaming ServiceにバインドされているOracle WebLogic Serverのネーム・サービスの正しいバインド名をCOSNaming Serviceに渡す必要があります。

次のコードは、ネーミング・コンテキストを取得する例です。WLSは、『Oracle WebLogic Server WebLogic Tuxedo Connectorの管理』のCorbaアプリケーションの管理に関する項で説明されているcnsbindコマンドで指定されたバインド名です。

例4-3 ネーミング・コンテキストを取得するサンプル・コード

.
.
.
// obtain a naming context
     TP::userlog("Narrowing to a naming context");
     CosNaming::NamingContext_var context =
          CosNaming::NamingContext::_narrow(o);
     CosNaming::Name name;
     name.length(1);
     name[0].id = CORBA::string_dup("WLS");
     name[0].kind = CORBA::string_dup("");
.
.
.

Oracle WebLogic Tuxedo Connectorを使用するために
発信RMI/IIOPアプリケーションを開発する方法

EJBは、リモートOracle Tuxedo CORBAオブジェクトにアクセスする目的で使用される初期コンテキストを取得するためにFederationURLを使用する必要があります。Oracle WebLogic Tuxedo Connectorを使用するために発信RMI/IIOPアプリケーションを修正する方法を次の節で説明します。

FederationURLをEJBに渡すためにejb-jar.xmlファイルを修正する方法

次のコードは、実行時にFederationURLフォーマットをEJBに渡すためにejb-jar.xmlファイルを構成する方法の例です。

例4-4 FederationURLをEJBに渡すサンプルejb-jar.xmlファイル

<?xml version="1.0"?>

<!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 
1.1//EN' 'http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd'>

<ejb-jar>
     <small-icon>images/green-cube.gif</small-icon>
     <enterprise-beans>
     <session>
          <small-icon>images/orange-cube.gif</small-icon>
          <ejb-name>IIOPStatelessSession</ejb-name>
          <home>examples.iiop.ejb.stateless.TraderHome</home>
          <remote>examples.iiop.ejb.stateless.Trader</remote>
          <ejb-class>examples.iiop.ejb.stateless.TraderBean</ejb-class>
          <session-type>Stateless</session-type>
          <transaction-type>Container</transaction-type>
          <env-entry>
               <env-entry-name>foreignOrb</env-entry-name>
               <env-entry-type>java.lang.String </env-entry-type>
               <env-entry-value>corbaloc:tgiop:simpapp</env-entry-value>
          </env-entry>
          <env-entry>
               <env-entry-name>WEBL</env-entry-name>
               <env-entry-type>java.lang.Double </env-entry-type>
               <env-entry-value>10.0</env-entry-value>
          </env-entry>
          <env-entry>
               <env-entry-name>INTL</env-entry-name>
               <env-entry-type>java.lang.Double </env-entry-type>
               <env-entry-value>15.0</env-entry-value>
          </env-entry>
          <env-entry>
               <env-entry-name>tradeLimit</env-entry-name>
               <env-entry-type>java.lang.Integer </env-entry-type>
               <env-entry-value>500</env-entry-value>
          </env-entry>
     </session>
     </enterprise-beans>
     <assembly-descriptor>
          <container-transaction>
               <method>
                    <ejb-name>IIOPStatelessSession</ejb-name>
                    <method-intf>Remote</method-intf>
                    <method-name>*</method-name>
               </method>
          <trans-attribute>NotSupported</trans-attribute>
          </container-transaction>
     </assembly-descriptor>
</ejb-jar>

実行時にFederationURLをEJBに渡すには、アプリケーションのejb-jar.xmlファイルにそのEJB用のenv-entryを追加します。次のenv-entry下位要素を割り当てる必要があります。

env-entry-nameの割当て

env-entry-name要素は、env-entry-value要素内の値をEJBに渡すために使われる変数の名前を指定するために使用されます。例4-4で示したコード例では、env-entry-nameforeignOrbと指定しています。

env-entry-typeの割当て

env-entry-type要素は、EJBに渡されるenv-entry-value要素のデータ型(たとえばString、Integer、Double)を指定するために使用されます。例4-4に示したサンプル・コードでは、foreignOrb変数がStringデータをEJBに渡しています。

env-entry-valueの割当て

env-entry-value要素は、EJBに渡されるデータを指定するために使用されます。例4-4に示したサンプル・コードでは、foreignOrb変数が次のFederationURLフォーマットでEJBに渡すということを指定しています。

corbaloc:tgiop:simpapp

simpappとは、Oracle Tuxedo UBBで指定されているOracle Tuxedoリモート・サービスのDOMAINIDです。

オブジェクトにアクセスするためのFederationURLを使用するためにEJBを変更する方法

この節では、リモートOracle Tuxedo CORBAオブジェクトにアクセスするために使用されるInitialContextを取得するためのFederationURLを使用する方法に関する情報を提供します。

次のコードはInitialContextを取得するためのFederationURLの使い方の例です。

例4-5 InitialContextを取得するためのサンプルTraderBean.javaコード

.
.
.
public void createRemote() throws CreateException {
     log("createRemote() called");

     try {
          InitialContext ic = new InitialContext();

     // Lookup a EJB-like CORBA server in a remote CORBA domain
          Hashtable env = new Hashtable();
          env.put(Context.PROVIDER_URL, (String)
             ic.lookup("java:/comp/env/foreignOrb")
             + "/NameService");

          InitialContext cos = new InitialContext(env);
          TraderHome thome =
             (TraderHome)PortableRemoteObject.narrow(
             cos.lookup("TraderHome_iiop"),TraderHome.class);
             remoteTrader = thome.create();
}
     catch (NamingException ne) {
     throw new CreateException("Failed to find value "+ne);
}
     catch (RemoteException re) {
     throw new CreateException("Error creating remote ejb "+re);
}
}
.
.
.

リモートOracle Tuxedo CORBAオブジェクトのInitialContextを取得するFederationURLを使用するための手順を以下に示します。

  1. ejb-jar.xmlファイルで定義されているFederationURLフォーマットを取り出します。

    例:

    "ic.lookup("java:/comp/env/foreignOrb")
    

    例4-4に示したサンプル・コードでは、foreignOrb変数が次のFederationURLフォーマットでEJBに渡すということを指定しています。

    corbaloc:tgiop:simpapp
    
  2. 「/NameService」というFederationURLフォーマットを、先のFederationURLに連結します。

    "ic.lookup("java:/comp/env/foreignOrb") + "/NameService"
    

    連結結果のFederationURLは次のとおりです。

    corbaloc:tgiop:simpapp/NameService
    
  3. InitialContextを取得します。

    例:

    env.put(Context.PROVIDER_URL, (String)
         ic.lookup("java:/comp/env/foreignOrb") + "/NameService");
    InitialContext cos = new InitialContext(env);
    

    実行結果はOracle Tuxedo CORBAオブジェクトのInitialContextです。

FederationURLフォーマットの使用方法

この節では、以下のFederationURLフォーマットの構文に関する情報を提供します。

corbaloc URLフォーマットの使用

この節では、corbaloc URLフォーマットの構文を示します。

<corbaloc> = "corbaloc:tgiop":[<version>] <domain>["/"<key_string>]
<version> = <major> "." <minor> "@" | empty_string
<domain> = TUXEDO CORBA domain name
<major> = number
<minor> = number
<key_string> = <string> | empty_string

corbaloc:tgiopの例

この節では、corbaloc:tgiopの使用例を示します。

orb.string_to_object("corbaloc:tgiop:simpapp/NameService");
orb.string_to_object("corbaloc:tgiop:simpapp/FactoryFinder");
orb.string_to_object("corbaloc:tgiop:simpapp/InterfaceRepository");
orb.string_to_object("corbaloc:tgiop:simpapp/Tobj_SimpleEventsService");
orb.string_to_object("corbaloc:tgiop:simpapp/NotificationService");
orb.string_to_object("corbaloc:tgiop:1.1@simpapp/NotificationService);

-ORBInitRefの使用例

orb.initおよびresolve_initial_reference-ORBInitRefオプションを使用することもできます。

次の-ORBInitRef定義を指定します。

-ORBInitRef FactoryFinder=corbaloc:tgiop:simp/FactoryFinder
-ORBInitRef InterfaceRepository=corbaloc:tgiop:simp/InterfaceRepository
-ORBInitRef Tobj_SimpleEventService=corbaloc:tgiop:simp/Tobj_SimpleEventsService
-ORBInitRef NotificationService=corbaloc:tgiop:simp/NotificationService

次に、

orb.resolve_initial_references("NameService");
orb.resolve_initial_references("FactoryFinder");
orb.resolve_initial_references("InterfaceRepository");
orb.resolve_initial_references("Tobj_SimpleEventService");
orb.resolve_initial_references("NotificationService");

-ORBDefaultInitRefの使用例

-ORBDefaultInitRefおよびresolve_initial_referenceを使用できます。

次の-ORBDefaultInitRef定義を指定します。

-ORBDefaultInitRef corbaloc:tgiop:simpapp

次に、

orb.resolve_initial_references("NameService");

corbaname URLフォーマットの使用

corbalocフォーマットのかわりにcorbanameフォーマットを使用することもできます。

-ORBInitRefの使用例

次の-ORBInitRef定義を指定します。

-ORBInitRef NameService=corbaloc:tgiop:simpapp/NameService

次に、

orb.string_to_object("corbaname:rir:#simple_factory");
orb.string_to_object("corbaname:tgiop:simpapp#simple_factory");
orb.string_to_object("corbaname:tgiop:1.1@simpapp#simple_factory");
orb.string_to_object("corbaname:tgiop:simpapp#simple/simple_factory");

Oracle Tuxedo CORBAアプリケーションに対するトランザクションを管理する方法


注意:

Oracle Tuxedo CORBAアプリケーションでのトランザクションの管理の詳細は、http://docs.oracle.com/cd/E13203_01/tuxedo/tux100/trans/gstrx.htmlにあるCORBAトランザクションの使用のTuxedo CORBAアプリケーションにおけるトランザクションの概要に関する項を参照してください。


Oracle WebLogic Tuxedo Connectorは、Java Transaction API (JTA)を使って、Oracle Tuxedo CORBAアプリケーションでのトランザクションを管理します。詳細については、以下を参照してください。