tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1401503 [1/4] - in /tomcat/trunk: ./ java/org/apache/catalina/ java/org/apache/catalina/core/ java/org/apache/catalina/loader/ java/org/apache/catalina/mapper/ java/org/apache/catalina/servlets/ java/org/apache/catalina/startup/ java/org/a...
Date Tue, 23 Oct 2012 22:38:18 GMT
Author: markt
Date: Tue Oct 23 22:38:16 2012
New Revision: 1401503

URL: http://svn.apache.org/viewvc?rev=1401503&view=rev
Log:
Merge new resources implementation from sandbox/trunk-resources

Added:
    tomcat/trunk/java/org/apache/catalina/WebResource.java
      - copied unchanged from r1401258, tomcat/sandbox/trunk-resources/java/org/apache/catalina/WebResource.java
    tomcat/trunk/java/org/apache/catalina/WebResourceRoot.java
      - copied, changed from r1401258, tomcat/sandbox/trunk-resources/java/org/apache/catalina/WebResourceRoot.java
    tomcat/trunk/java/org/apache/catalina/WebResourceSet.java
      - copied unchanged from r1401465, tomcat/sandbox/trunk-resources/java/org/apache/catalina/WebResourceSet.java
    tomcat/trunk/java/org/apache/catalina/webresources/
      - copied from r1401495, tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/
    tomcat/trunk/test/org/apache/catalina/core/TesterContext.java
      - copied unchanged from r1401495, tomcat/sandbox/trunk-resources/test/org/apache/catalina/core/TesterContext.java
    tomcat/trunk/test/org/apache/catalina/webresources/
      - copied from r1401495, tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/
    tomcat/trunk/test/webresources/
      - copied from r1401252, tomcat/sandbox/trunk-resources/test/webresources/
    tomcat/trunk/test/webresources/dir2/
      - copied from r1401465, tomcat/sandbox/trunk-resources/test/webresources/dir2/
Removed:
    tomcat/trunk/java/org/apache/catalina/loader/VirtualWebappLoader.java
    tomcat/trunk/java/org/apache/naming/resources/
    tomcat/trunk/test/org/apache/naming/resources/TestDirContextURLStreamHandlerFactory.java
    tomcat/trunk/test/org/apache/naming/resources/TestProxyDirContext.java
Modified:
    tomcat/trunk/build.xml
    tomcat/trunk/java/org/apache/catalina/Context.java
    tomcat/trunk/java/org/apache/catalina/Loader.java
    tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java
    tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties
    tomcat/trunk/java/org/apache/catalina/core/StandardContext.java
    tomcat/trunk/java/org/apache/catalina/core/mbeans-descriptors.xml
    tomcat/trunk/java/org/apache/catalina/loader/LocalStrings.properties
    tomcat/trunk/java/org/apache/catalina/loader/LocalStrings_es.properties
    tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java
    tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java
    tomcat/trunk/java/org/apache/catalina/loader/mbeans-descriptors.xml
    tomcat/trunk/java/org/apache/catalina/mapper/Mapper.java
    tomcat/trunk/java/org/apache/catalina/mapper/MapperListener.java
    tomcat/trunk/java/org/apache/catalina/servlets/DefaultServlet.java
    tomcat/trunk/java/org/apache/catalina/servlets/WebdavServlet.java
    tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java
    tomcat/trunk/java/org/apache/catalina/startup/ContextRuleSet.java
    tomcat/trunk/java/org/apache/catalina/startup/FailedContext.java
    tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties
    tomcat/trunk/java/org/apache/catalina/startup/TldConfig.java
    tomcat/trunk/java/org/apache/catalina/util/ConcurrentDateFormat.java
    tomcat/trunk/java/org/apache/catalina/util/ExtensionValidator.java
    tomcat/trunk/java/org/apache/jasper/compiler/TldLocationsCache.java
    tomcat/trunk/java/org/apache/tomcat/JarScannerCallback.java
    tomcat/trunk/java/org/apache/tomcat/util/scan/LocalStrings.properties
    tomcat/trunk/java/org/apache/tomcat/util/scan/StandardJarScanner.java
    tomcat/trunk/test/javax/el/TestCompositeELResolver.java
    tomcat/trunk/test/org/apache/catalina/core/TestStandardContextAliases.java
    tomcat/trunk/test/org/apache/catalina/loader/TestVirtualContext.java
    tomcat/trunk/test/org/apache/catalina/loader/TestVirtualWebappLoader.java
    tomcat/trunk/test/org/apache/catalina/mbeans/TestRegistration.java
    tomcat/trunk/test/org/apache/catalina/startup/TestContextConfigAnnotation.java
    tomcat/trunk/test/org/apache/jasper/compiler/TestGenerator.java
    tomcat/trunk/test/org/apache/naming/resources/TestNamingContext.java
    tomcat/trunk/webapps/docs/changelog.xml
    tomcat/trunk/webapps/docs/config/context.xml
    tomcat/trunk/webapps/docs/config/loader.xml
    tomcat/trunk/webapps/docs/config/resources.xml
    tomcat/trunk/webapps/docs/security-howto.xml

Modified: tomcat/trunk/build.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/build.xml?rev=1401503&r1=1401502&r2=1401503&view=diff
==============================================================================
--- tomcat/trunk/build.xml (original)
+++ tomcat/trunk/build.xml Tue Oct 23 22:38:16 2012
@@ -492,6 +492,7 @@
         <!-- Exclude simple test files -->
         <exclude name="test/webapp-3.0/bug53257/*.txt"/>
         <exclude name="test/webapp-3.0-fragments/WEB-INF/classes/*.txt"/>
+        <exclude name="test/webresources/**"/>
       </fileset>
       <fileset dir="modules/jdbc-pool" >
         <exclude name=".*/**"/>

Modified: tomcat/trunk/java/org/apache/catalina/Context.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/Context.java?rev=1401503&r1=1401502&r2=1401503&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/Context.java (original)
+++ tomcat/trunk/java/org/apache/catalina/Context.java Tue Oct 23 22:38:16 2012
@@ -20,7 +20,6 @@ import java.net.URL;
 import java.util.Locale;
 import java.util.Set;
 
-import javax.naming.directory.DirContext;
 import javax.servlet.ServletContainerInitializer;
 import javax.servlet.ServletContext;
 import javax.servlet.ServletRegistration;
@@ -1256,14 +1255,6 @@ public interface Context extends Contain
 
 
     /**
-     * Add a URL for a JAR that contains static resources in a
-     * META-INF/resources directory that should be included in the static
-     * resources for this context.
-     */
-    public void addResourceJarUrl(URL url);
-
-
-    /**
      * Add a ServletContainerInitializer instance to this web application.
      *
      * @param sci       The instance to add
@@ -1391,14 +1382,14 @@ public interface Context extends Contain
     /**
      * Return the Resources with which this Context is associated.
      */
-    public DirContext getResources();
+    public WebResourceRoot getResources();
 
     /**
      * Set the Resources object with which this Context is associated.
      *
      * @param resources The newly associated Resources
      */
-    public void setResources(DirContext resources);
+    public void setResources(WebResourceRoot resources);
 
     /**
      * Return the Manager with which this Context is associated.  If there is
@@ -1413,5 +1404,21 @@ public interface Context extends Contain
      * @param manager The newly associated Manager
      */
     public void setManager(Manager manager);
+
+    /**
+     * Sets the flag that indicates if /WEB-INF/classes should be treated like
+     * an exploded JAR and JAR resources made available as if they were in a
+     * JAR.
+     *
+     * @param addWebinfClassesResources The new value for the flag
+     */
+    public void setAddWebinfClassesResources(boolean addWebinfClassesResources);
+
+    /**
+     * Gets the flag that indicates if /WEB-INF/classes should be treated like
+     * an exploded JAR and JAR resources made available as if they were in a
+     * JAR.
+     */
+    public boolean getAddWebinfClassesResources();
 }
 

