Oracle8i CORBA Developer's Guide and Reference Release 3 (8.1.7) Part Number A83722-01 |
|
It is possible for clients to access server objects without using the JNDI classes shown in the other sections of this chapter. These clients can connect to an Oracle server by using CosNaming methods.
In order to use the CORBA ORB methods, you must first retrieve the naming service object. Oracle8i prepublishes a NameService
object that you can retrieve through the ORB resolve_initial_references
method.
In CORBA, there are two methods to retrieve the NameService
initial reference: using ORBInitRef
or ORBDefaultInitRef
. At this time, we have provided only the ORBDefaultInitRef
methodology.
You must provide a service URL to the ORBDefaultInitRef
of the form of host, port, and SID. Or you can provide the service URL with host, port, service name. In addition, you can specify some optional properties, such as:
ORBUseSSL
property to true:
System.setProperty("ORBUseSSL", "true");
sess_iiop
or iiop
. Set the TRANSPORT_TYPE
property, as follows:
System.setProperty("TRANSPORT_TYPE", "sess_iiop");
NameService
without first accessing the BootService
, set the backward compatible property (ORBNameServiceBackCompat
) to false, as follows:
System.setProperty("ORBNameServiceBackCompat", "false");
USE_SERVICE_NAME
property to true, as follows:
System.setProperty("USE_SERVICE_NAME", "true");
The following example demonstrates how to retrieve the NameService
object. From this object, the login is executed and the server object is retrieved.
import java.lang.Exception; import org.omg.CORBA.Object; import org.omg.CORBA.SystemException; import org.omg.CosNaming.NameComponent; import oracle.aurora.client.Login; import oracle.aurora.AuroraServices.LoginServer; import oracle.aurora.AuroraServices.LoginServerHelper; import oracle.aurora.AuroraServices.PublishedObject; import oracle.aurora.AuroraServices.PublishingContext; import oracle.aurora.AuroraServices.PublishedObjectHelper; import oracle.aurora.AuroraServices.PublishingContextHelper; import Bank.Account; import Bank.AccountManager; import Bank.AccountManagerHelper; public class Client { public static void main(String args[]) throws Exception { // Parse the args if (args.length < 4 || args.length > 5 ) { System.out.println ("usage: Client host port username password <sid>"); System.exit(1); } String host = args[0]; String port = args[1]; String username = args[2]; String password = args[3]; String sid = null; if(args.length == 5) sid = args[4]; // Declarations for an account and manager Account account = null; AccountManager manager = null; PublishingContext rootCtx = null; // access the Aurora Names Service try { // Initialize the ORB // The service URL for the server is provided in a string // that is prefixed with 'iioploc://' and includes either // host, port, sid or, if the USE_SERVICE_NAME is set to true, // host, port, service_name. This example uses host, port, sid // and sets it in the ORBDefaultInitRef. String initref; initref = (sid == null) ? "iioploc://" + host + ":" + port : "iioploc://" + host + ":" + port + ":" + sid; System.setProperty("ORBDefaultInitRef", initref); /* * Alternatively, you can set the host, port, sid or service in the * following individual properties. If set, these properties * take precedence over the URL set within the ORBDefaultInitRef property System.setProperty("ORBBootHost", host); System.setProperty("ORBBootPort", port); if (sid != null) //set the SID. alternatively, if the USE_SERVICE_NAME property is //true, this should contain the service name instead of the sid. System.setProperty("ORACLE_SID", sid); */ /* * Some of the other properties that you can set * include the backwards compatibility flag, the service name * indicator, the SSL protocol definition, and the transport type. System.setProperty("ORBNameServiceBackCompat", "false"); System.setProperty("USE_SERVICE_NAME", "true"); System.setProperty("ORBUseSSL", "true"); //transport type can be either sess_iiop or iiop System.setProperty("TRANSPORT_TYPE", "sess_iiop"); */ //initialize the ORB com.visigenic.vbroker.orb.ORB orb =
oracle.aurora.jndi.orb_dep.Orb.init(); // Get the Name service Object reference with the
// resolve_initial_references method rootCtx = PublishingContextHelper.narrow(orb.resolve_initial_references( "NameService")); //After retrieving the NameService initial reference, you must perform // the login, as follows: // Get the pre-published login object reference PublishedObject loginPubObj = null; LoginServer serv = null; NameComponent[] nameComponent = new NameComponent[2]; nameComponent[0] = new NameComponent ("etc", ""); nameComponent[1] = new NameComponent ("login", ""); // Lookup this object in the Name service Object loginCorbaObj = rootCtx.resolve (nameComponent); // Make sure it is a published object loginPubObj = PublishedObjectHelper.narrow (loginCorbaObj); // create and activate this object (non-standard call) loginCorbaObj = loginPubObj.activate_no_helper (); serv = LoginServerHelper.narrow (loginCorbaObj); // Create a client login proxy object and authenticate to the DB Login login = new Login (serv); login.authenticate (username, password, null); // Now create and get the bank object reference PublishedObject bankPubObj = null; nameComponent[0] = new NameComponent ("test", ""); nameComponent[1] = new NameComponent ("bank", ""); // Lookup this object in the name service Object bankCorbaObj = rootCtx.resolve (nameComponent); // Make sure it is a published object bankPubObj = PublishedObjectHelper.narrow (bankCorbaObj); // create and activate this object (non-standard call) bankCorbaObj = bankPubObj.activate_no_helper (); manager = AccountManagerHelper.narrow (bankCorbaObj); account = manager.open ("Jack.B.Quick"); float balance = account.balance (); System.out.println ("The balance in Jack.B.Quick's account is $" + balance); } catch (SystemException e) { System.out.println ("Caught System Exception: " + e); e.printStackTrace (); } catch (Exception e) { System.out.println ("Caught Unknown Exception: " + e); e.printStackTrace (); } } }
See "Ending a Session" for more information on the LoginServer
, Login
, and LogoutServer
objects.
CORBA 2.3 Interoperable Name Service supports both the ORBInitRef
and ORBDefaultInitRef
methodologies for creating and retrieving initial references. At this time, Oracle8i only supports an IIOP URL scheme within the ORBDefaultInitRef
, as shown in "Retrieving the NameService Initial Reference". You can only provide either a host, port, SID or host, port, service name combination--prefixed by "iioploc://
"--to the ORBDefaultInitRef
for locating the initial reference. Within this location, the service must have been activated. Any service activated within the specified location can be retrieved using the resolve_initial_references
method with its object key, which is defined at the time of activation.
For example, if you set the ORBDefaultInitRef to the following server URL:
System.setProperty("ORBDefaultInitRef","iioploc://myHost:myPort:mySID);
Then, initialize the ORB and retrieve your service, as follows:
//initialize the ORB com.visigenic.vbroker.orb.ORB orb = oracle.aurora.jndi.orb_dep.Orb.init(); // Get the myService service Object reference with resolve_initial_references rootCtx = PublishingContextHelper.narrow(orb.resolve_initial_references( "myService"));
The object key that is used to retrieve the service is "myService
". The object with this key is returned with the resolve_initial_references
method.
The following are the Oracle8i services that are activated during startup: NameService
, BootService
, AuroraSSLCurrent
, and AuroraSSLCertificateManager
.
If you want Oracle8i to initiate any services for you during startup, supply a string with a comma-separated list of services to be installed when the ORB is initialized in the UserORBServices
property. Each service must be a fully-qualified package name and name of the class that extends the ORBServiceInit
class. You must extend this class in order for your service to be installed by Oracle8i.
|
Copyright © 1996-2000, Oracle Corporation. All Rights Reserved. |
|