8 Replies Latest reply on Apr 10, 2006 6:44 PM by tvanbuskirk

    EJB Deploy, Lookup Problem

    tvanbuskirk

      Hi everyone, if you could help me with this I would be forever grateful! I've exhausted searching on the internet, and I've been through the trailblazer 3 times (but it focuses on accessing a local bean, rather than remote)

      I'm getting a NameNotFoundException that has nothing to do w/ it not being bound. Looking in the JNDI, the name exists, and, according to the trailblazer, I'm accessing it correctly.

      I downloaded JBoss AS 4.0.4.CR2 and installed the EJB 3.0 w/ Clustering.

      The strangest part is that the error occurs no matter what name you put into the ctx.lookup() method. So, if it doesn't matter if I pass "HelloWorldBean/remote" or "JBossRocks" as a parameter to lookup(), I still get

      javax.naming.NameNotFoundException: HelloWorldBean/remote.
      


      I would really appreciate any help I can get ... thanks!! The details are below:

      Here's the error:
      
      javax.naming.NameNotFoundException: HelloWorldBean/remote
       at org.jboss.ha.jndi.TreeHead.lookup(TreeHead.java:237)
       at org.jboss.ha.jndi.HAJNDI.lookup(HAJNDI.java:150)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.ha.framework.server.HARMIServerImpl.invoke(HARMIServerImpl.java:209)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
       at sun.rmi.transport.Transport$1.run(Transport.java:153)
       at java.security.AccessController.doPrivileged(Native Method)
       at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
       at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
       at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
       at java.lang.Thread.run(Thread.java:613)
       at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
       at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
       at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:126)
       at org.jboss.ha.framework.server.HARMIServerImpl_Stub.invoke(Unknown Source)
       at org.jboss.ha.framework.interfaces.HARMIClient.invokeRemote(HARMIClient.java:172)
       at org.jboss.ha.framework.interfaces.HARMIClient.invoke(HARMIClient.java:267)
       at $Proxy0.lookup(Unknown Source)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
       at javax.naming.InitialContext.lookup(InitialContext.java:351)
       at HelloWorldJBossClient.connectToJBoss(HelloWorldJBossClient.java:134)
       at HelloWorldJBossClient.main(HelloWorldJBossClient.java:114)
      


      Here's my remote interface:

      public interface HelloWorld {
       public String getHelloWorldString(String reverseThis);
      }


      Here's my stateless bean:
      import javax.ejb.Remote;
      import javax.ejb.Stateless;
      
      import org.jboss.annotation.ejb.RemoteBinding;
      
      @Stateless
      @Remote ({HelloWorld.class})
      @RemoteBinding (jndiBinding="HelloWorld")
      public class HelloWorldBean implements HelloWorld
      {
       public String getHelloWorldString(String reverseThis) {
       return reverseThis + "Back";
       }
      }


      This is JBoss showing the bean being deployed:
      23:24:44,845 INFO [JmxKernelAbstraction] installing MBean: jboss.j2ee:jar=MentorBaseballBeans.jar,name=HelloWorldBean,service=EJB3 with dependencies:
      23:24:45,374 INFO [EJBContainer] STARTED EJB: com.contendi.helloworld.beans.HelloWorldBean ejbName: HelloWorldBean
      23:24:45,514 INFO [EJB3Deployer] Deployed: file:/Applications/jboss-4.0.4.CR2/server/default/deploy/MentorBaseballBeans.jar
      23:24:45,599 INFO [TomcatDeployer] deploy, ctxPath=/jmx-console, warUrl=.../deploy/jmx-console.war/
      23:24:45,986 INFO [Http11BaseProtocol] Starting Coyote HTTP/1.1 on http-10.0.1.6-8080
      


      Here is my client code:
      try
       {
       InitialContext ctx = new InitialContext();
       ctx.addToEnvironment("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
       ctx.addToEnvironment("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
       ctx.addToEnvironment("java.naming.provider.url","10.0.1.6:8080");
       HelloWorld hwRemote = (HelloWorld) ctx.lookup("HelloWorldBean/remote");
      System.out.println(hwRemote.getHelloWorldString("TestThisString"));
       System.out.println(hwRemote.getHelloWorldString("TestAnotherString"));
       }
       catch (NamingException ex) {
       System.out.println(ex.toString());
       }


        • 1. Re: EJB Deploy, Lookup Problem
          asack

          Please post your JNDI space by using the JMX console and looking at the JNDI service (invoke the list() function). My guess is in all cases, it doesn't exist:

          My guess would be is you are using @RemoteBinding ( jndiBinding ="HelloWorld"), that means your bean is located at HelloWorld not HelloWorld/remote. You get the HelloWorld/remote by default if you don't use the Remote or LocalBinding annotation. The jndiBinding argument overrides this behavior.

          Either change your lookup to HelloWorld or change your jndiBinding name to HelloWorld/remote.

          • 2. Re: EJB Deploy, Lookup Problem
            tvanbuskirk

            Thanks for your reply asack!

            Prior to making any changes, here's what my jndi list() function returns:

             +- HelloWorld (proxy: $Proxy60 implements interface com.contendi.helloworld.beans.HelloWorld,interface org.jboss.ejb3.JBossProxy,interface javax.ejb.EJBObject)
            


            I tried changing my lookup to "HelloWorld", and I still got the same error:
            javax.naming.NameNotFoundException: HelloWorldBean/remote
            

            (note: the "HelloWorldBean" here is not a typo)

            I tried changing the binding name to "HelloWorld/remote", and got the above exception also.

            The jndi list() method changes to the following after changing the binding:
            +- HelloWorld (class: org.jnp.interfaces.NamingContext)
             | +- remote (proxy: $Proxy104 implements interface com.contendi.helloworld.beans.HelloWorld,interface org.jboss.ejb3.JBossProxy,interface javax.ejb.EJBObject)
            


            I've tried accessing it with the following lookups (all of them return the above exception):
            HelloWorld hwRemote = (HelloWorld) ctx.lookup("HelloWorldBean/remote");
            HelloWorld hwRemote = (HelloWorld) ctx.lookup("HelloWorldBean");
            HelloWorld hwRemote = (HelloWorld) ctx.lookup("HelloWorld/remote");
            HelloWorld hwRemote = (HelloWorld) ctx.lookup("HelloWorld");
            


            Thanks in advance for your replies!!

            • 3. Re: EJB Deploy, Lookup Problem
              tvanbuskirk

              OK, here's some more light shed on the situation.

              I shut down jboss, removed my .jar file from the .../server/default/deploy/ directory (undeployed it), and re-started jboss.

              Afterwards, as a sanity check, I ran the jndi list() function from the JMX Console. Here is the return: (showing no depoyed beans).

              +- XAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
               +- TopicConnectionFactory (class: org.jboss.naming.LinkRefPair)
               +- EventDispatcher (class: org.jboss.ws.eventing.mgmt.DispatcherDelegate)
               +- UserTransactionSessionFactory (proxy: $Proxy38 implements interface org.jboss.tm.usertx.interfaces.UserTransactionSessionFactory)
               +- UIL2ConnectionFactory[link -> ConnectionFactory] (class: javax.naming.LinkRef)
               +- UIL2XAConnectionFactory[link -> XAConnectionFactory] (class: javax.naming.LinkRef)
               +- HAPartition (class: org.jnp.interfaces.NamingContext)
               | +- DefaultPartition (class: org.jboss.ha.framework.server.HAPartitionImpl)
               +- QueueConnectionFactory (class: org.jboss.naming.LinkRefPair)
               +- topic (class: org.jnp.interfaces.NamingContext)
               | +- testDurableTopic (class: org.jboss.mq.SpyTopic)
               | +- testTopic (class: org.jboss.mq.SpyTopic)
               | +- securedTopic (class: org.jboss.mq.SpyTopic)
               +- queue (class: org.jnp.interfaces.NamingContext)
               | +- A (class: org.jboss.mq.SpyQueue)
               | +- testQueue (class: org.jboss.mq.SpyQueue)
               | +- ex (class: org.jboss.mq.SpyQueue)
               | +- DLQ (class: org.jboss.mq.SpyQueue)
               | +- D (class: org.jboss.mq.SpyQueue)
               | +- C (class: org.jboss.mq.SpyQueue)
               | +- B (class: org.jboss.mq.SpyQueue)
               +- HASessionState (class: org.jnp.interfaces.NamingContext)
               | +- Default (class: org.jboss.ha.hasessionstate.server.HASessionStateImpl)
               +- ConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
               +- UserTransaction (class: org.jboss.tm.usertx.client.ClientUserTransaction)
               +- jmx (class: org.jnp.interfaces.NamingContext)
               | +- invoker (class: org.jnp.interfaces.NamingContext)
               | | +- RMIAdaptor (proxy: $Proxy37 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)
               +- UILXAConnectionFactory[link -> XAConnectionFactory] (class: javax.naming.LinkRef)
               +- UILConnectionFactory[link -> ConnectionFactory] (class: javax.naming.LinkRef)
              


              Then I ran my client app, with the following code:
              public static void main(String[] args)
               {
               try
               {
               InitialContext ctx = new InitialContext();
               ctx.addToEnvironment("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
               ctx.addToEnvironment("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
               ctx.addToEnvironment("java.naming.provider.url","10.0.1.6:8080");
               HelloWorld hwRemote = (HelloWorld) ctx.lookup("ThisIsVeryWeird");
              
               }
               catch (NamingException ex) {
               ex.printStackTrace();
               }
               }
              


              Now, as far as I understand, this should fail because there is nothing in the JBoss AS, let alone anything named "ThisIsVeryWeird". Instead, it's failing with the same exception posted above several times.
              javax.naming.NameNotFoundException: HelloWorldBean/remote
              .
              .
              .
              


              Is it possible that JBoss is somehow retaining historical bean information that it should not be retaining?

              Hmmmm? ....

              For the record, when I run the list() function from the JMX Console, I'm getting the following command line error from JBoss. Would this have something to do with it?
              10:20:48,324 ERROR [JNDIView] JNDIView.getHAJndiAttributes() failed
              java.lang.NullPointerException: name cannot be null
               at javax.management.ObjectName.construct(ObjectName.java:342)
               at javax.management.ObjectName.<init>(ObjectName.java:1304)
               at org.jboss.naming.JNDIView.getHAJndiAttributes(JNDIView.java:836)
               at org.jboss.naming.JNDIView.getHAUrl(JNDIView.java:811)
               at org.jboss.naming.JNDIView.list(JNDIView.java:193)
               at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
               at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
               at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
               at java.lang.reflect.Method.invoke(Method.java:585)
               at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
               at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
               at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
               at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
               at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
               at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
               at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:260)
               at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
               at org.jboss.jmx.adaptor.control.Server.invokeOpByName(Server.java:258)
               at org.jboss.jmx.adaptor.control.Server.invokeOp(Server.java:223)
               at org.jboss.jmx.adaptor.html.HtmlAdaptorServlet.invokeOp(HtmlAdaptorServlet.java:262)
               at org.jboss.jmx.adaptor.html.HtmlAdaptorServlet.processRequest(HtmlAdaptorServlet.java:100)
               at org.jboss.jmx.adaptor.html.HtmlAdaptorServlet.doPost(HtmlAdaptorServlet.java:82)
               at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
               at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
               at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
               at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
               at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
               at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
               at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
               at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
               at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
               at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:54)
               at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:174)
               at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
               at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
               at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
               at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
               at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
               at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
               at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
               at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
               at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
               at java.lang.Thread.run(Thread.java:613)
              


              • 4. Re: EJB Deploy, Lookup Problem
                tvanbuskirk

                Ok,

                Went back to old EJB 3.0 RC3 bean creation, just changed the lookup. I would like to use RC5 or higher though, so if anyone knows why I couldn't create the bean as described by the trailblazer, please let me know. FYI, my remote interface after the change became:

                import javax.ejb.Remote;
                
                @Remote
                public interface HelloWorld {
                 public String getHelloWorldString(String reverseThis);
                }
                


                And my bean became:
                import javax.ejb.Stateless;
                
                import com.contendi.helloworld.beans.HelloWorld;
                
                @Stateless
                public class HelloWorldBean implements HelloWorld
                {
                 public String getHelloWorldString(String reverseThis) {
                 return reverseThis + "Back";
                 }
                }
                


                Then accessed it with:
                InitialContext ctx = new InitialContext();
                 ctx.addToEnvironment("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
                 ctx.addToEnvironment("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
                 ctx.addToEnvironment("java.naming.provider.url","10.0.1.6:8080");
                 HelloWorld hwRemote = (HelloWorld) ctx.lookup("HelloWorldBean/remote");
                 System.out.println(hwRemote.getHelloWorldString("TestThisString"));
                 System.out.println(hwRemote.getHelloWorldString("TestAnotherString"));
                


                I know that eventually I'd probably like to specify the jndi name using the RemoteBinding, but it seems like that may have been the problem. Any thoughts?

                • 5. Re: EJB Deploy, Lookup Problem
                  edwinfrederick

                  I've tried this and it works.
                  i hope it could help you

                  try
                   {
                   InitialContext ctx = new InitialContext();
                  
                   HelloWorld hwRemote = (HelloWorld) ctx.lookup("java:HelloWorld");
                   System.out.println(hwRemote.getHelloWorldString("TestThisString"));
                   System.out.println(hwRemote.getHelloWorldString("TestAnotherString"));
                   }
                   catch (NamingException ex) {
                   System.out.println(ex.toString());
                   }


                  as you can see i've just changed HelloWorld hwRemote = (HelloWorld) ctx.lookup("java:HelloWorld");


                  • 6. Re: EJB Deploy, Lookup Problem
                    edwinfrederick

                     

                    import javax.ejb.Remote;
                    import javax.ejb.Stateless;
                    
                    import org.jboss.annotation.ejb.RemoteBinding;
                    
                    @Stateless
                    @Remote ({HelloWorld.class})
                    @RemoteBinding (jndiBinding="HelloWorld")
                    public class HelloWorldBean implements HelloWorld
                    {
                     public String getHelloWorldString(String reverseThis) {
                     return reverseThis + "Back";
                     }
                    }


                    you must use this bean definition


                    • 7. Re: EJB Deploy, Lookup Problem
                      edwinfrederick

                      the interface does not need any change

                      • 8. Re: EJB Deploy, Lookup Problem
                        tvanbuskirk

                        Great! Thank you very much for looking into it!