Oracle8i Enterprise JavaBeans and CORBA Developer's Guide
Release 8.1.5

A64683-01

Library

Product

Contents

Index

Prev  Chap Top Next

RMI Examples

helloworld

readme.txt

Overview
========

The CORBA/RMI helloworld example is the basic example that shows you how
to do RMI calls using the Oracle8i IIOP/RMI transport.

The hello directory contains the interface file Hello.java. This file is
compiled by the java2rmi_iiop compiler to produce the stub and helper files
that are needed to access the remote object that is defined in:
helloServer/HelloImpl.java

Note that hello/Hello.java imports both java.rmi.Remote and
java.rmi.RemoteException, which is required for RMI interfaces.

This example uses the java2rmi_iiop command line tool to generate the required
support classes for the remore object. See the "Tools" chapter of the Oracle8i
EJB and CORBA Developer's Guide for information about this tool.


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

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

You 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:2481:ORCL \
     /test/myHello scott tiger

where LIBs is the classpath that must include

$ORACLE_HOME/lib/aurora_client.jar
$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
   - invokes the hello() method on the server object
   - prints the return from hello()

The printed output is the unsurprising:

Hello World!


helloServer/HelloImpl.java
--------------------------

HelloImpl.java defines the hello() method. 


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.

Client.java

import hello.Hello;

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

    Hello hello = (Hello)ic.lookup (serviceURL + objectName);
    System.out.println (hello.helloWorld ());
  }
}

hello/Hello.java

package hello;

import java.rmi.Remote;
import java.rmi.RemoteException;

public interface Hello extends Remote {
  public String helloWorld () throws RemoteException;
}

helloServer/HelloImpl.java

package helloServer;

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

public class HelloImpl extends _HelloImplBase implements ActivatableObject
{
  public String helloWorld () throws java.rmi.RemoteException {
    return "Hello World!";
  }

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

callouts

Client.java

import hello.Hello;

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

    Hello hello = (Hello)ic.lookup (serviceURL + objectName);
    System.out.println (hello.helloWorld ());
  }
}

HelloRMIClient.java

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

import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;

public class HelloRMIClient
{
  static public void main (String args[]) throws Exception {
    Hello hello = (Hello) Naming.lookup ("rmi://localhost/subHello");
    System.out.println (hello.helloWorld ());
  }
}

HelloRMIServer.java

import hello.Hello;
import helloServer.HelloRMIImpl;
import java.rmi.*;
import java.rmi.server.*;

public class HelloRMIServer {
  public static void main (String args[]) throws Exception {
    //    System.setSecurityManager (new RMISecurityManager ());
    HelloRMIImpl hello = new HelloRMIImpl ();
    System.out.println("Hello RMI Server ready.");
  }
}

hello/Hello.java

package hello;

import java.rmi.Remote;
import java.rmi.RemoteException;

public interface Hello extends Remote {
  public String helloWorld () throws RemoteException;
}

helloServer/HelloImpl.java

package helloServer;

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

import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;

public class HelloImpl extends _HelloImplBase implements ActivatableObject 
{
  public String helloWorld () throws RemoteException {
    try {
      Hello hello = (Hello) Naming.lookup ("rmi://localhost/subHello");
      return hello.helloWorld ();
    } catch (Exception e) {
      return (e.toString ());
    }
  }

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

helloServer/HelloRMIImpl.java

package helloServer;
import hello.*;

import java.util.*;
import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;

public class HelloRMIImpl extends UnicastRemoteObject implements Hello
{
  public HelloRMIImpl () throws RemoteException {
    super ();
    try {
      Naming.rebind ("subHello", this);
    } catch (Exception e) { 
      System.out.println("Caught exception: " + e.getMessage());
      e.printStackTrace();
    }
  }

  public String helloWorld () throws java.rmi.RemoteException {
    return "Hello from the RMI server!";
  }
}

callback

readme.txt

Overview
========

The CORBA/RMI callback example shows how you can do a callback from a CORBA
server object to a client system using RMI for the callback. There is no IDL
for this example. Rather, the sources server/Server.java and
client/Client.java are used by the java2rmi_iiop compiler to generate the
required stub and helper classes.

Compare this example with the corba/basic/callback example, which uses CORBA
IDL, and CORBA callback mechanisms on the client.


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

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

You 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
$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
   - instantiates a Client callback object
   - invokes the hello() method on the server object, passing it the callback
       object reference (clientImpl)
   - prints the return from hello(clientImpl)

The printed output is:

I Called back and got: Hello Client World!


server/Server.java
------------------

Server.java defines the hello() method. 


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

Implements the hello() method defined in server/Server.java.


client/Client.java
------------------

Defines the helloback() method.


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

Implements the helloback() method.



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.

Client.java

import server.Server;
import clientServer.ClientImpl;

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

    ClientImpl clientImpl = new ClientImpl ();
    Server server = (Server)ic.lookup (serviceURL + objectName);
    System.out.println (server.hello (clientImpl));
  }
}

client/Client.java

package client;

import java.rmi.Remote;
import java.rmi.RemoteException;

public interface Client extends Remote {
  public String helloBack () throws RemoteException;
}

clientServer/ClientImpl.java

package clientServer;

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

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

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

server/Server.java

package server;

import client.Client;

import java.rmi.Remote;
import java.rmi.RemoteException;

public interface Server extends Remote {
  public String hello (Client client) throws RemoteException;
}

serverServer/ServerImpl.java

package serverServer;

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

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

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




Prev

Top

Next
Oracle
Copyright © 1999 Oracle Corporation.

All Rights Reserved.

Library

Product

Contents

Index