Modified: tomcat/trunk/java/org/apache/catalina/Loader.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/Loader.java?rev=1401503&r1=1401502&r2=1401503&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/Loader.java (original)
+++ tomcat/trunk/java/org/apache/catalina/Loader.java Tue Oct 23 22:38:16 2012
@@ -129,21 +129,6 @@ public interface Loader {
 
 
     /**
-     * Add a new repository to the set of repositories for this class loader.
-     *
-     * @param repository Repository to be added
-     */
-    public void addRepository(String repository);
-
-
-    /**
-     * Return the set of repositories defined for this class loader.
-     * If none are defined, a zero-length array is returned.
-     */
-    public String[] findRepositories();
-
-
-    /**
      * Has the internal repository associated with this Loader been modified,
      * such that the loaded classes should be reloaded?
      */

Copied: tomcat/trunk/java/org/apache/catalina/WebResourceRoot.java (from r1401258, tomcat/sandbox/trunk-resources/java/org/apache/catalina/WebResourceRoot.java)
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/WebResourceRoot.java?p2=tomcat/trunk/java/org/apache/catalina/WebResourceRoot.java&p1=tomcat/sandbox/trunk-resources/java/org/apache/catalina/WebResourceRoot.java&r1=1401258&r2=1401503&rev=1401503&view=diff
==============================================================================
--- tomcat/sandbox/trunk-resources/java/org/apache/catalina/WebResourceRoot.java (original)
+++ tomcat/trunk/java/org/apache/catalina/WebResourceRoot.java Tue Oct 23 22:38:16 2012
@@ -67,7 +67,6 @@ import java.util.Set;
  * <li>Resource JARs         - Same feature but implemented using the same
  *                             mechanism as all the other additional
  *                             resources.</li>
- * <li>TODO                  - More to list here</li>
  * </ul>
  */
 /*

Modified: tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java?rev=1401503&r1=1401502&r2=1401503&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java Tue Oct 23 22:38:16 2012
@@ -19,7 +19,6 @@ package org.apache.catalina.core;
 import java.io.InputStream;
 import java.lang.reflect.InvocationTargetException;
 import java.net.MalformedURLException;
-import java.net.URI;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -34,9 +33,7 @@ import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 
-import javax.naming.Binding;
 import javax.naming.NamingException;
-import javax.naming.directory.DirContext;
 import javax.servlet.Filter;
 import javax.servlet.FilterRegistration;
 import javax.servlet.RequestDispatcher;
@@ -62,14 +59,12 @@ import org.apache.catalina.Globals;
 import org.apache.catalina.Host;
 import org.apache.catalina.LifecycleState;
 import org.apache.catalina.Service;
+import org.apache.catalina.WebResourceRoot;
 import org.apache.catalina.Wrapper;
 import org.apache.catalina.connector.Connector;
 import org.apache.catalina.deploy.FilterDef;
 import org.apache.catalina.mapper.MappingData;
-import org.apache.catalina.util.ResourceSet;
 import org.apache.catalina.util.ServerInfo;
-import org.apache.naming.resources.DirContextURLStreamHandler;
-import org.apache.naming.resources.Resource;
 import org.apache.tomcat.util.ExceptionUtils;
 import org.apache.tomcat.util.buf.CharChunk;
 import org.apache.tomcat.util.buf.MessageBytes;
@@ -518,27 +513,12 @@ public class ApplicationContext
         if (normPath == null)
             return (null);
 
-        DirContext resources = context.getResources();
+        WebResourceRoot resources = context.getResources();
         if (resources != null) {
-            String fullPath = context.getPath() + normPath;
-            String hostName = context.getParent().getName();
-            try {
-                resources.lookup(normPath);
-                URI uri = new URI("jndi", null, "", -1,
-                        getJNDIUri(hostName, fullPath), null, null);
-                return new URL(null, uri.toString(),
-                        new DirContextURLStreamHandler(resources));
-            } catch (NamingException e) {
-                // Ignore
-            } catch (Exception e) {
-                // Unexpected
-                log(sm.getString("applicationContext.lookup.error", path,
-                        getContextPath()), e);
-            }
+            return resources.getResource(normPath).getURL();
         }
 
-        return (null);
-
+        return null;
     }
 
 
@@ -563,29 +543,20 @@ public class ApplicationContext
         if (normalizedPath == null)
             return (null);
 
-        DirContext resources = context.getResources();
+        WebResourceRoot resources = context.getResources();
         if (resources != null) {
-            try {
-                Object resource = resources.lookup(normalizedPath);
-                if (resource instanceof Resource)
-                    return (((Resource) resource).streamContent());
-            } catch (NamingException e) {
-                // Ignore
-            } catch (Exception e) {
-                // Unexpected
-                log(sm.getString("applicationContext.lookup.error", path,
-                        getContextPath()), e);
-            }
+            return resources.getResource(normalizedPath).getInputStream();
         }
-        return (null);
 
+        return null;
     }
 
 
     /**
      * Return a Set containing the resource paths of resources member of the
      * specified collection. Each path will be a String starting with
-     * a "/" character. The returned set is immutable.
+     * a "/" character. Paths representing directories will end with a "/"
+     * character. The returned set is immutable.
      *
      * @param path Collection path
      */
@@ -605,33 +576,12 @@ public class ApplicationContext
         if (normalizedPath == null)
             return (null);
 
-        DirContext resources = context.getResources();
+        WebResourceRoot resources = context.getResources();
         if (resources != null) {
-            return (getResourcePathsInternal(resources, normalizedPath));
-        }
-        return (null);
-
-    }
-
-
-    /**
-     * Internal implementation of getResourcesPath() logic.
-     *
-     * @param resources Directory context to search
-     * @param path Collection path
-     */
-    private Set<String> getResourcePathsInternal(DirContext resources,
-            String path) {
-
-        ResourceSet<String> set = new ResourceSet<>();
-        try {
-            listCollectionPaths(set, resources, path);
-        } catch (NamingException e) {
-            return (null);
+            return resources.listWebAppPaths(normalizedPath);
         }
-        set.setLocked(true);
-        return (set);
 
+        return null;
     }
 
 
@@ -1529,47 +1479,6 @@ public class ApplicationContext
     }
 
     /**
-     * List resource paths (recursively), and store all of them in the given
-     * Set.
-     */
-    private static void listCollectionPaths(Set<String> set,
-            DirContext resources, String path) throws NamingException {
-
-        Enumeration<Binding> childPaths = resources.listBindings(path);
-        while (childPaths.hasMoreElements()) {
-            Binding binding = childPaths.nextElement();
-            String name = binding.getName();
-            StringBuilder childPath = new StringBuilder(path);
-            if (!"/".equals(path) && !path.endsWith("/"))
-                childPath.append("/");
-            childPath.append(name);
-            Object object = binding.getObject();
-            if (object instanceof DirContext) {
-                childPath.append("/");
-            }
-            set.add(childPath.toString());
-        }
-
-    }
-
-
-    /**
-     * Get full path, based on the host name and the context path.
-     */
-    private static String getJNDIUri(String hostName, String path) {
-        String result;
-
-        if (path.startsWith("/")) {
-            result = "/" + hostName + path;
-        } else {
-            result = "/" + hostName + "/" + path;
-        }
-
-        return result;
-    }
-
-
-    /**
      * Internal class used as thread-local storage when doing path
      * mapping during dispatch.
      */

Modified: tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties?rev=1401503&r1=1401502&r2=1401503&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties (original)
+++ tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties Tue Oct 23 22:38:16 2012
@@ -88,6 +88,7 @@ standardContext.applicationListener=Erro
 standardContext.applicationSkipped=Skipped installing application listeners due to previous error(s)
 standardContext.backgroundProcess.loader=Exception processing loader {0} background process
 standardContext.backgroundProcess.manager=Exception processing manager {0} background process
+standardContext.backgroundProcess.resources=Exception processing resources {0} background process
 standardContext.cluster.noManager=No manager found. Checking if cluster manager should be used. Cluster configured: [{0}], Application distributable: [{1}]
 standardContext.duplicateListener=The listener "{0}" is already configured for this context. The duplicate definition has been ignored.
 standardContext.errorPage.error=Error page location {0} must start with a ''/''

Modified: tomcat/trunk/java/org/apache/catalina/core/StandardContext.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardContext.java?rev=1401503&r1=1401502&r2=1401503&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/StandardContext.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/StandardContext.java Tue Oct 23 22:38:16 2012
@@ -27,7 +27,6 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
@@ -48,9 +47,7 @@ import javax.management.NotificationBroa
 import javax.management.NotificationEmitter;
 import javax.management.NotificationFilter;
 import javax.management.NotificationListener;
-import javax.management.ObjectName;
 import javax.naming.NamingException;
-import javax.naming.directory.DirContext;
 import javax.servlet.FilterConfig;
 import javax.servlet.RequestDispatcher;
 import javax.servlet.Servlet;
@@ -87,6 +84,8 @@ import org.apache.catalina.Manager;
 import org.apache.catalina.Pipeline;
 import org.apache.catalina.Realm;
 import org.apache.catalina.Valve;
+import org.apache.catalina.WebResource;
+import org.apache.catalina.WebResourceRoot;
 import org.apache.catalina.Wrapper;
 import org.apache.catalina.deploy.ApplicationParameter;
 import org.apache.catalina.deploy.ErrorPage;
