my dog learned polymorphism*
The moose likes EJB and other Java EE Technologies and the fly likes ctx.lookup of Session Bean from Messaging Bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "ctx.lookup of Session Bean from Messaging Bean" Watch "ctx.lookup of Session Bean from Messaging Bean" New topic
Author

ctx.lookup of Session Bean from Messaging Bean

Per Lovdinger
Ranch Hand

Joined: Jun 11, 2001
Posts: 35
Hi All,
My environment: wsad 5.1.1 J2EE 1.3
I'm trying to run this scenario for test purpose:
Servlet -> Messaging Bean -> EJB Session bean
The servlet starts the the Messaging Bean using a Connection factory and queue.
In the web-deployment descriptor I have declared them as refererences.
This works fine.
I get the messaging bean to start, but then I get an exception in messaging bean
doing lockup for the Session Bean.
In the EJB deployment the 2 EJB beans are declared.
I'm confused over how I should do a lockup to the session bean from the messaging bean
1. Should I create a new InitialContext ?
Context ctx = new InitialContext();
2. I have tested with this:
Context ctx = new InitialContext();
String name = "ejb/jmstest/ValidationBeanLocalHome";
Object objref = ctx.lookup(name);

and this:
Context ctx = new InitialContext();
String name = "java:comp/env/ejb/jmstest/ValidationBeanLocalHome";
Object objref = ctx.lookup(name);

Help regarding this deeply appreciated.
..Per
======================= EJB Deployment ========================================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar id="ejb-jar_ID">
<display-name>JMSTestEJB</display-name>
<enterprise-beans>
<session id="TestFacade">
<ejb-name>TestFacade</ejb-name>
<home>jmstest.TestFacadeHome</home>
<remote>jmstest.TestFacade</remote>
<local-home>jmstest.TestFacadeLocalHome</local-home>
<local>jmstest.TestFacadeLocal</local>
<ejb-class>jmstest.TestFacadeBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<resource-ref id="ResourceRef_1080135215816">
<description></description>
<res-ref-name>jms/myQueueConnectionFactory</res-ref-name>
<res-type>javax.jms.QueueConnectionFactory</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
<resource-env-ref id="ResourceEnvRef_1080132922692">
<description></description>
<resource-env-ref-name>jms/myQueue</resource-env-ref-name>
<resource-env-ref-type>javax.jms.Queue</resource-env-ref-type>
</resource-env-ref>
</session>
<message-driven id="TestMDB">
<ejb-name>TestMDB</ejb-name>
<ejb-class>jmstest.TestMDBBean</ejb-class>
<transaction-type>Container</transaction-type>
<message-driven-destination>
<destination-type>javax.jms.Queue</destination-type>
</message-driven-destination>
</message-driven>
<session id="ValidationBean">
<ejb-name>ValidationBean</ejb-name>
<local-home>jmstest.ValidationBeanLocalHome</local-home>
<local>jmstest.ValidationBeanLocal</local>
<ejb-class>jmstest.ValidationBeanBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>
Web deployment descriptor ======================================================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app id="WebApp">
<display-name>JMSTestWeb</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<resource-ref id="ResourceRef_1081168157808">
<res-ref-name>jms/MyConnectionFactoryRef</res-ref-name>
<res-type>javax.jms.QueueConnectionFactory</res-type>
<res-auth>Application</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
<resource-ref id="ResourceRef_1081168223965">
<res-ref-name>jms/MyQueueRef</res-ref-name>
<res-type>javax.jms.Queue</res-type>
<res-auth>Application</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
<ejb-local-ref id="EJBLocalRef_1080132757050">
<ejb-ref-name>ejb/myFacade</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local-home>jmstest.TestFacadeLocalHome</local-home>
<local>jmstest.TestFacadeLocal</local>
<ejb-link>JMSTestEJB.jar#TestFacade</ejb-link>
</ejb-local-ref>
<ejb-local-ref id="EJBLocalRef_1081237979566">
<ejb-ref-name>ejb/myValidation</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local-home>jmstest.ValidationBeanLocalHome</local-home>
<local>jmstest.ValidationBeanLocal</local>
<ejb-link>JMSTestEJB.jar#ValidationBean</ejb-link>
</ejb-local-ref>
</web-app>
 
wood burning stoves
 
subject: ctx.lookup of Session Bean from Messaging Bean