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

Part Number A83722-01

Library

Solution Area

Contents

Index

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

Callback Example

The callback example is available online at demo/examples/corba/basic/callback.

README

Overview
========

callback shows a CORBA server object that calls back to the client-side
object. It works by activating a new object in the client-side ORB, using the
Basic Object Adapter (BOA), and boa.obj_is_ready(), and sending a reference to
that object to the CORBA server object.

Source files
============

client.idl
----------

The CORBA IDL that defines the client-side object, that will be called
from the server.

interface Client
  wstring helloBack()


server.idl
----------

The CORBA IDL that defines the server-side object, that will be called
from the client, and that will in turn call back to the client.

interface Server
  wstring hello (in client::Client object)

Since the object is registered on the client side, and is not
published in the database, to perform a callback the server object
must have a reference to the client-side object. In this example, the
server is called with a reference to the object that has been
registered with the client-side Basic Object Adapter (BOA) as a
parameter.


Client.java
-----------

Invoke the client program from a command prompt, and pass it four arguments,
the

   - service URL (service ID, hostname, port, and SID if port is a listener)
   - name of the published bean to lookup and instantiate
   - username
   - password that authenticates the client to the Oracle8i database server

For example:

% java -classpath LIBs Client sess_iiop://localhost:2222 \
    /test/myHello scott tiger

where LIBs is the classpath that must include

$ORACLE_HOME/lib/aurora_client.jar
#If using Java 2, use classes12.zip instead of classes111.zip
$ORACLE_HOME/jdbc/lib/classes111.zip
$ORACLE_HOME/lib/vbjorb.jar
$ORACLE_HOME/lib/vbjapp.jar
$JAVA_HOME/lib/classes.zip

The client code performs the following steps:

   - gets the arguments passed on the command line
   - creates a new JNDI Context (InitialContext())
   - looks up the published CORBA 'Server' object to find and activate it
   - starts up the ORB on the client system (ORB.init())
   - gets the basic object adapter object (BOA)
   - instantiates a new client callback object (new ClientImpl()), and
       registers it with the object adapater (boa.obj_is_ready(client))
   - invokes the hello() method on the server object, passing it the
       reference to the client callback object

It is important to do the lookup() before initializing the ORB on the Client
side: The lookup call initializes the ORB in a way that's compatible with
Oracle 8i.  The following org.omg.CORBA.ORB.init() call does not initialize a
new ORB instance but just returns the orb that was initialized by the lookup
call.

The client prints:

I Called back and got: Hello Client World!

which is the concatenation of the strings returned by the server
object, and the called-back client-side object.


serverServer/ServerImpl.java
----------------------------

This class implements the server interface. The code has one method, hello(),
which returns its own String ("I called back and got: ") plus the
String that it gets as the return from the callback to the client.


clientServer/ClientImpl.java
----------------------------

This class implements the client interface. It has a public constructor, which
is required, and a single method, helloBack(), which simply returns the String
"Hello Client World!" to the client that called it (the server object 'server'
in this case).



Compiling and Running the Example
=================================

UNIX
----

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.

IDL Files

Client.IDL

module client {
  interface Client {
    wstring helloBack ();
  };
};

Server.IDL

#include <client.idl>

module server {
  interface Server {
    wstring hello (in client::Client object);
  };
};

Server

ServerImpl.java

/* $Header: ServerImpl.java 14-mar-00.13:48:31 ielayyan Exp $ */
/* Copyright (c) Oracle Corporation 2000. All Rights Reserved. */
package serverServer;

import server.*;
import client.*;
import oracle.aurora.AuroraServices.ActivatableObject;

public class ServerImpl extends _ServerImplBase implements ActivatableObject 
{
  public String hello (Client client) {
    return "I Called back and got: " + client.helloBack ();
  }

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

Client

The client invokes the server object, which calls back to another object on the client-side. The originating client is implemented in Client.java. The client-side callback object is implemented in ClientImpl.java.

Client.java

import server.*;
import client.*;
import clientServer.*;

import oracle.aurora.jndi.sess_iiop.ServiceCtx;

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];

    Hashtable env = new Hashtable ();
    env.put (Context.URL_PKG_PREFIXES, "oracle.aurora.jndi");
    env.put (Context.SECURITY_PRINCIPAL, user);
    env.put (Context.SECURITY_CREDENTIALS, password);
    env.put (Context.SECURITY_AUTHENTICATION, ServiceCtx.NON_SSL_LOGIN);
    Context ic = new InitialContext (env);

    // Get the server object before preparing the client object
    // You have to do it in that order to get the ORB initialized correctly
    Server server = (Server)ic.lookup (serviceURL + objectName);

    // Create the client object and publish it to the orb in the client
    //org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init ();
    com.visigenic.vbroker.orb.ORB orb = oracle.aurora.jndi.orb_dep.Orb.init();
    org.omg.CORBA.BOA boa = orb.BOA_init ();
    ClientImpl client = new ClientImpl ();
    boa.obj_is_ready (client);

    // Pass the client to the server that will call us back
    System.out.println (server.hello (client));
  }
}

ClientImpl.java

/* $Header: ClientImpl.java 14-mar-00.13:48:25 ielayyan Exp $ */
/* Copyright (c) Oracle Corporation 2000. All Rights Reserved. */
package clientServer;

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

public class ClientImpl extends _ClientImplBase implements ActivatableObject 
{
  public String helloBack () {
    return "Hello Client World!";
  }

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


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

All Rights Reserved.

Library

Solution Area

Contents

Index