@@ -108,19 +107,14 @@ import org.apache.catalina.util.ContextN
 import org.apache.catalina.util.ExtensionValidator;
 import org.apache.catalina.util.RequestUtil;
 import org.apache.catalina.util.URLEncoder;
+import org.apache.catalina.webresources.StandardRoot;
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
 import org.apache.naming.ContextBindings;
-import org.apache.naming.resources.BaseDirContext;
-import org.apache.naming.resources.DirContextURLStreamHandler;
-import org.apache.naming.resources.FileDirContext;
-import org.apache.naming.resources.ProxyDirContext;
-import org.apache.naming.resources.WARDirContext;
 import org.apache.tomcat.InstanceManager;
 import org.apache.tomcat.JarScanner;
 import org.apache.tomcat.util.ExceptionUtils;
 import org.apache.tomcat.util.IntrospectionUtils;
-import org.apache.tomcat.util.modeler.Registry;
 import org.apache.tomcat.util.scan.StandardJarScanner;
 
 /**
@@ -667,17 +661,7 @@ public class StandardContext extends Con
     protected int cacheTTL = 5000;
 
 
-    /**
-     * List of resource aliases.
-     */
-    private String aliases = null;
-
-
-    private DirContext resources = null;
-    /**
-     * Non proxied resources.
-     */
-    private DirContext webappResources = null;
+    private WebResourceRoot resources;
     private final ReadWriteLock resourcesLock = new ReentrantReadWriteLock();
 
     private long startupTime;
@@ -877,12 +861,14 @@ public class StandardContext extends Con
     }
 
 
+    @Override
     public void setAddWebinfClassesResources(
             boolean addWebinfClassesResources) {
         this.addWebinfClassesResources = addWebinfClassesResources;
     }
 
 
+    @Override
     public boolean getAddWebinfClassesResources() {
         return addWebinfClassesResources;
     }
@@ -1157,56 +1143,6 @@ public class StandardContext extends Con
 
 
     /**
-     * Return the list of resource aliases.
-     */
-    public String getAliases() {
-        return this.aliases;
-    }
-
-
-    /**
-     * Add a URL for a JAR that contains static resources in a
-     * META-INF/resources directory that should be included in the static
-     * resources for this context.
-     */
-    @Override
-    public void addResourceJarUrl(URL url) {
-        DirContext webappResources = getWebappResources();
-        if (webappResources instanceof BaseDirContext) {
-            ((BaseDirContext) webappResources).addResourcesJar(url);
-        } else {
-            log.error(sm.getString("standardContext.noResourceJar", url,
-                    getName()));
-        }
-    }
-
-    /**
-     * Add a URL for a JAR that contains static resources in a
-     * META-INF/resources directory that should be included in the static
-     * resources for this context.
-     */
-    public void addResourcesDirContext(DirContext altDirContext) {
-        DirContext webappResources = getWebappResources();
-        if (webappResources instanceof BaseDirContext) {
-            ((BaseDirContext) webappResources).addAltDirContext(altDirContext);
-        } else {
-            log.error(sm.getString("standardContext.noResourceJar", altDirContext,
-                    getName()));
-        }
-    }
-
-    /**
-     * Set the current alias configuration. The list of aliases should be of the
-     * form "/aliasPath1=docBase1,/aliasPath2=docBase2" where aliasPathN must
-     * include a leading '/' and docBaseN must be an absolute path to either a
-     * .war file or a directory.
-     */
-    public void setAliases(String aliases) {
-        this.aliases = aliases;
-    }
-
-
-    /**
      * Add a ServletContainerInitializer instance to this web application.
      *
      * @param sci       The instance to add
@@ -2479,7 +2415,7 @@ public class StandardContext extends Con
 
 
     @Override
-    public DirContext getResources() {
+    public WebResourceRoot getResources() {
         Lock readLock = resourcesLock.readLock();
         readLock.lock();
         try {
@@ -2490,50 +2426,29 @@ public class StandardContext extends Con
     }
 
 
-    private DirContext getWebappResources() {
-        Lock readLock = resourcesLock.readLock();
-        readLock.lock();
-        try {
-            return webappResources;
-        } finally {
-            readLock.unlock();
-        }
-    }
-
-
     @Override
-    public void setResources(DirContext resources) {
+    public void setResources(WebResourceRoot resources) {
 
         Lock writeLock = resourcesLock.writeLock();
         writeLock.lock();
-        DirContext oldResources = null;
+        WebResourceRoot oldResources = null;
         try {
             if (getState().isAvailable()) {
                 throw new IllegalStateException
                     (sm.getString("standardContext.resources.started"));
             }
 
-            oldResources = this.webappResources;
+            oldResources = this.resources;
             if (oldResources == resources)
                 return;
 
-            if (resources instanceof BaseDirContext) {
-                // Caching
-                ((BaseDirContext) resources).setCached(isCachingAllowed());
-                ((BaseDirContext) resources).setCacheTTL(getCacheTTL());
-                ((BaseDirContext) resources).setCacheMaxSize(getCacheMaxSize());
-                ((BaseDirContext) resources).setCacheObjectMaxSize(
-                        getCacheObjectMaxSize());
-                // Alias support
-                ((BaseDirContext) resources).setAliases(getAliases());
+            this.resources = resources;
+            if (oldResources != null) {
+                oldResources.setContext(null);
             }
-            if (resources instanceof FileDirContext) {
-                ((FileDirContext) resources).setAllowLinking(isAllowLinking());
+            if (resources != null) {
+                resources.setContext(this);
             }
-            this.webappResources = resources;
-
-            // The proxied resources will be refreshed on start
-            this.resources = null;
 
             support.firePropertyChange("resources", oldResources,
                     resources);
@@ -4464,9 +4379,8 @@ public class StandardContext extends Con
      */
     @Override
     public String getRealPath(String path) {
-        DirContext webappResources = getWebappResources();
-        if (webappResources instanceof BaseDirContext) {
-            return ((BaseDirContext) webappResources).getRealPath(path);
+        if (resources != null) {
+            return resources.getResource(path).getCanonicalPath();
         }
         return null;
     }
@@ -4853,68 +4767,27 @@ public class StandardContext extends Con
      * Return <code>true</code> if initialization was successfull,
      * or <code>false</code> otherwise.
      */
-    public boolean resourcesStart() {
+    public boolean resourcesStart() throws LifecycleException {
 
         boolean ok = true;
 
-        Hashtable<String, String> env = new Hashtable<>();
-        if (getParent() != null)
-            env.put(ProxyDirContext.HOST, getParent().getName());
-        env.put(ProxyDirContext.CONTEXT, getName());
-
-        Lock writeLock = resourcesLock.writeLock();
-        writeLock.lock();
-        try {
-            ProxyDirContext proxyDirContext =
-                new ProxyDirContext(env, webappResources);
-            if (webappResources instanceof FileDirContext) {
-                ((FileDirContext) webappResources).setAllowLinking
-                    (isAllowLinking());
-            }
-            if (webappResources instanceof BaseDirContext) {
-                ((BaseDirContext) webappResources).setDocBase(getBasePath());
-                ((BaseDirContext) webappResources).setCached
-                    (isCachingAllowed());
-                ((BaseDirContext) webappResources).setCacheTTL(getCacheTTL());
-                ((BaseDirContext) webappResources).setCacheMaxSize
-                    (getCacheMaxSize());
-                ((BaseDirContext) webappResources).allocate();
-                // Alias support
-                ((BaseDirContext) webappResources).setAliases(getAliases());
+        resources.setAllowLinking(isAllowLinking());
 
-                if (effectiveMajorVersion >=3 && addWebinfClassesResources) {
-                    try {
-                        DirContext webInfCtx =
-                            (DirContext) webappResources.lookup(
-                                    "/WEB-INF/classes");
-                        // Do the lookup to make sure it exists
-                        webInfCtx.lookup("META-INF/resources");
-                        ((BaseDirContext) webappResources).addAltDirContext(
-                                webInfCtx);
-                    } catch (NamingException e) {
-                        // Doesn't exist - ignore and carry on
-                    }
-                }
+        resources.setCachingAllowed(isCachingAllowed());
+        resources.setCacheTtl(getCacheTTL());
+        resources.setCacheMaxSize(getCacheMaxSize());
+        resources.setCacheMaxObjectSize(getCacheObjectMaxSize());
+
+        resources.start();
+
+        if (effectiveMajorVersion >=3 && addWebinfClassesResources) {
+            WebResource webinfClassesResource = resources.getResource(
+                    "/WEB-INF/classes/META-INF/resources");
+            if (webinfClassesResource.isDirectory()) {
+                getResources().createWebResourceSet(
+                        WebResourceRoot.ResourceSetType.RESOURCE_JAR,
+                        webinfClassesResource.getURL(), "", "");
             }
-            // Register the cache in JMX
-            if (isCachingAllowed()) {
-                String contextName = getName();
-                if (!contextName.startsWith("/")) {
-                    contextName = "/" + contextName;
-                }
-                ObjectName resourcesName =
-                    new ObjectName(this.getDomain() + ":type=Cache,host="
-                                   + getHostname() + ",context=" + contextName);
-                Registry.getRegistry(null, null).registerComponent
-                    (proxyDirContext.getCache(), resourcesName, null);
-            }
-            this.resources = proxyDirContext;
-        } catch (Throwable t) {
-            ExceptionUtils.handleThrowable(t);
-            log.error(sm.getString("standardContext.resourcesStart"), t);
-            ok = false;
-        } finally {
-            writeLock.unlock();
         }
 
         return ok;
@@ -4932,33 +4805,12 @@ public class StandardContext extends Con
         writeLock.lock();
         try {
             if (resources != null) {
-                if (resources instanceof Lifecycle) {
-                    ((Lifecycle) resources).stop();
-                }
-                if (webappResources instanceof BaseDirContext) {
-                    ((BaseDirContext) webappResources).release();
-                }
-                // Unregister the cache in JMX
-                if (isCachingAllowed()) {
-                    String contextName = getName();
-                    if (!contextName.startsWith("/")) {
-                        contextName = "/" + contextName;
-                    }
-                    ObjectName resourcesName =
-                        new ObjectName(this.getDomain()
-                                       + ":type=Cache,host="
-                                       + getHostname() + ",context="
-                                       + contextName);
-                    Registry.getRegistry(null, null)
-                        .unregisterComponent(resourcesName);
-                }
+                resources.stop();
             }
-            this.resources = null;
         } catch (Throwable t) {
             ExceptionUtils.handleThrowable(t);
             log.error(sm.getString("standardContext.resourcesStop"), t);
             ok = false;
-            this.resources = null;
         } finally {
             writeLock.unlock();
         }
@@ -5040,16 +4892,12 @@ public class StandardContext extends Con
         }
 
         // Add missing components as necessary
-        DirContext webappResources = getWebappResources();
-        if (webappResources == null) {   // (1) Required by Loader
+        if (getResources() == null) {   // (1) Required by Loader
             if (log.isDebugEnabled())
                 log.debug("Configuring default Resources");
+
             try {
-                if ((getDocBase() != null) && (getDocBase().endsWith(".war")) &&
-                        (!(new File(getBasePath())).isDirectory()))
-                    setResources(new WARDirContext());
-                else
-                    setResources(new FileDirContext());
+                setResources(new StandardRoot(this));
             } catch (IllegalArgumentException e) {
                 log.error("Error initializing resources: " + e.getMessage());
                 ok = false;
@@ -5151,9 +4999,6 @@ public class StandardContext extends Con
                 Realm realm = getRealmInternal();
                 if ((realm != null) && (realm instanceof Lifecycle))
                     ((Lifecycle) realm).start();
-                DirContext resources = getResources();
-                if ((resources != null) && (resources instanceof Lifecycle))
-                    ((Lifecycle) resources).start();
 
                 // Notify our interested LifecycleListeners
                 fireLifecycleEvent(Lifecycle.CONFIGURE_START_EVENT, null);
@@ -5503,9 +5348,6 @@ public class StandardContext extends Con
             if (context != null)
                 context.clearAttributes();
 
-            // Stop resources
-            resourcesStop();
-
             Realm realm = getRealmInternal();
             if ((realm != null) && (realm instanceof Lifecycle)) {
                 ((Lifecycle) realm).stop();
@@ -5519,6 +5361,9 @@ public class StandardContext extends Con
                 ((Lifecycle) loader).stop();
             }
 
+            // Stop resources
+            resourcesStop();
+
         } finally {
 
             // Unbinding thread
@@ -5595,6 +5440,10 @@ public class StandardContext extends Con
             ((Lifecycle) manager).destroy();
         }
 
+        if (resources != null) {
+            resources.destroy();
+        }
+
         super.destroyInternal();
     }
 
@@ -5620,6 +5469,16 @@ public class StandardContext extends Con
                         e);
             }
         }
+        WebResourceRoot resources = getResources();
+        if (resources != null) {
+            try {
+                resources.backgroundProcess();
+            } catch (Exception e) {
+                log.warn(sm.getString(
+                        "standardContext.backgroundProcess.resources",
+                        resources), e);
+            }
+        }
         super.backgroundProcess();
     }
 
@@ -5794,16 +5653,11 @@ public class StandardContext extends Con
         ClassLoader oldContextClassLoader =
             Thread.currentThread().getContextClassLoader();
 
-        if (getResources() == null)
-            return oldContextClassLoader;
-
         if (getLoader().getClassLoader() != null) {
             Thread.currentThread().setContextClassLoader
                 (getLoader().getClassLoader());
         }
 
-        DirContextURLStreamHandler.bindThread(getResources());
-
         if (isUseNaming()) {
             try {
                 ContextBindings.bindThread(this, this);
@@ -5814,7 +5668,6 @@ public class StandardContext extends Con
         }
 
         return oldContextClassLoader;
-
     }
 
 
@@ -5827,8 +5680,6 @@ public class StandardContext extends Con
             ContextBindings.unbindThread(this, this);
         }
 
