3 Replies Latest reply on Dec 16, 2005 11:33 PM by nikhilkumar

    Ejb not bound problem Help!

    nikhilkumar Newbie

      I have been trying to get to connect to my EJB from a servlet.



      I have been trying to figure out how to deal with an ejb reference:

      It is my undertanding that:
      1. The ejb-jar.xml needs to have
      ejb-name defined. In my case this is
      <ejb-name>HelloWorld</ejb-name>
      2. The jboss.xml (and I am not clear if this is necessary, though i want to support clustering in the future and so cannot guarantee that everything will be on the same server).


      <ejb-name>HelloWorld</ejb-name>
      <jndi-name>/tsm/HelloWorld</jndi-name>

      <method-attributes>
      </method-attributes>


      3. The web.xml entry
      <ejb-ref>
      <ejb-ref-name>ejb/HelloWorld</ejb-ref-name>
      <ejb-ref-type>Session</ejb-ref-type>
      com.aptsi.applications.tsm.ejb.HelloWorldHome
      com.aptsi.applications.tsm.ejb.HelloWorld
      <ejb-link>HelloWorld</ejb-link>
      </ejb-ref
      4. The jboss-web.xml entry

      ><ejb-ref>
      <ejb-ref-name>ejb/HelloWorld</ejb-ref-name>
      <jndi-name>/tsm/HelloWorld</jndi-name>
      </ejb-ref>

      5. The application.xml entry (using this setup I am connecting to web resources (though not the EJB)

      <web-uri>tsm.war</web-uri>
      <context-root>/tsm/web-app</context-root>


      5. The code:

      try
      {
      System.out.println("Testing ejb access - before context lookup");
      Context ctx = new InitialContext();
      ctx = (Context)ctx.lookup("java:comp/env/ejb");
      Object o = ctx.lookup("HelloWorld");
      System.out.println("Testing ejb access - after context lookup");
      HelloWorldHome home = (HelloWorldHome)
      PortableRemoteObject.narrow(o, HelloWorldHome.class);

      System.out.println("Testing ejb access - jndi op complete");
      // get the bean remote instance
      //
      try
      {
      System.out.println("Testing ejb access - before create");
      HelloWorld h = home.create();
      System.out.println("EJB created, Need to test ejb access");
      System.out.println(h.helloWorld());
      }
      catch (javax.ejb.CreateException e)
      {
      System.out.println(e.getMessage());
      }
      catch (java.rmi.RemoteException e)
      {
      System.out.println(e.getMessage());
      }
      }
      catch (javax.naming.NamingException e)
      {
      e.printStackTrace() ;
      }


      The stack trace is:
      06:56:47,937 ERROR [STDERR] javax.naming.NamingException: Could not dereference object [Root exception is javax.naming.NameNotFoundE
      xception: tsm not bound]
      06:56:47,937 ERROR [STDERR] at org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:970)
      06:56:47,937 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:613)
      06:56:47,937 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:507)
      06:56:47,937 ERROR [STDERR] at com.aptsi.applications.tsm.web.servlets.frontcontroller.RegLogout.doProcess(Unknown Source)
      06:56:47,937 ERROR [STDERR] at com.aptsi.applications.tsm.web.servlets.frontcontroller.RegLogout.doGet(Unknown Source)
      06:56:47,937 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
      06:56:47,937 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      06:56:47,937 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)

      06:56:47,937 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
      06:56:47,937 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
      06:56:47,953 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipelin
      e.java:643)
      06:56:47,953 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      06:56:47,953 ERROR [STDERR] at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      06:56:47,953 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      06:56:47,953 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipelin
      e.java:643)
      06:56:47,953 ERROR [STDERR] at org.jboss.web.tomcat.security.JBossSecurityMgrRealm.invoke(JBossSecurityMgrRealm.java:220)
      06:56:47,953 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipelin
      e.java:641)
      06:56:47,953 ERROR [STDERR] at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:494)
      06:56:47,953 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipelin
      e.java:641)
      06:56:47,953 ERROR [STDERR] at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
      06:56:47,953 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipelin
      e.java:641)
      06:56:47,953 ERROR [STDERR] at org.jboss.web.tomcat.tc4.statistics.ContainerStatsValve.invoke(ContainerStatsValve.java:76)
      06:56:47,953 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipelin
      e.java:641)
      06:56:47,953 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      06:56:47,953 ERROR [STDERR] at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      06:56:47,953 ERROR [STDERR] at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2417)
      06:56:47,953 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
      06:56:47,953 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipelin
      e.java:643)
      06:56:47,953 ERROR [STDERR] at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
      06:56:47,953 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipelin
      e.java:641)
      06:56:47,953 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
      06:56:47,953 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipelin
      e.java:641)
      06:56:47,953 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:65)
      06:56:47,953 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipelin
      e.java:641)
      06:56:47,953 ERROR [STDERR] at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:577)
      06:56:47,953 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipelin
      e.java:641)
      06:56:47,953 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      06:56:47,953 ERROR [STDERR] at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      06:56:47,953 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
      06:56:47,953 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipelin
      e.java:643)
      06:56:47,968 ERROR [STDERR] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      06:56:47,968 ERROR [STDERR] at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      06:56:47,968 ERROR [STDERR] at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:197)
      06:56:47,968 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:781)
      06:56:47,968 ERROR [STDERR] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.
      java:549)
      06:56:47,968 ERROR [STDERR] at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:605)
      06:56:47,968 ERROR [STDERR] at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:677)
      06:56:47,968 ERROR [STDERR] at java.lang.Thread.run(Thread.java:534)
      06:56:47,968 ERROR [STDERR] Caused by: javax.naming.NameNotFoundException: tsm not bound
      06:56:47,968 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(NamingServer.java:495)
      06:56:47,968 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(NamingServer.java:503)
      06:56:47,968 ERROR [STDERR] at org.jnp.server.NamingServer.getObject(NamingServer.java:509)
      06:56:47,968 ERROR [STDERR] at org.jnp.server.NamingServer.lookup(NamingServer.java:253)
      06:56:47,968 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:528)
      06:56:47,968 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:507)
      06:56:47,968 ERROR [STDERR] at javax.naming.InitialContext.lookup(InitialContext.java:347)
      06:56:47,968 ERROR [STDERR] at org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:964)
      06:56:47,968 ERROR [STDERR] ... 47 more
      06:56:49,718 INFO [STDOUT] the action is /logout.jsp

      It looks like a JNDI naming issue. What do I need to do to fix this!.
      Help!.
      Nikhil

        • 1. Re: Ejb not bound problem Help!
          nikhilkumar Newbie

          Note that I am using JBOSS 3.2.3

          • 2. Re: Ejb not bound problem Help!
            nikhilkumar Newbie

            JNDI View output for reference. on deployment

            --------------------------------------------------------------------------------

            java: Namespace
            +- SecurityProxyFactory (class: org.jboss.security.SubjectSecurityProxyFactory)
            +- DefaultJMSProvider (class: org.jboss.jms.jndi.JBossMQProvider)
            +- mySQL (class: org.jboss.resource.adapter.jdbc.WrapperDataSource)
            +- comp (class: javax.naming.Context)
            +- JmsXA (class: org.jboss.resource.adapter.jms.JmsConnectionFactoryImpl)
            +- jaas (class: javax.naming.Context)
            | +- JmsXARealm (class: org.jboss.security.plugins.SecurityDomainContext)
            | +- ial (class: org.jboss.security.plugins.SecurityDomainContext)
            +- timedCacheFactory (class: javax.naming.Context)
            Failed to lookup: timedCacheFactory, errmsg=null
            +- TransactionPropagationContextExporter (class: org.jboss.tm.TransactionPropagationContextFactory)
            +- Mail (class: javax.mail.Session)
            +- StdJMSPool (class: org.jboss.jms.asf.StdServerSessionPoolFactory)
            +- TransactionPropagationContextImporter (class: org.jboss.tm.TransactionPropagationContextImporter)
            +- TransactionManager (class: org.jboss.tm.TxManager)

            Global JNDI Namespace
            +- UserTransaction (class: org.jboss.tm.usertx.client.ClientUserTransaction)
            +- invokers (class: org.jnp.interfaces.NamingContext)
            | +- atsi_nikhilkumar (class: org.jnp.interfaces.NamingContext)
            | | +- jrmp (class: org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxy)
            | | +- http (class: org.jboss.invocation.http.interfaces.HttpInvokerProxy)
            | +- 0.0.0.0 (class: org.jnp.interfaces.NamingContext)
            | | +- pooled (class: org.jboss.invocation.pooled.interfaces.PooledInvokerProxy)
            +- UUIDKeyGeneratorFactory (class: org.jboss.ejb.plugins.keygenerator.uuid.UUIDKeyGeneratorFactory)
            +- console (class: org.jnp.interfaces.NamingContext)
            | +- PluginManager (proxy: $Proxy23 implements interface org.jboss.console.manager.PluginManagerMBean)
            +- jmx (class: org.jnp.interfaces.NamingContext)
            | +- invoker (class: org.jnp.interfaces.NamingContext)
            | | +- RMIAdaptor (proxy: $Proxy22 implements interface org.jboss.jmx.adaptor.rmi.RMIAdaptor)
            | +- rmi (class: org.jnp.interfaces.NamingContext)
            | | +- RMIAdaptor[link -> jmx/invoker/RMIAdaptor] (class: javax.naming.LinkRef)
            +- UserTransactionSessionFactory (proxy: $Proxy10 implements interface org.jboss.tm.usertx.interfaces.UserTransactionSessionFactory)
            +- UILXAConnectionFactory[link -> UIL2XAConnectionFactory] (class: javax.naming.LinkRef)
            +- UILConnectionFactory[link -> UIL2ConnectionFactory] (class: javax.naming.LinkRef)


            • 3. Re: Ejb not bound problem Help!-fixed
              nikhilkumar Newbie

              Finally fixed it. The issue was the way I was setting up the ejb dir that was getting packaged, the structure of the manifest file and the application.xml needed to have a module for the ejb.jar.

              Also, for debugging:

              1. The EJB not bound error almost always seems to occur when the ejb does not deploy. I used the JNDIView in the JMX console to check.
              2. I cleaned everything out in the deploy dir and then focused on deploying the ejb.jar. Once I started down that path, it was pretty straightforward and easy to debug.

              Cheers!