5 Replies Latest reply on Dec 1, 2006 3:48 PM by boomboom

    JNDI called in EJB30

    boomboom

      I am new to JBOSS, and I tried to deploy EJB30 in JBoss4.0.4.GA. I can deploy my EJB30 archive file and I can see it in JMX-console. However I cannot use client to call the stateless session bean. I don't write any deployment description since in EJB30 we can use annotation.

      I can see my ejb30 deployed in JMX-CONSOLE.
      jar=HelloBean30.jar,name=HelloBean,service=EJB3
      module=HelloBean30.jar,service=EJB3

      The Exception is following:
      Exception in thread "main" javax.naming.NameNotFoundException: examples not bound
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
      at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
      at org.jnp.server.NamingServer.lookup(NamingServer.java:267)
      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:466)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:707)
      at java.lang.Thread.run(Thread.java:595)
      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.jnp.server.NamingServer_Stub.lookup(Unknown Source)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:492)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:471)
      at javax.naming.InitialContext.lookup(InitialContext.java:351)
      at examples.session.stateless.HelloClient.main(HelloClient.java:34)


      The following is my session bean, remote interface and client.

      -------------HelloBean.java------------
      package examples.session.stateless;

      import javax.ejb.Remote;
      import javax.ejb.Stateless;

      /**
      * Demonstration stateless session bean.
      */
      @Stateless
      @Remote(Hello.class)

      public class HelloBean implements Hello {
      public String sayHello() {
      System.out.println("hello()");
      return "Hello, World!";
      }

      -----------------Hello.java-----------
      package examples.session.stateless;

      ///import org.jboss.annotation.ejb.RemoteBinding;

      //@RemoteBinding(jndiBinding="/examples/session/stateless/Hello")
      public interface Hello {
      String sayHello();
      }

      ---------------HelloCLient.java--------------------
      package examples.session.stateless;

      import java.util.Hashtable;

      import javax.naming.Context;
      import javax.naming.InitialContext;
      import examples.session.stateless.Hello;
      /**
      * This class is an example of client code which invokes
      * methods on a simple, remote stateless session bean.
      */
      public class HelloClient {

      public static void main(String[] args) throws Exception {
      /*
      * Obtain the JNDI initial context.
      *
      * The initial context is a starting point for
      * connecting to a JNDI tree. We choose our JNDI
      * driver, the network location of the server, etc
      * by passing in the environment properties.
      */
      Hashtable<String,String> h= new Hashtable<String,String>();
      h.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
      h.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
      h.put(Context.PROVIDER_URL, "jnp://localhost:1099");

      Context ctx = new InitialContext(h);

      // Context ctx = new InitialContext();
      /*
      * Get a reference to a bean instance, looked up by class name
      */
      Hello hello = (Hello) ctx.lookup("/examples/session/stateless/Hello/remote");

      /*
      * Call the hello() method on the bean.
      * We then print the result to the screen.
      */
      System.out.println(hello.sayHello());

      }
      }

        • 1. Re: JNDI called in EJB30
          peterj

          In the jmx-console, click the jboss:service=JNDIView mbean link, and on the resulting page, click the Invoke button for the list() method. That will give you all of the JNDI names.

          I think that your EJB is named "Hello/remote", but use the above technique to verify that.

          • 2. Re: JNDI called in EJB30
            boomboom

            To PeterJ:
            When I use Hello hello = (Hello) ctx.lookup("Hello/remote"); It has the exception: Exception in thread "main" javax.naming.NameNotFoundException: Hello not bound
            at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
            at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
            at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
            at org.jnp.server.NamingServer.lookup(NamingServer.java:267)
            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:466)
            at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:707)
            at java.lang.Thread.run(Thread.java:595)
            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.jnp.server.NamingServer_Stub.lookup(Unknown Source)
            at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:492)
            at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:471)
            at javax.naming.InitialContext.lookup(InitialContext.java:351)
            at examples.session.stateless.HelloClient.main(HelloClient.java:34)

            When I invoked jboss:service, and I found my bean is here+- HelloBean (class: org.jnp.interfaces.NamingContext)
            | +- remote (proxy: $Proxy138 implements interface examples.session.stateless.Hello,interface org.jboss.ejb3.JBossProxy,interface javax.ejb.EJBObject)

            However, when I use Hello hello = (Hello) ctx.lookup("HelloBean/remote");

            Exception in thread "main" java.lang.NoClassDefFoundError: [Lorg/jboss/aop/advice/Interceptor;
            at java.lang.Class.getDeclaredFields0(Native Method)
            at java.lang.Class.privateGetDeclaredFields(Class.java:2259)
            at java.lang.Class.getDeclaredField(Class.java:1852)
            at java.io.ObjectStreamClass.getDeclaredSUID(ObjectStreamClass.java:1582)
            at java.io.ObjectStreamClass.access$700(ObjectStreamClass.java:52)
            at java.io.ObjectStreamClass$2.run(ObjectStreamClass.java:408)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.io.ObjectStreamClass.(ObjectStreamClass.java:400)
            at java.io.ObjectStreamClass.lookup(ObjectStreamClass.java:297)
            at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:531)
            at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1552)
            at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1466)
            at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1552)
            at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1466)
            at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1552)
            at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1466)
            at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1699)
            at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1305)
            at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1908)
            at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1832)
            at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1719)
            at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1305)
            at java.io.ObjectInputStream.readObject(ObjectInputStream.java:348)
            at java.rmi.MarshalledObject.get(MarshalledObject.java:135)
            at org.jnp.interfaces.MarshalledValuePair.get(MarshalledValuePair.java:30)
            at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:514)
            at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:471)
            at javax.naming.InitialContext.lookup(InitialContext.java:351)
            at examples.session.stateless.HelloClient.main(HelloClient.java:34)

            • 3. Re: JNDI called in EJB30
              boomboom

              When I invoke jboss:service MBean-List, I found the exception in jboss:

              10:11:31,447 ERROR [JNDIView] JNDIView.getHAJndiAttributes() failed
              java.lang.NullPointerException: name cannot be null
              at javax.management.ObjectName.construct(ObjectName.java:342)
              at javax.management.ObjectName.(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)

              • 4. Re: JNDI called in EJB30
                peterj

                You are getting closer. "HelloBean/remote" is the correct name. I am not sure why you are getting an AOP class involved on the client, but you can supply the class by adding the server/default/deploy/jboss-aop.deployer/jboss-aop.jar file to your client's classpath.

                • 5. Re: JNDI called in EJB30
                  boomboom

                  Thank you, PeterJ. I got it.

                  It requires jboss-4.0.4.GA\server\default\deploy\jboss-aop-jdk50.deployer\jboss-aop-jdk50.jar and jboss-aspect-library-jdk50.jar to set in my client's classpath.

                  Can you figure out why? And it's weird that it is not used the interface's name for JNDI lookup but use bean's name for lookup.

                  If you know why, please tell me.