vmassol     02/04/21 06:45:11

  Modified:    documentation/docs/xdocs changes.xml
               framework/src/java/share/org/apache/cactus/server
                        AbstractTestCaller.java
  Log:
  better handling of classloaders (Tomcat 3.2.x now works again).
  
  Revision  Changes    Path
  1.9       +10 -0     jakarta-cactus/documentation/docs/xdocs/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/documentation/docs/xdocs/changes.xml,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- changes.xml       21 Apr 2002 12:53:46 -0000      1.8
  +++ changes.xml       21 Apr 2002 13:45:11 -0000      1.9
  @@ -48,6 +48,16 @@
       </devs>
   
       <release version="1.3 in CVS">
  +      <action dev="VMA" type="update">
  +        Improved classloader support on the server side : Cactus first tries
  +        to load the Class to test using the Context class loader (thus, if you
  +        container has set the context class loader to point to the webapp
  +        classloader you'll be able to use Cactus as an extension and share it
  +        between projects). If the class cannot be loaded through the context
  +        class loader, Cactus then tries to load it using the Webapp classloader
  +        (in that case you'll need to have <code>cactus.jar</code> in your
  +        <code>WEB-INF/lib</code> directory).
  +      </action>
         <action dev="VMA" type="fix" due-to="Kjeld" due-to-email="[EMAIL PROTECTED]">
          (<link href="http://nagoya.apache.org/bugzilla/show_bug.cgi?id=6093";>
           Bug #6093</link>). Modified the mechanism to get test result from the
  
  
  
  1.6       +42 -36    
jakarta-cactus/framework/src/java/share/org/apache/cactus/server/AbstractTestCaller.java
  
  Index: AbstractTestCaller.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/server/AbstractTestCaller.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AbstractTestCaller.java   21 Apr 2002 12:45:44 -0000      1.5
  +++ AbstractTestCaller.java   21 Apr 2002 13:45:11 -0000      1.6
  @@ -75,7 +75,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Vincent Massol</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Nicholas Lesiecki</a>
    *
  - * @version $Id: AbstractTestCaller.java,v 1.5 2002/04/21 12:45:44 vmassol Exp $
  + * @version $Id: AbstractTestCaller.java,v 1.6 2002/04/21 13:45:11 vmassol Exp $
    */
   public abstract class AbstractTestCaller
   {
  @@ -288,20 +288,6 @@
       protected AbstractTestCase getTestClassInstance(String theClassName,
           String theTestCaseName) throws ServletException
       {
  -        // Print info on the classloader used to load this class
  -        if (LOGGER.isDebugEnabled()) {
  -            StringBuffer buffer = new StringBuffer("Classloaders = ");
  -            ClassLoader classLoader = getAppropriateClassLoader();
  -            while (classLoader != null) {
  -                buffer.append(classLoader.toString());
  -                classLoader = classLoader.getParent();
  -                if (classLoader != null) {
  -                    buffer.append(", ");
  -                }
  -            }
  -            LOGGER.debug(buffer.toString());
  -        }
  -
           // Get the class to call and build an instance of it.
           Class testClass = getTestClassClass(theClassName);
           AbstractTestCase testInstance = null;
  @@ -333,18 +319,25 @@
           // Get the class to call and build an instance of it.
           Class testClass = null;
           try {
  -            testClass = Class.forName(theClassName, true,
  -                getAppropriateClassLoader());
  +
  +            try {
  +                // Try first from Context class loader so that we can put the
  +                // Cactus jar as an external library.
  +                testClass = getTestClassFromContextClassLoader(theClassName);
  +            } catch (Exception internalException) {
  +                // It failed... Try from the webapp classloader.
  +                testClass = getTestClassFromWebappClassLoader(theClassName);
  +            }
  +
           } catch (Exception e) {
               String message = "Error finding class [" + theClassName +
  -                "] in classpath. ";
  -            message += "If you are getting this message Cactus may ";
  -            message += "not be able to see your test cases.\r\n ";
  -            message += "Possible causes include:\r\n";
  -            message += "\t- Your webapp may not include your test classes,\r\n";
  -            message += "\t- The cactus.jar resides in a global location and";
  -            message += " your test classes reside in a specific webapp,\r\n";
  -            message += "\t- Something else ... !";
  +                "] using both the Context classloader and the webapp " +
  +                "classloader. Possible causes include:\r\n";
  +            message += "\t- Your webapp does not include your test " +
  +                "classes,\r\n";
  +            message += "\t- The cactus.jar is not located in your " +
  +                "WEB-INF/lib directory and your Container has not set the " +
  +                "Context classloader to point to the webapp one";
   
               LOGGER.error(message, e);
               throw new ServletException(message, e);
  @@ -354,20 +347,33 @@
       }
   
       /**
  -     * Enable the Cactus jar to be put in the system classpath and still be
  -     * able to load classes that must be loaded by the webapp classloader by
  -     * using the Context class loader (if set) to load these classes.
  +     * Try loading test class using the Context class loader.
        *
  -     * @return either the Context class loader or the class loader that was
  -     *         used to load the current class.
  +     * @param theClassName the test class to load
  +     * @return the <code>Class</code> object for the class to load
  +     * @exception ClassNotFoundException if the class cannot be loaded through
  +     *            this class loader
        */
  -    private ClassLoader getAppropriateClassLoader()
  +    private Class getTestClassFromContextClassLoader(String theClassName)
  +        throws ClassNotFoundException
       {
  -        ClassLoader loader = Thread.currentThread().getContextClassLoader();
  -        if (loader == null) {
  -            loader = this.getClass().getClassLoader();
  -        }
  -        return loader;
  +        return Class.forName(theClassName, true,
  +            Thread.currentThread().getContextClassLoader());
  +    }
  +
  +    /**
  +     * Try loading test class using the Webapp class loader.
  +     *
  +     * @param theClassName the test class to load
  +     * @return the <code>Class</code> object for the class to load
  +     * @exception ClassNotFoundException if the class cannot be loaded through
  +     *            this class loader
  +     */
  +    private Class getTestClassFromWebappClassLoader(String theClassName)
  +        throws ClassNotFoundException
  +    {
  +        return Class.forName(theClassName, true,
  +            this.getClass().getClassLoader());
       }
   
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to