Looking up Remote Objects
Looking Up
Remote Objects:
EJBs
| This tutorial describes how to remotely access EJBs deployed
to standalone OC4J and EJBs deployed to OC4J embedded in Oracle Application
Server. In addition, you learn to use ORMI tunneling through HTTP to access
EJBs through a firewall. |
Approximately 40 minutes
This tutorial covers the following topics:
Place the cursor over this icon to load and view
all the screenshots for this tutorial. (Caution: Because this action loads all
screenshots simultaneously, response time may be slow depending on your Internet
connection.)
Note: Alternatively, you can place the cursor over
each icon in the following steps to load and view only the screenshot associated
with that step.
| Enterprise JavaBeans (EJB) are reusable business components.
You can decide to implement discrete business functionalities as EJBs and
make use of them in your applications. To make use of such EJBs, you must
know how to access them and also the protocol to use. To access objects
deployed to OC4J, you must get an instance of InitialContext.
Initial context factories provide an easy way for getting instances of InitialContext.
There are two initial context factories that are used for OC4J. |
 |
ApplicationClientInitialContextFactory:
The ApplicationClientInitialContextFactory
is used when looking up remote objects from standalone application clients.
It uses the refs and ref-mappings found in application-client.xml
and orion-application-client.xml.
It can be used for looking up remote EJBs in the same application. It can
also be used for looking up EJBs with local interface. |
 |
RMIInitialContextFactory:
The RMIInitialContextFactory
is used when looking up remote objects between different containers. It
is also used when browsing the complete JNDI namespace and not using the
application context. |
|
You can use three protocols to access EJBs remotely:
ORMI, RMI-IIOP, and ORMI tunneling over HTTP. It is recommended that you
use ORMI protocol by default because it provides several features such
as high availability, load balancing, and so on. ORMI is a modified flavor
of RMI. Use RMI-IIOP to access EJBs across different containers and also
for CORBA clients. You can also use ORMI to access EJBs across containers.
Whereas RMI-IIOP is a standard protocol, ORMI is Oracle's proprietary
protocol. Use ORMI tunneling over HTTP to access EJBs through firewall.
In this OBE, you learn how to
remotely access EJB that is
- Deployed to standalone OC4J
- Deployed to OC4J embedded in Application Server 10g
- Behind a firewall
You use a bean called ValidateBean.
The bean contains a business method that takes the customer card number
in the form of a String and validates the card. A card number can be alphanumeric.
A card is valid if:
- The length of the String is nine
- It starts with "AN", "BN", "CN",
or "LN"
- The last character is 'A'
- The rest of the characters are numbers and
not letters
|
Back to Topic List
Before starting this tutorial, you should:
| 1. |
Have access to two windows machines: client and server.
|
| 2. |
Install jdk1.4.2 or higher on both the machines. Also, include <jdk_install_folder>/bin
in the PATH.
|
Back to Topic List
| 1. |
Download the oc4j_client.zip
for 10.1.2 from www.otn.oracle.com.
|
| 2. |
Unzip oc4j_client.zip
file into a client-side directory (for example, d:\oc4jclient). Download
the ojdl.jar
file and place it in the d:\oc4jclient folder.
|
Back to Topic List
Configuring the Client
| 1. |
Install the OC4J client on the
client machine.
|
| 2. |
Download the client_jar.zip
file and unzip into the d:\EJB_client folder. After unzipping, the EJB_client
folder should have the following files:
ValidateCard.jar
ValidateCardClient.java
jndi.properties

|
| 3. |
At the command prompt, change directory to EJB_client
and set the CLASSPATH to
include the following:
d:\oc4jclient\j2ee\home\oc4jclient.jar
d:\oc4jclient\j2ee\home\lib\ejb.jar
d:\oc4jclient\ojdl.jar
d:\EJB_client\ValidateCard.jar
Execute the following command to set the CLASSPATH:
set CLASSPATH=%CLASSPATH%;d:\oc4jclient\j2ee\home\
oc4jclient.jar;d:\oc4jclient\j2ee\home\lib\ejb.jar;d:\oc4jclient
\ojdl.jar;d:\EJB_client\ValidateCard.jar;.;

