3 Replies Latest reply on Oct 21, 2008 3:10 AM by jaikiran pai

    War to remote EJB fails with ClassCastException

    Ilane Walberg Newbie

      I'm playing with the Jython/ZK framework, trying to set an application up to get information from an existing Session Bean on a remote server.

      I successfully receive the session EJB back from the InitialContext lookup, but when I call any method on it that returns an object, it gets ClassCastException (even if I don't save the result), e.g.:

      projectService.getProject(new Long(2));
      
      gets java.lang.ClassCastException: com.comp.data.ProjectDTO cannot be cast to com.comp.data.ProjectDTO, where ProjectDTO is the object passed back from the Session Bean (see log below for stack trace.)

      If I run the same class outside of a web app (i.e. via its main method) it works. If I call a method with no return value (i.e. void) it works. I'm guessing a ClassLoader issue, but I can't for the life of me figure out how (see from the log below, I dumped some classloader info but didn't really know what to look for).

      The jar that holds the ProjectDTO class and the service interface is in the war only once in WEB-INF/lib (and I did notice that the path to this jar is not listed in the classloader as a repository).

      JBoss-4.2.2.GA on both machines running Linux.
      App being developed under NetBeans with Maven plugin.

      Any ideas on how to fix this?

      23:57:16,690 INFO [STDOUT] InitialContext Type: javax.naming.InitialContext
      23:57:16,690 INFO [STDOUT] Returned Object Type: $Proxy59
      23:57:16,690 INFO [STDOUT] ClassLoader of Type: WebappClassLoader
      delegate: false
      repositories:
      /WEB-INF/classes/
      ----------> Parent Classloader:
      java.net.FactoryURLClassLoader@10e0904
      23:57:16,691 INFO [STDOUT] ClassLoader of This: WebappClassLoader
      delegate: false
      repositories:
      /WEB-INF/classes/
      ----------> Parent Classloader:
      java.net.FactoryURLClassLoader@10e0904
      23:57:16,691 INFO [STDOUT] ClassLoader of Thread: WebappClassLoader
      delegate: false
      repositories:
      /WEB-INF/classes/
      ----------> Parent Classloader:
      java.net.FactoryURLClassLoader@10e0904
      23:57:16,974 ERROR [[zkLoader]] Servlet.service() for servlet zkLoader threw exception
      java.lang.ClassCastException: com.comp.data.ProjectDTO cannot be cast to com.comp.data.ProjectDTO
      at $Proxy59.getProject(Unknown Source)
      at com.comp.demo.ProjectManager.getProjects(ProjectManager.java:74)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at bsh.Reflect.invokeMethod(Unknown Source)
      at bsh.Reflect.invokeObjectMethod(Unknown Source)
      at bsh.Name.invokeMethod(Unknown Source)
      at bsh.BSHMethodInvocation.eval(Unknown Source)
      at bsh.BSHPrimaryExpression.eval(Unknown Source)
      at bsh.BSHPrimaryExpression.eval(Unknown Source)
      at bsh.BSHAssignment.eval(Unknown Source)
      at bsh.Interpreter.eval(Unknown Source)
      at bsh.Interpreter.eval(Unknown Source)
      at org.zkoss.zk.scripting.bsh.BSHInterpreter.exec(BSHInterpreter.java:100)
      at org.zkoss.zk.scripting.util.GenericInterpreter.interpret(GenericInterpreter.java:292)
      at org.zkoss.zk.ui.impl.PageImpl.interpret(PageImpl.java:858)
      at org.zkoss.zk.ui.impl.UiEngineImpl.execNonComponent(UiEngineImpl.java:728)
      at org.zkoss.zk.ui.impl.UiEngineImpl.execCreate0(UiEngineImpl.java:547)
      at org.zkoss.zk.ui.impl.UiEngineImpl.execCreate(UiEngineImpl.java:492)
      at org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild0(UiEngineImpl.java:612)
      at org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild(UiEngineImpl.java:581)
      at org.zkoss.zk.ui.impl.UiEngineImpl.execCreate0(UiEngineImpl.java:525)
      at org.zkoss.zk.ui.impl.UiEngineImpl.execCreate(UiEngineImpl.java:492)
      at org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage0(UiEngineImpl.java:374)
      at org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage(UiEngineImpl.java:296)
      at org.zkoss.zk.ui.http.DHtmlLayoutServlet.process(DHtmlLayoutServlet.java:230)
      at org.zkoss.zk.ui.http.DHtmlLayoutServlet.doGet(DHtmlLayoutServlet.java:167)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
      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(JaccContextValalve.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)

      TIA,
      Ilane

        • 1. Re: War to remote EJB fails with ClassCastException
          jaikiran pai Master

           

          The jar that holds the ProjectDTO class and the service interface is in the war only once in WEB-INF/lib


          The best way to debug such issues is to add the -verbose:class JVM parameter to your run.bat and start JBoss. This parameter will dump the classes that are being loaded and the corresponding jar files from where they are being picked up. This will help you to understand what's going on. You might want to redirect the console output to a file because adding this option writes out a lot of logs.



          • 2. Re: War to remote EJB fails with ClassCastException
            Ilane Walberg Newbie

            I started the server with option -verbose:class as you recommended and got:

            [Loaded com.comp.service.ProjectService from file:/data/jboss-4.2.2.GA/server/default/tmp/deploy/tmp5998StatusTool-exp.war/WEB-INF/lib/project-common-1.3.SNAPSHOT.jar]
            [Loaded org.jboss.ejb3.JBossProxy from file:/data/jboss-4.2.2.GA/server/default/tmp/deploy/tmp5917jboss-ejb3.jar]
            [Loaded com.comp.data.ProjectDTO from file:/data/jboss-4.2.2.GA/server/default/tmp/deploy/tmp5998StatusTool-exp.war/WEB-INF/lib/project-common-1.3.SNAPSHOT.jar]
            [Loaded $Proxy59 from org.jboss.web.tomcat.service.WebAppClassLoader]
            ...
            [Loaded org.jboss.remoting.loading.ClassByteClassLoader$MyRef from file:/data/jboss-4.2.2.GA/server/default/lib/jboss-remoting.jar]
            [Loaded com.comp.data.ProjectDTO from org.jboss.remoting.loading.ClassByteClassLoader]


            Both my EJB (ProjectService interface) and data object (ProjectDTO) are loaded from the expected jar. This jar is a copy of the same jar located in the remote server's server/default/deploy directory.

            I see that JBoss is also loading my data object from its remoting ClassByteClassLoader.

            In making sure that both servers were using the same class, I noticed that the common jar did not live inside the project ear deployed remotely, but instead was sitting standalone in the server/default/deploy directory. This had been deployed by others and built and deployed by Maven and I don't know why that was done. I decided to do the same on the local JBoss. It worked!

            Now, I want to know why! Can anyone help me understand what's really happening here? Any thoughts on why the commons jar should be outside the ear?

            Ilane


            • 3. Re: War to remote EJB fails with ClassCastException
              jaikiran pai Master

               

              "iwalberg" wrote:

              It worked!


              Good to know it worked :-)

              "iwalberg" wrote:

              In making sure that both servers were using the same class, I noticed that the common jar did not live inside the project ear deployed remotely, but instead was sitting standalone in the server/default/deploy directory. This had been deployed by others and built and deployed by Maven and I don't know why that was done.

              Now, I want to know why! Can anyone help me understand what's really happening here? Any thoughts on why the commons jar should be outside the ear?




              Which "common" jar are we talking about? And what does it contain? Is it part of your application? And what is your client application? Is it a standalone application or a web application on a remote server?