-        DirContextURLStreamHandler.unbindThread();
-
         Thread.currentThread().setContextClassLoader(oldContextClassLoader);
     }
 
@@ -6233,6 +6084,10 @@ public class StandardContext extends Con
             namingResources.init();
         }
 
+        if (resources != null) {
+            resources.start();
+        }
+
         // Send j2ee.object.created notification
         if (this.getObjectName() != null) {
             Notification notification = new Notification("j2ee.object.created",

Modified: tomcat/trunk/java/org/apache/catalina/core/mbeans-descriptors.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/mbeans-descriptors.xml?rev=1401503&r1=1401502&r2=1401503&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/mbeans-descriptors.xml (original)
+++ tomcat/trunk/java/org/apache/catalina/core/mbeans-descriptors.xml Tue Oct 23 22:38:16 2012
@@ -70,10 +70,6 @@
                is="true"
                type="boolean"/>
 
-    <attribute name="aliases"
-               description="List of resource aliases"
-               type="java.lang.String" />
-
     <attribute name="altDDName"
                description="The alternate deployment descriptor name."
                type="java.lang.String" />

Modified: tomcat/trunk/java/org/apache/catalina/loader/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/loader/LocalStrings.properties?rev=1401503&r1=1401502&r2=1401503&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/loader/LocalStrings.properties (original)
+++ tomcat/trunk/java/org/apache/catalina/loader/LocalStrings.properties Tue Oct 23 22:38:16 2012
@@ -13,12 +13,6 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-virtualWebappLoader.token=Processing token [{0}]
-virtualWebappLoader.token.file=Adding location: [{0}]
-virtualWebappLoader.token.glob.dir=Listing files in a directory: [{0}]
-virtualWebappLoader.token.notDirectory=Path is skipped, because it does not exist or is not a directory: [{0}]
-virtualWebappLoader.token.notExists=Path is skipped, because it does not exist: [{0}]
-virtualWebappLoader.token.notFile=Path is skipped, because it does not exist or is not a file: [{0}]
 webappClassLoader.illegalJarPath=Illegal JAR entry detected with name {0}
 webappClassLoader.jdbcRemoveFailed=JDBC driver de-registration failed for web application [{0}]
 webappClassLoader.jdbcRemoveStreamError=Exception closing input stream during JDBC driver de-registration for web application [{0}]
@@ -53,4 +47,4 @@ webappLoader.starting=Starting this Load
 webappLoader.stopping=Stopping this Loader
 webappLoader.copyFailure=Failed to copy resources
 webappLoader.mkdirFailure=Failed to create destination directory to copy resources
-webappLoader.namingFailure=Failed to access resource {0}
+webappLoader.readFailure=Unable to read resource {0}

Modified: tomcat/trunk/java/org/apache/catalina/loader/LocalStrings_es.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/loader/LocalStrings_es.properties?rev=1401503&r1=1401502&r2=1401503&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/loader/LocalStrings_es.properties (original)
+++ tomcat/trunk/java/org/apache/catalina/loader/LocalStrings_es.properties Tue Oct 23 22:38:16 2012
@@ -12,12 +12,6 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
-virtualWebappLoader.token = Procesando ficha [{0}]
-virtualWebappLoader.token.file = A\u00F1adiendo localizaci\u00F3n\: [{0}]
-virtualWebappLoader.token.glob.dir = listando ficheros en un directorio\: [{0}]
-virtualWebappLoader.token.notDirectory = Se salta la ruta porque no existe o no es un directorio\: [{0}]
-virtualWebappLoader.token.notExists = Ruta saltada porque no existe\: [{0}]
-virtualWebappLoader.token.notFile = Se salta la ruta porque no exuste o no es un fichero\: [{0}]
 webappClassLoader.illegalJarPath = Detectada entrada ilegal de JAR con nombre {0}
 webappClassLoader.jdbcRemoveFailed = Ha fallado el desregistro del conductor JDBC para la aplicaci\u00F3n web [{0}]
 webappClassLoader.jdbcRemoveStreamError = Excepci\u00F3n al cerrar flujo de entrada durante desregistro de conductor JDBC para apliicaci\u00F3n web [{0}]
@@ -51,4 +45,3 @@ webappLoader.starting = Arrancando este 
 webappLoader.stopping = Parando este Cargador
 webappLoader.copyFailure = No pude copiar los recursos
 webappLoader.mkdirFailure = No pude crear directorio de destino para copiar los recursos
-webappLoader.namingFailure = No pude acceder al recurso {0}

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=1401503&r1=1401502&r2=1401503&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java (original)
+++ tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java Tue Oct 23 22:38:16 2012
@@ -14,8 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
-
 package org.apache.catalina.loader;
 
 import java.io.ByteArrayInputStream;
@@ -60,21 +58,13 @@ import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
 import java.util.jar.Manifest;
 
-import javax.naming.Binding;
-import javax.naming.NameClassPair;
-import javax.naming.NamingEnumeration;
-import javax.naming.NamingException;
-import javax.naming.directory.DirContext;
-
 import org.apache.catalina.Globals;
 import org.apache.catalina.Lifecycle;
 import org.apache.catalina.LifecycleException;
 import org.apache.catalina.LifecycleListener;
 import org.apache.catalina.LifecycleState;
-import org.apache.naming.JndiPermission;
-import org.apache.naming.resources.ProxyDirContext;
-import org.apache.naming.resources.Resource;
-import org.apache.naming.resources.ResourceAttributes;
+import org.apache.catalina.WebResource;
+import org.apache.catalina.WebResourceRoot;
 import org.apache.tomcat.util.ExceptionUtils;
 import org.apache.tomcat.util.IntrospectionUtils;
 import org.apache.tomcat.util.res.StringManager;
@@ -267,7 +257,7 @@ public class WebappClassLoader
      * Associated directory context giving access to the resources in this
      * webapp.
      */
-    protected DirContext resources = null;
+    protected WebResourceRoot resources = null;
 
 
     /**
@@ -310,10 +300,9 @@ public class WebappClassLoader
 
 
     /**
-     * The list of local repositories, in the order they should be searched
-     * for locally loaded classes or resources.
+     * The local repository for locally loaded classes or resources.
      */
-    protected String[] repositories = new String[0];
+    protected String repository = null;
 
 
      /**
@@ -323,11 +312,11 @@ public class WebappClassLoader
 
 
     /**
-     * Repositories translated as path in the work directory (for Jasper
-     * originally), but which is used to generate fake URLs should getURLs be
+     * Repository translated as path in the work directory (for Jasper
+     * originally), but which is used to generate a fake URL should getURLs be
      * called.
      */
-    protected File[] files = new File[0];
+    protected File file = null;
 
 
     /**
@@ -416,16 +405,6 @@ public class WebappClassLoader
 
 
     /**
-     * Has external repositories.
-     */
-    protected boolean hasExternalRepositories = false;
-
-    /**
-     * Search external repositories first
-     */
-    protected boolean searchExternalFirst = false;
-
-    /**
      * need conversion for properties files
      */
     protected boolean needConvert = false;
@@ -484,38 +463,22 @@ public class WebappClassLoader
      */
     private boolean clearReferencesHttpClientKeepAliveThread = true;
 
-    /**
-     * Name of associated context used with logging and JMX to associate with
-     * the right web application. Particularly useful for the clear references
-     * messages. Defaults to unknown but if standard Tomcat components are used
-     * it will be updated during initialisation from the resources.
-     */
-    private String contextName = "unknown";
-
 
     // ------------------------------------------------------------- Properties
 
-
     /**
      * Get associated resources.
      */
-    public DirContext getResources() {
-
+    public WebResourceRoot getResources() {
         return this.resources;
-
     }
 
 
     /**
      * Set associated resources.
      */
-    public void setResources(DirContext resources) {
-
+    public void setResources(WebResourceRoot resources) {
         this.resources = resources;
-
-        if (resources instanceof ProxyDirContext) {
-            contextName = ((ProxyDirContext) resources).getContextName();
-        }
     }
 
 
@@ -523,9 +486,11 @@ public class WebappClassLoader
      * Return the context name for this class loader.
      */
     public String getContextName() {
-
-        return (this.contextName);
-
+        if (resources == null) {
+            return "Unknown";
+        } else {
+            return resources.getContext().getName();
+        }
     }
 
 
@@ -575,21 +540,6 @@ public class WebappClassLoader
     }
 
     /**
-     * @return Returns the searchExternalFirst.
-     */
-    public boolean getSearchExternalFirst() {
-        return searchExternalFirst;
-    }
-
-    /**
-     * @param searchExternalFirst Whether external repositories should be searched first
-     */
-    public void setSearchExternalFirst(boolean searchExternalFirst) {
-        this.searchExternalFirst = searchExternalFirst;
-    }
-
-
-    /**
      * If there is a Java SecurityManager create a read FilePermission
      * or JndiPermission for the file directory path.
      *
@@ -604,21 +554,13 @@ public class WebappClassLoader
 
         if (securityManager != null) {
             Permission permission = null;
-            if (path.startsWith("jndi:") || path.startsWith("jar:jndi:")) {
-                if (!path.endsWith("/")) {
-                    path = path + "/";
-                }
-                permission = new JndiPermission(path + "*");
-                addPermission(permission);
-            } else {
-                if (!path.endsWith(File.separator)) {
-                    permission = new FilePermission(path, "read");
-                    addPermission(permission);
-                    path = path + File.separator;
-                }
-                permission = new FilePermission(path + "-", "read");
+            if (!path.endsWith(File.separator)) {
+                permission = new FilePermission(path, "read");
                 addPermission(permission);
+                path = path + File.separator;
             }
+            permission = new FilePermission(path + "-", "read");
+            addPermission(permission);
         }
     }
 
@@ -797,42 +739,7 @@ public class WebappClassLoader
 
 
     /**
-     * Add a new repository to the set of places this ClassLoader can look for
-     * classes to be loaded.
-     *
-     * @param repository Name of a source of classes to be loaded, such as a
-     *  directory pathname, a JAR file pathname, or a ZIP file pathname
-     *
-     * @exception IllegalArgumentException if the specified repository is
-     *  invalid or does not exist
-     */
-    public void addRepository(String repository) {
-
-        // Ignore any of the standard repositories, as they are set up using
-        // either addJar or addRepository
-        if (repository.startsWith("/WEB-INF/lib")
-            || repository.startsWith("/WEB-INF/classes"))
-            return;
-
-        // Add this repository to our underlying class loader
-        try {
-            URL url = new URL(repository);
-            super.addURL(url);
-            hasExternalRepositories = true;
-            repositoryURLs = null;
-        } catch (MalformedURLException e) {
-            IllegalArgumentException iae = new IllegalArgumentException
-                ("Invalid repository: " + repository);
-            iae.initCause(e);
-            throw iae;
-        }
-
-    }
-
-
-    /**
-     * Add a new repository to the set of places this ClassLoader can look for
-     * classes to be loaded.
+     * Set the place this ClassLoader can look for classes to be loaded.
      *
      * @param repository Name of a source of classes to be loaded, such as a
      *  directory pathname, a JAR file pathname, or a ZIP file pathname
@@ -840,7 +747,7 @@ public class WebappClassLoader
      * @exception IllegalArgumentException if the specified repository is
      *  invalid or does not exist
      */
-    synchronized void addRepository(String repository, File file) {
+    synchronized void setRepository(String repository, File file) {
 
         // Note : There should be only one (of course), but I think we should
         // keep this a bit generic
@@ -851,24 +758,8 @@ public class WebappClassLoader
         if (log.isDebugEnabled())
             log.debug("addRepository(" + repository + ")");
 
-        int i;
-
-        // Add this repository to our internal list
-        String[] result = new String[repositories.length + 1];
-        for (i = 0; i < repositories.length; i++) {
-            result[i] = repositories[i];
-        }
-        result[repositories.length] = repository;
-        repositories = result;
-
-        // Add the file to the list
-        File[] result2 = new File[files.length + 1];
-        for (i = 0; i < files.length; i++) {
-            result2[i] = files[i];
-        }
-        result2[files.length] = file;
-        files = result2;
-
+        this.repository = repository;
+        this.file = file;
     }
 
 
@@ -902,31 +793,23 @@ public class WebappClassLoader
 
         }
 
-        try {
-
-            // Register the JAR for tracking
+        // Register the JAR for tracking
 
-            long lastModified =
-                ((ResourceAttributes) resources.getAttributes(jar))
-                .getLastModified();
-
-            String[] result = new String[paths.length + 1];
-            for (i = 0; i < paths.length; i++) {
-                result[i] = paths[i];
-            }
-            result[paths.length] = jar;
-            paths = result;
+        long lastModified = resources.getResource(jar).getLastModified();
 
-            long[] result3 = new long[lastModifiedDates.length + 1];
-            for (i = 0; i < lastModifiedDates.length; i++) {
-                result3[i] = lastModifiedDates[i];
-            }
-            result3[lastModifiedDates.length] = lastModified;
-            lastModifiedDates = result3;
+        String[] result = new String[paths.length + 1];
+        for (i = 0; i < paths.length; i++) {
+            result[i] = paths[i];
+        }
+        result[paths.length] = jar;
+        paths = result;
 
-        } catch (NamingException e) {
-            // Ignore
+        long[] result3 = new long[lastModifiedDates.length + 1];
+        for (i = 0; i < lastModifiedDates.length; i++) {
+            result3[i] = lastModifiedDates[i];
         }
+        result3[lastModifiedDates.length] = lastModified;
+        lastModifiedDates = result3;
 
         // If the JAR currently contains invalid classes, don't actually use it
         // for classloading
@@ -951,19 +834,6 @@ public class WebappClassLoader
 
 
     /**
-     * Return a String array of the current repositories for this class
-     * loader.  If there are no repositories, a zero-length array is
-     * returned.For security reason, returns a clone of the Array (since
-     * String are immutable).
-     */
-    public String[] findRepositories() {
-
-        return (repositories.clone());
-
-    }
-
-
-    /**
      * Have one or more classes or resources been modified so that a reload
      * is appropriate?
      */
@@ -983,21 +853,15 @@ public class WebappClassLoader
             length = length2;
 
         for (int i = 0; i < length; i++) {
-            try {
-                long lastModified =
-                    ((ResourceAttributes) resources.getAttributes(paths[i]))
-                    .getLastModified();
-                if (lastModified != lastModifiedDates[i]) {
-                    if( log.isDebugEnabled() )
-                        log.debug("  Resource '" + paths[i]
-                                  + "' was modified; Date is now: "
-                                  + new java.util.Date(lastModified) + " Was: "
-                                  + new java.util.Date(lastModifiedDates[i]));
-                    return (true);
-                }
-            } catch (NamingException e) {
-                log.error("    Resource '" + paths[i] + "' is missing");
-                return (true);
+            long lastModified =
+                    resources.getResource(paths[i]).getLastModified();
+            if (lastModified != lastModifiedDates[i]) {
+                if( log.isDebugEnabled() )
+                    log.debug("  Resource '" + paths[i]
+                              + "' was modified; Date is now: "
+                              + new java.util.Date(lastModified) + " Was: "
+                              + new java.util.Date(lastModifiedDates[i]));
+                return true;
             }
         }
 
@@ -1006,54 +870,41 @@ public class WebappClassLoader
         // Check if JARs have been added or removed
         if (getJarPath() != null) {
 
-            try {
-                NamingEnumeration<Binding> enumeration =
-                    resources.listBindings(getJarPath());
-                int i = 0;
-                while (enumeration.hasMoreElements() && (i < length)) {
-                    NameClassPair ncPair = enumeration.nextElement();
-                    String name = ncPair.getName();
-                    // Ignore non JARs present in the lib folder
-                    if (!name.endsWith(".jar"))
-                        continue;
-                    if (!name.equals(jarNames[i])) {
-                        // Missing JAR
-                        log.info("    Additional JARs have been added : '"
-                                 + name + "'");
-                        return (true);
-                    }
-                    i++;
-                }
-                if (enumeration.hasMoreElements()) {
-                    while (enumeration.hasMoreElements()) {
-                        NameClassPair ncPair = enumeration.nextElement();
-                        String name = ncPair.getName();
-                        // Additional non-JAR files are allowed
-                        if (name.endsWith(".jar")) {
-                            // There was more JARs
-                            log.info("    Additional JARs have been added");
-                            return (true);
-                        }
+            WebResource[] jars = resources.listResources(getJarPath());
+
+            int i = 0;
+            int j = 0;
+            for (; j < jars.length && i < length; j++) {
+                // Ignore non JARs present in the lib folder
+                String name = jars[j].getName();
+                if (!name.endsWith(".jar"))
+                    continue;
+                if (!name.equals(jarNames[i])) {
+                    // Missing JAR
+                    log.info("    Additional JARs have been added : '"
+                             + name + "'");
+                    return true;
+                }
+                i++;
+            }
+            if (j < jars.length ) {
+                for (; j < jars.length; j++) {
+                    // Additional non-JAR files are allowed
+                    if (jars[j].getName().endsWith(".jar")) {
+                        // There was more JARs
+                        log.info("    Additional JARs have been added");
+                        return true;
                     }
-                } else if (i < jarNames.length) {
-                    // There was less JARs
-                    log.info("    Additional JARs have been added");
-                    return (true);
                 }
-            } catch (NamingException e) {
-                if (log.isDebugEnabled())
-                    log.debug("    Failed tracking modifications of '"
-                        + getJarPath() + "'");
-            } catch (ClassCastException e) {
-                log.error("    Failed tracking modifications of '"
-                          + getJarPath() + "' : " + e.getMessage());
+            } else if (i < jarNames.length) {
+                // There was less JARs
+                log.info("    Additional JARs have been added");
+                return (true);
             }
-
         }
 
         // No classes have been modified
-        return (false);
-
+        return false;
     }
 
 
@@ -1065,19 +916,14 @@ public class WebappClassLoader
 
         StringBuilder sb = new StringBuilder("WebappClassLoader\r\n");
         sb.append("  context: ");
-        sb.append(contextName);
+        sb.append(getContextName());
         sb.append("\r\n");
         sb.append("  delegate: ");
         sb.append(delegate);
         sb.append("\r\n");
-        sb.append("  repositories:\r\n");
-        if (repositories != null) {
-            for (int i = 0; i < repositories.length; i++) {
-                sb.append("    ");
-                sb.append(repositories[i]);
-                sb.append("\r\n");
-            }
-        }
+        sb.append("  repository: ");
+        sb.append(repository);
+        sb.append("\r\n");
         if (this.parent != null) {
             sb.append("----------> Parent Classloader:\r\n");
             sb.append(this.parent.toString());
@@ -1092,17 +938,6 @@ public class WebappClassLoader
 
 
     /**
-     * Add the specified URL to the classloader.
-     */
-    @Override
-    protected void addURL(URL url) {
-        super.addURL(url);
-        hasExternalRepositories = true;
-        repositoryURLs = null;
-    }
-
-
-    /**
      * Expose this method for use by the unit tests.
      */
     protected final Class<?> doDefineClass(String name, byte[] b, int off, int len,
@@ -1151,55 +986,20 @@ public class WebappClassLoader
         try {
             if (log.isTraceEnabled())
                 log.trace("      findClassInternal(" + name + ")");
-            if (hasExternalRepositories && searchExternalFirst) {
-                try {
-                    clazz = super.findClass(name);
-                } catch(ClassNotFoundException cnfe) {
-                    // Ignore - will search internal repositories next
-                } 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)) {
-                try {
-                    clazz = findClassInternal(name);
-                } catch(ClassNotFoundException cnfe) {
-                    if (!hasExternalRepositories || searchExternalFirst) {
-                        throw cnfe;
-                    }
-                } 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) && hasExternalRepositories && !searchExternalFirst) {
-                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) {
+            try {
+                clazz = findClassInternal(name);
+            } catch(ClassNotFoundException cnfe) {
                 if (log.isDebugEnabled())
                     log.debug("    --> Returning ClassNotFoundException");
-                throw new ClassNotFoundException(name);
+                throw cnfe;
+            } 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;
             }
         } catch (ClassNotFoundException e) {
             if (log.isTraceEnabled())
@@ -1241,27 +1041,19 @@ public class WebappClassLoader
 
         URL url = null;
 
-        if (hasExternalRepositories && searchExternalFirst)
-            url = super.findResource(name);
-
-        if (url == null) {
-            ResourceEntry entry = resourceEntries.get(name);
-            if (entry == null) {
-                if (securityManager != null) {
-                    PrivilegedAction<ResourceEntry> dp =
-                        new PrivilegedFindResourceByName(name, name);
-                    entry = AccessController.doPrivileged(dp);
-                } else {
-                    entry = findResourceInternal(name, name);
-                }
-            }
-            if (entry != null) {
-                url = entry.source;
+        ResourceEntry entry = resourceEntries.get(name);
+        if (entry == null) {
+            if (securityManager != null) {
+                PrivilegedAction<ResourceEntry> dp =
+                    new PrivilegedFindResourceByName(name, name);
+                entry = AccessController.doPrivileged(dp);
+            } else {
+                entry = findResourceInternal(name, name);
             }
         }
-
-        if ((url == null) && hasExternalRepositories && !searchExternalFirst)
-            url = super.findResource(name);
+        if (entry != null) {
+            url = entry.source;
+        }
 
         if (log.isDebugEnabled()) {
             if (url != null)
@@ -1289,45 +1081,24 @@ public class WebappClassLoader
         if (log.isDebugEnabled())
             log.debug("    findResources(" + name + ")");
 
-        //we use a LinkedHashSet instead of a Vector to avoid duplicates with virtualmappings
         LinkedHashSet<URL> result = new LinkedHashSet<>();
 
         int jarFilesLength = jarFiles.length;
-        int repositoriesLength = repositories.length;
-
-        int i;
-
-        // Adding the results of a call to the superclass
-        if (hasExternalRepositories && searchExternalFirst) {
-
-            Enumeration<URL> otherResourcePaths = super.findResources(name);
 
-            while (otherResourcePaths.hasMoreElements()) {
-                result.add(otherResourcePaths.nextElement());
-            }
-
-        }
-        // Looking at the repositories
-        for (i = 0; i < repositoriesLength; i++) {
-            try {
-                String fullPath = repositories[i] + name;
-                resources.lookup(fullPath);
-                // Note : Not getting an exception here means the resource was
-                // found
-                try {
-                    result.add(getURI(new File(files[i], name)));
-                } catch (MalformedURLException e) {
-                    // Ignore
+        if (repository != null) {
+            // Looking at the repository
+            WebResource[] webResources = resources.getResources(repository + name);
+            for (WebResource webResource : webResources) {
+                if (webResource.exists()) {
+                    result.add(webResource.getURL());
                 }
-            } catch (NamingException e) {
-                // Ignore
             }
         }
 
         // Looking at the JAR files
         synchronized (jarFiles) {
             if (openJARs()) {
-                for (i = 0; i < jarFilesLength; i++) {
+                for (int i = 0; i < jarFilesLength; i++) {
                     JarEntry jarEntry = jarFiles[i].getJarEntry(name);
                     if (jarEntry != null) {
                         try {
@@ -1342,17 +1113,6 @@ public class WebappClassLoader
             }
         }
 
-        // Adding the results of a call to the superclass
-        if (hasExternalRepositories && !searchExternalFirst) {
-
-            Enumeration<URL> otherResourcePaths = super.findResources(name);
-
-            while (otherResourcePaths.hasMoreElements()) {
-                result.add(otherResourcePaths.nextElement());
-            }
-
-        }
-
         final Iterator<URL> iterator = result.iterator();
 
         return new Enumeration<URL>() {
@@ -1508,12 +1268,6 @@ public class WebappClassLoader
             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);
         }
@@ -1758,35 +1512,22 @@ public class WebappClassLoader
             return repositoryURLs.clone();
         }
 
-        URL[] external = super.getURLs();
+        int resultLength;
+        if (file == null) {
+            resultLength = jarRealFiles.length;
+        } else {
+            resultLength = jarRealFiles.length + 1;
+        }
 
-        int filesLength = files.length;
-        int jarFilesLength = jarRealFiles.length;
-        int externalsLength = external.length;
         int off = 0;
-        int i;
 
         try {
-
-            URL[] urls = new URL[filesLength + jarFilesLength + externalsLength];
-            if (searchExternalFirst) {
-                for (i = 0; i < externalsLength; i++) {
-                    urls[i] = external[i];
-                }
-                off = externalsLength;
-            }
-            for (i = 0; i < filesLength; i++) {
-                urls[off + i] = getURI(files[i]);
-            }
-            off += filesLength;
-            for (i = 0; i < jarFilesLength; i++) {
-                urls[off + i] = getURI(jarRealFiles[i]);
-            }
-            off += jarFilesLength;
-            if (!searchExternalFirst) {
-                for (i = 0; i < externalsLength; i++) {
-                    urls[off + i] = external[i];
-                }
+            URL[] urls = new URL[resultLength];
+            if (file != null) {
+                urls[off ++] = getURI(file);
+            }
+            for (File jarRealFile : jarRealFiles) {
+                urls[off++] = getURI(jarRealFile);
             }
 
             repositoryURLs = urls;
@@ -1901,12 +1642,9 @@ public class WebappClassLoader
 
         started = false;
 
-        int length = files.length;
-        for (int i = 0; i < length; i++) {
-            files[i] = null;
-        }
+        file = null;
 
-        length = jarFiles.length;
+        int length = jarFiles.length;
         for (int i = 0; i < length; i++) {
             try {
                 if (jarFiles[i] != null) {
@@ -1921,16 +1659,15 @@ public class WebappClassLoader
         notFoundResources.clear();
         resourceEntries.clear();
         resources = null;
-        repositories = null;
+        repository = null;
         repositoryURLs = null;
-        files = null;
+        file = null;
         jarFiles = null;
         jarRealFiles = null;
         jarPath = null;
         jarNames = null;
         lastModifiedDates = null;
         paths = null;
-        hasExternalRepositories = false;
         parent = null;
 
         permissionList.clear();
@@ -2068,14 +1805,14 @@ public class WebappClassLoader
                     "clearJdbcDriverRegistrations").invoke(obj);
             for (String name : driverNames) {
                 log.error(sm.getString("webappClassLoader.clearJdbc",
-                        contextName, name));
+                        getContextName(), name));
             }
         } catch (Exception e) {
             // So many things to go wrong above...
             Throwable t = ExceptionUtils.unwrapInvocationTargetException(e);
             ExceptionUtils.handleThrowable(t);
             log.warn(sm.getString(
-                    "webappClassLoader.jdbcRemoveFailed", contextName), t);
+                    "webappClassLoader.jdbcRemoveFailed", getContextName()), t);
         } finally {
             if (is != null) {
                 try {
@@ -2083,7 +1820,7 @@ public class WebappClassLoader
                 } catch (IOException ioe) {
                     log.warn(sm.getString(
                             "webappClassLoader.jdbcRemoveStreamError",
-                            contextName), ioe);
+                            getContextName()), ioe);
                 }
             }
         }
@@ -2263,10 +2000,10 @@ public class WebappClassLoader
 
                     if (isRequestThread(thread)) {
                         log.error(sm.getString("webappClassLoader.warnRequestThread",
-                                contextName, thread.getName()));
+                                getContextName(), thread.getName()));
                     } else {
                         log.error(sm.getString("webappClassLoader.warnThread",
-                                contextName, thread.getName()));
+                                getContextName(), thread.getName()));
                     }
 
                     // Don't try an stop the threads unless explicitly
@@ -2314,19 +2051,19 @@ public class WebappClassLoader
                     } catch (SecurityException e) {
                         log.warn(sm.getString(
                                 "webappClassLoader.stopThreadFail",
-                                thread.getName(), contextName), e);
+                                thread.getName(), getContextName()), e);
                     } catch (NoSuchFieldException e) {
                         log.warn(sm.getString(
                                 "webappClassLoader.stopThreadFail",
-                                thread.getName(), contextName), e);
+                                thread.getName(), getContextName()), e);
                     } catch (IllegalArgumentException e) {
                         log.warn(sm.getString(
                                 "webappClassLoader.stopThreadFail",
-                                thread.getName(), contextName), e);
+                                thread.getName(), getContextName()), e);
                     } catch (IllegalAccessException e) {
                         log.warn(sm.getString(
                                 "webappClassLoader.stopThreadFail",
-                                thread.getName(), contextName), e);
+                                thread.getName(), getContextName()), e);
                     }
 
                     // This method is deprecated and for good reason. This is
