This chapter describes how to modify applications to use Oracle WebLogic Tuxedo Connector to support interoperability between Oracle WebLogic Server and Oracle Tuxedo CORBA objects.
This chapter includes the following sections:
How to Develop Oracle WebLogic Tuxedo Connector Client Beans using the CORBA Java API
How to Develop RMI/IIOP Applications for the Oracle WebLogic Tuxedo Connector
How to Manage Transactions for Oracle Tuxedo CORBA Applications
Note:
You will need to perform some administration tasks to configure the Oracle WebLogic Tuxedo Connector for CORBA interoperability. For information on how to administer the Oracle WebLogic Tuxedo Connector for CORBA interoperability, see "Administration of Corba Applications"For information on how to develop Oracle Tuxedo CORBA applications, see CORBA Programming at http://docs.oracle.com/cd/E13203_01/tuxedo/tux100/interm/corbaprog.html
.
The Oracle WebLogic Tuxedo Connector enables objects (such as EJBs or RMI objects) to invoke upon CORBA objects deployed in Oracle Tuxedo using the CORBA Java API (Outbound). Oracle WebLogic Tuxedo Connector implements a WTC ORB which uses Oracle WebLogic Server RMI-IIOP runtime and CORBA support. This enhancement provides the following features:
Support of out and inout parameters
Support for a call a CORBA service from Oracle WebLogic Server using transactions and security.
Support for an ORB hosted in JNDI rather than an instance of the JDK ORB used in previous releases.
A wrapper is provided to allow users with legacy applications to use the new ORB without modifying their existing applications. Oracle recommends that users migrate to the new method of looking up the ORB in JNDI instead of doing:
ORB orb = ORB.init(args, Prop);
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 Oracle Tuxedo:
Note:
For more information on object references, see How to Use FederationURL FormatsThe Oracle WebLogic Tuxedo Connector uses the CosNaming service to get a reference to an object in the remote Oracle 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 an Oracle Tuxedo CORBA Object:
// Get the simple factory.
org.omg.CORBA.Object simple_fact_oref =
orb.string_to_object("corbaname:tgiop:simpapp#simple_factory");
Where:
simpapp
is the domain id of the Oracle Tuxedo domain specified in the Oracle Tuxedo UBB.
simple_factory
is the name that the object reference was bound to in the Oracle Tuxedo CORBA CosNaming server.
Note:
For an example on how to develop client beans for outbound Oracle Tuxedo CORBA objects, see theORACLE_HOME
\wlserver\samples\server\wtc\corba\simpappcns
package in your Oracle WebLogic Server examples distribution. For more information on the WebLogic Server code examples, see "Sample Applications and Code ExamplesThe following ToupperCorbaBean.java
code provides an example of how to call the WTC ORB and get an object reference using the COSNaming Service.
Example 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); } } . . .
Note:
For more information on object references, see How to Use FederationURL FormatsOracle 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:
simpapp
is the domain id of the Oracle Tuxedo domain specified in the Oracle Tuxedo UBB.
FactoryFinder
is the name that the object reference was bound to in the Oracle Tuxedo CORBA server.
WLEC is no longer available or supported in Oracle WebLogic Server. WLEC users should migrate their applications to Oracle WebLogic Tuxedo Connector. For more information, see WebLogic Tuxedo Connector Migration Guide for WLEC to Oracle WebLogic Server.
The following code provides an example of how to call the WTC ORB and get an object reference using FactoryFinder.
Example 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); } . . .
Note:
For more information on how to develop RMI/IIOP applications, see Developing RMI Applications for Oracle WebLogic ServerRMI 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 Oracle WebLogic Tuxedo Connector:
Enables Oracle Tuxedo CORBA objects to invoke upon EJBs deployed in Oracle WebLogic Server (Inbound).
Enables objects (such as EJBs or RMI objects) to invoke upon CORBA objects deployed in Oracle Tuxedo (Outbound).
The following sections provide information on how to modify RMI/IIOP applications to use the Oracle WebLogic Tuxedo Connector to interoperate with Oracle Tuxedo CORBA applications:
How to Modify Inbound RMI/IIOP Applications to use the Oracle WebLogic Tuxedo Connector
How to Develop Outbound RMI/IIOP Applications to use the Oracle WebLogic Tuxedo Connector
A client must pass the correct name to which the Oracle 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 "Administration of Corba Applications" in Administering WebLogic Tuxedo Connector for Oracle WebLogic Server.
Example 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(""); . . .
An EJB must use a FederationURL to obtain the initial context used to access a remote Oracle Tuxedo CORBA object. Use the following sections to modify outbound RMI/IIOP applications to use the Oracle WebLogic Tuxedo Connector:
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.
Example 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:
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 Example 4-4 specifies the
env-entry-name
as foreignOrb
.
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 Example 4-4 specifies that the
foreignOrb
variable passes String
data to the EJB.
The env-entry-value
element is used to specify the data that is passed to the EJB. The example code shown in Example 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 Oracle Tuxedo remote service specified in the Oracle Tuxedo UBB.
This section provides information on how to use the FederationURL to obtain the InitialContext used to access a remote Oracle Tuxedo CORBA object.
The following code provides an example of how to use FederationURL to get an InitialContext.
Example 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 Oracle Tuxedo CORBA object:
Retrieve the FederationURL format defined in the ejb-jar.xml
file.
Example:
"ic.lookup("java:/comp/env/foreignOrb")
The example code shown in Example 4-4 specifies that the
foreignOrb
variable passes the following FederationURL format to the EJB:
corbaloc:tgiop:simpapp
Concatenate the FederationURL format with "/NameService
" to form the FederationURL.
Example:
"ic.lookup("java:/comp/env/foreignOrb") + "/NameService"
The resulting FederationURL is:
corbaloc:tgiop:simpapp/NameService
Get the InitialContext.
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 Oracle Tuxedo CORBA object.
This section provides information on the syntax for the following FederationURL formats:
The CORBA URL
syntax is described in the CORBA specification. For more information, see the OMG Web Site at http://www.omg.org/
.
The corbaloc:tgiop
form is specific to the Oracle tgiop protocol.
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
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);
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");
You can also use the corbaname
format instead of the corbaloc
format.
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");
Note:
For more information on managing transactions in Oracle Tuxedo CORBA applications, see "Overview of Transactions in Tuxedo CORBA Applications" in Using CORBA Transactions athttp://docs.oracle.com/cd/E13203_01/tuxedo/tux100/trans/gstrx.html
.The Oracle WebLogic Tuxedo Connector uses the Java Transaction API (JTA) to manage transactions with Oracle Tuxedo Corba Applications. For more detailed information, see:
"Transaction Design and Management Options" in Developing Enterprise JavaBeans, Version 2.1, for Oracle WebLogic Server