WebLogic Server 6.0 Code Examples, BEA Systems, Inc.

Package examples.rmi_iiop.hello

This example demonstrates connectivity between an RMI server and a JavaIDL client (CORBA).

See:
          Description

Interface Summary
HelloWorld The HelloWorld interface.
 

Class Summary
HelloClient This CORBA client initializes an ORB, obtains a reference to the HelloServer, and calls HelloServer methods.
HelloImpl Implements the HelloWorld interface.
 

Package examples.rmi_iiop.hello Description

This example demonstrates connectivity between an RMI server and a JavaIDL client (CORBA).

The example illustrates:

Due to problems originating in the mapping of IDL to java (the so-called reverse mapping), more complex java client examples that begin with RMI interfaces are not useful in practice. The java example is included here for completeness. In general, a more complex example involving mapping an RMI interface to IDL and compiling the IDL into java is just not possible. For complex examples involving c++, see the sample ejb's accompanying the rmi-iiop examples

In this example, a remote object is created and accessed by two types of CORBA clients:

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. Instructions for building and running the Java CORBA client are described later in this section. 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 4.0. You will need to have a copy of VisiBroker for Java installed on your machine to run this example.

The following section describes how to build and run the examples:

  1. Build the example
  2. Configure the server
  3. Run the example

Build the example

This example provides three separate build script:

Build the RMI object

  1. Set up your development shell as described in Setting up your environment.

  2. Execute the build_rmi script provided for this example in the samples/examples/rmi_iiop/hello directory as shown in this example for Windows NT/2000:

    $ build_rmi

    The preceding script will perform the following steps:

    1. Compile the RMI interface and implementation class as shown in this example for Windows NT:

      $ javac -d %SERVER_CLASSES% HelloWorld.java HelloImpl.java

    2. Run the RMI compiler on the implementation class as shown in this example for Windows NT:

      $ java weblogic.rmic -d %SERVER_CLASSES% -idl 
           -idlDirectory idlSources examples.rmi_iiop.hello.HelloImpl
    The step above generates a HelloWorld.idl file in the /idlSources/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 /idlSources/java/rmi directory below the current directory.

Build the Java 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.
  1. Open a new command shell.

  2. Set up your development shell as described in Setting up your environment.

  3. Note: Edit the variable VISIBROKER_HOME in the build_client file provided for this example in the samples/examples/rmi_iiop/hello directory for your VisiBroker for Java installation.

  4. Execute the build_client script provided for this example in the samples/examples/rmi_iiop/hello directory as shown in this example for Windows NT/2000:

    $ build_client

    The preceding script will perform the following steps:

    1. Create a directory for the CORBA client classes named corbaclient under the /config/examples directory in your WebLogic Server distribution as shown in this example for Windows NT:

      $ mkdir %WL_HOME%\config\examples\corbaclient

    2. Set the CLASSPATH as shown in this example for Windows NT (from the point forward, this shell will be refered to as the "client shell"):

      $ set CLASSPATH=%WL_HOME%\config\examples\corbaclient;
              %WL_HOME%\lib\ir.idl;
      	%WL_HOME%\lib\orb.idl;
      	%VISIBROKER_HOME%\lib\vbjdev.jar;
              %VISIBROKER_HOME%\lib\vbjorb.jar;
              %VISIBROKER_HOME%\lib\migration.jar;
              %VISIBROKER_HOME%\lib\vbdev.jar
      where:
      %WL_HOME%
      Installation directory of WebLogic Server
      %VISIBROKER_HOME%
      Installation directory of VisiBroker for Java 4.0

    3. Set the PATH as shown in this example for Windows NT:

      $ set PATH=%PATH%;%VISIBROKER_HOME%\bin
      where:
      %VISIBROKER_HOME%
      Installation directory of VisiBroker for Java 4.0

      Notice that the client application does not require any WebLogic classes. The /weblogic/config/examples/corbaclient directory is included in the classpath only as a repository for the client classes created in this example.

    4. 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.

    5. Compile the HelloWorld.idl file with the VisiBroker idlj utility as shown in this example for Windows NT:

      $ idlj -I%WL_HOME%\lib -IidlSources idlSources\examples\rmi_iiop\hello\HelloWorld.idl
      
    6. 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 %WL_HOME%\config\examples\corbaclient examples\rmi_iiop\hello\*.java
      where %WL_HOME% is the WebLogic Server installation directory.

    7. Compile HelloClient as shown in this example for Windows NT:

      $ javac -d %WL_HOME%\config\examples\corbaclient HelloClient.java
      where %WL_HOME% is the WebLogic Server installation directory.

Configure the server

Configure the implementation class as a startup class by:
  1. Start the server with the examples configuration.
  2. Bring up the Administration Console in your browser.
  3. Click to expand the Deployments node in the left-hand pane.
  4. Click to expand the Startup & Shutdown node in the left-hand pane.
  5. Select the hello_iiop node.
  6. Select the Targets tab in the right-hand pane to display the Available and Chosen targets.
  7. Enable the hello_iiop startup class on the examplesServer.

Run the example

  1. Since startup classes are only activated when the server boots, you will need to re-start the server with the examples configuration.

  2. 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.

  3. 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:


Documentation is available at
http://e-docs.bea.com/wls/docs60

Copyright © 2000 BEA Systems, Inc. All Rights Reserved.