@@ -2408,7 +2145,7 @@ public class WebappClassLoader
             }
 
             log.error(sm.getString("webappClassLoader.warnTimerThread",
-                    contextName, thread.getName()));
+                    getContextName(), thread.getName()));
 
         } catch (Exception e) {
             // So many things to go wrong above...
@@ -2416,7 +2153,7 @@ public class WebappClassLoader
             ExceptionUtils.handleThrowable(t);
             log.warn(sm.getString(
                     "webappClassLoader.stopTimerThreadFail",
-                    thread.getName(), contextName), t);
+                    thread.getName(), getContextName()), t);
         }
     }
 
@@ -2461,25 +2198,25 @@ public class WebappClassLoader
             }
         } catch (SecurityException e) {
             log.warn(sm.getString("webappClassLoader.checkThreadLocalsForLeaksFail",
-                    contextName), e);
+                    getContextName()), e);
         } catch (NoSuchFieldException e) {
             log.warn(sm.getString("webappClassLoader.checkThreadLocalsForLeaksFail",
-                    contextName), e);
+                    getContextName()), e);
         } catch (ClassNotFoundException e) {
             log.warn(sm.getString("webappClassLoader.checkThreadLocalsForLeaksFail",
-                    contextName), e);
+                    getContextName()), e);
         } catch (IllegalArgumentException e) {
             log.warn(sm.getString("webappClassLoader.checkThreadLocalsForLeaksFail",
-                    contextName), e);
+                    getContextName()), e);
         } catch (IllegalAccessException e) {
             log.warn(sm.getString("webappClassLoader.checkThreadLocalsForLeaksFail",
-                    contextName), e);
+                    getContextName()), e);
         } catch (InvocationTargetException e) {
             log.warn(sm.getString("webappClassLoader.checkThreadLocalsForLeaksFail",
-                    contextName), e);
+                    getContextName()), e);
         } catch (NoSuchMethodException e) {
             log.warn(sm.getString("webappClassLoader.checkThreadLocalsForLeaksFail",
-                    contextName), e);
+                    getContextName()), e);
         }
     }
 
