7 Replies Latest reply: Oct 2, 2006 7:15 PM by Bo?tjan Plevnik RSS

    lookup ClassCastException

    Viet Linh Dang Newbie

      I have a problem with the remote interface:

      The code:

      ctx = getInitialContext();
      Object ref = ctx.lookup("challenge/AddLinkServiceBean/remote");
      AddLinkServiceRemote addLinkService = (AddLinkServiceRemote) PortableRemoteObject
       .narrow(ref,AddLinkServiceRemote.class);
      


      The error:
      12:38:04,828 ERROR [STDERR] Caused by: java.lang.ClassCastException: $Proxy97
      12:38:04,828 ERROR [STDERR] at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:212)
      


      The jmx-console:
      +- challenge (class: org.jnp.interfaces.NamingContext)
       | +- AddLinkServiceBean(class: org.jnp.interfaces.NamingContext)
       | | +- remote (class: java.lang.Object)
       | | +- remoteStatefulProxyFactory (proxy: $Proxy92 implements interface org.jboss.ejb3.ProxyFactory)
      


      I don't understand why it has the remoteStatefulProxyFactory here. Could you help me please?

        • 1. Re: lookup ClassCastException
          Frank Stolle Newbie

          Wouldn't it be enough to write:

          ctx = getInitialContext();
          AddLinkServiceRemote addLinkService = (AddLinkServiceRemote) = ctx.lookup("challenge/AddLinkServiceBean/remote");
          


          • 2. Re: lookup ClassCastException
            brent wilson Newbie

            I'm getting the same problem. This only seems to happen when I use the @stateful annotation. When I use @stateless the problem goes away.

            • 3. Re: lookup ClassCastException
              Frank Stolle Newbie

              I also have this problem.

              I have two ears. One with the StateFul Bean and one with the war-file and a Servlet. I run the following code in the Servlet:

              Context ctx;
               try {
               ctx = new InitialContext();
               Object o = ctx.lookup("StatefulTest/remote");
               Class[] interfaces = o.getClass().getInterfaces();
               for (Class intf : interfaces) {
               writer.println(intf.getName());
               }
               StatefulTest stateFulBean = (StatefulTest) o;
               writer.println(stateFulBean.sayHello("mike"));
               } catch (Exception e) {
               e.printStackTrace(writer);
               }
              


              The output is:
              my.test.StatefulTest
              org.jboss.ejb3.JBossProxy
              javax.ejb.EJBLocalObject
              java.lang.ClassCastException: $Proxy267
               at my.test.TestServlet.doGet(TestServlet.java:70)
               at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
               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.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
               at org.jboss.web.tomcat.tc5.session.ClusteredSessionValve.invoke(ClusteredSessionValve.java:95)
               at org.jboss.web.tomcat.tc5.session.JvmRouteValve.invoke(JvmRouteValve.java:84)
               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:869)
               at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
               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(Unknown Source)
              


              Any hints?

              • 4. Re: lookup ClassCastException
                Weston M. Price Master

                Is this really a remote EJB? Try doing a narrow on the interface prior to use

                StatefulTest stateFulBean = (StatefulTest)PortableRemoteObject.narrow(o, StatefulTest.class);

                • 5. Re: lookup ClassCastException
                  Frank Stolle Newbie

                  Sorry I posted the wrong output. I also tried it with local-binding (which of course isn't correct).

                  Here the correct output, now also included your line:

                  my.test.StatefulTest
                  org.jboss.ejb3.JBossProxy
                  javax.ejb.EJBObject
                  java.lang.ClassCastException
                   at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(Unknown Source)
                   at javax.rmi.PortableRemoteObject.narrow(Unknown Source)
                   at my.test.TestServlet.doGet(TestServlet.java:71)
                   at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
                   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.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
                   at org.jboss.web.tomcat.tc5.session.ClusteredSessionValve.invoke(ClusteredSessionValve.java:95)
                   at org.jboss.web.tomcat.tc5.session.JvmRouteValve.invoke(JvmRouteValve.java:84)
                   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:869)
                   at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
                   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(Unknown Source)
                  Caused by: java.lang.ClassCastException: $Proxy302
                   ... 25 more
                  


                  • 6. Re: lookup ClassCastException
                    Logan Kiefer Newbie

                    This sounds exactly like my problem as well. I had a thread called "ClassCastException when updating ear-jar.xml schema" on this that I'm still having problems with. I'm not sure if that thread will give you the slightest hint of a solution or not, but I'm all ears if anyone solves it in this thread.

                    • 7. Re: lookup ClassCastException
                      Bo?tjan Plevnik Newbie

                      Hi.

                      I had the same problem.
                      After long googling i found the answer here:

                      http://wiki.jboss.org/wiki/Wiki.jsp?page=CommonHurdlesAndDifficultiesYouMayEncounterDuringEJB3Development

                      There are two possible error scenaries:
                      1. You packaged the same class file twice in the same EAR (in two different JARs for example)
                      2. You specified incomplete JNDI name at lookup (forgot /local or /remote)

                      Solution to the first scenario is to either enable call by value in the conf file naming-service.xml or repackage your ear without duplicates
                      You don't have to be genious to figure out solution to the second scenario ;)