|
Back to Topic
Configuring the Server
| 1. |
Install standalone OC4J 10.1.2 on the server.
|
| 2. |
Download the deploy.zip
file and unzip into c:\. Check whether you have the ValidateCard.ear
file in the c drive.
|
| 3. |
Start the OC4J server. Open a command prompt and change
directory to <OC4J_Home>\j2ee\home. Issue the following
command to start the OC4J server:
java -jar oc4j.jar


|
| 4. |
Open another command prompt and deploy the ear file to OC4J.


|
Back to Topic
Invoking the EJB
| 1. |
Switch to the client machine. Open the ValidateCardClient.java
file. Observe the code that is used to remotely invoke the EJB.
For a client to access the EJB on a server, you must
set some properties. These properties are constants in the Context
interface.
INITIAL_CONTEXT_FACTORY:
This specifies the initial context factory to use.
SECURITY_PRINCIPAL: This
specifies the identity of the user for authenticating to the service that
is being invoked.
SECURITY_ CREDENTIALS:
This specifies the credentials, such as password, for the user specified
in SECURITY_PRINCIPAL.
PROVIDER_URL: To remotely
access an EJB, you must specify the protocol, host, domain, and the JNDI
name. The PROVIDER_URL
contains all this information and therefore specifies the location of
the EJB. The value of a PROVIDER_URL
is a URL that can be used to search for the EJB. The URL changes depending
on the protocol used.
Instead of hard coding these properties in the client,
you can set them in the jndi.properties
file. Open the jndi.properties
file and change the IP address in the PROVIDER_URL
to the IP address of your server and save the file. You can also use hostname
instead of IP address. Change the password in java.naming.security.credentials
if the password for your installation is different.
In this example, the provider URL is ormi://152.69.149.60:23791/ValidateCard.
23791 is the default rmi port and you need not explicitly
mention the port number if you are using the default port.

|
| 2. |
Ensure that you have included all the necessary jar
files in the CLASSPATH
as per step 3 of Configuring the Client.
|
| 3. |
Switch to the command prompt and compile the client
as shown in the following screenshot.

|
| 4. |
Run the client as shown in the following screenshot.

|
Back to Topic List
Configuring the Client
| 1. |
You use the same client that you used to access an
EJB deployed to standalone OC4J. Open a command prompt. Set OC4J_HOME
to the oc4jclient install folder. Change directory to EJB_Client.

|
| 2. |
Download the setcp.bat
file and place it in the d:\EJB_Client folder. Execute the file to set
CLASSPATH.

|
Back to Topic
Deploying the ear File
to Oracle Application Server
| 1. |
Install Oracle Application Server 10g Mid Tier
(J2EE and Web Cache).
|
| 2. |
Download the deploy.zip
file and unzip to your hard disk. Check whether you have the ValidateCard.ear
file.
|
| 3. |
Open a browser window and enter the URL, http://<hostname.domain>:1810.
Note: 1810 is the default port assigned while
installing Application Server. However, if another instance is already
running on 1810, then the next port may be assigned during installation.
Enter ias_admin for User Name and enter the admin
password you specified during installation in the Password field. Click
OK.

|
| 4. |
You see the Application Server Home page. Click home in System
Components.

|
| 5. |
Click Applications.

|
| 6. |
Click Deploy EAR file.

|
| 7. |
Click Browse to select the ear file that you downloaded.


|
| 8. |
Enter ValidateCard for Application Name and click Continue.

|
| 9. |
Click Next. Again click Next. The Deploy Application: Review
page is displayed. Click Deploy.


|
| 10. |
Click OK when you see the confirmation.

You see the ValidateCard application in the Deployed Applications table.

