WebLogic Tuxedo Connector Programmer's Guide

     Previous  Next    Open TOC in new window    View as PDF - New Window  Get Adobe Reader - New Window
Content starts here

Using WebLogic Tuxedo Connector for RMI/IIOP and CORBA Interoperability

Note: You will need to perform some administration tasks to configure the WebLogic Tuxedo Connector for CORBA interoperability. For information on how to administer the WebLogic Tuxedo Connector for CORBA interoperability, see Administration of CORBA Applications.
Note: For information on how to develop Tuxedo CORBA applications, see CORBA Programming.

The following sections provide information on how to modify your applications to use WebLogic Tuxedo Connector to support interoperability between WebLogic Server and Tuxedo CORBA objects:

 


How to Develop WebLogic Tuxedo Connector Client Beans using the CORBA Java API

The WebLogic Tuxedo Connector enables objects (such as EJBs or RMI objects) to invoke upon CORBA objects deployed in Tuxedo using the CORBA Java API (Outbound). WebLogic Tuxedo Connector implements a WTC ORB which uses WebLogic Server RMI-IIOP runtime and CORBA support. This enhancement provides the following features:

To use CORBA Java API, you must use the WTC ORB. Use one of the following methods to obtain an ORB in your Bean:

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

or

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

or

ORB orb = ORB.init();

You can use either of the following methods to reference objects deployed in Tuxedo:

Using CosNaming Service

Note: For more information on object references, see How to Use FederationURL Formats.
  1. The WebLogic Tuxedo Connector uses the CosNaming service to get a reference to an object in the remote Tuxedo CORBA domain. This is accomplished by using a corbaloc:tgiop or corbaname:tgiop object reference. The following statements use the CosNaming service to get a reference to a Tuxedo CORBA Object:
  2. // Get the simple factory.
    org.omg.CORBA.Object simple_fact_oref =
         orb.string_to_object("corbaname:tgiop:simpapp#simple_factory");

Where:

Example ToupperCorbaBean.java Code

Note: For an example on how to develop client beans for outbound Tuxedo CORBA objects, see the SAMPLES_HOME\server\examples\src\examples\wtc\corba\simpappcns package in your WebLogic Server examples distribution.

The following ToupperCorbaBean.java code provides an example of how to call the WTC ORB and get an object reference using the COSNaming Service.

Listing 4-1 Example Service Application
.
.
.
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);
     }
}
.
.
.

Using FactoryFinder

Note: For more information on object references, see How to Use FederationURL Formats.

WebLogic Tuxedo Connector provides support for FactoryFinder objects using the find_one_factory_by_id method. This is accomplished by using a corbaloc:tgiop or corbaname:tgiop object reference. Use the following method to obtain the FactoryFinder object using the ORB:

// 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());

Where:

WLEC to WebLogic Tuxedo Connector Migration

WLEC is no longer available or supported in WebLogic Server. WLEC users should migrate their applications to WebLogic Tuxedo Connector. For more information, see WLEC to WebLogic Tuxedo Connector Migration Guide.

Example Code

The following code provides an example of how to call the WTC ORB and get an object reference using FactoryFinder.

Listing 4-2 Example FactoryFinder Code
.
.
.
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);
}
.
.
.

 


How to Develop RMI/IIOP Applications for the WebLogic Tuxedo Connector

Note: For more information on how to develop RMI/IIOP applications, see Programming WebLogic RMI.

RMI over IIOP (Internet Inter-ORB Protocol) extends RMI so that Java programs can interact with Common Object Request Broker Architecture (CORBA) clients and execute CORBA objects. The WebLogic Tuxedo Connector:

The following sections provide information on how to modify RMI/IIOP applications to use the WebLogic Tuxedo Connector to interoperate with Tuxedo CORBA applications:

How to Modify Inbound RMI/IIOP Applications to use the WebLogic Tuxedo Connector

A client must pass the correct name to which the WebLogic Server's name service has been bound to the COSNaming Service.

The following code provides an example for obtaining a naming context. "WLS" is the bind name specified in the cnsbind command detailed in the Administration of CORBA Applications.

