1 2 Previous Next 20 Replies Latest reply on Jan 22, 2003 7:14 PM by adrian.brock

    Classcastexception(again) driving me crazy

    anderssv

      I've searched the forums and seen alot of tal about classcastexceptions on lookup, but I havn't found an answer. As a newbie this issue is driving me insane. ;)

      My setup:
      - Jboss 3.0.4 with jetty.
      - JDK 1.4.1_01
      - One ear directory
      - One war directrory inside the ear
      - One jar directory inside the ear with the EJB

      The ear seems to be loading fine, and my configuration seems to work, as the context.lookup("myEJB") doesn't throw an exception. The war archive is deployed successfully, since I can run struts-code that doesn't interact with EJB.

      First of all, I would like to know if I'm making an error in assuming that the EJB's in the jar directory, are available to servlets in the war directory without adding them to the classpath for the war? If not, this explains the classcastexception, since the servlet cannot locate the home interface. It would seem natural though, since Jboss is handling it all that they would be available.

      Either way, I decided to try to add the interfaces to the WEB-INF/lib directory of the war. Starting jboss again and yipee, things work! My joy is soon killed, as the classcastexception returns after reloading the application, by touching application.xml. This happens every time. When I first start the server it works and returns the correct string from one of the EJB methods. After touching application.xml and redeploying it does not work!

      Is there someone out there that can tell me if this is a bug or am I doing something wrong?

      Let me know if you need the stacktrace. The error occurs on the same line TestHome testh = (TestHome) context.lookup("Test") every time.

      Thanks,
      Anders,

        • 1. Re: Classcastexception(again) driving me crazy
          anderssv

          So I figured the question of the EJB's in the war classpath from the quick start guide. You have to include the client interfaces in the lib dir. But that still doesn't solve the problem of classcastexception after a redeploy.

          Anders,

          • 2. Re: Classcastexception(again) driving me crazy
            anderssv

            The problem is still present with the 3.0.5 release of JBoss. :(

            Anders,

            • 3. Re: Classcastexception(again) driving me crazy

              Try the following piece of code:

              Object obj = context.lookup("Test");

              System.out.println(obj.getClass() + " " + obj.getClass().getClassLoader());

              Class[] interfaces = obj.getClass().getInterfaces();
              for (int i = 0; i < interfaces; ++i)
              {
              System.out.println(interfaces + " " + interfaces.getClassLoader());
              }

              Before and after the re-deployment.

              Regards,
              Adrian

              • 4. Re: Classcastexception(again) driving me crazy

                The italics mark-up in the forums got in the way :-)

                for (int xx = 0; xx < interfaces.length; ++xx)
                {
                System.out.println(interfaces[xx] + " " + interfaces[xx].getClassLoader());
                }


                Regards,
                Adrian

                • 5. Re: Classcastexception(again) driving me crazy
                  anderssv

                  Hjm, tried it, and the objects seem the same. Should they be changed?

                  Before reload, the pages load fine:

                  19:11:46,642 INFO [STDOUT] Loader:
                  class $Proxy25 : org.jboss.mx.loading.UnifiedClassLoader3@13adc56{ url=file:/C:/java/jboss-3.0.4/server/default/tmp/deploy/server/default/lib/jnpserver.jar/36.jnpserver.jar }

                  19:11:46,642 INFO [STDOUT] Interfaces:
                  interface no.f12.ejb.TestHome : org.jboss.mx.loading.UnifiedClassLoader3@1b09282{ url=file:/C:/java/jboss-3.0.4/server/default/deploy/f12.ear/f12ejb.jar/ }
                  interface javax.ejb.Handle : org.jboss.mx.loading.UnifiedClassLoader3@1bd2664{ url=file:/C:/java/jboss-3.0.4/server/default/tmp/deploy/server/default/lib/jboss-j2ee.jar/17.jboss-j2ee.jar }

                  After reload, the pages fail with a 500 error:

                  19:13:51,391 INFO [STDOUT] Loader:
                  class $Proxy25 : org.jboss.mx.loading.UnifiedClassLoader3@13adc56{ url=file:/C:/java/jboss-3.0.4/server/default/tmp/deploy/server/default/lib/jnpserver.jar/36.jnpserver.jar }

                  19:13:51,391 INFO [STDOUT] Interfaces:
                  interface no.f12.ejb.TestHome : org.jboss.mx.loading.UnifiedClassLoader3@1b09282{ url=file:/C:/java/jboss-3.0.4/server/default/deploy/f12.ear/f12ejb.jar/ }
                  interface javax.ejb.Handle : org.jboss.mx.loading.UnifiedClassLoader3@1bd2664{ url=file:/C:/java/jboss-3.0.4/server/default/tmp/deploy/server/default/lib/jboss-j2ee.jar/17.jboss-j2ee.jar }

                  The exception I'm getting is:
                  19:13:51,652 WARN [jbossweb] WARNING: Exception for /f12/info/Info.do?command=testEJB
                  java.lang.ClassCastException
                  at no.f12.actions.info.InfoAction.testEJB(InfoAction.java:57)
                  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:324)
                  at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:280)
                  at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:220)
                  at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:446)
                  at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:266)
                  at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1292)
                  at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:492)
                  at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
                  at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
                  at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:366)
                  at org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:293)
                  at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:581)
                  at org.mortbay.http.HttpContext.handle(HttpContext.java:1687)
                  at org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:544)
                  at org.mortbay.http.HttpContext.handle(HttpContext.java:1637)
                  at org.mortbay.http.HttpServer.service(HttpServer.java:875)
                  at org.jboss.jetty.Jetty.service(Jetty.java:543)
                  at org.mortbay.http.HttpConnection.service(HttpConnection.java:806)
                  at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:956)
                  at org.mortbay.http.HttpConnection.handle(HttpConnection.java:823)
                  at org.mortbay.http.SocketListener.handleConnection(SocketListener.java:203)
                  at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:290)
                  at org.mortbay.util.ThreadPool$JobRunner.run(ThreadPool.java:743)
                  at java.lang.Thread.run(Thread.java:536)

                  Thanks,
                  Anders,

                  • 6. Re: Classcastexception(again) driving me crazy
                    anderssv

                    Hjm, tried it, and the objects seem the same. Should they be changed?

                    Before reload, the pages load fine:

                    19:11:46,642 INFO [STDOUT] Loader:
                    class $Proxy25 : org.jboss.mx.loading.UnifiedClassLoader3@13adc56{ url=file:/C:/java/jboss-3.0.4/server/default/tmp/deploy/server/default/lib/jnpserver.jar/36.jnpserver.jar }

                    19:11:46,642 INFO [STDOUT] Interfaces:
                    interface no.f12.ejb.TestHome : org.jboss.mx.loading.UnifiedClassLoader3@1b09282{ url=file:/C:/java/jboss-3.0.4/server/default/deploy/f12.ear/f12ejb.jar/ }
                    interface javax.ejb.Handle : org.jboss.mx.loading.UnifiedClassLoader3@1bd2664{ url=file:/C:/java/jboss-3.0.4/server/default/tmp/deploy/server/default/lib/jboss-j2ee.jar/17.jboss-j2ee.jar }

                    After reload, the pages fail with a 500 error:

                    19:13:51,391 INFO [STDOUT] Loader:
                    class $Proxy25 : org.jboss.mx.loading.UnifiedClassLoader3@13adc56{ url=file:/C:/java/jboss-3.0.4/server/default/tmp/deploy/server/default/lib/jnpserver.jar/36.jnpserver.jar }

                    19:13:51,391 INFO [STDOUT] Interfaces:
                    interface no.f12.ejb.TestHome : org.jboss.mx.loading.UnifiedClassLoader3@1b09282{ url=file:/C:/java/jboss-3.0.4/server/default/deploy/f12.ear/f12ejb.jar/ }
                    interface javax.ejb.Handle : org.jboss.mx.loading.UnifiedClassLoader3@1bd2664{ url=file:/C:/java/jboss-3.0.4/server/default/tmp/deploy/server/default/lib/jboss-j2ee.jar/17.jboss-j2ee.jar }

                    The exception I'm getting is:
                    19:13:51,652 WARN [jbossweb] WARNING: Exception for /f12/info/Info.do?command=testEJB
                    java.lang.ClassCastException
                    at no.f12.actions.info.InfoAction.testEJB(InfoAction.java:57)
                    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:324)
                    at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:280)
                    at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:220)
                    at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:446)
                    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:266)
                    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1292)
                    at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:492)
                    at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
                    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
                    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:366)
                    at org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:293)
                    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:581)
                    at org.mortbay.http.HttpContext.handle(HttpContext.java:1687)
                    at org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:544)
                    at org.mortbay.http.HttpContext.handle(HttpContext.java:1637)
                    at org.mortbay.http.HttpServer.service(HttpServer.java:875)
                    at org.jboss.jetty.Jetty.service(Jetty.java:543)
                    at org.mortbay.http.HttpConnection.service(HttpConnection.java:806)
                    at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:956)
                    at org.mortbay.http.HttpConnection.handle(HttpConnection.java:823)
                    at org.mortbay.http.SocketListener.handleConnection(SocketListener.java:203)
                    at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:290)
                    at org.mortbay.util.ThreadPool$JobRunner.run(ThreadPool.java:743)
                    at java.lang.Thread.run(Thread.java:536)

                    Thanks,
                    Anders,

                    • 7. Re: Classcastexception(again) driving me crazy
                      anderssv

                      Is there a max limit on a posting here? Can't post my reply.

                      • 8. Re: Classcastexception(again) driving me crazy
                        anderssv

                        Why the hell can't i reply here? Damn!

                        • 9. Re: Classcastexception(again) driving me crazy
                          anderssv

                          What is wrong?! I can't post.

                          • 10. Re: Classcastexception(again) driving me crazy

                            I believe the problem you are having is because when you re-deploy the EJB, the application using it still has a reference to the OLD EJB, and it's classloader.

                            Are you deploying the application as a whole ?

                            If you are, try closing the session to the appserver, and starting a new one, as, once again your "session" has the reference to the old class, and it's class loader, not the new one.

                            Hope this helps
                            G

                            • 11. Re: Classcastexception(again) driving me crazy
                              anderssv

                              Test? Can i post again?

                              • 12. Re: Classcastexception(again) driving me crazy
                                anderssv

                                Hjm, tried it, and the objects seem the same. Should they be changed?

                                Before reload, the pages load fine:

                                19:11:46,642 INFO [STDOUT] Loader:
                                class $Proxy25 : org.jboss.mx.loading.UnifiedClassLoader3@13adc56{ url=file:/C:/java/jboss-3.0.4/server/default/tmp/deploy/server/default/lib/jnpserver.jar/36.jnpserver.jar }

                                19:11:46,642 INFO [STDOUT] Interfaces:
                                interface no.f12.ejb.TestHome : org.jboss.mx.loading.UnifiedClassLoader3@1b09282{ url=file:/C:/java/jboss-3.0.4/server/default/deploy/f12.ear/f12ejb.jar/ }
                                interface javax.ejb.Handle : org.jboss.mx.loading.UnifiedClassLoader3@1bd2664{ url=file:/C:/java/jboss-3.0.4/server/default/tmp/deploy/server/default/lib/jboss-j2ee.jar/17.jboss-j2ee.jar }

                                After reload, the pages fail with a 500 error:

                                19:13:51,391 INFO [STDOUT] Loader:
                                class $Proxy25 : org.jboss.mx.loading.UnifiedClassLoader3@13adc56{ url=file:/C:/java/jboss-3.0.4/server/default/tmp/deploy/server/default/lib/jnpserver.jar/36.jnpserver.jar }

                                19:13:51,391 INFO [STDOUT] Interfaces:
                                interface no.f12.ejb.TestHome : org.jboss.mx.loading.UnifiedClassLoader3@1b09282{ url=file:/C:/java/jboss-3.0.4/server/default/deploy/f12.ear/f12ejb.jar/ }
                                interface javax.ejb.Handle : org.jboss.mx.loading.UnifiedClassLoader3@1bd2664{ url=file:/C:/java/jboss-3.0.4/server/default/tmp/deploy/server/default/lib/jboss-j2ee.jar/17.jboss-j2ee.jar }

                                The exception I'm getting is:
                                19:13:51,652 WARN [jbossweb] WARNING: Exception for /f12/info/Info.do?command=testEJB
                                java.lang.ClassCastException
                                at no.f12.actions.info.InfoAction.testEJB(InfoAction.java:57)
                                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:324)
                                at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:280)
                                at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:220)
                                at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:446)
                                at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:266)
                                at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1292)
                                at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:492)
                                at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
                                at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
                                at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:366)
                                at org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:293)
                                at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:581)
                                at org.mortbay.http.HttpContext.handle(HttpContext.java:1687)
                                at org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:544)
                                at org.mortbay.http.HttpContext.handle(HttpContext.java:1637)
                                at org.mortbay.http.HttpServer.service(HttpServer.java:875)
                                at org.jboss.jetty.Jetty.service(Jetty.java:543)
                                at org.mortbay.http.HttpConnection.service(HttpConnection.java:806)
                                at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:956)
                                at org.mortbay.http.HttpConnection.handle(HttpConnection.java:823)
                                at org.mortbay.http.SocketListener.handleConnection(SocketListener.java:203)
                                at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:290)
                                at org.mortbay.util.ThreadPool$JobRunner.run(ThreadPool.java:743)
                                at java.lang.Thread.run(Thread.java:536)

                                Thanks,
                                Anders,

                                • 13. Re: Classcastexception(again) driving me crazy
                                  anderssv

                                  Sorry for the mess on the postings. Must be some hidden cache server or something that didn't update the thread.

                                  I'm deploying the application as a whole. When re-deploying i touch the application.xml file.

                                  I'm not sure what you mean by session to the appserver. Where can i find methods to reset it? But why doesn't jboss do that when i ask it to reload the app? Seems logical to me, but then I'm only a newbie. ;)

                                  If you mean the session with the user/webbrowser, I've verified that it is not the same session after a reload.

                                  Thanks for the help,
                                  Anders,

                                  • 14. Re: Classcastexception(again) driving me crazy

                                    Just out of curiosity, I tried this

                                    (Jboss 3.0.4/Jetty)

                                    Deploy an EJB in a jar file
                                    Deploy a web app that uses the EJB in a war file

                                    Pull up a test page (Works great)

                                    Change the EJB && redeploy

                                    Web app breaks (ClassCastException)

                                    Redeploy web app that uses EJB

                                    Web app works again


                                    SO!

                                    My conclusion is that just starting a new session, (Brand new request from new client), isn't enough, if the web-app, still has the reference to the EJB, it's going to use it, and since the EJB is now different, and has reloaded, you will get a ClassCastException.

                                    I'm not sure if this is supposed to be this way, particularly if you are deploying your EJB && webapp, in the same ear file.

                                    Very strange...............

                                    Anyone else have some input ?

                                    G

                                    1 2 Previous Next