Problems with loolup of EJBs using JNDI
ashw.kumar May 22, 2006 9:13 AMHi,
I am getting following error while i am trying to lookup ejb.
Could not dereference object [Root exception is javax.naming.NameNotFoundException: ejb not bound]
I am using following code for lookup in a Sevlet.
try {
Context context = new InitialContext();
Object ref = context.lookup("java:/comp/env/ejb/MapSession");
home = (MapSessionHome) PortableRemoteObject.narrow(ref, MapSessionHome.class);
} catch (Exception e) {
e.printStackTrace();
throw new ServletException("look up of java:/comp/env/ejb/MapSession failed",e);
}
Following is ejb-jar.xml.
<enterprise-beans>
<!-- Session Beans -->
<session >
<description><![CDATA[Description for MapSession]]></description>
<display-name>Name for MapSession</display-name>
<ejb-name>MapSession</ejb-name>
<home>com.virtualcityindia.ejbs.MapSessionHome</home>
<remote>com.virtualcityindia.ejbs.MapSession</remote>
<ejb-class>com.virtualcityindia.ejbs.MapSessionSession</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
Following is the jboss.xml file:
<jboss>
<enterprise-beans>
<!--
To add beans that you have deployment descriptor info for, add
a file to your XDoclet merge directory called jboss-beans.xml that contains
the <session></session>, <entity></entity> and <message-driven></message-driven>
markup for those beans.
-->
<session>
<ejb-name>MapSession</ejb-name>
<invoker>
<jndi-name>ejb/MapSession</jndi-name>
</invoker>
</session>
<!--
write a merge file jboss-webservices.ent for webservice-description
-->
</enterprise-beans>
<resource-managers>
</resource-managers>
<!--
| for container settings, you can merge in jboss-container.xml
| this can contain <invoker-proxy-bindings/> and <container-configurations/>
-->
</jboss>
Following is the jboss-web.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jboss-web PUBLIC "-//JBoss//DTD Web Application 2.3//EN" "http://www.jboss.org/j2ee/dtd/jboss-web_3_0.dtd">
<jboss-web>
<!-- Resource Environment References -->
<!--
For additional resouce-env-ref tags add a merge file called jbossweb-resource-env-ref.xml
-->
<!-- Resource references -->
<!--
For additional resouce-ref tags add a merge file called jbossweb-resource-ref.xml
-->
<!-- EJB References -->
<!--
For additional ejb-ref tags add a merge file called jbossweb-ejb-ref.xml
-->
<ejb-ref>
<ejb-ref-name>ejb/MapSession</ejb-ref-name>
<jndi-name>ejb/MapSession</jndi-name>
</ejb-ref>
<!-- EJB Local References -->
</jboss-web>
Following the relevenat portion of web.xml file:
<web-app>
<ejb-ref >
<description><![CDATA[Reference to the MapSession EJB]]></description>
<ejb-ref-name>ejb/MapSession</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<home>com.virtualcityindia.interfaces.MapSessionHome</home>
<remote>com.virtualcityindia.interfaces.MapSession</remote>
</ejb-ref>
</web-app>
When i deploys the ear file to JBoss server: I get following trace:
18:32:20,228 INFO [EARDeployer] Init J2EE application: file:/C:/Program Files/jboss-4.0.3SP1/server/default/deploy/virtaualcity.ear
18:32:20,688 INFO [EjbModule] Deploying MapSession
18:32:20,949 INFO [ProxyFactory] Bound EJB Home 'MapSession' to jndi 'MapSession'
18:32:20,949 INFO [EJBDeployer] Deployed: file:/C:/Program Files/jboss-4.0.3SP1/server/default/tmp/deploy/tmp56751virtaualcity.ear-contents/webapp.jar
18:32:21,019 INFO [TomcatDeployer] deploy, ctxPath=/virtualcity, warUrl=.../tmp/deploy/tmp56751virtaualcity.ear-contents/virtualcity-exp.war/
18:32:21,309 INFO [JBossCacheManager] init(): replicationGranularity_ is 0 and invaldateSessionPolicy is 2
18:32:21,359 INFO [JBossCacheManager] Starting JBossManager
18:32:21,470 INFO [EARDeployer] Started J2EE application: file:/C:/Program Files/jboss-4.0.3SP1/server/default/deploy/virtaualcity.ear
It says that EJB is deployed correctly.
I checked in jmx controller also ... the ejb is deployed correctly.
But still when i try to look up (Using the code i specified in the start) ; i gets following error:
description The server encountered an internal error () that prevented it from fulfilling this request.
exception :
javax.servlet.ServletException: look up of java:/comp/env/ejb/MapSession failed
com.virtualcityindia.web.IndexServlet.init(IndexServlet.java:60)
javax.servlet.GenericServlet.init(GenericServlet.java:211)
org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
org.jboss.web.tomcat.tc5.session.ClusteredSessionValve.invoke(ClusteredSessionValve.java:81)
org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
java.lang.Thread.run(Thread.java:595)
root cause :
javax.naming.NamingException: Could not dereference object [Root exception is javax.naming.NameNotFoundException: ejb not bound]
org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1052)
org.jnp.interfaces.NamingContext.lookup(NamingContext.java:685)
org.jnp.interfaces.NamingContext.lookup(NamingContext.java:701)
org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
javax.naming.InitialContext.lookup(InitialContext.java:351)
com.virtualcityindia.web.IndexServlet.init(IndexServlet.java:56)
javax.servlet.GenericServlet.init(GenericServlet.java:211)
org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
org.jboss.web.tomcat.tc5.session.ClusteredSessionValve.invoke(ClusteredSessionValve.java:81)
org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
java.lang.Thread.run(Thread.java:595)
root cause :
javax.naming.NameNotFoundException: ejb not bound
org.jnp.server.NamingServer.getBinding(NamingServer.java:514)
org.jnp.server.NamingServer.getBinding(NamingServer.java:522)
org.jnp.server.NamingServer.getObject(NamingServer.java:528)
org.jnp.server.NamingServer.lookup(NamingServer.java:252)
org.jnp.interfaces.NamingContext.lookup(NamingContext.java:610)
org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
javax.naming.InitialContext.lookup(InitialContext.java:351)
org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1046)
org.jnp.interfaces.NamingContext.lookup(NamingContext.java:685)
org.jnp.interfaces.NamingContext.lookup(NamingContext.java:701)
org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
javax.naming.InitialContext.lookup(InitialContext.java:351)
com.virtualcityindia.web.IndexServlet.init(IndexServlet.java:56)
javax.servlet.GenericServlet.init(GenericServlet.java:211)
org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
org.jboss.web.tomcat.tc5.session.ClusteredSessionValve.invoke(ClusteredSessionValve.java:81)
org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
java.lang.Thread.run(Thread.java:595)
Can somebody pleae reply early. I need to solve this problem as quickly as possible.
Thanks in advance,
Best Regards,
Ashwani