Oracle8i CORBA Developer's Guide and Reference
Release 3 (8.1.7)

Part Number A83722-01


Solution Area



Go to previous page Go to beginning of chapter Go to next page

Session Example

You can manage sessions in multiple ways, which are all discussed in "Session Management Scenarios". The example presented here demonstrates how to access two sessions from a single client.



Twosessions demostrates a client that instantiates two separate sessions in
the server, and calls methods on objects in each session. It also demos use of
the login object for client authentication.

Compare this example to the ../examples/corba/session/clientserverserver
example, in which the client instantiates a server object, and that server
object then instantiates a second server object in a different session.

Source files


The CORBA IDL for the example. The IDL for the Hello object simply
defines two methods:

interface Hello
  wstring helloWorld ();
  void setMessage (in wstring message);

which must be implemented by the code.

You invoke the client program from a command line prompt, and pass it
four arguments: the service URL (service ID, hostname, and port), the
name of the published object to lookup and instantiate, and a username
and password that authenticate the client to the Oracle8i database

For example:
% java -classpath LIBs Client sess_iiop://localhost:2222 scott tiger

where LIBs is the classpath that must include

#If using Java 2, use instead of

The client first obtains a service context in the normal way, by
getting a JNDI Context object, and looking up the service context on
it, using the service URL (e.g., sess_iiop://localhost:2222).
The service context is then used to create new named sessions,
:session1 and :session2. On each session, a login server object is
instantiated, then a login client is obtained, and the authenticate()
method on the login client is used to authenticate the client.

Note that this form of authentication is what happens automatically
when a server object is instantiated, and the JNDI context is obtained
by passing in the username, password, optional database role, and the
value NON_SSL_LOGIN in the environmentg hashtable.

In this example, because the sessions are instantiated overtly, it is
necessary to also do the authentication overtly.

After session instantiation and authentication, a Hello object is
instantiated in each session, the helloWorld() method is invoked
on each, and the returned String is printed on the console.

The printed output is:

Hello from Session1
Hello from Session2


This source file implements the two methods specified in the hello.idl
file: setMessage() to set the instance variable message, and
helloWorld() to return the value set in message.

Compiling and Running the Example


Enter the command 'make all' or simply 'make' in the shell to compile,
load, and deploy the objects, and run the client program.  Other
targets are 'run' and 'clean'.

Make sure that a shell environment variable ORACLE_HOME is set to
point to the home location of the Oracle installation. This is
operating system dependent, so see the Installation documentation that
came with your system for the location. Also, review the README file
for the Oracle database, and the README file for the CORBA/EJB server
(the Oracle8i ORB), for additional up-to-date information.

Windows NT

On Windows NT, run the batch file makeit.bat from a DOS command prompt
to compile, load, and deploy the objects. Run the batch file runit.bat
to run the client program, and see the results.

Make sure that the environment variables %ORACLE_HOME%, %CLASSPATH%,
and %SERVICE% are set appropriately for the DOS command window. You
can set these as either user or system environment variables from the
Control Panel. Double click on System in the Control Panel then on
the Environment tab to set these variables. Start a new DOS window
after setting environment variable values.

See the Installation documentation that came with your Oracle8i system
for the values of these variables. Also, review the README file for
the Oracle database, and the README file for the CORBA/EJB server (the
Oracle8i ORB), for additional up-to-date information.

You can also set an environment variable %JAVA_HOME% to point to the
root of your Java JDK. For example, SET JAVA_HOME=C:\JDK1.1.6.


module hello {
  interface Hello {
    wstring helloWorld ();
    void setMessage (in wstring message);

import hello.Hello;

import oracle.aurora.jndi.sess_iiop.ServiceCtx;
import oracle.aurora.jndi.sess_iiop.SessionCtx;
import oracle.aurora.AuroraServices.LoginServer;
import oracle.aurora.client.Login;

import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.Hashtable;

public class Client
  public static void main (String[] args) throws Exception {
    if (args.length != 4) {
      System.out.println ("usage: Client serviceURL objectName user password");
      System.exit (1);
    String serviceURL = args [0];
    String objectName = args [1];
    String user = args [2];
    String password = args [3];

    // Prepare a simplified Initial Context as we are going to do
    // everything by hand
    Hashtable env = new Hashtable ();
    env.put (Context.URL_PKG_PREFIXES, "oracle.aurora.jndi");
    Context ic = new InitialContext (env);

    // Get a SessionCtx that represents a database instance
    ServiceCtx service = (ServiceCtx)ic.lookup (serviceURL);

    // Create and authenticate a first session in the instance.  
    SessionCtx session1 = (SessionCtx)service.createSubcontext (":session1");
    LoginServer login_server1 = (LoginServer)session1.activate ("etc/login");
    Login login1 = new Login (login_server1);
    login1.authenticate (user, password, null);

    // Create and authenticate a second session in the instance.  
    SessionCtx session2 = (SessionCtx)service.createSubcontext (":session2");
    LoginServer login_server2 = (LoginServer)session2.activate ("etc/login");
    Login login2 = new Login (login_server2);
    login2.authenticate (user, password, null);

    // Activate one Hello object in each session
    Hello hello1 = (Hello)session1.activate (objectName);
    Hello hello2 = (Hello)session2.activate (objectName);

    // Verify that the objects are indeed different
    hello1.setMessage ("Hello from Session1");
    hello2.setMessage ("Hello from Session2");

    System.out.println (hello1.helloWorld ());
    System.out.println (hello2.helloWorld ());


package helloServer;

import hello.*;
import oracle.aurora.AuroraServices.ActivatableObject;

public class HelloImpl extends _HelloImplBase implements ActivatableObject 
  String message;

  public String helloWorld () {
    return message;

  public void setMessage (String message) {
    this.message = message;

  public org.omg.CORBA.Object _initializeAuroraObject () {
    return this;

Go to previous page
Go to beginning of chapter
Go to next page
Copyright © 1996-2000, Oracle Corporation.

All Rights Reserved.


Solution Area