4 Replies Latest reply on Feb 17, 2009 6:56 AM by wolfgangknauf

    Problem with new InitialContext().lookup(

    luftballon

      Hi everybody,

      i try to build a client that uses an EJB3.0. This EJB is deployed on JBOSS 5.0.0

      the following code creates an exception

      Context context = new InitialContext();
      Object ref = context.lookup("HelloBean/remote");
      


      the exception


      javax.naming.NamingException: Could not dereference object [Root exception is java.lang.reflect.UndeclaredThrowableException]
      at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1463)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:809)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:673)
      at javax.naming.InitialContext.lookup(InitialContext.java:392)
      at client.Client.doSomething(Client.java:20)
      at client.Client.main(Client.java:36)
      Caused by: java.lang.reflect.UndeclaredThrowableException
      at $Proxy0.createProxyBusiness(Unknown Source)
      at org.jboss.ejb3.proxy.objectfactory.session.SessionProxyObjectFactory.createProxy(SessionProxyObjectFactory.java:129)
      at org.jboss.ejb3.proxy.objectfactory.session.stateless.StatelessSessionProxyObjectFactory.getProxy(StatelessSessionProxyObjectFactory.java:79)
      at org.jboss.ejb3.proxy.objectfactory.ProxyObjectFactory.getObjectInstance(ProxyObjectFactory.java:156)
      at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
      at org.jnp.interfaces.NamingContext.getObjectInstance(NamingContext.java:1438)
      at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1455)
      ... 5 more
      Caused by: java.lang.ClassNotFoundException: beanpackage.HelloBeanRemote
      at org.jboss.remoting.serialization.ClassLoaderUtility.loadClass(ClassLoaderUtility.java:103)
      at org.jboss.remoting.loading.RemotingClassLoader.loadClass(RemotingClassLoader.java:86)
      at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Class.java:247)
      at org.jboss.remoting.loading.ObjectInputStreamWithClassLoader.resolveProxyClass(ObjectInputStreamWithClassLoader.java:250)
      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:1215)
      at org.jboss.remoting.transport.socket.MicroSocketClientInvoker.transport(MicroSocketClientInvoker.java:845)
      at org.jboss.remoting.MicroRemoteClientInvoker.invoke(MicroRemoteClientInvoker.java:160)
      at org.jboss.remoting.Client.invoke(Client.java:1708)
      at org.jboss.remoting.Client.invoke(Client.java:612)
      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.remoting.IsLocalProxyFactoryInterceptor.invoke(IsLocalProxyFactoryInterceptor.java:72)
      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.objectfactory.session.SessionProxyObjectFactory.createProxy(SessionProxyObjectFactory.java:129)
      at org.jboss.ejb3.proxy.objectfactory.session.stateless.StatelessSessionProxyObjectFactory.getProxy(StatelessSessionProxyObjectFactory.java:79)
      at org.jboss.ejb3.proxy.objectfactory.ProxyObjectFactory.getObjectInstance(ProxyObjectFactory.java:156)
      at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
      at org.jnp.interfaces.NamingContext.getObjectInstance(NamingContext.java:1438)
      at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1455)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:809)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:673)
      at javax.naming.InitialContext.lookup(InitialContext.java:392)
      at client.Client.doSomething(Client.java:20)
      at client.Client.main(Client.java:36)
      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.remoting.IsLocalProxyFactoryInterceptor.invoke(IsLocalProxyFactoryInterceptor.java:72)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
      at org.jboss.aspects.remoting.PojiProxy.invoke(PojiProxy.java:62)
      ... 12 more


      The "JMX MBean Operation View" of JBOSS says
      +- HelloBean (class: org.jnp.interfaces.NamingContext)
       | +- remote-beanpackage.HelloBeanRemote (class: Proxy for: beanpackage.HelloBeanRemote)
       | +- remote (class: Proxy for: beanpackage.HelloBeanRemote)
      

      I suppose there is somewhere a problem with beanpackage.HelloBeanRemote, but where. Someone an idea?

        • 1. Re: Problem with new InitialContext().lookup(
          wolfgangknauf

          Hi,

          you have to initialize your InitialContext with the server connection, so that it can access the remote JNDI:

          Properties props = new Properties();
          props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
          props.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming.client");
          props.setProperty(Context.PROVIDER_URL, "jnp://localhost:1099");
          
          InitialContext initialContext = new InitialContext(props);
          
          Object ref = context.lookup("HelloBean/remote");


          Hope this helps

          Wolfgang

          • 2. Re: Problem with new InitialContext().lookup(
            peterj

            When interpreting an exception stack trace, always follow the "caused by" chain - the final "caused by" is usually the root cause. In this case:

            Caused by: java.lang.ClassNotFoundException: beanpackage.HelloBeanRemote

            Apparently, you did not include the client library for your EJB in your client's classpath. (The client EJB library contains the interfaces for the EJB, but not the EJBs themselves.)

            • 3. Re: Problem with new InitialContext().lookup(
              luftballon

              @PeterJ
              Yes it works and the hint with "caused by" is really useful for me :) Thank you very much. I placed the remote interface (HelloBeanRemote) in the wrong package on the client side and thought there is a problem on the EJB side arrrrrr.

              @Wolfgang
              There is a possibility to initialize the InitialContext with the "indi.properties" file as well.

              • 4. Re: Problem with new InitialContext().lookup(
                wolfgangknauf

                Oops, I was too quick with my reply after seeing the "new InitialContext();" ;-). Should have read on...

                Wolfgang