2 Replies Latest reply on Apr 24, 2008 6:05 PM by Jesus Borra

    jboss throws an exception when casting a proxy class

    Jesus Borra Newbie

      Hi all,

      A casting exception is thrown when my servlet tries to bind to an EJB. I am running jboss-4.2.2.GA. Java version 1.6.0_05.

      I have a servlet that tries to get a reference to a session ejb as in the following code:

      1. InitialContext initialContext = new InitialContext();
      2. j2eetest.ejb.ConfigurationRemoteHome configurationRemoteHome = (j2eetest.ejb.ConfigurationRemoteHome) initialContext.lookup("ConfigurationBean");
      3. ConfigurationRemote configurationRemote = configurationRemoteHome.create();

      When line '2.' is executed I get the following exception:

      20:42:13,140 ERROR [[/J2EETest-war]] StandardWrapper.Throwable
      java.lang.ClassCastException: $Proxy71 cannot be cast to j2eetest.ejb.ConfigurationRemoteHome
      at j2eetest.J2EETester.init(J2EETester.java:39)
      at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1161)
      at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:806)
      at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:623)
      at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:445)
      at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:379)
      at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:292)
      at j2eetest.Controller.processRequest(Controller.java:44)
      at j2eetest.Controller.doPost(Controller.java:85)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
      at java.lang.Thread.run(Thread.java:619)
      20:42:13,140 ERROR [[J2EETester]] Allocate exception for servlet J2EETester
      java.lang.ClassCastException: $Proxy71 cannot be cast to j2eetest.ejb.ConfigurationRemoteHome
      at j2eetest.J2EETester.init(J2EETester.java:39)
      at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1161)
      at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:806)
      at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:623)
      at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:445)
      at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:379)
      at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:292)
      at j2eetest.Controller.processRequest(Controller.java:44)
      at j2eetest.Controller.doPost(Controller.java:85)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
      at java.lang.Thread.run(Thread.java:619)
      20:42:13,140 ERROR [[Controller]] Servlet.service() for servlet Controller threw exception
      java.lang.ClassCastException: $Proxy71 cannot be cast to j2eetest.ejb.ConfigurationRemoteHome
      at j2eetest.J2EETester.init(J2EETester.java:39)
      at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1161)
      at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:806)
      at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:623)
      at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:445)
      at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:379)
      at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:292)
      at j2eetest.Controller.processRequest(Controller.java:44)
      at j2eetest.Controller.doPost(Controller.java:85)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
      at java.lang.Thread.run(Thread.java:619)

      When inspecting JNDIView in jboss' JMX Console I see the following entry under the Global JNDI Namespace
      ...
      +- ConfigurationBean (proxy: $Proxy71 implements interface j2eetest.ejb.ConfigurationRemoteHome,interface javax.ejb.Handle)
      ...

      which makes me believe that, as $Proxy71 implements the ConfigurationRemoteHome interface, there shouldn't be any problem when casting the reference returned by InitialContext.lookup(...) into the indicated type.

      What could be the root of the problem I experience?

      Thank you for your help,
      Jesus Borra

        • 1. Re: jboss throws an exception when casting a proxy class
          jaikiran pai Master

          Do you have the bean interfaces in more than one jar/war file? See this for more details http://wiki.jboss.org/wiki/en/ClassCastExceptions. See if the jmx-console method mentioned in that wiki helps.

          • 2. Re: jboss throws an exception when casting a proxy class
            Jesus Borra Newbie

            Jaikiran,

            First of all, thank you for your suggestion.

            No, I do not have the bean interface in more than one jar (at least not in the files I have deployed). I have read the document for which you sent a link and also followed the suggested jmx-console steps to verify if the bean interface appears in multiple places. This is what I found:

            j2eetest.ejb.ConfigurationBean Information
            Repository cache version:
            j2eetest.ejb.ConfigurationBean(77b794).ClassLoader=org.jboss.mx.loading.UnifiedClassLoader3@1186cf9{ url=file:/C:/apps/jboss-4.2.2.GA/server/default/tmp/deploy/tmp1179J2EETest-ejb.jar ,addedOrder=47}
            ..org.jboss.mx.loading.UnifiedClassLoader3@1186cf9{ url=file:/C:/apps/jboss-4.2.2.GA/server/default/tmp/deploy/tmp1179J2EETest-ejb.jar ,addedOrder=47}
            ....file:/C:/apps/jboss-4.2.2.GA/server/default/tmp/deploy/tmp1179J2EETest-ejb.jar
            ....file:/C:/apps/jboss-4.2.2.GA/server/default/tmp/deploy/tmp1179J2EETest-ejb.jar-contents/TKUSA.jar
            ..org.jboss.system.server.NoAnnotationURLClassLoader@8a0d5d
            ..sun.misc.Launcher$AppClassLoader@df6ccd
            ....file:/C:/apps/jboss-4.2.2.GA/bin/run.jar
            ....file:/C:/Program%20Files/Java/jdk1.6.0/lib/tools.jar
            ..sun.misc.Launcher$ExtClassLoader@601bb1
            ....file:/C:/Program%20Files/Java/jdk1.6.0/jre/lib/ext/dnsns.jar
            ....file:/C:/Program%20Files/Java/jdk1.6.0/jre/lib/ext/localedata.jar
            ....file:/C:/Program%20Files/Java/jdk1.6.0/jre/lib/ext/sunjce_provider.jar
            ....file:/C:/Program%20Files/Java/jdk1.6.0/jre/lib/ext/sunmscapi.jar
            ....file:/C:/Program%20Files/Java/jdk1.6.0/jre/lib/ext/sunpkcs11.jar
            ++++CodeSource: (file:/C:/apps/jboss-4.2.2.GA/server/default/tmp/deploy/tmp1179J2EETest-ejb.jar )
            Implemented Interfaces:
            ++interface javax.ejb.SessionBean(1b57dcb)
            ++++ClassLoader: org.jboss.mx.loading.UnifiedClassLoader3@11e0c13{ url=null ,addedOrder=2}
            ++++CodeSource: (file:/C:/apps/jboss-4.2.2.GA/server/default/lib/jboss-j2ee.jar )

            ### Instance0 found in UCL: org.jboss.mx.loading.UnifiedClassLoader3@1186cf9{ url=file:/C:/apps/jboss-4.2.2.GA/server/default/tmp/deploy/tmp1179J2EETest-ejb.jar ,addedOrder=47}

            From the documentation and jmx's output I would say that I only have one instance of my test bean (ConfigurationBean).

            I have more information but still do not know how to correct the problem. :(

            Regards,
            Jesus