8 Replies Latest reply on Aug 11, 2006 7:54 AM by Andrew

    Proxy problem

    Andrew Newbie

      Hello! I've a little problem over here. I want to create a simple stand-alone client, which creates a bean and invokes a method on it.

      Here's the code for beans:

      package bean;
      
      import javax.ejb.Stateless;
      
      @Stateless
      public class CreaterRemote implements Creater {
      
       public Foo create() {
       return new FooRemote();
       }
      
      }


      package bean;
      
      import javax.ejb.Stateful;
      
      @Stateful
      public class FooRemote implements Foo, java.io.Serializable {
      
       private static final long serialVersionUID = 7316005043521549778L;
       private String name = "Hello!";
      
       public String print() {
       return this.name;
       }
      
      }


      The code of the client:
      package client;
      
      import java.util.Properties;
      
      import javax.naming.Context;
      
      import bean.Creater;
      import bean.Foo;
      
      public class Client {
       public static void main(String [] args) {
       try {
      
       Context jndiContext = getInitialContext( );
       Object ref = jndiContext.lookup("CreaterRemote/remote");
       Creater factory = (Creater)ref;
      
       Foo foo = factory.create();
      
       System.out.println(foo.print());
      
       } catch (javax.naming.NamingException ne){ne.printStackTrace( );}
       }
      
       public static Context getInitialContext( )
       throws javax.naming.NamingException {
      
       Properties p = new Properties( );
       p.put(Context.INITIAL_CONTEXT_FACTORY,
       "org.jnp.interfaces.NamingContextFactory");
       p.put(Context.URL_PKG_PREFIXES,
       "org.jboss.naming:org.jnp.interfaces");
       p.put(Context.PROVIDER_URL, "localhost");
       return new javax.naming.InitialContext(p);
       }
      }


      The client class is situated in the other project with remote interfaces imported.

      When i try to ru it, the following errors occure:
      Exception in thread "main" java.lang.reflect.UndeclaredThrowableException
       at $Proxy1.create(Unknown Source)
       at client.Client.main(Client.java:18)
      Caused by: java.lang.ClassNotFoundException: bean.Foo
       at java.net.URLClassLoader$1.run(Unknown Source)
       at java.security.AccessController.doPrivileged(Native Method)
       at java.net.URLClassLoader.findClass(Unknown Source)
       at java.lang.ClassLoader.loadClass(Unknown Source)
       at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
       at java.lang.ClassLoader.loadClass(Unknown Source)
       at org.jboss.remoting.loading.RemotingClassLoader.loadClass(RemotingClassLoader.java:50)
       at org.jboss.remoting.loading.ObjectInputStreamWithClassLoader.resolveClass(ObjectInputStreamWithClassLoader.java:139)
       at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
       at java.io.ObjectInputStream.readClassDesc(Unknown Source)
       at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
       at java.io.ObjectInputStream.readObject0(Unknown Source)
       at java.io.ObjectInputStream.readObject(Unknown Source)
       at org.jboss.aop.joinpoint.InvocationResponse.readExternal(InvocationResponse.java:122)
       at java.io.ObjectInputStream.readExternalData(Unknown Source)
       at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
       at java.io.ObjectInputStream.readObject0(Unknown Source)
       at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
       at java.io.ObjectInputStream.readSerialData(Unknown Source)
       at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
       at java.io.ObjectInputStream.readObject0(Unknown Source)
       at java.io.ObjectInputStream.readObject(Unknown Source)
       at org.jboss.remoting.serialization.impl.java.JavaSerializationManager.receiveObject(JavaSerializationManager.java:128)
       at org.jboss.remoting.marshal.serializable.SerializableUnMarshaller.read(SerializableUnMarshaller.java:66)
       at org.jboss.remoting.transport.socket.SocketClientInvoker.transport(SocketClientInvoker.java:279)
       at org.jboss.remoting.RemoteClientInvoker.invoke(RemoteClientInvoker.java:143)
       at org.jboss.remoting.Client.invoke(Client.java:525)
       at org.jboss.remoting.Client.invoke(Client.java:488)
       at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:55)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:61)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.aspects.security.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:55)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:65)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.stateful.StatefulRemoteProxy.invoke(StatefulRemoteProxy.java:133)
       ... 2 more


      As I understand the server didn't generated proxy stub, as it must do. Maybe I have to change some settings on the server or something else?

      I would be very grateful if somebody could help me.

        • 1. Re: Proxy problem
          jaikiran pai Master

           

          Caused by: java.lang.ClassNotFoundException: bean.Foo


          bean.Foo needs to be placed in the client's classpath. Make it (the class/jar) available in the client's classpath to resolve the issue.



          • 2. Re: Proxy problem
            Andrew Newbie

             

            "jaikiran" wrote:
            bean.Foo needs to be placed in the client's classpath. Make it (the class/jar) available in the client's classpath to resolve the issue.


            Yes, then it works - I've tried this. But what's the benefit of the client program then? It contains all the interfaces and implementations like the bean itself. In the books about JBoss they say I do nat have to generate stubs myself but the server does this work for me. And the Context passes this srubs to the clint during the runtime. When I used Sun Application Server the server generated stubs, either. But then I took generated jars and imported them to my project - everything worked fine.

            • 3. Re: Proxy problem
              jaikiran pai Master

               

              It contains all the interfaces and implementations like the bean itself


              No. The client classpath just has to have the interfaces of the bean and NOT the bean implementation.

              • 4. Re: Proxy problem
                Andrew Newbie

                 

                "jaikiran" wrote:
                It contains all the interfaces and implementations like the bean itself


                No. The client classpath just has to have the interfaces of the bean and NOT the bean implementation.


                Yess... Sorry I misunderstood you :) Right, I've imported bean interfaces - but that doesn't work anyway. I've paid attention on one interesting thing. When we lookup our bean, we lookup our bean implementation class, but not it's interface:
                Object ref = jndiContext.lookup("CreaterRemote/remote");


                As I understand the clent class must not know about bean implementation classes at all, but here we lookup implementation class CreaterRemote. I've tried to write this example on the base of the book O'Reilly Enterprise JavaBeans, 3.0 There when they lookup bean, they lookup the implmentation class. Maybe the "/remote" statement tells that we are lookin up to the remote interface, but I haven't found any information concerning this.

                • 5. Re: Proxy problem
                  jaikiran pai Master

                   

                  As I understand the clent class must not know about bean implementation classes at all, but here we lookup implementation class CreaterRemote


                  No. That's not the case. The name that you are specifying as the argument to the lookup method is the jndi name to which the bean is bound. Its NOT the name of the bean implementation class. The jndi name can be configured to be anything(even 'xyz'). In this example, just for simplicity they have used the jndi name same as the bean implementation classname


                  • 6. Re: Proxy problem
                    Andrew Newbie

                    Aha! Got it, thanks a lot! But I do not use xml deployment descriptors, but annotations. Maybe you can tell me, if I can specify the name for my interface before deployment and how I do it?

                    Suppose I've changed remote interface's name, but for simplicity let it left as is now. But why then my program crashes? The same thing with the examples fro the book mentioned above.

                    • 7. Re: Proxy problem
                      jaikiran pai Master

                       

                      But why then my program crashes?


                      Post the exception stacktrace, lets see what the issue is.




                      • 8. Re: Proxy problem
                        Andrew Newbie

                        Here you are:

                        Exception in thread "main" java.lang.reflect.UndeclaredThrowableException
                         at $Proxy0.create(Unknown Source)
                         at client.FooClient.main(FooClient.java:18)
                        Caused by: java.lang.ClassNotFoundException: bean.FooRemote
                         at java.net.URLClassLoader$1.run(Unknown Source)
                         at java.security.AccessController.doPrivileged(Native Method)
                         at java.net.URLClassLoader.findClass(Unknown Source)
                         at java.lang.ClassLoader.loadClass(Unknown Source)
                         at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
                         at java.lang.ClassLoader.loadClass(Unknown Source)
                         at org.jboss.remoting.loading.RemotingClassLoader.loadClass(RemotingClassLoader.java:50)
                         at org.jboss.remoting.loading.ObjectInputStreamWithClassLoader.resolveClass(ObjectInputStreamWithClassLoader.java:139)
                         at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
                         at java.io.ObjectInputStream.readClassDesc(Unknown Source)
                         at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
                         at java.io.ObjectInputStream.readObject0(Unknown Source)
                         at java.io.ObjectInputStream.readObject(Unknown Source)
                         at org.jboss.aop.joinpoint.InvocationResponse.readExternal(InvocationResponse.java:122)
                         at java.io.ObjectInputStream.readExternalData(Unknown Source)
                         at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
                         at java.io.ObjectInputStream.readObject0(Unknown Source)
                         at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
                         at java.io.ObjectInputStream.readSerialData(Unknown Source)
                         at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
                         at java.io.ObjectInputStream.readObject0(Unknown Source)
                         at java.io.ObjectInputStream.readObject(Unknown Source)
                         at org.jboss.remoting.serialization.impl.java.JavaSerializationManager.receiveObject(JavaSerializationManager.java:128)
                         at org.jboss.remoting.marshal.serializable.SerializableUnMarshaller.read(SerializableUnMarshaller.java:66)
                         at org.jboss.remoting.transport.socket.SocketClientInvoker.transport(SocketClientInvoker.java:279)
                         at org.jboss.remoting.RemoteClientInvoker.invoke(RemoteClientInvoker.java:143)
                         at org.jboss.remoting.Client.invoke(Client.java:525)
                         at org.jboss.remoting.Client.invoke(Client.java:488)
                         at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:55)
                         at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                         at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:61)
                         at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                         at org.jboss.aspects.security.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:55)
                         at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                         at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:65)
                         at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                         at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:102)
                         ... 2 more
                        


                        One thing that confuses me is that it outputs:
                        Caused by: java.lang.ClassNotFoundException: bean.FooRemote


                        That is why I thought that something's wrong with the proxy-stubs.