5 Replies Latest reply on Apr 4, 2006 12:31 PM by Ulrich Staudinger

    java.lang.ClassCastException: $Proxy0

    Ulrich Staudinger Newbie

      Hello,

      i am having a problem with a stateless session bean used from a remote client:

      The exception i get is:
      Looking up HelloWorld
      java.lang.ClassCastException: $Proxy0
      at SimpleClient.main(SimpleClient.java:33)


      Here is the code to my easy client :

       Hashtable hashtable = new Hashtable();
       hashtable.put("java.naming.factory.initial",
       "org.jnp.interfaces.NamingContextFactory");
      
       hashtable.put(Context.PROVIDER_URL, "jnp://localhost:1099");
       //hashtable.put(Context.PROVIDER_URL, "localhost");
      
      
       hashtable.put("java.naming.factory.url.pkgs",
       "org.jboss.naming:org.jnp.interfaces");
      
      
       Context context = new InitialContext(hashtable);
       System.out.println("Looking up HelloWorld");
      
       SimpleFacade sf = (SimpleFacade)
       context.lookup("SimpleFacade/local");
      
       sf.log();
      



      Here is my easy stateless bean:
      package web;
      import javax.ejb.Stateless;
      import javax.ejb.TransactionAttribute;
      import javax.ejb.TransactionAttributeType;
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;
      
      @Stateless
      public class SimpleFacade implements ISimpleFacadeLocal, ISimpleFacadeRemote{
      
       @PersistenceContext(unitName="web")
       protected EntityManager manager;
      
       public void log(){
       System.out.println("Calling simple facade");
       }
      
      }
      


      And my two interfaces:
      package web;
      
      import javax.ejb.Remote;
      
      @Remote
      public interface ISimpleFacadeRemote {
       public void log();
      }
      
      
      package web;
      
      import javax.ejb.Local;
      
      
      @Local
      public interface ISimpleFacadeLocal {
       public void log();
      }
      
      
      


      I can use that bean from a jsp without problems ( through the local interface) but from a standalone client it doesn't work.


      Can someone please tell me what is wrong ?

      Many thanks,
      Ulrich


        • 1. Re: java.lang.ClassCastException: $Proxy0
          Thomas Termin Newbie

          Hello

          SimpleFacade sf = (SimpleFacade) context.lookup("SimpleFacade/local");

          Are you sure about doing a lookup for the remote interface?

          And you should always do a lookup for the remote/local interface not for the bean directly.

          Thomas

          • 2. Re: java.lang.ClassCastException: $Proxy0
            Ulrich Staudinger Newbie

            Hi,
            thanks for replying.

            So, you mean it should look more like this :


            ISimpleFacadeRemote sf = (ISimpleFacadeRemote)
            context.lookup("SimpleFacade/remote");




            Actually this produces on the client side:

            log4j:WARN No appenders could be found for logger (org.jboss.remoting.Client).
            log4j:WARN Please initialize the log4j system properly.
            org.jboss.remoting.CannotConnectException: Can not get connection to server. Problem establishing socket connection.
             at org.jboss.remoting.transport.socket.SocketClientInvoker.transport(SocketClientInvoker.java:253)
             at org.jboss.remoting.RemoteClientInvoker.invoke(RemoteClientInvoker.java:136)
             at org.jboss.remoting.Client.invoke(Client.java:444)
             at org.jboss.remoting.Client.invoke(Client.java:407)
             at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:55)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
             at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:61)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
             at org.jboss.aspects.security.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:55)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
             at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:65)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
             at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:102)
             at $Proxy0.log(Unknown Source)
             at SimpleClient.main(SimpleClient.java:36)
            Caused by: java.lang.reflect.InvocationTargetException
             at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
             at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
             at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
             at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
             at org.jboss.remoting.transport.socket.SocketClientInvoker.createClientSocket(SocketClientInvoker.java:504)
             at org.jboss.remoting.transport.socket.SocketClientInvoker.getConnection(SocketClientInvoker.java:471)
             at org.jboss.remoting.transport.socket.SocketClientInvoker.transport(SocketClientInvoker.java:249)
             ... 14 more
            Caused by: java.lang.NoClassDefFoundError
             at org.jboss.remoting.transport.socket.ClientSocketWrapper.createOutputStream(ClientSocketWrapper.java:91)
             at org.jboss.remoting.transport.socket.ClientSocketWrapper.createStreams(ClientSocketWrapper.java:75)
             at org.jboss.remoting.transport.socket.ClientSocketWrapper.<init>(ClientSocketWrapper.java:54)
             ... 21 more
            


            Am a little bit confused ...

            Thanks
            Ulrich

            • 3. Re: java.lang.ClassCastException: $Proxy0
              Thomas Termin Newbie

              Hello,

              I guess you forgot some client jars.

              Look for the NoClassDefFoundError mesages and find the jars.

              Thomas

              • 4. Re: java.lang.ClassCastException: $Proxy0
                Ulrich Staudinger Newbie

                Aaah :-) you genius. Ugh. ;-)

                I simply added all the libs from JBOSS_HOME/lib and all the libs from JBOSS_HOME/server/default/lib and now it works.

                Thanks!


                • 5. Re: java.lang.ClassCastException: $Proxy0
                  Ulrich Staudinger Newbie

                  Unfortunately it still doesnt work ....
                  It only works with the SimpleClient and the jboss server on the same host.

                  When i have SimpleClient and Jboss server on different hosts, i still get this one on the SimpleFacade server:

                  
                  18:12:17,174 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
                  org.jboss.remoting.CannotConnectException: Can not get connection to server. Problem establishing socket connection.
                   at org.jboss.remoting.transport.socket.SocketClientInvoker.transport(SocketClientInvoker.java:253)
                   at org.jboss.remoting.RemoteClientInvoker.invoke(RemoteClientInvoker.java:136)
                   at org.jboss.remoting.Client.invoke(Client.java:444)
                   at org.jboss.remoting.Client.invoke(Client.java:407)
                   at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:55)
                   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                   at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:61)
                   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                   at org.jboss.aspects.security.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:55)
                   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                   at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:65)
                   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
                   at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:102)
                   at $Proxy68.log(Unknown Source)
                   at org.apache.jsp.statelesscall_jsp._jspService(org.apache.jsp.statelesscall_jsp:107)
                   at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
                   at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
                   at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
                   at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
                   at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
                   at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
                   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
                   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
                   at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
                   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
                   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
                   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
                   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
                   at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:54)
                   at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:174)
                   at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
                   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
                   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
                   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
                   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
                   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:868)
                   at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:663)
                   at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
                   at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
                   at java.lang.Thread.run(Thread.java:595)
                  Caused by: java.lang.reflect.InvocationTargetException
                   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
                   at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
                   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
                   at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
                   at org.jboss.remoting.transport.socket.SocketClientInvoker.createClientSocket(SocketClientInvoker.java:504)
                   at org.jboss.remoting.transport.socket.SocketClientInvoker.getConnection(SocketClientInvoker.java:471)
                   at org.jboss.remoting.transport.socket.SocketClientInvoker.transport(SocketClientInvoker.java:249)
                   ... 39 more
                  Caused by: java.lang.NoClassDefFoundError
                   at org.jboss.remoting.transport.socket.ClientSocketWrapper.createOutputStream(ClientSocketWrapper.java:91)
                   at org.jboss.remoting.transport.socket.ClientSocketWrapper.createStreams(ClientSocketWrapper.java:75)
                   at org.jboss.remoting.transport.socket.ClientSocketWrapper.<init>(ClientSocketWrapper.java:54)
                   ... 46 more