Author: markt
Date: Mon Feb 10 13:42:25 2014
New Revision: 1566622

URL: http://svn.apache.org/r1566622
Log:
Restore the ability to use addURL()

Modified:
    tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java
    tomcat/trunk/webapps/docs/changelog.xml

Modified: tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java?rev=1566622&r1=1566621&r2=1566622&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java Mon Feb 
10 13:42:25 2014
@@ -277,8 +277,6 @@ public class WebappClassLoader extends U
 
     /**
      * Associated web resources for this webapp.
-     * TODO Review the use of resources in this class to see if further
-     *      simplifications can be made.
      */
     protected WebResourceRoot resources = null;
 
@@ -419,6 +417,13 @@ public class WebappClassLoader extends U
     private final List<ClassFileTransformer> transformers = new 
CopyOnWriteArrayList<>();
 
 
+    /**
+     * Flag that indicates that {@link #addURL(URL)} has been called which
+     * creates a requirement to check the super class when searching for
+     * resources.
+     */
+    private boolean hasExternalRepositories = false;
+
     // ------------------------------------------------------------- Properties
 
     /**
@@ -870,9 +875,9 @@ public class WebappClassLoader extends U
             try {
                 clazz = findClassInternal(name);
             } catch(ClassNotFoundException cnfe) {
-                if (log.isDebugEnabled())
-                    log.debug("    --> Returning ClassNotFoundException");
-                throw cnfe;
+                if (!hasExternalRepositories) {
+                    throw cnfe;
+                }
             } catch(AccessControlException ace) {
                 log.warn("WebappClassLoader.findClassInternal(" + name
                         + ") security exception: " + ace.getMessage(), ace);
@@ -882,6 +887,24 @@ public class WebappClassLoader extends U
                     log.trace("      -->RuntimeException Rethrown", e);
                 throw e;
             }
+            if ((clazz == null) && hasExternalRepositories) {
+                try {
+                    clazz = super.findClass(name);
+                } catch(AccessControlException ace) {
+                    log.warn("WebappClassLoader.findClassInternal(" + name
+                            + ") security exception: " + ace.getMessage(), 
ace);
+                    throw new ClassNotFoundException(name, ace);
+                } catch (RuntimeException e) {
+                    if (log.isTraceEnabled())
+                        log.trace("      -->RuntimeException Rethrown", e);
+                    throw e;
+                }
+            }
+            if (clazz == null) {
+                if (log.isDebugEnabled())
+                    log.debug("    --> Returning ClassNotFoundException");
+                throw new ClassNotFoundException(name);
+            }
         } catch (ClassNotFoundException e) {
             if (log.isTraceEnabled())
                 log.trace("    --> Passing on ClassNotFoundException");
@@ -938,6 +961,10 @@ public class WebappClassLoader extends U
             url = entry.source;
         }
 
+        if ((url == null) && hasExternalRepositories) {
+            url = super.findResource(name);
+        }
+
         if (log.isDebugEnabled()) {
             if (url != null)
                 log.debug("    --> Returning '" + url.toString() + "'");
@@ -975,6 +1002,14 @@ public class WebappClassLoader extends U
             }
         }
 
+        // Adding the results of a call to the superclass
+        if (hasExternalRepositories) {
+            Enumeration<URL> otherResourcePaths = super.findResources(name);
+            while (otherResourcePaths.hasMoreElements()) {
+                result.add(otherResourcePaths.nextElement());
+            }
+        }
+
         return Collections.enumeration(result);
     }
 
@@ -1092,6 +1127,12 @@ public class WebappClassLoader extends U
             if (log.isDebugEnabled())
                 log.debug("  --> Returning stream from local");
             stream = findLoadedResource(name);
+            try {
+                if (hasExternalRepositories && (stream == null))
+                    stream = url.openStream();
+            } catch (IOException e) {
+                // Ignore
+            }
             if (stream != null)
                 return (stream);
         }
@@ -2723,4 +2764,11 @@ public class WebappClassLoader extends U
         return true;
 
     }
+
+
+    @Override
+    protected void addURL(URL url) {
+        super.addURL(url);
+        hasExternalRepositories = true;
+    }
 }

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1566622&r1=1566621&r2=1566622&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Mon Feb 10 13:42:25 2014
@@ -45,6 +45,15 @@
   issues to not "pop up" wrt. others).
 -->
 <section name="Tomcat 8.0.4 (markt)">
+  <subsection name="Catalina">
+    <changelog>
+      <fix>
+        Restore the ability to use the <code>addURL()</code> method of the
+        web application class loader to add external resources to the web
+        application. (markt) 
+      </fix>
+    </changelog>
+  </subsection>
   <subsection name="Other">
     <changelog>
       <fix>



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to