11 Replies Latest reply on Aug 2, 2007 2:16 AM by jaikiran

    Proxy ClassCastException after successful EJB lookup

    cupdike

      Using the EJB3 trailerblazer as a guide (http://trailblazer.demo.jboss.com/EJB3Trail/serviceobjects/slsb/index.html)
      I've been trying to reference a SLSB via a local interface in the web tier.

      The jndi environment looks like this for my APLEntityFacade EJB3 SLSB:

       | +- APLEntityFacadeBean (class: org.jnp.interfaces.NamingContext)
       | | +- local (proxy: $Proxy1344 implements interface edu.jhuapl.ermp.service.ejb.APLEntityFacade,interface org.jboss.ejb3.JBossProxy,interface javax.ejb.EJBLocalObject)
       | | +- remote (proxy: $Proxy1343 implements interface edu.jhuapl.ermp.service.ejb.APLEntityFacade,interface org.jboss.ejb3.JBossProxy,interface javax.ejb.EJBObject)
      


      I'm successfully doing a lookup on "ermpJpaHib/APLEntityFacadeBean/local". However, the cast below fails with the ClassCastException (exception given at end of post):

      aplEntityFacade = (APLEntityFacade)facade;

      APLEntityFacadeBean is defined like this:

      @Stateless
      @Local
      @TransactionAttribute(TransactionAttributeType.REQUIRED)
      public class APLEntityFacadeBean
       extends GenericEJB3DAO<APLEntity, Long>
       implements APLEntityFacade {
      


      Anyone have any idea what I'm doing wrong?

      TIA, Clark

      $Proxy1344
      java.lang.ClassCastException: $Proxy1344
       at edu.jhuapl.ermp.ServiceFactory.getAPLEntityFacade(ServiceFactory.java:47)
       at edu.jhuapl.ermp.contact.view.backing.SelectEntityView.getEntityTypes(SelectEntityView.java:15)
       at org.apache.jsp.contact.selectEntityType_jsp._jspService(selectEntityType_jsp.java:103)
       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:334)
       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.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
       at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:524)
       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.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
       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(Thread.java:595)


        • 1. Re: Proxy ClassCastException after successful EJB lookup
          cupdike

          I noticed that tomatkist reported a similar problem (I'm also using 4.05 GA) several days ago: http://www.jboss.com/index.html?module=bb&op=viewtopic&t=100439

          Unfortunately, his solution is what I was already trying (lookup the bean and cast to the biz interface).

          What is bizarre/frustrating is that the $Proxy1344 class is failing the cast to APLEntityFacade, yet the jndi environment indicates that $Proxy1344 implements APLEntityFacade--so how can it possibly fail to cast to it?

          Am I doing something wrong?

          • 2. Re: Proxy ClassCastException after successful EJB lookup
            peterj

            You probably have a classloader issue. Looks like the code that does the casting is in a servlet. You do not, by any chance, have the APLEntityFacade class in both the EJB jar file and in a jar file (or in the classes directory) in your war file?

            • 3. Re: Proxy ClassCastException after successful EJB lookup
              cupdike

              Peter-

              Nice catch... that was indeed the problem. I forgot about that whole "class identity = class + classloader" thing, and was lazy about how I had configured ant. There are also some useful wiki pages on this and other potential classloader issues:
              http://wiki.jboss.org/wiki/Wiki.jsp?page=ClassLoadingOverview

              Thanks very much, Clark

              • 4. Re: Proxy ClassCastException after successful EJB lookup
                skymic

                Hi cupdike and Peter,

                I think I have the same problem with classloaders.
                I am using a standalone tomcat V5.5 and try to lookup a remote EJB in a JBoss4.0.5 (on a different machine) using this code in my servlet:

                String urlName = "jnp://localhost:1099";
                Properties p = new Properties();
                p.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
                p.put(Context.PROVIDER_URL, urlName);
                p.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
                InitialContext ic = new InitialContext(p);
                Object ref = ic.lookup("SDOCI/remote/SDOCIBusinessService");
                SDOCIBusinessService busiService = (SDOCIBusinessService )PortableRemoteObject.narrow(ref, SDOCIBusinessService.class);

                I get the following exception:
                java.lang.ClassCastException
                at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:229)
                Caused by: java.lang.ClassCastException: javax.naming.Reference

                Yes I have deployed my remote EJB in an ear on JBoss and also included the interface of my remote bean in a jar in WEB-INF/lib since my webapp must know the interface I am trying to narrow.

                Anyway I get this exception.
                Does anyone of you have an idea?

                Thanks for your help.



                • 5. Re: Proxy ClassCastException after successful EJB lookup
                  peterj

                  skymic, you should have started a new post, not appended to an existing one.

                  I suspect that you are using EJB3 (you didn't say which version of ejb you are using), in which case you might want to try the lookup as:

                  Object ref = ic.lookup("SDOCI/remote/SDOCIBusinessService/remote");

                  If this does not work, use the jmx-console to invoke the list() method in the jboss:service=JNDIView mbean to list the entire JNDI tree. That should tell you what to use for the name.

                  • 6. Re: Proxy ClassCastException after successful EJB lookup
                    skymic

                    Hi Peter,

                    thanks for replying anyway ...

                    Yes I am using EJB3.0.

                    The EJB I am trying to lookup is registered in JNDI as:

                    +- SDOCIBusinessApp (class: org.jnp.interfaces.NamingContext)
                    | +- ExcelConverterImpl (class: org.jnp.interfaces.NamingContext)
                    | | +- local (proxy: $Proxy94 implements No ClassLoaders found for: ch.skyguide.aim.interfaces.businesslogic.converter.ExcelConverter (no security manager: RMI class loader disabled))
                    | +- IBriefingExportInvokerImpl (class: org.jnp.interfaces.NamingContext)
                    | | +- local (proxy: $Proxy97 implements No ClassLoaders found for: ch.skyguide.aim.interfaces.businesslogic.exportinvoker.IBriefingExportInvoker (no security manager: RMI class loader disabled))
                    +- SDOCI (class: org.jnp.interfaces.NamingContext)
                    | +- remote (class: org.jnp.interfaces.NamingContext)
                    | | +- SDOCIBusinessService (class: java.lang.Object)
                    | | +- SDOCIBusinessServiceStatefulProxyFactory (proxy: $Proxy87 implements interface org.jboss.ejb3.ProxyFactory)

                    I have used a RemoteBinding annotation to set the JNDIO name.

                    The head of my EJB class look like this:

                    @Stateful
                    @RemoteBinding(jndiBinding = "SDOCI/remote/SDOCIBusinessService")
                    public class SDOCIBusinessServiceImpl implements SDOCIBusinessService {

                    The head of the interface looks like this:


                    @Remote
                    public interface SDOCIBusinessService {

                    The lookup call actually works fine:

                    Object ref = ic.lookup("SDOCI/remote/SDOCIBusinessService");

                    Its the narrow call where I get the ClassCastException:

                    SDOCIBusinessService narrowed = (SDOCIBusinessService)PortableRemoteObject.narrow(ref, SDOCIBusinessService.class);

                    Thanks for helping.

                    • 7. Re: Proxy ClassCastException after successful EJB lookup
                      venkatesh_s5

                      I too have the same problem pls any one suggest me.

                      • 8. Re: Proxy ClassCastException after successful EJB lookup
                        peterj

                        venkatesh_s5, did you read all of the posts on this topic? Especially the first line of my reply to skymic? Also, without providing details on your exact problem, we cannot help you.

                        • 9. Re: Proxy ClassCastException after successful EJB lookup
                          chrisrevilla

                          skymic Iam suffering the same problem as you ... it works fine when I use a simple class as cliente but when I use a dispatch class in a Strut it throws the exception Proxy ClassCastException:
                          I am using jboss 4.0.5 GA.. Please somebody help me please:

                          Context context = new InitialContext();
                          operacionesRHRemoto operacionesRHRemoto = (OperacionesRH) context.lookup("RHumanosEAR/"+OperacionesRH/remote);

                          and:

                          +- RHumanosEAR (class: org.jnp.interfaces.NamingContext)
                          | +- EmpBean (class: org.jnp.interfaces.NamingContext)
                          | | +- local (proxy: $Proxy179 implements interface em.facade.EmpBeanLocal,interface org.jboss.ejb3.JBossProxy,interface javax.ejb.EJBLocalObject)
                          | | +- remote (proxy: $Proxy178 implements interface em.facade.EmpBeanRemoto,interface org.jboss.ejb3.JBossProxy,interface javax.ejb.EJBObject)
                          | +- DepBean (class: org.jnp.interfaces.NamingContext)
                          | | +- local (proxy: $Proxy183 implements interface de.facade.DepBeanLocal,interface org.jboss.ejb3.JBossProxy,interface javax.ejb.EJBLocalObject)
                          | | +- remote (proxy: $Proxy182 implements interface de.facade.DepBeanRemote,interface org.jboss.ejb3.JBossProxy,interface javax.ejb.EJBObject)
                          | +- OperacionesRH (class: org.jnp.interfaces.NamingContext)
                          | | +- localStatefulProxyFactory (class: org.jboss.ejb3.stateful.StatefulLocalProxyFactory)
                          | | +- local (class: java.lang.Object)
                          | | +- remote (class: java.lang.Object)
                          | | +- remoteStatefulProxyFactory (proxy: $Proxy102 implements interface org.jboss.ejb3.ProxyFactory)

                          trace trace is:

                          19:30:19,453 ERROR [[action]] Servlet.service() for servlet action threw exception
                          java.lang.ClassCastException: $Proxy186
                          at de.struts.action.ManejarOperacionAction.anadiraOperacion(ManejarOperacionAction.java:62)
                          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                          at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
                          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                          at java.lang.reflect.Method.invoke(Unknown Source)
                          at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:280)
                          at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:216)
                          at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
                          at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
                          at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
                          at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
                          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.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.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
                          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)

                          I dont know wwhat is wrong, this work fine when I use a simple class as client but it throws an error when I use a dispatch or action class in struts.
                          thank you... PLEASE HELP ME , I am fighting with this problem almost a week.
                          Please :(

                          • 10. Re: Proxy ClassCastException after successful EJB lookup

                            Same problem, seems specific to JBoss 4.2

                            • 11. Re: Proxy ClassCastException after successful EJB lookup
                              jaikiran

                              Have a look at http://wiki.jboss.org/wiki/Wiki.jsp?page=ClassCastExceptions. Specifically, try out the jmx-console method mentioned over there.