*
The moose likes Tomcat and the fly likes Question about accessing EJB components in OC4J Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Question about accessing EJB components in OC4J" Watch "Question about accessing EJB components in OC4J" New topic
Author

Question about accessing EJB components in OC4J

Benny Tang
Greenhorn

Joined: Aug 03, 2003
Posts: 26
Dear all,

I have written and deployed a stateless session bean in OC4J. Now I want to use a servlet, which is hosted in tomcat, to act as an EJB client to this session bean in OC4J.

However, I fail to get the remote reference when the servlet perform JNDI lookup for the remote reference. The exception is something like 'Cannot create object.....'

Do anyone have the experience of getting EJB remote reference from OC4J by using servlet act as a EJB client hosted in tomcat ?

If yes, can you tell me about the correct procedures in getting it done ?

Thank you for your kind attention

Yours faithfully,
Benny
Deepak Raina
Greenhorn

Joined: Jul 27, 2004
Posts: 6
I'm doing the same. Please give more information on the steps you are doing. I will be able to help you.
Benny Tang
Greenhorn

Joined: Aug 03, 2003
Posts: 26
I have deployed a stateless session bean EmployeeEJB in OC4J. I have tested that the servlet, which is within the same OC4J, can obtain the remote home reference to the EmployeeEJB.

But when I wrote another servlet, which is located in Apache tomcat, to obtain the remote home reference to EmployeeEJB. It fails when the program starts to lookup through JNDI. Part of exception that I got is shown as follow:

javax.naming.NamingException: Cannot create resource instance
at org.apache.naming.factory.EjbFactory.getObjectInstance(EjbFactory.java:184)

The following shows the coding which I try to obtain the remote reference for the EJB

Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.evermind.server.rmi.RMIInitialContextFactory");
env.put(Context.SECURITY_PRINCIPAL, "admin");
env.put(Context.SECURITY_CREDENTIALS, "pho5930");
env.put(Context.PROVIDER_URL, "ormi://192.168.32.129:23791/employee");

try{
Context context = new InitialContext(env);

Object homeObject = context.lookup("java:comp/env/EmployeeBean");

// Narrow the reference to EmployeeHome.
EmployeeHome home =
(EmployeeHome) PortableRemoteObject.narrow(homeObject, EmployeeHome.class);

// Create remote object and narrow the reference to Employee.
Employee remote =
(Employee) PortableRemoteObject.narrow(home.create(), Employee.class);

Can you know the reason why I got this exception ?
Deepak Raina
Greenhorn

Joined: Jul 27, 2004
Posts: 6
Your settings seem to be fine. What is the entry for the bean in your ejb deployment descripters ejb-jar.xml and orion-ejb-jar.xml file?
Also, make sure you have kept oc4jclient.jar in your web application's or tomcat's classpath.
Benny Tang
Greenhorn

Joined: Aug 03, 2003
Posts: 26
Hello,

I have kept the oc4jclient.jar under tomcat's common library. That's ok.

But I don't know the two xml files you mentioned as I just deployed the example, which is downloaded from otn.oracle.com. This example is about the stateless session bean. I follow the instruction of the example to deploy in OC4J.

Can you tell me more detail which configuration files required for the EJB client (i.e. The servlet I used in tomcat) to obtain the remote home
reference to the EJB ?

If anyone know any resource about using EJB deployed in OC4j from tomcat, please let me know.

Thank you for your kind attention.

Thanks,
Benny
Deepak Raina
Greenhorn

Joined: Jul 27, 2004
Posts: 6
These configuration files are required for OC4J only. This will be there in the ear file or jar file you would have deployed in OC4J. Check in those configuration file for the jndi name of the ejb. post your configuration files and also give the exact error you are getting.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question about accessing EJB components in OC4J
 
Similar Threads
How to manage the session for GUI and Web client
Stateful EJB internal mechanism
Chapter 3 - HF Sark study group
Dependency Injection Problem !!!
Doubt on interfaces for EJB 3