BEA Logo BEA WebLogic Enterprise Release 5.0

  Corporate Info  |  News  |  Solutions  |  Products  |  Partners  |  Services  |  Events  |  Download  |  How To Buy

 

   WLE Doc Home   |   J2EE Programming & Related Topics   |   Previous   |   Next   |   Contents   |   Index

Converting Sun JavaSoft RMI to WLE RMI Classes

It is easier to use WebLogic Enterprise (WLE) RMI if you have already written classes in the Sun Microsystems JavaSoft reference implementation of RMI. This section explains how to convert Sun JavaSoft RMI classes to WebLogic RMI using the WebLogic RMI Hello World application as an example.

Suppose you have an RMI Hello World example written similar to those found in the Sun JavaSoft documentation distribution. To convert these files for use with WLE, you must do the following.

Step 1. Modify the Java source code files.

To convert the RMI Hello World example from Sun JavaSoft RMI to WLE RMI, you must first modify the Java source code files to adjust for the following major differences:

You need to modify the following Java source code files:

Note that the file Hello.java , which contains the remote interface, is exactly the same in both the Sun JavaSoft Hello World RMI example and in WebLogic Enterprise RMI. Therefore, you do not need to make any changes to this Java source file-you can use it as is. You will need to recompile it, though, along with the other Java files.

HelloImpl.java - A Remote Object Implementation

Modify this file as follows:

  1. Remove the package imports statements for the following packages, which are not used in WLE RMI:

  2. Add package import statements for the following Java Naming and Directory Interface (JNDI) packages, which are needed by WLE RMI:

  3. Edit the rest of the code in this file based on the WLE RMI Hello World example to use the appropriate packages and J2EE features.

    For details, see Step 3. Write the source code for a remote object that implements the remote interface. in Developing RMI Applications in WLE.

HelloClient.java - A Client That Invokes Methods on the Remote Object

The RMI client can be either an applet or a Java client similar to that shown in our WLE RMI Hello World example. To convert either type of client from Sun JavaSoft RMI to WLE RMI, you must modify the client file similar to the following to account for some basic differences:

  1. Remove the following package import statement, which is not used in WLE:

  2. Add package import statements for the following Java Naming and Directory Interface (JNDI) packages, which are needed by WLE RMI:

  3. Edit the rest of the code in this file to use the appropriate packages and J2EE features. In particular, this means using JNDI for the lookup and connection bootstrapping. Once you get the object reference, be sure to use javax.rmi.PortableRemoteObject.narrow to narrow it to the appropriate type.

    For details, see the explanation of the code for the WLE Hello World RMI client in Step 4. Write the source code for a client that invokes methods on the remote object. in Developing RMI Applications in WLE.

Step 2. Compile the Java source files.

Compile the Java source files including the remote object implementation source file (HelloImpl.java), the remote interface that it extends (Hello.java ), the RMI client (HelloClient.java or an applet file), along with any other associated Java files needed for the application.

For example, the following command compiles the Java source files in examples/hello and puts the resulting class files under a directory called classes .

javac -d classes examples/hello/*.java

For more information on using the javac compiler to generate WLE RMI classes, see Step 5. Compile the source code files to create the executable RMI classes. in Developing RMI Applications in WLE.

Step 3. Run the WebLogic RMI compiler on the implementation class.

To create a proxy stub file for the client and skeleton file for the server, run the weblogic.rmic compiler on the fully-qualified package names of compiled class files that contain remote object implementations.

For the WLE RMI Hello World Example, you would run the weblogic.rmic compiler on the class file HelloImpl as follows:

java weblogic.rmic -d . examples.hello.HelloImpl

For more information about stubs and skeletons and about using the WebLogic RMI compiler to generate them, see Step 6. Run the WebLogic RMI compiler on the implementation class to generate stubs and skeletons. in Developing RMI Applications in WLE.

Step 4. Build and package the application for WLE.

Once you have the WLE RMI class files, all that is left to do is create a bootstrapping mechanism for your application and package the application into a JAR file. For information on how to do this, see the topic Building Your RMI Application in the WLE Environment.