Oracle 9iAS Containers for J2EE - Release 2

Date: 07/02/02

How-To: Connect to EJBs in OC4J via RMI over IIOP

After completing this how-to you should be able to:

Software Requirements

Although no software is required for this document, the software listed below is the minimum required for providing a How-To.

Notation

Introduction

Application integration is fast becoming a prime requirement for enterprise applications. Many projects require Java applications to inter-operate with legacy systems, and systems written in other programming languages. Enabling JavaTM applications to communicate with other applications and systems was a prime requirement for the J2EETM 1.3 specification and this is achieved using RMI-IIOP. RMI-IIOP delivers CORBA distributed computing capabilities to the JavaTM programming platform. For further information on RMI-IIOP, please see Sun's RMI-IIOP site.

OC4J configuration

To enable RMI-IIOP, there are 4 steps that have to be taken. First is to configure the server.xml, the second is to start the server in IIOP mode, the third is to deploy your application to OC4J and the fourth is obtain the client stubs. Follow the steps below to enable IIOP in OC4J

  1. Edit the file %J2EE_HOME%/config/server.xml. After the line defining the rmi.xml file location, add the line below. The internal-settings.xml file is used to configure the port that IIOP requests are received on (4444 by default), the server name and the server extension class that is used to process the IIOP calls.
  2. <sep-config path="./internal-settings.xml" />

  3. Start the server in IIOP mode with the command below. This starts the server extension supporting IIOP mode, enabling the IIOP protocol in addition to the default ORMI protocol for communications with the server.

    java -DGenerateIIOP=true -jar oc4j.jar

  4. Deploy your application to OC4J using the admin.jar utility. Client stubs will only be generated for applications deployed to OC4J when it is started in IIOP mode. Applications already deployed are not affected and do not have client stubs generated. An example deployment command is shown below.

    Java -jar admin.jar ormi://localhost admin manager -deploy -file ./applications/myapp.ear -deploymentName myapp

  5. Copy the generated client stubs into your client's source path. The generated stubs can be located in %J2EE_HOME%/application-deployments/<application-name>/<ejb-module-name> directory. Copy the file named <EJB-module-name>_iiopClient.jar into your client's classpath. For example, if your EJB module is called myejb.jar, and the parent application is called myapp, the generated client stubs will be %J2EE_HOME%/application-deployments/myapp/myejb.jar/myejb.jar_iiopClient.jar.

Once you have copied the generated stubs into the client's classpath, you can run the client as normal. If you are used to the default ORMI protocol, the connect string for the server is now slightly different. For example, to connect to the application myapp on the server myserver, using ORMI, your connect string would be ormi//myserver/myapp, using IIOP it is now corbaname::myserver:4444#/myapp. The '#' is not a typo but is required. Alternative URL constructions may be used for RMI-IIOP as well. For example, the preceding URL may also be written as corbaloc:iiop:1.2@myserver:4444/myapp

For more information on CORBA naming schema's in Java, check out Sun's documentation

Gotchas

Watch out for the following points.

Prerequisites for running the examples

Before running the example make sure:

The ZIP file contains the following files

Compiling and deploying the application

To generate the EAR files, Ant can be used with the provided build scripts. The script can be used to build the EAR file, deploy it to OC4J and run the client.

Using Ant

  1. Ensure Ant 1.4.x or above is installed on your machine and configured correctly.

  2. Set %JAVA_HOME% and %OC4J_HOME% environment variables.  Note: On some operating systems Ant does not currently support the use of environment variables,  if this is the case for your operating system,  please modify the common.xml file located in the root example directory.

  3. Start OC4J in a separate command window with the command below
  4. java -DGenerateIIOP=true -jar oc4j.jar

  5. From the <example_home> directory [the directory where the build.xml file is located] execute the following command to build the EAR file:
  6. ant

  7. To deploy the EAR file, from the same command window, execute the following command:
  8. ant deploy-usingadmin.jar

  9. Check the the client stubs have been generated by looking for rmiiiop-ejb.jar_iiopClient.jar in the directory %J2EE_HOME%/application-deployments/rmiiiop/rmiiiop-ejb.jar

Running the application

After building and deploying the application, you can run the provided client. Make sure that OC4J is still up and running. To run the client, from the same window (and directory) that you deployed the application from, execute the following command:

ant run.

You will see output similar to the one below.

Buildfile: build.xml

common:
    [echo] BuildName: RMI-IIOP
    [echo] BuildHome: D:\projects\PM\docs\how-to-RMI-over-IIOP
    [echo] BuildFile: D:\projects\PM\docs\how-to-RMI-over-IIOP\build.xml
    [echo] BuildJVM: 1.3

init:

setup:

cli-classes:
    [javac] Compiling 1 source file to D:\projects\PM\docs\how-to-RMI-over-IIOP\build\rmiiiop\rmiiiop-client

cli-descriptor:

cli-jar:
    [jar] Building jar: D:\projects\PM\docs\how-to-RMI-over-IIOP\lib\rmiiiop-client.jar

rmi-cli-jar:
    [copy] Copying 1 file to D:\projects\PM\docs\how-to-RMI-over-IIOP\lib

run:
    [java] Connected via RMI-IIOP
    [java] Object = IOR:0000000000000037524d493a686f77746f2e726d6969696f702e6f63346a2e656a622e52656 d6f7465486f6d653a30303030303030303030303030303030000000000001000000000000007c000102000000000e3133382 e332e3136372e31363600115c00000031afabcb0000000020bd1a46e60000000100000000000000010000000c4e616d65536 572766963650000000004000000020a000000000000010000000100000020000000000001000100000002050100010001002 0000101090000000100010100
    [java] Message from remote bean: You have successfully accesed the remote bean!
    [java] Connected via ORMI
    [java] Object = Remote EJBHome
    [java] Message from remote bean: You have successfully accesed the remote bean!

BUILD SUCCESSFUL

Total time: 7 seconds

Summary

After completing this how-to, you should now be able to