@@ -2513,7 +2250,7 @@ public class WebappClassLoader
                         }
                         if (potentialLeak) {
                             Object[] args = new Object[5];
-                            args[0] = contextName;
+                            args[0] = getContextName();
                             if (key != null) {
                                 args[1] = getPrettyClassName(key.getClass());
                                 try {
@@ -2683,19 +2420,19 @@ public class WebappClassLoader
             }
         } catch (ClassNotFoundException e) {
             log.info(sm.getString("webappClassLoader.clearRmiInfo",
-                    contextName), e);
+                    getContextName()), e);
         } catch (SecurityException e) {
             log.warn(sm.getString("webappClassLoader.clearRmiFail",
-                    contextName), e);
+                    getContextName()), e);
         } catch (NoSuchFieldException e) {
             log.warn(sm.getString("webappClassLoader.clearRmiFail",
-                    contextName), e);
+                    getContextName()), e);
         } catch (IllegalArgumentException e) {
             log.warn(sm.getString("webappClassLoader.clearRmiFail",
-                    contextName), e);
+                    getContextName()), e);
         } catch (IllegalAccessException e) {
             log.warn(sm.getString("webappClassLoader.clearRmiFail",
-                    contextName), e);
+                    getContextName()), e);
         }
     }
 
@@ -2760,30 +2497,30 @@ public class WebappClassLoader
             if (countRemoved > 0 && log.isDebugEnabled()) {
                 log.debug(sm.getString(
                         "webappClassLoader.clearReferencesResourceBundlesCount",
-                        Integer.valueOf(countRemoved), contextName));
+                        Integer.valueOf(countRemoved), getContextName()));
             }
         } catch (SecurityException e) {
             log.error(sm.getString(
                     "webappClassLoader.clearReferencesResourceBundlesFail",
-                    contextName), e);
+                    getContextName()), e);
         } catch (NoSuchFieldException e) {
             if (System.getProperty("java.vendor").startsWith("Sun")) {
                 log.error(sm.getString(
                 "webappClassLoader.clearReferencesResourceBundlesFail",
-                contextName), e);
+                getContextName()), e);
             } else {
                 log.debug(sm.getString(
                 "webappClassLoader.clearReferencesResourceBundlesFail",
-                contextName), e);
+                getContextName()), e);
             }
         } catch (IllegalArgumentException e) {
             log.error(sm.getString(
                     "webappClassLoader.clearReferencesResourceBundlesFail",
-                    contextName), e);
+                    getContextName()), e);
         } catch (IllegalAccessException e) {
             log.error(sm.getString(
                     "webappClassLoader.clearReferencesResourceBundlesFail",
-                    contextName), e);
+                    getContextName()), e);
         }
     }
 
