I've seen some confusion around looking up remote EJB in OC4J although this has been documented in the EJB Guide and Services Guide. So let me clarify how do you look up an EJB in OC4J standalone and OC4J in OracleAS environment.
OC4J allows to lookup remote EJBs using ORMI, RMI-IIOP or HTTP Tunneling over ORMI. In this blog, I will discuss use of ORMI.
What Context Factory to Use
OC4J 10.1.2 and earlier
com.evermind.server.RMIInitialContextFactory – Use this from remote web , ejb and thick Java client and you do not have a application client.
com.evermind.server.ApplicationClientInitialContextFactory – Only if you are using application (thick ) java client and you have application-client.xml available at the client side with EJB references
OC4J 10.1.3
If you are using 10.1.3 then the package names for these context factories have been renamed and you should start using oracle.j2ee.rmi.RMIInitialContextFactory and oracle.j2ee.naming.ApplicationClientInitialContextFactory.
Provider URL
Incorrect provider URL is the cause of the most of the errors encountered by users.
Standalone
The value for java.naming.provider.url should be of format ormi://<hostname>:<ormi port>/<appName>
The ORMI port is configured using the rmi.xml. The default port is 23791.
The appName is the application name that you used while deploying the application and can be found in the server.xml.
For example the provider URL could be java.naming.provider.url=ormi://dpanda-us:23793/ejb30slsb
Where dpanda-us is my hostname and 23793 is my ORMI port and ejb30slsb is the name of my application.
OC4J in OracleAS Install (Managed by OPMN)
The value for java.naming.provider.url should be of format opmn:ormi://<hostname>:<opmn request port>:<oc4j-instance-name>/ejbsamples
OC4J is managed by OPMN in an OracleAS install and ORMI port is dynamically allocated and you may have more than one OC4J processes that may be used for load balancing / failover by OPMN. You have to use the opmn request port instead of using the ORMI port. You can find the ORMI request port from opmn.xml as follows:
<notification-server>
<port local="6100" remote="6200" request="6004"/>
…..
</notification-server>
The default request port is 6003
In an OracleAS install you may have more than one instance of OC4J and you use the name the instance where you have deployed the application. The default instance name is home.
So if my hostname is dpanda-us, request port is 6004 and name of instance is home1 then my provider URL will look like follows
java.naming.provider.url=opmn:ormi://dpanda-us:6004:home1 /ejb30slsb
What EJB name to lookup
The context factory you are using determines what values to use in the conext.lookup.
RMIInitialContextFactory
If you are using RMIInitialContextFactory then you have to use the ejb-name specified in the ejb-jar.xml or name element when using annotation with EJB 3.0 .e.g. I’ve defined ejb-name as “HelloWorldBean” in the deployment descriptor as follows
<session>
<ejb-name>HelloBean</ejb-name>
<home>hello.HelloHome</home>
then I look up as follows:
// This for use with com.evermind.server.rmi.RMIInitialContextFactory
Object homeObject = context.lookup("HelloBean");
ApplicationClientInitialContextFactory
If you are using ApplicationClientInitialContextFactory then you have to lookup using the ejb-ref-name defined in the application-client.xml in the format java:comp/env/<ejb-ref-name>.
For example, I’ve defined the ejb-references in the application-client.xml as follows
<ejb-ref>
<ejb-ref-name>Helloworld</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
..
</ejb-ref>
then I lookup as follows:
// This is for use with com.evermind.server.ApplicationClientInitialContextFactory
Object homeObject = context.lookup("java:comp/env/Helloworld");
Use of Dedicated.connection vs dedicated.rmicontext
Set dedicated.rmicontext or dedicated.connection true as appropriate.
You have to use either of this OC4J specific property while looking of remote EJB from web or ejb client in 10.1.2 and earlier.These properties will not be required in 10.1.3.
Hope I clarified the use of remote EJB and I will describe how to lookup EJBs in OC4J from a third-party web container like Tomcat.
7:29:56 AM
|