3 Replies Latest reply on Apr 3, 2007 3:06 AM by warrenc5

    Problems with loolup of EJBs using JNDI

    ashw.kumar

      Hi,

      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

        • 1. Re: Problems with loolup of EJBs using JNDI
          bdecoste

          Can you confirm that "ejb/MapSession" and "ejb/MapSessionHome" are bound into the global jndi space?

          Also, in jboss-web.xml, you need to reference the jndi binding of the hom interface, not the business interface.

          <ejb-ref>
           <ejb-ref-name>ejb/MapSession</ejb-ref-name>
           <jndi-name>ejb/MapSessionHome</jndi-name>
          </ejb-ref>
          


          • 2. Re: Problems with loolup of EJBs using JNDI
            ashw.kumar

            Hi,

            About changing jndi-name to "ejb/MapSessionHome" I tried it but same problem persist.

            But i think the look up of MapSessionHome will happen using the ejb-jar.xml. The info abt MapSessionHome is specified there.

            I looked into Global JNDI Namespace using jmx-console.
            I found following relevant entried there.

            Looks like MapSession is registered but no class loading available for MapSessionHome.

            Do you have any clue why ?


            +- jmx (class: org.jnp.interfaces.NamingContext)
            | +- invoker (class: org.jnp.interfaces.NamingContext)
            | | +- RMIAdaptor (proxy: $Proxy38 implements interface org.jboss.jmx.adaptor.rmi.RMIAdaptor,interface org.jboss.jmx.adaptor.rmi.RMIAdaptorExt)
            | +- rmi (class: org.jnp.interfaces.NamingContext)
            | | +- RMIAdaptor[link -> jmx/invoker/RMIAdaptor] (class: javax.naming.LinkRef)
            +- MapSession (proxy: $Proxy58 implements No ClassLoaders found for: com.virtualcityindia.interfaces.MapSessionHome (no security manager: RMI class loader disabled))




            Regards.
            Ashwani

            • 3. Re: Problems with loolup of EJBs using JNDI
              warrenc5

              That message in the Log

              8:32:20,949 INFO [ProxyFactory] Bound EJB Home 'MapSession' to jndi 'MapSession' is the default.

              So basically jboss is ignoring your jboss.xml mapping.


              Can you please;

              Change <jndi-name> jboss.xml or Change it to the Default MapSession, i.e. remove the ejb/ prefix

              Change you jboss-web.xml <jndi-name> to MapSession, i.e. remove the ejb/ prefix

              add a link to your web.xml

              <ejb-ref>
              <ejb-link>MapSession</ejb-link>