@@ -2959,31 +2696,19 @@ public class WebappClassLoader
         boolean isClassResource = path.endsWith(".class");
 
         int jarFilesLength = jarFiles.length;
-        int repositoriesLength = repositories.length;
 
-        int i;
-
-        Resource resource = null;
+        WebResource resource = null;
 
         boolean fileNeedConvert = false;
 
-        for (i = 0; (entry == null) && (i < repositoriesLength); i++) {
-            try {
+        if (repository != null) {
+            String fullPath = repository + path;
+            resource = resources.getResource(fullPath);
 
-                String fullPath = repositories[i] + path;
+            if (resource.exists()) {
 
-                Object lookupResult = resources.lookup(fullPath);
-                if (lookupResult instanceof Resource) {
-                    resource = (Resource) lookupResult;
-                }
-
-                // Note : Not getting an exception here means the resource was
-                // found
-
-                ResourceAttributes attributes =
-                    (ResourceAttributes) resources.getAttributes(fullPath);
-                contentLength = (int) attributes.getContentLength();
-                String canonicalPath = attributes.getCanonicalPath();
+                contentLength = (int) resource.getContentLength();
+                String canonicalPath = resource.getCanonicalPath();
                 if (canonicalPath != null) {
                     // we create the ResourceEntry based on the information returned
                     // by the DirContext rather than just using the path to the
@@ -2993,52 +2718,39 @@ public class WebappClassLoader
                 } else {
                     // probably a resource not in the filesystem (e.g. in a
                     // packaged war)
-                    entry = findResourceInternal(files[i], path);
+                    entry = findResourceInternal(file, path);
                 }
-                entry.lastModified = attributes.getLastModified();
-
-                if (resource != null) {
-
+                entry.lastModified = resource.getLastModified();
 
-                    try {
-                        binaryStream = resource.streamContent();
-                    } catch (IOException e) {
-                        return null;
-                    }
+                binaryStream = resource.getInputStream();
 
-                    if (needConvert) {
-                        if (path.endsWith(".properties")) {
-                            fileNeedConvert = true;
-                        }
+                if (needConvert) {
+                    if (path.endsWith(".properties")) {
+                        fileNeedConvert = true;
                     }
+                }
 
-                    // Register the full path for modification checking
-                    // Note: Only syncing on a 'constant' object is needed
-                    synchronized (allPermission) {
-
-                        int j;
-
-                        long[] result2 =
-                            new long[lastModifiedDates.length + 1];
-                        for (j = 0; j < lastModifiedDates.length; j++) {
-                            result2[j] = lastModifiedDates[j];
-                        }
-                        result2[lastModifiedDates.length] = entry.lastModified;
-                        lastModifiedDates = result2;
+                // Register the full path for modification checking
+                // Note: Only syncing on a 'constant' object is needed
+                synchronized (allPermission) {
 
-                        String[] result = new String[paths.length + 1];
-                        for (j = 0; j < paths.length; j++) {
-                            result[j] = paths[j];
-                        }
-                        result[paths.length] = fullPath;
-                        paths = result;
+                    int j;
 
+                    long[] result2 =
+                        new long[lastModifiedDates.length + 1];
+                    for (j = 0; j < lastModifiedDates.length; j++) {
+                        result2[j] = lastModifiedDates[j];
                     }
+                    result2[lastModifiedDates.length] = entry.lastModified;
+                    lastModifiedDates = result2;
 
+                    String[] result = new String[paths.length + 1];
+                    for (j = 0; j < paths.length; j++) {
+                        result[j] = paths[j];
+                    }
+                    result[paths.length] = fullPath;
+                    paths = result;
                 }
-
-            } catch (NamingException e) {
-                // Ignore
             }
         }
 
@@ -3053,7 +2765,7 @@ public class WebappClassLoader
                 if (!openJARs()) {
                     return null;
                 }
-                for (i = 0; (entry == null) && (i < jarFilesLength); i++) {
+                for (int i = 0; (entry == null) && (i < jarFilesLength); i++) {
 
                     jarEntry = jarFiles[i].getJarEntry(path);
 



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


Mime
View raw message