Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide 10g (10.1.3.5.0) Part Number E13981-01 |
|
|
View PDF |
This section describes the following:
A remote multitier situation exists when you have the servlets executing in one server, which are to connect and communicate with enterprise beans in another server. Both the servlets and enterprise beans are contained in the same application. When you deploy the application to two different servers, the servlets normally look for the local enterprise bean first.
In Figure 29-1, the HelloBean
application is deployed to both server 1 and 2. In order to ensure that the servlets only call out from server 1 to the enterprise beans in server 2, you must set the remote
attribute appropriately in the application before deploying on both servers.
The remote
attribute in the <ejb-module>
element in orion-application.xml
for the EJB module denotes whether the enterprise beans for this application are deployed or not.
In server 1, you must set remote=true
in the <ejb-module>
element of the orion-application.xml
file ,and then deploy the application. The EJB module within the application will not be deployed. Thus, the servlets will not look for the enterprise beans locally, but will go out to the remote server for the EJB requests.
In server 2, you must set remote=false
in the <ejb-module>
element of the orion-application.xml
file and then deploy the application. The application, including the EJB module, is deployed as normal. The default for the remote
attribute is false
; thus, simply ensure that the remote
attribute is not true
and redeploy the application.
Configure RMI options:
In a standalone OC4J, specify RMI server data in the RMI configuration file, rmi.xml
. Specify the location of this file in server.xml
, the OC4J configuration file. By default, both these files are installed in <
ORACLE_HOME
>/j2ee/home/config
.
For more information, see "Configuring RMI in a Standalone OC4J Installation" in the Oracle Containers for J2EE Services Guide.
In an Oracle Application Server environment, you must edit the opmn.xml
file to specify the port range, on which this local RMI server listens for RMI requests. Note that manual changes to configuration files in an Oracle Application Server environment must be manually updated on each OC4J instance.
For more information, see "Configuring RMI in an Oracle Application Server Environment" in the Oracle Containers for J2EE Services Guide.
Set JNDI properties java.naming.provider.url
and java.naming.factory.initial
.
For more information see the following:
"Setting JNDI Properties for RMI" in the Oracle Containers for J2EE Services Guide.
Look up the remote enterprise bean.
If multiple remote servers are configured, OC4J searches all remote servers for the intended EJB application.
For more information, see "Using Remote Method Invocation in OC4J" in the Oracle Containers for J2EE Services Guide.
A local multitier situation exists when both the servlets and enterprise beans are contained in the same application and deployed to the same server.
The remote
attribute in the <ejb-module>
element in orion-application.xml
for the EJB module denotes whether the enterprise beans for this application are deployed or not.
In the server, to which you deploy your application, you must set remote=false
in the <ejb-module>
element of the orion-application.xml
file, and then deploy the application. The application, including the EJB module, is deployed as normal. The default for the remote
attribute is false
.
Set JNDI properties java.naming.provider.url
and java.naming.factory.initial
.
For more information see the following:
"Setting JNDI Properties for RMI" in the Oracle Containers for J2EE Services Guide.
Look up the local EJB.
Example 29-33 shows the type of lookup that you can use from a standalone Java client (see "Standalone Java Client") in this release to look up an OC4J-deployed enterprise bean without having to specify an RMI port. Example 29-33 shows how to look up the enterprise bean named MyCart
in the Java EE application ejbsamples
deployed to the OC4J instance named oc4j_inst1
running on host myServer
.
Example 29-33 Accessing an EJB 2.1 Enterprise Bean Using RMI from a Standalone Java Client
Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY,"oracle.j2ee.rmi.RMIInitialContextFactory"); env.put(Context.SECURITY_PRINCIPAL, "oc4jadmin"); env.put(Context.SECURITY_CREDENTIALS, "password"); env.put(Context.PROVIDER_URL,"opmn:ormi://myServer:oc4j_inst1/ejbsamples"); Context context = new InitialContext(env); Object homeObject = context.lookup("MyCart"); CartHome home = (CartHome)PortableRemoteObject.narrow(homeObject,CartHome.class);
For more information, see the following:
To access an EJB 2.1 enterprise bean from an EJB 3.0 client:
Create an environement reference to the EJB 2.1 enterprise bean's home and remote interface as Example 29-34 shows.
In this example, you configure an environment reference to the home and remote interface of the EJB 2.1 Scheduler
bean. For more information on Job Scheduler, see the Oracle Containers for J2EE Job Scheduler Developer's Guide.
Example 29-34 Creating an Environment Reference to an EJB 2.1 Enterprise Bean's Home and Remote Interface
<ejb-ref> <ejb-ref-name>ejb/scheduler</ejb-ref-name> <ejb-ref-type>Session</ejb-ref-type> <home>oracle.ias.scheduler.SchedulerHome</home> <remote>oracle.ias.scheduler.SchedulerRemote</remote> </ejb-ref>
For more information, see Chapter 19, "Configuring JNDI Services"
Access the EJB 2.1 enterprise bean from the EJB 3.0 client:
An EJB 3.0 client can access an EJB 2.1 enterprise bean in a variety of ways, including, but not limited to, the following:
Inject the EJB 2.1home interface using the @EJB
annotation as Example 29-35 shows.
In this example, you set the @EJB
annotation name attribute to the <ejb-ref-name>
of the EJB 2.1 enterprise bean.
Inject the EJB 2.1 home interface using the <injection-target
> element in deployment XML.
Example 29-36 shows how to add an <injection-target>
element to the deployment XML to associate the EJB 2.1 home interface with an instance variable named home
. As Example 29-37 shows, at deployment time, OC4J will ensure that instance variable home
in the EJB 3.0 client is initialized appropriately.
Example 29-36 Adding an <injection-target> to the Deployment XML
<ejb-ref> <ejb-ref-name>ejb/scheduler</ejb-ref-name> <ejb-ref-type>Session</ejb-ref-type> <home>oracle.ias.scheduler.SchedulerHome</home> <remote>oracle.ias.scheduler.SchedulerRemote</remote> <injection-target> <injection-target-name>home</injection-target-name> </injection-target> </ejb-ref>
Look up the EJB 2.1 home interface using JNDI as Example 29-38 shows.
In this example, you look up the EJB 2.1 enterprise bean's <ejb-ref-name>
prefixed with java:comp/env/
.