All Examples
package examples.rmi_iiop.hello
hello example package
about this example
This example illustrates:
- Creating an RMI remote object
- Separation of RMI classes and CORBA classes
- Using the RMI compiler to generate an IDL
- Compiling the IDL to obtain client-side stubs and helper classes
- Using the utils.host2ior utility to
produce the server's Inter-operable Object Reference (IOR)
- Accessing an RMI object from a CORBA client (Java and C++ client)
The example demonstrates connectivity between an RMI server and a CORBA client.
In this example, a remote object is created and accessed by two types of CORBA clients,
a Java client and a C++ client. Both clients are "IDL clients" developed using the CORBA/
CosNaming programming model and therefore
do not require any WebLogic classes. The
remote object, HelloImpl,
is created implementing the HelloWorld
interface. The WebLogic RMI compiler is used to create IDL file that defines
the HelloWorld interface. The HelloWorld.idl file is then used to create stubs and helper
classes appropriate for the type of client. Intructions for building and running
the Java CORBA client are included below. See C++ client
for instructions on building and running the C++ CORBA client.
In this example, the Java client was created to use
VisiBroker for Java, version 3.4.
You will need to have a copy of VisiBroker for Java installed on your machine
to run this example. Since
RMI over IIOP is only supported under the 1.3 JVM, you must run WebLogic Server
using the 1.3 JVM.
how to use this example
Build the example:
Build the RMI object
- Set up your development shell, as described in
Setting up
your environment.
- Compile the RMI interface and implementation class as
shown in this example for Windows NT:
$ javac -d %SERVER_CLASSES% HelloWorld.java HelloImpl.java
- Run the RMI compiler on the implementation class as show in this example for Windows NT:
$ java weblogic.rmic -d %SERVER_CLASSES% -idl
-idlDirectory idlSource examples.rmi_iiop.hello.HelloImpl
The step above generates a HelloWorld.idl file
in the /idlSource/examples/rmi_iiop/hello directory
below the current directory. Since the HelloWorld interface extends
java.rmi.Remote, a Remote.idl
file is also generated in the /idlSource/java/rmi directory
below the current directory.
Build the client
Now that you have an IDL describing the remote interface, you can build your CORBA client application.
Package and class names can be repeated on the server- and client- side, particularly with the class
that defines the remote interface. Since the RMI object and the CORBA client have different type systems, the
class that defines the interface for the server-side will be very different from the class that
defines the interface on the client-side. Because of this, it is essential that your CLASSPATH does
not include the RMI object classes when building or running the client. The following steps create
a new development environment prior to building and running the client.
- Create a directory for the CORBA client classes named
corbaclient under the /myserver directory in your
WebLogic Server distribution.
- Create a new command shell and set the CLASSPATH and PATH as shown in this example for Windows NT (from
the point forward, this shell will be refered to as the "client shell").
$ set CLASSPATH=JavaHome\lib\classes.zip;
WebLogicHome\myserver\corbaclient;
VisiBrokerHome\lib\vbjcosnm.jar;
VisiBrokerHome\lib\vbjorb.jar;
VisiBrokerHome\lib\vbjapp.jar
$ set PATH=JavaHome\bin;VisiBrokerHome\bin
where:
- JavaHome
- Installation directory of your JDK (this entry may be omitted if you are using Java2)
- WebLogicHome
- Installation directory of WebLogic Server
- VisiBrokerHome
- Installation directory of VisiBroker for Java 3.4
Notice that the client application does not require any WebLogic classes. The
/weblogic/myserver/corbaclient directory is included in the
classpath only as a repository for the client classes created in this example.
- Both the HelloWorld.idl and the
Remote.idl files contain the directive
#include orb.idl. If your ORB vendor has
provided an orb.idl file, you should add the
directory containing orb.idl to the include path
when running the IDL compiler. The
orb.idl that is shipped in the
/weblogic/lib directory is intended to work with
ORBs that support Objects-By-Value. Since VisiBroker 3.4 does not support Objects-By-Value and does not
provide its own orb.idl, you will need to
comment-out the #include orb.idl line from the
HelloWorld.idl and
Remote.idl files prior to performing the following step.
- In the client shell, cd to this directory and compile the HelloWorld.idl file with the
VisiBroker idl2java utility
as shown in this example for Windows NT:
$ idl2java -IidlSource idlSource\examples\rmi_iiop\hello\HelloWorld.idl
- The step above generates additional Java classes into
the subdirectory \examples\rmi_iiop\hello
underneath the current directory. In the client shell, compile the
generated files as shown in this examples for Windows NT:
$ javac -d WebLogicHome\myserver\corbaclient examples\rmi_iiop\hello\*.java
where WebLogicHome is the WebLogic Server
installation directory.
- In the client shell, compile HelloClient as shown
in this example for Windows NT:
$ javac -d WebLogicHome\myserver\corbaclient HelloClient.java
where WebLogicHome is the WebLogic Server
installation directory.
Configure the server:
- Configure the implementation class as a startup class by adding the
following line in the
weblogic.properties file:
weblogic.system.startupClass.hello=examples.rmi_iiop.hello.HelloImpl
Run the example:
-
Start the WebLogic Server in a new command shell using JDK 1.3.
- Obtain the WebLogic Server Inter-operable Object Reference (IOR) by running the
host2ior utility in the command shell that
you compiled the RMI object as shown in this example for Windows NT:
$ java utils.host2ior hostname port
where:
- hostname
- Host name of the WebLogic Server
- port
- Port where the WebLogic Server is listening for connections
(weblogic.system.ListenPort).
The WebLogic Server IOR will be returned to the console. Select and copy the IOR to the clipboard. The console
may insert line breaks into the IOR where it wraps to the next line. You must remove the linebreaks before pasting the IOR
into the command-line argument list of an RMI over IIOP example. You can remove the line breaks by pasting into the IOR into
an text editor, deleting the linebreaks, then re-copying the IOR to the clipboard.
-
In the client shell, run the HelloClient
client with the following command:
$ java examples.rmi_iiop.hello.HelloClient ServerIOR
where ServerIOR is the IOR you obtained by
running the host2ior utility.
You should see "Hello world!!!" printed in the command shell running the server. The server will throw two
java.net.SocketExceptions. This
is the expected behavior, when the socket is closed by a client application.
there's more...
Read more about WebLogic RMI over IIOP in the Developer Guide,
Using
WebLogic RMI over IIOP.
Read more about WebLogic RMI in the Developer Guide,
Using
WebLogic RMI.
Copyright © 2000 BEA Systems, Inc.
All rights reserved.
Last updated
3/7/2000