6 Replies Latest reply on Mar 9, 2002 6:17 PM by Ron Jawanda

    JBoss-2.4.4_Tomcat-4.0.1 ClassCastException Problem

    Frank Morton Newbie

      Anyone really have this running? I've been beating my head against the wall for three days now trying to get this going. Would have done something a long time ago if I didn't have to have servlet 2.3.....but I digress.

      I've gotten this running with help from other posts in this forum, but now I'm stumped. I have a stateless session bean that has a method that returns a "com.base2inc.bean.value.object.ProfileValueObject" object. I am certain that the object is really such a thing because I did a o.getClass().getName(), which returns the right class name. I also wrote a test application that uses the bean, which works fine.

      However, when I make the same call from a servlet, it looks to me like the proxy is messed up or something because I get a ClassCastException.

      Does anyone have a clue what to do about this? The other strangeness with JBoss-2.4.4_Tomcat-4.0.1 I have been able to code around, but there is only one way to do a return from a method with an object of a certain type.

      I'm stuck and will try any suggestions.

      The code for the method in question is:

      public ProfileValueObject getByProfileHandle(String profileHandle) throws FinderException,RemoteException,NamingException {
      ValueList list = get("profileHandle='"+String.valueOf(profileHandle)+"'",0);
      if(list.size() == 0) return(null);
      ProfileValueObject profileValueObject = (ProfileValueObject)(list.get(0));
      // exception from the return statement...makes it to here just fine

      The exception caused by the return statement:

      [ERROR,EmbeddedCatalinaServiceSX] StandardWrapperValve[invoker]: Servlet.service() for servlet invoker threw exception
      java.lang.ClassCastException: com.base2inc.bean.value.object.ProfileValueObject
      at $Proxy16.getByProfileHandle(Unknown Source)
      at com.base2inc.app.util.ServletEnvironment.authenticate(ServletEnvironment.java:596)
      at com.base2inc.app.framework.JspFramework.authenticate(JspFramework.java:212)
      at com.base2inc.app.framework.JspFramework.doService(JspFramework.java:76)
      at com.base2inc.app.util.HttpServletExtended.doPost(HttpServletExtended.java:62)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:446)

        • 1. Re: JBoss-2.4.4_Tomcat-4.0.1 ClassCastException Problem
          Frank Morton Newbie

          I threw in the towel. Went back to JBoss-2.4.1_Tomcat-3.2.3 and had it running in about 15 minutes without any problems.

          I think the JBoss-2.4.4_Tomcat-4.0.1 distribution is not only missing pieces, but has problems, particularly related to tomcat.

          I'm going to run with this until 3.0.0+4.1.x has been in use for some time.

          • 2. Re: JBoss-2.4.4_Tomcat-4.0.1 ClassCastException Problem
            Mike Newbie

            ProfileValueObject profileValueObject = (ProfileValueObject)(list.get(0));
            appears to be causing the problem...

            Try checking the return value of list.get(0) with instanceof to see if that function returns your value object.

            What does com.base2inc.bean.value.object.ProfileValueObject derive from?

            How are you calling this function in the servlet?

            Let me know unless you give up.


            • 3. Re: JBoss-2.4.4_Tomcat-4.0.1 ClassCastException Problem
              Alain Coetmeur Newbie

              I've got a similar problem between MBean and EJB...
              this is , as usual a classloader subtlety (not a bug).
              I suppose you have the same.

              like you I had an EJB with an interface that had a method that returned a value object. The class was stored in a "client jar"

              the client jar was loaded in the contect of the MBeans.
              the MBean was using and thus have loaded the value object class in it's MBean classloader context.

              The EJB implementation did the same, usin it's own EJB ClassLoader, and the client jar deployed around the EJB.

              when the EJB returned an instance of the value object,
              it could not be cast upon the class which was loaded in the MBean context, despite the same name and same binary code.

              I think you have the same proble between your EJB and WebApp class loaders...

              the solution is probably to make an EAR, which
              will load the object value class into a common classloader used by EJB ans Servlets...

              In theory you may have to put the object-value class
              in a shared jar in the .ear itself, with Class-Path:
              entries in the Manifest.mf of the EJB jar and Webapp war...
              but in fact, for me it works without...

              the client jar was also

              • 4. Re: JBoss-2.4.4_Tomcat-4.0.1 ClassCastException Problem
                Jim Newbie


                I have just found a ClassCastException problem with my code migrating to the above release(from 241a+323) and I think it could be a class loader subtlety as you mentioned.

                coetmeur, could you perhaps expand a bit on your solution to this problem?

                The problem on my side is when I attempt to cast to a type I know is correct. The same wrapper class is stored in the myejb.jar and the mywebapp.war.

                I'll just compare the classloader instances...

                un moment!

                • 5. Re: JBoss-2.4.4_Tomcat-4.0.1 ClassCastException Problem
                  Jim Newbie


                  Ok, I have the following classloaders used in the cast:

                  java.net.URLClassLoader(on the ejb side) vs org.apache.catalina.loader.WebappClassLoader(on the servlet side).

                  Could this be the reason for the ClassCastException exception?

                  If so, how can I get around this problem?



                  • 6. Re: JBoss-2.4.4_Tomcat-4.0.1 ClassCastException Problem
                    Ron Jawanda Novice

                    Download Tomcat 4.03 and replace the catalina directory with the new one.
                    Also use JAVA 1.4
                    I am not saying your problem will go away but I had similar problems that did go away with the new tomcat and java 1.4