12 Replies Latest reply on Nov 21, 2011 4:04 AM by jaikiran

    Jndi lookup error in from a java client

    supunm

      Hi All,

       

      I'm a newbee to ejb area. So please bare with me if I sound really silly.

       

      So I have a java client that is supposed to invoke an ejb3 which is deployed under jboss AS6.

      Intially I got some class not found errors and was able to solve it by adding some client jars found in, "jboss-6.1.0.Final/client". After that was solved now i'm getting the following exception,

       

      Caused by: javax.naming.NameNotFoundException: org.wso2.appserver.samples.ejb.Hello not bound

      ..

      [2011-11-03 12:10:58,254] ERROR {org.apache.axis2.rpc.receivers.RPCMessageReceiver} -  Exception occurred while trying to invoke service method null

      ..

       

      * The code i'm using is,

      InitialContext context = new InitialContext(properties));

      context.lookup(beanJndiName);

       

      property values:

      <ProviderURL>jnp://localhost:1099</ProviderURL>

      <JNDIContextClass>org.jnp.interfaces.NamingContextFactory</JNDIContextClass>

       

      beanJndiName = "org.wso2.appserver.samples.ejb.Hello"

      ......

      I have attached the sample ejb3.

      Really appreciate your help.

       

      thanks,

      SupunM

        • 1. Re: Jndi lookup error in from a java client
          mp911de

          Hi there,

          your problem seems to be the JNDI binding. Usually the JNDI name is name-of-your-ear/NameOfYourEjbBeanImpl/local or name-of-your-ear/NameOfYourEjbBeanImpl/remote (this depends whether you use @Remote or @Local). Take a look into the jmx-console (default: http://localhost:8080/jmx-console). There is a service named JNDIView, there you choose listAll and there you should find your bean.

           

          Please note: EJB's should be deployed withing a EAR-file (put your EJB-JAR to an EAR-file), from outside the JBoss you can only access remote EJB's

           

          Best regards,

          Mark

          • 2. Re: Jndi lookup error in from a java client
            wdfink

            You should have a look to your server.log file, here you will see the name of your deployed bean. Check that the Bean implement a Remote interface and there are no ERROR messages in the logfile.

            Also remember that the deployment (and the resulting default JNDI name) is different if you deploy EJB's in a JAR or EAR archive.

            • 3. Re: Jndi lookup error in from a java client
              supunm

              Hi Mrak,

              thanks for the quick reply

               

              I tried what you said,

              In jmx-console i see the below entries,

              |   +- HelloWorldEJB (class: org.jnp.interfaces.NamingContext)

                |   |   +- HelloWorld[link -> HelloWorld/remote-org.wso2.appserver.samples.ejb.Hello] (class: javax.naming.LinkRef)

                |   |   +- HelloWorld!org.wso2.appserver.samples.ejb.Hello[link -> HelloWorld/remote-org.wso2.appserver.samples.ejb.Hello] (class: javax.naming.LinkRef)

               

              +- HelloWorld (class: org.jnp.interfaces.NamingContext)

                |   +- remote-org.wso2.appserver.samples.ejb.Hello (class: Proxy for: org.wso2.appserver.samples.ejb.Hello)

                |   +- remote (class: Proxy for: org.wso2.appserver.samples.ejb.Hello)

               

              So what value should I pass in to, context.lookup(<value>); ?

               

              I renamed the jar into ear and deployed. No luck.

               

              thanks

              • 4. Re: Jndi lookup error in from a java client
                supunm

                Hi Fink,

                 

                Thnks for the quick reply.

                I checked logs, no Exceptions. And sample ejb is OK.

                 

                thanks

                • 5. Re: Jndi lookup error in from a java client
                  wdfink

                  Renaming of an jar into .ear dosn't help.

                  An EAR file is a different structure, see JEE tutorials http://docs.jboss.org/ejb3/docs/tutorial/1.0.7/html_single/index.html

                  Also it might help to attach the sources and the server.log file

                  • 6. Re: Jndi lookup error in from a java client
                    wdfink

                    If you add no special annotation the JAR should be deployed as "HelloWorld/remote" you should try this as lookup string.

                     

                    If you pack an EAR you should use this structure:

                    META-INF/application.xml (description, <ejb> and <java> -element)

                    <ejb-impl>.jar ==> the Bean implementation

                    <api.>jar ==> the api classes

                     

                    So you have a clear structure and the api.jar is usable at client side.

                    1 of 1 people found this helpful
                    • 7. Re: Jndi lookup error in from a java client
                      supunm

                      Hi all,

                       

                      I did made it into .ear and deployed in jboss 6. In console I could see following,

                       

                      22:01:04,425 INFO  [JBossASKernel] Created KernelDeployment for: HelloWorldEJB.jar

                      22:01:04,428 INFO  [JBossASKernel] installing bean: jboss.j2ee:ear=HelloWorldEJB.ear,jar=HelloWorldEJB.jar,name=HelloWorld,service=EJB3

                      22:01:04,428 INFO  [JBossASKernel]   with dependencies:

                      22:01:04,428 INFO  [JBossASKernel]   and demands:

                      22:01:04,429 INFO  [JBossASKernel]           jboss.ejb:service=EJBTimerService; Required: Described

                      22:01:04,429 INFO  [JBossASKernel]           jboss-switchboard:appName=HelloWorldEJB,module=HelloWorldEJB,name=HelloWorld; Required: Create

                      22:01:04,429 INFO  [JBossASKernel]   and supplies:

                      22:01:04,429 INFO  [JBossASKernel]           jndi:HelloWorld

                      22:01:04,429 INFO  [JBossASKernel]           Class:org.wso2.appserver.samples.ejb.Hello

                      22:01:04,429 INFO  [JBossASKernel]           jndi:HelloWorldEJB/HelloWorld/remote

                      22:01:04,429 INFO  [JBossASKernel]           jndi:HelloWorldEJB/HelloWorld/remote-org.wso2.appserver.samples.ejb.Hello

                      22:01:04,591 INFO  [JBossASKernel] Added bean(jboss.j2ee:ear=HelloWorldEJB.ear,jar=HelloWorldEJB.jar,name=HelloWorld,service=EJB3) to KernelDeployment of: HelloWorldEJB.jar

                      22:01:04,676 INFO  [SessionSpecContainer] Starting jboss.j2ee:ear=HelloWorldEJB.ear,jar=HelloWorldEJB.jar,name=HelloWorld,service=EJB3

                      22:01:04,684 INFO  [EJBContainer] STARTED EJB: org.wso2.appserver.samples.ejb.HelloWorld ejbName: HelloWorld

                      22:01:04,733 INFO  [JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:

                       

                       

                                HelloWorldEJB/HelloWorld/remote - EJB3.x Default Remote Business Interface

                                HelloWorldEJB/HelloWorld/remote-org.wso2.appserver.samples.ejb.Hello - EJB3.x Remote Business Interface

                       

                      So I'am assuming it got deployed correctly.

                      In jmx console I can see,

                      +- HelloWorldEJB (class: org.jnp.interfaces.NamingContext)

                        |   |   +- HelloWorldEJB (class: org.jnp.interfaces.NamingContext)

                        |   |   |   +- HelloWorld[link -> HelloWorldEJB/HelloWorld/remote-org.wso2.appserver.samples.ejb.Hello] (class: javax.naming.LinkRef)

                        |   |   |   +- HelloWorld!org.wso2.appserver.samples.ejb.Hello[link -> HelloWorldEJB/HelloWorld/remote-org.wso2.appserver.samples.ejb.Hello] (class: javax.naming.LinkRef)

                       

                      My client code looks like,

                              Properties properties = new Properties();

                       

                              properties.setProperty(Context.SECURITY_PRINCIPAL, "");

                              properties.setProperty(Context.SECURITY_CREDENTIALS, "");

                              properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");

                              properties.setProperty(Context.PROVIDER_URL, "jnp://localhost:1099");

                              properties.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");

                       

                                  InitialContext initialContext = new InitialContext(properties);

                                  initialContext.lookup("org.wso2.appserver.samples.ejb.Hello");

                       

                      I have included jbossall-client.jar from jboss 6 into client classpath.

                      I'm getting,

                       

                      javax.naming.NameNotFoundException: org.wso2.appserver.samples.ejb.Hello not bound

                      at org.jnp.server.NamingServer.getBinding(NamingServer.java:771)

                       

                      I tried to change the lookup string.

                      tried thing like,

                      HelloWorldEJB/HelloWorld/remote

                      HelloWorldEJB/remote

                      HelloWorld/remote

                       

                      None didn't work.

                       

                      Please tell me what i'm doing wrong here.

                       

                      thank u!

                      • 8. Re: Jndi lookup error in from a java client
                        jaikiran

                        initialContext.lookup("org.wso2.appserver.samples.ejb.Hello");

                        You are using the wrong JNDI name. You should be using:

                         

                        initialContext.lookup("HelloWorldEJB/HelloWorld/remote");

                         

                        or

                         

                        initialContext.lookup("HelloWorldEJB/HelloWorld/remote-org.wso2.appserver.samples.ejb.Hello");

                         

                        If those 2 don't work then post the new exception stacktrace that you get while using those JNDI names.

                        • 9. Re: Jndi lookup error in from a java client
                          supunm

                          Hi jaikiran,

                           

                          for both lookup strings I get following exception.

                           

                          javax.naming.NamingException: Could not dereference object [Root exception is java.lang.reflect.UndeclaredThrowableException]

                                    at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1508)

                                    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:824)

                                    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:688)

                                    at javax.naming.InitialContext.lookup(InitialContext.java:392)

                                    at Client.main(Client.java:24)

                                    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:597)

                                    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:115)

                          Caused by: java.lang.reflect.UndeclaredThrowableException

                                    at $Proxy0.createProxyBusiness(Unknown Source)

                                    at org.jboss.ejb3.proxy.impl.objectfactory.session.SessionProxyObjectFactory.createProxy(SessionProxyObjectFactory.java:129)

                                    at org.jboss.ejb3.proxy.impl.objectfactory.session.stateful.StatefulSessionProxyObjectFactory.getProxy(StatefulSessionProxyObjectFactory.java:64)

                                    at org.jboss.ejb3.proxy.impl.objectfactory.ProxyObjectFactory.getObjectInstance(ProxyObjectFactory.java:161)

                                    at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)

                                    at org.jnp.interfaces.NamingContext.getObjectInstance(NamingContext.java:1483)

                                    at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1500)

                                    ... 9 more

                          Caused by: java.lang.ClassNotFoundException: org.wso2.appserver.samples.ejb.Hello

                                    at org.jboss.remoting.serialization.ClassLoaderUtility.loadClass(ClassLoaderUtility.java:103)

                                    at org.jboss.remoting.loading.RemotingClassLoader.loadClass(RemotingClassLoader.java:94)

                                    at java.lang.Class.forName0(Native Method)

                                    at java.lang.Class.forName(Class.java:247)

                                    at org.jboss.remoting.loading.ObjectInputStreamWithClassLoader.resolveProxyClass(ObjectInputStreamWithClassLoader.java:253)

                                    at java.io.ObjectInputStream.readProxyDesc(ObjectInputStream.java:1531)

                                    at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1493)

                                    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1732)

                                    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)

                                    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)

                                    at org.jboss.aop.joinpoint.InvocationResponse.readExternal(InvocationResponse.java:119)

                                    at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1792)

                                    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1751)

                                    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)

                                    at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1947)

                                    at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1871)

                                    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)

                                    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)

                                    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)

                                    at org.jboss.remoting.serialization.impl.java.JavaSerializationManager.receiveObjectVersion2_2(JavaSerializationManager.java:238)

                                    at org.jboss.remoting.serialization.impl.java.JavaSerializationManager.receiveObject(JavaSerializationManager.java:138)

                                    at org.jboss.remoting.marshal.serializable.SerializableUnMarshaller.read(SerializableUnMarshaller.java:123)

                                    at org.jboss.remoting.transport.socket.MicroSocketClientInvoker.versionedRead(MicroSocketClientInvoker.java:1299)

                                    at org.jboss.remoting.transport.socket.MicroSocketClientInvoker.transport(MicroSocketClientInvoker.java:907)

                                    at org.jboss.remoting.MicroRemoteClientInvoker.invoke(MicroRemoteClientInvoker.java:169)

                                    at org.jboss.remoting.Client.invoke(Client.java:2070)

                                    at org.jboss.remoting.Client.invoke(Client.java:879)

                                    at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:60)

                                    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

                                    at org.jboss.ejb3.proxy.impl.remoting.IsLocalProxyFactoryInterceptor.invoke(IsLocalProxyFactoryInterceptor.java:104)

                                    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

                                    at org.jboss.aspects.remoting.PojiProxy.invoke(PojiProxy.java:62)

                                    at $Proxy0.createProxyBusiness(Unknown Source)

                                    at org.jboss.ejb3.proxy.impl.objectfactory.session.SessionProxyObjectFactory.createProxy(SessionProxyObjectFactory.java:129)

                                    at org.jboss.ejb3.proxy.impl.objectfactory.session.stateful.StatefulSessionProxyObjectFactory.getProxy(StatefulSessionProxyObjectFactory.java:64)

                                    at org.jboss.ejb3.proxy.impl.objectfactory.ProxyObjectFactory.getObjectInstance(ProxyObjectFactory.java:161)

                                    at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)

                                    at org.jnp.interfaces.NamingContext.getObjectInstance(NamingContext.java:1483)

                                    at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1500)

                                    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:824)

                                    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:688)

                                    at javax.naming.InitialContext.lookup(InitialContext.java:392)

                                    at Client.main(Client.java:24)

                                    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:597)

                                    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:115)

                                    at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:72)

                                    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

                                    at org.jboss.ejb3.proxy.impl.remoting.IsLocalProxyFactoryInterceptor.invoke(IsLocalProxyFactoryInterceptor.java:104)

                                    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

                                    at org.jboss.aspects.remoting.PojiProxy.invoke(PojiProxy.java:62)

                                    ... 16 more

                           

                          thanks,

                          • 10. Re: Jndi lookup error in from a java client
                            jaikiran

                            Caused by: java.lang.ClassNotFoundException: org.wso2.appserver.samples.ejb.Hello

                            Your client classpath should have the jar containing those bean interfaces.

                            1 of 1 people found this helpful
                            • 11. Re: Jndi lookup error in from a java client
                              supunm

                              Hi,

                               

                              yes that was the case, thanks a lot.

                               

                              So now I can do the lookup using

                              "HelloWorldEJB/HelloWorld/remote-org.wso2.appserver.samples.ejb.Hello" and

                              "HelloWorldEJB/HelloWorld/remote"

                               

                              Is is possible to get the context using the remote class name only.

                              eg: with, "org.wso2.appserver.samples.ejb.Hello". This is useful in beause name of the jar containing the ejb can be changed hense changing the lookup string. It would be much convenient if I can do the lookup without depending on the name of the .jar or .ear

                               

                              thanks,

                              • 12. Re: Jndi lookup error in from a java client
                                jaikiran

                                supun Malinga wrote:

                                 

                                It would be much convenient if I can do the lookup without depending on the name of the .jar or .ear

                                 

                                http://docs.jboss.org/ejb3/docs/tutorial/1.0.7/html/JNDI_Bindings.html