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:
- Configure OC4J to use RMI over IIOP (RMI-IIOP)
- Connect a client to a remote EJB via RMI-IIOP
- Run the supplied example
Software Requirements
Although no software is required for this document, the software listed below
is the minimum required for providing a How-To.
- Oracle9iAS Containers
for J2EE (9.0.3) Developer Preview is installed, available from OTN
- Jakarta Ant, to build the application example, available here
- Sun's JDK 1.3_01 or above, available here
Notation
- %OC4J_HOME% - The directory in which you installed OC4J.
- %J2EE_HOME% - The directory where the oc4j.jar file exists within
OC4J. This is typically 2 directories under %OC4J_HOME%. For example,
if you installed OC4J to c:\ then %J2EE_HOME% would be c:\j2ee\home
- %JAVA_HOME% - The directory where your JDK is installed
- <example_home> - The directory how-to-rmi-iiop under
the directory where the ZIP file was extracted to
- RMI - Remote Method Invocation
- IIOP - Internet Inter-Orb protocol
- J2EE - Java 2 Enterprise Edition
- CORBA - Common Object Request Broker Architecture
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
- 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.
<sep-config path="./internal-settings.xml" />
- 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
- 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
- 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.
- Make sure your connect string is in the correct format, including the '#'.
- Make sure you copy the generated client stubs into your clients classpath.
- When running a client, if you get errors creating the IIOP context, the
most likely problem is your client not being able to find your application.
Check your application name against the application name provided in the connect
string.
Prerequisites for running the examples
Before running the example make sure:
- You have OC4J 9.0.3 Developers Preview installed.
- Open the file %J2EE_HOME/config/server.xml and place the line below
just below the tag starting <rmi-config.../>
<sep-config path="./internal-setings.xml"
/>
The ZIP file contains the following files
- how-to-rmi-over-iiop/ - Top Level Directory
- /src - contains all Java source code for the example.
- client/
- RemoteClient.java - The source for the client that will
invoke the remote EJB. This file uses the jndi.properties
file to obtain the JNDI initial context information for RMI-IIOP,
as well as a hard-coded context for ORMI. If your OC4J's admin
account's password is not manager you will have to edit
this file.
- ejb/
- Remote.java - Remote EJB remote interface.
- RemoteHome.java - Remote EJB home interface.
- RemoteBean.java - Remote EJB implementation.
- /etc/
- jndi.properties - File containing JNDI properties. Note this
assumes that your OC4J admin user's password is manager.
If this is not the case, please edit this file. You will also have
to edit the client source code.
- ejb-jar.xml - EJB Deployment descriptor
- application-client.xml - Application client deployment descriptor
- application.xml - Application deployment descriptor.
- orion-application.xml - OC4J application deployment descriptor.
- meta-inf - JAR file descriptor
- doc/
- Readme.html - This document.
- /build.xml - An Ant build file.
- /common.xml - Used by build.xml
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
- Ensure Ant 1.4.x or above is installed on your machine and configured correctly.
- 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.
- Start OC4J in a separate command window with the command below
java -DGenerateIIOP=true -jar oc4j.jar
- From the <example_home> directory [the directory where the
build.xml file is located] execute the following command to build the EAR
file:
ant
- To deploy the EAR file, from the same command window, execute the following
command:
ant deploy-usingadmin.jar
- 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
- Configure OC4J to use RMI over IIOP (RMI-IIOP)
- Connect a client to a remote EJB via RMI-IIOP
- Run the supplied example