 |
RMI-IIOP
Hello IDL Sample
Copyright © 1999 Sun Microsystems, Inc.
Copyright © 1999 International Business Machines
Corporation. All Rights Reserved.
|
Sample: RMI-IIOP Inter-operating with IDL
This sample illustrates how an RMI-IIOP program can inter-operate with
a conventional IDL program. It assumes that you have already built and
run the RMI-IIOP" Hello World!" sample
program. This sample shows inter-operability with IDL programs built in
Java but of course any programming language which supports IDL could be
used.
When you have built the two sets of clients and servers you will be
able to run them in the following combinations:
Client |
Server |
RMI-IIOP |
RMI-IIOP |
IDL |
IDL |
RMI-IIOP |
IDL |
IDL |
RMI-IIOP |
The Files
The sample IDL source code is found in the $JAVA_HOME/demo/rmi-iiop/idl
directory.
There you will find the following files:
-
RemoteHelloServer.java - the server IDL application
-
RemoteHelloApplet.java - a client IDL applet
-
RemoteHelloApplication.java - a client IDL application
-
idl.html - HTML for applet with IDL settings
To provide a complete explanation in the steps that follow, we make the
following assumptions:
A server named aslan.narnia.com.
A writeable build directory of $DEMO_HOME (for example, $HOME/rmi-iiop/demo).
A running HTTP server with root $SERVER_ROOT. Class files resulting
from a sample build go into a codebase of $SERVER_ROOT/java. Classes
in this directory will be loaded remotely; files to be copied into this
directory will be listed in the instructions below.
The Transient Name Server will use port 1050. If you want to use a different
port number, you must change the org.omg.CORBA.ORBInitialPort
parameter in idl.html, as well as the number used in the steps
below.
Setting Up the Environment
Set your CLASSPATH environment variable so that the current directory
(".") is at the beginning. Set your PATH environment variable to include
$JAVA_HOME/jre/sh:$JAVA_HOME/sdk/jre/sh, where JAVA_HOME is the
directory where the Java SDK is installed.
Building the IDL program
After configuring your environment, as explained above, change directory
to $DEMO_HOME/idl.
-
Copy the demo files to your demo build directory:
cp $JAVA_HOME/demo/rmi-iiop/idl/*.java .
-
Change directory to $DEMO_HOME.
cd ..
-
Create the IDL files.
rmic -idl -d idl hello.RemoteHelloServer
-
Go to the IDL samples directory.
cd idl
-
Run the IDL to java converter to create the client-side .java
files.
idlj hello/RemoteHello.idl
(Note: the above is equivalent to: idlj -Fclient hello/RemoteHello.idl)
-
Compile the client IDL application and the client applet.
javac -d . RemoteHelloApplication.java
javac -d . RemoteHelloApplet.java
-
Run the IDL to java converter to create the sever-side .java files.
(Note: This step and the following step are optional if you only require
an IDL client.)
idlj -Fall hello/RemoteHello.idl
-
Compile the IDL server application
javac -d . RemoteHelloServer.java
Distributing the files
For the client IDL application you must copy the following files to a "hello"
sub-directory on your client system.
-
RemoteHelloApplication.class
-
RemoteHello.class
-
RemoteHelloOperations.class
-
RemoteHelloHelper.class
-
_RemoteHelloStub.class
Copy the following .class files to your server directory (e.g.
$SERVER_ROOT/java/hello
using our sample naming conventions).
-
RemoteHelloOperations.class
-
_RemoteHelloStub.class
-
RemoteHello.class
-
RemoteHelloApplet.class
-
RemoteHelloHelper.class
The idl.html file should be copied to $SERVER_ROOT.
Running the IDL Sample
Starting the name server
Run the transient name server that will be used to resolve the name "RemoteHelloServer"
that will be used by your applicaton. The name server you run is the same
whether you are running an RMI-IIOP program or an IDL one.
tnameserv -ORBInitialPort 1050
Starting your server application
Run the IDL server application, passing parameters to the system with the
-D option. Note that there must be no space between the -D and the property
text that follows it.
java -Dorg.omg.CORBA.ORBInitialHost=aslan.narnia.com
-Dorg.omg.CORBA.ORBInitialPort=1050
hello.RemoteHelloServer
Running your application client
Run the application, passing the host address and port number of the server
to the application as system properties.
java -Dorg.omg.CORBA.ORBInitialHost=aslan.narnia.com
-Dorg.omg.CORBA.ORBInitialPort=1050
hello.RemoteHelloApplication
Running your applet client
Run the applet using appletviewer.
appletviewer http://aslan.narnia.com/idl.html
It is simplest to test the applet using the appletviewer in this way.
If you want to use a browser such as Internet Explorer or Netscape Navigator you
will need to modify idl.html to enable the browser to use the Java
plug-in. Details of the Java plug-in can be found on the following website:
http://java.sun.com/products/plugin
Inter-operating
You now have a running IDL client and (optionally) an IDL server application.
If you have previously implemented the base
"Hello" sample you will also have a running RMI-IIOP client and server.
You are now ready to inter-operate between heterogeneous clients and servers.
IDL client with RMI-IIOP server
-
Start the RMI-IIOP server application as described in the instructions
for the base "Hello" sample
-
Run the IDL client (application or applet) as described above.
RMI-IIOP client with IDL server
-
Start the IDL server application as described above
-
Run the RMI-IIOP client (application or applet) as described in the instructions
for the base "Hello" sample .