5 Replies Latest reply on Jan 5, 2005 8:28 AM by hariv

    NameNotFoundException on EJB lookup in standalone client

    fchapuis

      Hi,

      I'm trying to test EJB access from a standalone java client.
      EJBs are part of J2EE application deploying and working fine on JBoss 3.2.7RC1 (default config).
      The client uses the jbossall-client.jar and an app-client.jar with interfaces of EJBs.
      Cautiously, I shutdown my personnal firewall.
      And here is the EJB from the JNDIView Global Namespace:

       +- ejb (class: org.jnp.interfaces.NamingContext)
       | +- com.fred.demat.core.MyService
      


      Below is the code doing the lookup:
      Hashtable env = new Hashtable();
      
      env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
      env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory" );
      env.put(Context.PROVIDER_URL, "jnp://localhost:1099");
      
      InitialContext ic = new InitialContext(env);
      
      Object objref = ic.lookup("MyService");
      Object obj = PortableRemoteObject.narrow(objref, MyServiceHome.class);
      MyServiceHome testHome = (MyServiceHome)obj;
      MyService svc = (MyService)testHome.create();
      


      And below is the error:
      javax.naming.NameNotFoundException: MyService not bound
       at org.jnp.server.NamingServer.getBinding(NamingServer.java:490)
       at org.jnp.server.NamingServer.getBinding(NamingServer.java:498)
       at org.jnp.server.NamingServer.getObject(NamingServer.java:504)
       at org.jnp.server.NamingServer.lookup(NamingServer.java:277)
       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:324)
       at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
       at sun.rmi.transport.Transport$1.run(Transport.java:148)
       at java.security.AccessController.doPrivileged(Native Method)
       at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
       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:536)
       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:133)
       at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:544)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:520)
       at javax.naming.InitialContext.lookup(InitialContext.java:347)
       at com.fred.test.TestJndiLookup.rmiTest(TestJndiLookup.java:95)
       at com.fred.test.TestJndiLookup.main(TestJndiLookup.java:43)


      I've seen many users having the this kind of problem but found no efficient answer.
      If anyone can help, thank you.

        • 1. Re: Please help
          tschraepen
          • 2. Re: NameNotFoundException on EJB lookup in standalone client
            tschraepen

            I'm having the same problem I think.

            But I'm getting "javax.naming.NameNotFoundException: comp not bound".
            But I don't have any EJB's called comp.
            I checked the JMX console ( service=JNDIview, invoke listXML() ) and there I find the following interesting piece of text:

            java:

            XAConnectionFactory
            org.jboss.mq.SpyXAConnectionFactory

            DefaultDS
            org.jboss.resource.adapter.jdbc.WrapperDataSource

            SecurityProxyFactory
            org.jboss.security.SubjectSecurityProxyFactory

            DefaultJMSProvider
            org.jboss.jms.jndi.JNDIProviderAdapter

            comp
            javax.naming.Context

            JmsXA
            org.jboss.resource.adapter.jms.JmsConnectionFactoryImpl

            ConnectionFactory
            org.jboss.mq.SpyConnectionFactory


            There's also this snippet in relation to my EJB's:
            null

            java:comp
            Person

            env
            org.jnp.interfaces.NamingContext


            java:comp
            Address

            env
            org.jnp.interfaces.NamingContext


            java:comp
            CredentialsSessionFacade

            env
            org.jnp.interfaces.NamingContext

            ejb
            org.jnp.interfaces.NamingContext

            PersonLocal
            ejb/PersonLocal
            javax.naming.LinkRef

            AddressLocal
            ejb/AddressLocal
            javax.naming.LinkRef




            • 3. Re: NameNotFoundException on EJB lookup in standalone client
              tschraepen

              Also, I'm deploying my EJB's through an .ear file using the JBossIDE for Eclipse.
              I've included the interfaces bundled in a .jar file in my Client project, along with jbossall-client.jar.

              I've generated most of the interface-classes using XDoclet and JBossIDE.
              The error occurs when I call "CredentialsSessionFacadeUtil.getHome(env)". This method in turn calls the .lookup method on the InitialContext.

              • 4. Re: NameNotFoundException on EJB lookup in standalone client
                tschraepen

                Hello everyone

                I "fixed" my problem.
                The generated Util class uses COMP_NAME to perform the lookup.
                COMP_NAME being "java:comp/env/ejb/CredentialsSessionFacade".
                That's why "comp" wasn't bound.
                Instead I used "ejb/CredentialsSessionFacade" and it worked.

                But I don't understand the difference between java:comp/env and ejb/...
                Can anyone explain the difference?

                Thanks in advance.

                • 5. Re: NameNotFoundException on EJB lookup in standalone client
                  hariv

                  Guys

                  You can set xdoclet to generate the utility classes to use the JNDI name referring to the global namespace instead on the local env.
                  If you add @ejb.util
                  * generate="physical"