Listing 4-3 Example Code to Obtain a Naming Context
.
.
.
// 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("");
.
.
.

How to Develop Outbound RMI/IIOP Applications to use the WebLogic Tuxedo Connector

An EJB must use a FederationURL to obtain the initial context used to access a remote Tuxedo CORBA object. Use the following sections to modify outbound RMI/IIOP applications to use the WebLogic Tuxedo Connector:

How to Modify the ejb-jar.xml File to Pass a FederationURL to EJBs

The following code provides an example of how to configure an ejb-jar.xml file to pass a FederationURL format to the EJB at run-time.

Listing 4-4 Example ejb-jar.xml File Passing a FederationURL to an EJB
<?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>

To pass the FederationURL to the EJB at run-time, add an env-entry for the EJB in the ejb-jar.xml file for your application. You must assign the following env-entry sub-elements:

Assign env-entry-name

The env-entry-name element is used to specify the name of the variable used to pass the value in the env-entry-value element to the EJB. The example code shown in Listing 4-4 specifies the env-entry-name as foreignOrb.

Assign env-entry-type

The env-entry-type element is used to specify the data type (example String, Integer, Double) of the env-entry-value element that is passed to the EJB. The example code shown in Listing 4-4 specifies that the foreignOrb variable passes String data to the EJB.

Assign env-entry-value

The env-entry-value element is used to specify the data that is passed to the EJB. The example code shown in Listing 4-4 specifies that the foreignOrb variable passes the following FederationURL format to the EJB:

corbaloc:tgiop:simpapp

Where simpapp is the DOMAINID of the Tuxedo remote service specified in the Tuxedo UBB.

How to Modify EJBs to Use FederationURL to Access an Object

This section provides information on how to use the FederationURL to obtain the InitialContext used to access a remote Tuxedo CORBA object.

The following code provides an example of how to use FederationURL to get an InitialContext.

Listing 4-5 Example TraderBean.java Code to get InitialContext
.
.
.
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);
}
}
.
.
.

Use the following steps to use FederationURL to obtain an InitialContext for a remote Tuxedo CORBA object:

  1. Retrieve the FederationURL format defined in the ejb-jar.xml file.
  2. Example:

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

    The example code shown in Listing 4-4 specifies that the foreignOrb variable passes the following FederationURL format to the EJB:

    corbaloc:tgiop:simpapp

  3. Concatenate the FederationURL format with "/NameService" to form the FederationURL.
  4. Example:

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

    The resulting FederationURL is:

    corbaloc:tgiop:simpapp/NameService

  5. Get the InitialContext.
  6. Example:

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

    The result is the InitialContext of the Tuxedo CORBA object.

 


How to Use FederationURL Formats

This section provides information on the syntax for the following FederationURL formats:

Using corbaloc URL Format

This section provides the syntax for corbaloc URL format:

<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

Examples of corbaloc:tgiop

This section provides examples on how to use 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);

Examples using -ORBInitRef

You can also use the -ORBInitRef option to orb.init and resolve_initial_reference.

Given the following -ORBInitRef definitions:

-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

then:

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");

Examples Using -ORBDefaultInitRef

You can use the -ORBDefaultInitRef and resolve_initial_reference.

Given the following -ORBDefaultInitRef definition:

-ORBDefaultInitRef corbaloc:tgiop:simpapp

then:

orb.resolve_initial_references("NameService");

Using the corbaname URL Format

You can also use the corbaname format instead of the corbaloc format.

Examples Using -ORBInitRef

Given the following -ORBInitRef definition:

-ORBInitRef NameService=corbaloc:tgiop:simpapp/NameService
then:
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");

 


How to Manage Transactions for Tuxedo CORBA Applications

Note: For more information on managing transactions in Tuxedo CORBA applications, see Overview of Transactions in BEA Tuxedo CORBA Applications.

The WebLogic Tuxedo Connector uses the Java Transaction API (JTA) to manage transactions with Tuxedo Corba Applications. For more detailed information, see:


  Back to Top       Previous  Next