|
Back to Topic
Invoking
the EJB
| 1. |
Switch to the client machine. Open the
jndi.properties file. Change
the value for the java.naming.provider.url
property to opmn:ormi://<hostname
or IP Address>:<opmn request port>:home/ValidateCard.
In this example, you use the following provider URL:
opmn:ormi://152.69.149.60:6004:home/ValidateCard
where:
152.69.149.60 is the IP address of the machine on which
Application Server is running
6004 is the OPMN request port
home is the OC4J instance to which you have deployed the EJB
ValidateCard is the Application Name you specified during deployment
Change the password in java.naming.security.credentials
if the password for your installation is different.
Note: To find out the OPMN request port, go to
the Application Server Home page and click Ports.
|
| 2. |
Run the client as shown in the following screenshot.

|
Back to Topic List
|
Firewalls are used to secure private networks. Most of the private networks
have access to internet via HTTP proxy servers. These servers establish
a secure external connection and are capable of filtering any vulnerable
data. So, if you want to use a service that is outside a firewall, then
you make use of proxy server and HTTP tunneling. HTTP is a firewall-friendly
protocol. HTTP tunneling is a process in which you package an RMI request
as HTTP and send it through the proxy server and similarly unpackage the
HTML reply into RMI. In HTTP tunneling, the following take place:
- The client packages the request as HTTP and directs it to the proxy
server.
- The proxy server then directs the request to the HTTP server specified
in the package.
- The HTTP server instantiates a servlet, which unwraps the package
and transforms the request into an RMI request.
- The servlet makes an RMI request for the service specified in the
package.
- The servlet packages the response from the service as HTML and the
HTTP server directs this package to the proxy server.
- The client converts the HTML response into RMI.
Tunneling is supported with RMI/ORMI and is not supported with RMI/IIOP.
|
| 1. |
On the server machine, open the global-web-application.xml
file in the <ORACLE_HOME>\j2ee\home\config folder. Verify
that the following entries are in the file (the
default installation has these entries preconfigured):
<servlet>
<servlet-name>rmi</servlet-name>
<servlet-class>com.evermind.server.rmi.RMIHttpTunnelServlet
</servlet-class>
</servlet>
<servlet>
<servlet-name>rmip</servlet-name>
<servlet-class>com.evermind.server.rmi.RMIHttpTunnelProxyServlet
</servlet-class>
</servlet>
|
| 2. |
Switch to the client machine. Open the
jndi.properties file. Change
the value for the java.naming.provider.url
property to http:ormi://<hostname
or IP Address>:<http port>/ValidateCard.
In this example, you use the following provider URL:
http:ormi://152.69.149.60:7780/ValidateCard
where 7780
is the port on which Oracle HTTP Server is listening. If you do not specify
the port, it defaults to 80.
If you are using an instance other than the home instance,
then the provider URL would be
http:ormi://<hostname>:<http_port>/<appName>@oc4j_mount.
Change the password in java.naming.security.credentials
if the password for your installation is different.
Note: To find out the Oracle HTTP Server listen
port, go to the Application Server Home page and click Ports.
|
| 3. |
Download the http_client.jar
file and place it in the d:\EJB_client folder. Include http_client.jar
in the CLASSPATH.

|
| 4. |
Run the client.

|
| 5. |
If your HTTP traffic goes through a proxy server, specify the proxyHost
and (optionally) proxyPort in the command line that starts the EJB client:
-Dhttp.proxyHost=proxy_host -Dhttp.proxyPort=proxy_port

|
Back to Topic List
In this lesson, you've learned how to:
|
Remotely access an EJB deployed standalone OC4J
|
|
Remotely access an EJB deployed to Oracle Application Server OC4J instance
|
 |
Use HTTP tunneling to access EJB outside the firewall |
 |
To ask a question about this OBE tutorial, post a query on the OBE
Discussion Forum. |
Place the cursor over this icon
to hide all screenshots.
|