tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1401503 [3/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
Modified: tomcat/trunk/java/org/apache/catalina/servlets/WebdavServlet.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/servlets/WebdavServlet.java?rev=1401503&r1=1401502&r2=1401503&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/servlets/WebdavServlet.java (original)
+++ tomcat/trunk/java/org/apache/catalina/servlets/WebdavServlet.java Tue Oct 23 22:38:16 2012
@@ -14,12 +14,8 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
-
 package org.apache.catalina.servlets;
 
-
-import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.StringReader;
 import java.io.StringWriter;
@@ -34,10 +30,6 @@ import java.util.Stack;
 import java.util.TimeZone;
 import java.util.Vector;
 
-import javax.naming.NameClassPair;
-import javax.naming.NamingEnumeration;
-import javax.naming.NamingException;
-import javax.naming.directory.DirContext;
 import javax.servlet.RequestDispatcher;
 import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
@@ -48,13 +40,11 @@ import javax.xml.parsers.DocumentBuilder
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 
+import org.apache.catalina.WebResource;
 import org.apache.catalina.util.ConcurrentDateFormat;
 import org.apache.catalina.util.DOMWriter;
 import org.apache.catalina.util.MD5Encoder;
 import org.apache.catalina.util.XMLWriter;
-import org.apache.naming.resources.CacheEntry;
-import org.apache.naming.resources.Resource;
-import org.apache.naming.resources.ResourceAttributes;
 import org.apache.tomcat.util.buf.B2CConverter;
 import org.apache.tomcat.util.http.FastHttpDateFormat;
 import org.apache.tomcat.util.http.RequestUtil;
@@ -66,8 +56,6 @@ import org.xml.sax.EntityResolver;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 
-
-
 /**
  * Servlet which adds support for WebDAV level 2. All the basic HTTP requests
  * are handled by the DefaultServlet. The WebDAVServlet must not be used as the
@@ -380,29 +368,17 @@ public class WebdavServlet
     }
 
 
-    /**
-     * Check if the conditions specified in the optional If headers are
-     * satisfied.
-     *
-     * @param request The servlet request we are processing
-     * @param response The servlet response we are creating
-     * @param resourceAttributes The resource information
-     * @return boolean true if the resource meets all the specified conditions,
-     * and false if any of the conditions is not satisfied, in which case
-     * request processing is stopped
-     */
     @Override
     protected boolean checkIfHeaders(HttpServletRequest request,
                                      HttpServletResponse response,
-                                     ResourceAttributes resourceAttributes)
+                                     WebResource resource)
         throws IOException {
 
-        if (!super.checkIfHeaders(request, response, resourceAttributes))
+        if (!super.checkIfHeaders(request, response, resource))
             return false;
 
         // TODO : Checking the WebDAV If header
         return true;
-
     }
 
 
@@ -464,12 +440,10 @@ public class WebdavServlet
 
         resp.addHeader("DAV", "1,2");
 
-        StringBuilder methodsAllowed = determineMethodsAllowed(resources,
-                                                              req);
+        StringBuilder methodsAllowed = determineMethodsAllowed(req);
 
         resp.addHeader("Allow", methodsAllowed.toString());
         resp.addHeader("MS-Author-Via", "DAV");
-
     }
 
 
@@ -481,8 +455,7 @@ public class WebdavServlet
 
         if (!listings) {
             // Get allowed methods
-            StringBuilder methodsAllowed = determineMethodsAllowed(resources,
-                                                                  req);
+            StringBuilder methodsAllowed = determineMethodsAllowed(req);
 
             resp.addHeader("Allow", methodsAllowed.toString());
             resp.sendError(WebdavStatus.SC_METHOD_NOT_ALLOWED);
@@ -583,12 +556,9 @@ public class WebdavServlet
 
         }
 
-        boolean exists = true;
-        Object object = null;
-        try {
-            object = resources.lookup(path);
-        } catch (NamingException e) {
-            exists = false;
+        WebResource resource = resources.getResource(path);
+
+        if (!resource.exists()) {
             int slash = path.lastIndexOf('/');
             if (slash != -1) {
                 String parentPath = path.substring(0, slash);
@@ -622,7 +592,7 @@ public class WebdavServlet
             }
         }
 
-        if (!exists) {
+        if (!resource.exists()) {
             resp.sendError(HttpServletResponse.SC_NOT_FOUND, path);
             return;
         }
@@ -655,30 +625,17 @@ public class WebdavServlet
                 parseProperties(req, generatedXML, currentPath,
                                 type, properties);
 
-                try {
-                    object = resources.lookup(currentPath);
-                } catch (NamingException e) {
-                    continue;
-                }
+                resource = resources.getResource(currentPath);
 
-                if ((object instanceof DirContext) && (depth > 0)) {
+                if (resource.isDirectory() && (depth > 0)) {
 
-                    try {
-                        NamingEnumeration<NameClassPair> enumeration =
-                            resources.list(currentPath);
-                        while (enumeration.hasMoreElements()) {
-                            NameClassPair ncPair = enumeration.nextElement();
-                            String newPath = currentPath;
-                            if (!(newPath.endsWith("/")))
+                    String[] entries = resources.list(currentPath);
+                    for (String entry : entries) {
+                        String newPath = currentPath;
+                        if (!(newPath.endsWith("/")))
                                 newPath += "/";
-                            newPath += ncPair.getName();
-                            stackBelow.push(newPath);
-                        }
-                    } catch (NamingException e) {
-                        resp.sendError
-                            (HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
-                             path);
-                        return;
+                        newPath += entry;
+                        stackBelow.push(newPath);
                     }
 
                     // Displaying the lock-null resources present in that
@@ -760,19 +717,13 @@ public class WebdavServlet
 
         String path = getRelativePath(req);
 
-        boolean exists = true;
-        try {
-            resources.lookup(path);
-        } catch (NamingException e) {
-            exists = false;
-        }
+        WebResource resource = resources.getResource(path);
 
         // Can't create a collection if a resource already exists at the given
         // path
-        if (exists) {
+        if (resource.exists()) {
             // Get allowed methods
-            StringBuilder methodsAllowed = determineMethodsAllowed(resources,
-                                                                  req);
+            StringBuilder methodsAllowed = determineMethodsAllowed(req);
 
             resp.addHeader("Allow", methodsAllowed.toString());
 
@@ -796,23 +747,15 @@ public class WebdavServlet
             }
         }
 
-        boolean result = true;
-        try {
-            resources.createSubcontext(path);
-        } catch (NamingException e) {
-            result = false;
-        }
-
-        if (!result) {
-            resp.sendError(WebdavStatus.SC_CONFLICT,
-                           WebdavStatus.getStatusText
-                           (WebdavStatus.SC_CONFLICT));
-        } else {
+        if (resources.mkdir(path)) {
             resp.setStatus(WebdavStatus.SC_CREATED);
             // Removing any lock-null resource which would be present
             lockNullResources.remove(path);
+        } else {
+            resp.sendError(WebdavStatus.SC_CONFLICT,
+                           WebdavStatus.getStatusText
+                           (WebdavStatus.SC_CONFLICT));
         }
-
     }
 
 
@@ -1120,13 +1063,7 @@ public class WebdavServlet
 
         lock.path = path;
 
-        boolean exists = true;
-        Object object = null;
-        try {
-            object = resources.lookup(path);
-        } catch (NamingException e) {
-            exists = false;
-        }
+        WebResource resource = resources.getResource(path);
 
         Enumeration<LockInfo> locksList = null;
 
@@ -1141,8 +1078,7 @@ public class WebdavServlet
             String lockToken = MD5Encoder.encode(md5Helper.digest(
                     lockTokenStr.getBytes(B2CConverter.ISO_8859_1)));
 
-            if ( (exists) && (object instanceof DirContext) &&
-                 (lock.depth == maxDepth) ) {
+            if (resource.isDirectory() && lock.depth == maxDepth) {
 
                 // Locking a collection (and all its member resources)
 
@@ -1281,13 +1217,7 @@ public class WebdavServlet
                     resourceLocks.put(lock.path, lock);
 
                     // Checking if a resource exists at this path
-                    exists = true;
-                    try {
-                        object = resources.lookup(path);
-                    } catch (NamingException e) {
-                        exists = false;
-                    }
-                    if (!exists) {
+                    if (!resource.exists()) {
 
                         // "Creating" a lock-null resource
                         int slash = lock.path.lastIndexOf('/');
@@ -1653,40 +1583,30 @@ public class WebdavServlet
 
         // Overwriting the destination
 
-        boolean exists = true;
-        try {
-            resources.lookup(destinationPath);
-        } catch (NamingException e) {
-            exists = false;
-        }
+        WebResource destination = resources.getResource(destinationPath);
 
         if (overwrite) {
-
             // Delete destination resource, if it exists
-            if (exists) {
+            if (destination.exists()) {
                 if (!deleteResource(destinationPath, req, resp, true)) {
                     return false;
                 }
             } else {
                 resp.setStatus(WebdavStatus.SC_CREATED);
             }
-
         } else {
-
             // If the destination exists, then it's a conflict
-            if (exists) {
+            if (destination.exists()) {
                 resp.sendError(WebdavStatus.SC_PRECONDITION_FAILED);
                 return false;
             }
-
         }
 
         // Copying source to destination
 
         Hashtable<String,Integer> errorList = new Hashtable<>();
 
-        boolean result = copyResource(resources, errorList,
-                                      path, destinationPath);
+        boolean result = copyResource(errorList, path, destinationPath);
 
         if ((!result) || (!errorList.isEmpty())) {
             if (errorList.size() == 1) {
@@ -1698,7 +1618,7 @@ public class WebdavServlet
         }
 
         // Copy was successful
-        if (exists) {
+        if (destination.exists()) {
             resp.setStatus(WebdavStatus.SC_NO_CONTENT);
         } else {
             resp.setStatus(WebdavStatus.SC_CREATED);
@@ -1709,91 +1629,60 @@ public class WebdavServlet
         lockNullResources.remove(destinationPath);
 
         return true;
-
     }
 
 
     /**
      * Copy a collection.
      *
-     * @param dirContext Resources implementation to be used
      * @param errorList Hashtable containing the list of errors which occurred
      * during the copy operation
      * @param source Path of the resource to be copied
      * @param dest Destination path
      */
-    private boolean copyResource(DirContext dirContext,
-            Hashtable<String,Integer> errorList, String source, String dest) {
+    private boolean copyResource(Hashtable<String,Integer> errorList,
+            String source, String dest) {
 
         if (debug > 1)
             log("Copy: " + source + " To: " + dest);
 
-        Object object = null;
-        try {
-            object = dirContext.lookup(source);
-        } catch (NamingException e) {
-            // Ignore
-        }
-
-        if (object instanceof DirContext) {
+        WebResource sourceResource = resources.getResource(source);
 
-            try {
-                dirContext.createSubcontext(dest);
-            } catch (NamingException e) {
-                errorList.put
-                    (dest, new Integer(WebdavStatus.SC_CONFLICT));
-                return false;
+        if (sourceResource.isDirectory()) {
+            if (!resources.mkdir(dest)) {
+                WebResource destResource = resources.getResource(dest);
+                if (!destResource.isDirectory()) {
+                    errorList.put(dest, new Integer(WebdavStatus.SC_CONFLICT));
+                    return false;
+                }
             }
 
-            try {
-                NamingEnumeration<NameClassPair> enumeration =
-                    dirContext.list(source);
-                while (enumeration.hasMoreElements()) {
-                    NameClassPair ncPair = enumeration.nextElement();
-                    String childDest = dest;
-                    if (!childDest.equals("/"))
-                        childDest += "/";
-                    childDest += ncPair.getName();
-                    String childSrc = source;
-                    if (!childSrc.equals("/"))
-                        childSrc += "/";
-                    childSrc += ncPair.getName();
-                    copyResource(dirContext, errorList, childSrc, childDest);
-                }
-            } catch (NamingException e) {
-                errorList.put
-                    (dest, new Integer(WebdavStatus.SC_INTERNAL_SERVER_ERROR));
+            String[] entries = resources.list(source);
+            for (String entry : entries) {
+                String childDest = dest;
+                if (!childDest.equals("/")) {
+                    childDest += "/";
+                }
+                childDest += entry;
+                String childSrc = source;
+                if (!childSrc.equals("/")) {
+                    childSrc += "/";
+                }
+                childSrc += entry;
+                copyResource(errorList, childSrc, childDest);
+            }
+        } else if (sourceResource.isFile()) {
+            if (!resources.write(dest, sourceResource.getInputStream())) {
+                errorList.put(source,
+                        new Integer(WebdavStatus.SC_INTERNAL_SERVER_ERROR));
                 return false;
             }
-
         } else {
-
-            if (object instanceof Resource) {
-                try {
-                    dirContext.bind(dest, object);
-                } catch (NamingException e) {
-                    if (e.getCause() instanceof FileNotFoundException) {
-                        // We know the source exists so it must be the
-                        // destination dir that can't be found
-                        errorList.put(source,
-                                new Integer(WebdavStatus.SC_CONFLICT));
-                    } else {
-                        errorList.put(source,
-                                new Integer(WebdavStatus.SC_INTERNAL_SERVER_ERROR));
-                    }
-                    return false;
-                }
-            } else {
-                errorList.put
-                    (source,
-                     new Integer(WebdavStatus.SC_INTERNAL_SERVER_ERROR));
-                return false;
-            }
-
+            errorList.put(source,
+                    new Integer(WebdavStatus.SC_INTERNAL_SERVER_ERROR));
+            return false;
         }
-
         return true;
-
     }
 
 
@@ -1841,25 +1730,15 @@ public class WebdavServlet
             return false;
         }
 
-        boolean exists = true;
-        Object object = null;
-        try {
-            object = resources.lookup(path);
-        } catch (NamingException e) {
-            exists = false;
-        }
+        WebResource resource = resources.getResource(path);
 
-        if (!exists) {
+        if (!resource.exists()) {
             resp.sendError(WebdavStatus.SC_NOT_FOUND);
             return false;
         }
 
-        boolean collection = (object instanceof DirContext);
-
-        if (!collection) {
-            try {
-                resources.unbind(path);
-            } catch (NamingException e) {
+        if (!resource.isDirectory()) {
+            if (!resource.delete()) {
                 resp.sendError(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
                 return false;
             }
@@ -1867,39 +1746,31 @@ public class WebdavServlet
 
             Hashtable<String,Integer> errorList = new Hashtable<>();
 
-            deleteCollection(req, resources, path, errorList);
-            try {
-                resources.unbind(path);
-            } catch (NamingException e) {
+            deleteCollection(req, path, errorList);
+            if (!resource.delete()) {
                 errorList.put(path, new Integer
                     (WebdavStatus.SC_INTERNAL_SERVER_ERROR));
             }
 
             if (!errorList.isEmpty()) {
-
                 sendReport(req, resp, errorList);
                 return false;
-
             }
-
         }
         if (setStatus) {
             resp.setStatus(WebdavStatus.SC_NO_CONTENT);
         }
         return true;
-
     }
 
 
     /**
      * Deletes a collection.
      *
-     * @param dirContext Resources implementation associated with the context
      * @param path Path to the collection to be deleted
      * @param errorList Contains the list of the errors which occurred
      */
     private void deleteCollection(HttpServletRequest req,
-                                  DirContext dirContext,
                                   String path,
                                   Hashtable<String,Integer> errorList) {
 
@@ -1920,54 +1791,34 @@ public class WebdavServlet
         if (lockTokenHeader == null)
             lockTokenHeader = "";
 
-        Enumeration<NameClassPair> enumeration = null;
-        try {
-            enumeration = dirContext.list(path);
-        } catch (NamingException e) {
-            errorList.put(path, new Integer
-                (WebdavStatus.SC_INTERNAL_SERVER_ERROR));
-            return;
-        }
+        String[] entries = resources.list(path);
 
-        while (enumeration.hasMoreElements()) {
-            NameClassPair ncPair = enumeration.nextElement();
+        for (String entry : entries) {
             String childName = path;
             if (!childName.equals("/"))
                 childName += "/";
-            childName += ncPair.getName();
+            childName += entry;
 
             if (isLocked(childName, ifHeader + lockTokenHeader)) {
 
                 errorList.put(childName, new Integer(WebdavStatus.SC_LOCKED));
 
             } else {
+                WebResource childResource = resources.getResource(childName);
+                if (childResource.isDirectory()) {
+                    deleteCollection(req, childName, errorList);
+                }
 
-                try {
-                    Object object = dirContext.lookup(childName);
-                    if (object instanceof DirContext) {
-                        deleteCollection(req, dirContext, childName, errorList);
-                    }
-
-                    try {
-                        dirContext.unbind(childName);
-                    } catch (NamingException e) {
-                        if (!(object instanceof DirContext)) {
-                            // If it's not a collection, then it's an unknown
-                            // error
-                            errorList.put
-                                (childName, new Integer
-                                    (WebdavStatus.SC_INTERNAL_SERVER_ERROR));
-                        }
+                if (!childResource.delete()) {
+                    if (!childResource.isDirectory()) {
+                        // If it's not a collection, then it's an unknown
+                        // error
+                        errorList.put(childName, new Integer(
+                                WebdavStatus.SC_INTERNAL_SERVER_ERROR));
                     }
-                } catch (NamingException e) {
-                    errorList.put
-                        (childName, new Integer
-                            (WebdavStatus.SC_INTERNAL_SERVER_ERROR));
                 }
             }
-
         }
-
     }
 
 
@@ -2046,8 +1897,8 @@ public class WebdavServlet
         if (isSpecialPath(path))
             return;
 
-        CacheEntry cacheEntry = resources.lookupCache(path);
-        if (!cacheEntry.exists) {
+        WebResource resource = resources.getResource(path);
+        if (!resource.exists()) {
             // File is in directory listing but doesn't appear to exist
             // Broken symlink or odd permission settings?
             return;
@@ -2065,7 +1916,7 @@ public class WebdavServlet
             href += path.substring(1);
         else
             href += path;
-        if ((cacheEntry.context != null) && (!href.endsWith("/")))
+        if (resource.isDirectory() && (!href.endsWith("/")))
             href += "/";
 
         generatedXML.writeText(rewriteUrl(href));
@@ -2085,25 +1936,24 @@ public class WebdavServlet
             generatedXML.writeElement("D", "prop", XMLWriter.OPENING);
 
             generatedXML.writeProperty("D", "creationdate",
-                    getISOCreationDate(cacheEntry.attributes.getCreation()));
+                    getISOCreationDate(resource.getCreation()));
             generatedXML.writeElement("D", "displayname", XMLWriter.OPENING);
             generatedXML.writeData(resourceName);
             generatedXML.writeElement("D", "displayname", XMLWriter.CLOSING);
-            if (cacheEntry.resource != null) {
+            if (resource.isFile()) {
                 generatedXML.writeProperty
                     ("D", "getlastmodified", FastHttpDateFormat.formatDate
-                           (cacheEntry.attributes.getLastModified(), null));
+                           (resource.getLastModified(), null));
                 generatedXML.writeProperty
                     ("D", "getcontentlength",
-                     String.valueOf(cacheEntry.attributes.getContentLength()));
-                String contentType = getServletContext().getMimeType
-                    (cacheEntry.name);
+                     String.valueOf(resource.getContentLength()));
+                String contentType = getServletContext().getMimeType(
+                        resource.getName());
                 if (contentType != null) {
                     generatedXML.writeProperty("D", "getcontenttype",
                             contentType);
                 }
-                generatedXML.writeProperty("D", "getetag",
-                        cacheEntry.attributes.getETag());
+                generatedXML.writeProperty("D", "getetag",resource.getETag());
                 generatedXML.writeElement("D", "resourcetype",
                         XMLWriter.NO_CONTENT);
             } else {
@@ -2146,7 +1996,7 @@ public class WebdavServlet
             generatedXML.writeElement("D", "creationdate",
                                       XMLWriter.NO_CONTENT);
             generatedXML.writeElement("D", "displayname", XMLWriter.NO_CONTENT);
-            if (cacheEntry.resource != null) {
+            if (resource.isFile()) {
                 generatedXML.writeElement("D", "getcontentlanguage",
                         XMLWriter.NO_CONTENT);
                 generatedXML.writeElement("D", "getcontentlength",
@@ -2189,7 +2039,7 @@ public class WebdavServlet
                 if (property.equals("creationdate")) {
                     generatedXML.writeProperty
                         ("D", "creationdate",
-                         getISOCreationDate(cacheEntry.attributes.getCreation()));
+                         getISOCreationDate(resource.getCreation()));
                 } else if (property.equals("displayname")) {
                     generatedXML.writeElement
                         ("D", "displayname", XMLWriter.OPENING);
@@ -2197,46 +2047,46 @@ public class WebdavServlet
                     generatedXML.writeElement
                         ("D", "displayname", XMLWriter.CLOSING);
                 } else if (property.equals("getcontentlanguage")) {
-                    if (cacheEntry.context != null) {
+                    if (resource.isDirectory()) {
                         propertiesNotFound.addElement(property);
                     } else {
                         generatedXML.writeElement("D", "getcontentlanguage",
                                                   XMLWriter.NO_CONTENT);
                     }
                 } else if (property.equals("getcontentlength")) {
-                    if (cacheEntry.context != null) {
+                    if (resource.isDirectory()) {
                         propertiesNotFound.addElement(property);
                     } else {
                         generatedXML.writeProperty
                             ("D", "getcontentlength",
-                             (String.valueOf(cacheEntry.attributes.getContentLength())));
+                             (String.valueOf(resource.getContentLength())));
                     }
                 } else if (property.equals("getcontenttype")) {
-                    if (cacheEntry.context != null) {
+                    if (resource.isDirectory()) {
                         propertiesNotFound.addElement(property);
                     } else {
                         generatedXML.writeProperty
                             ("D", "getcontenttype",
                              getServletContext().getMimeType
-                             (cacheEntry.name));
+                             (resource.getName()));
                     }
                 } else if (property.equals("getetag")) {
-                    if (cacheEntry.context != null) {
+                    if (resource.isDirectory()) {
                         propertiesNotFound.addElement(property);
                     } else {
                         generatedXML.writeProperty
-                            ("D", "getetag", cacheEntry.attributes.getETag());
+                            ("D", "getetag", resource.getETag());
                     }
                 } else if (property.equals("getlastmodified")) {
-                    if (cacheEntry.context != null) {
+                    if (resource.isDirectory()) {
                         propertiesNotFound.addElement(property);
                     } else {
                         generatedXML.writeProperty
                             ("D", "getlastmodified", FastHttpDateFormat.formatDate
-                                    (cacheEntry.attributes.getLastModified(), null));
+                                    (resource.getLastModified(), null));
                     }
                 } else if (property.equals("resourcetype")) {
-                    if (cacheEntry.context != null) {
+                    if (resource.isDirectory()) {
                         generatedXML.writeElement("D", "resourcetype",
                                 XMLWriter.OPENING);
                         generatedXML.writeElement("D", "collection",
@@ -2600,21 +2450,13 @@ public class WebdavServlet
      * Determines the methods normally allowed for the resource.
      *
      */
-    private StringBuilder determineMethodsAllowed(DirContext dirContext,
-                                                 HttpServletRequest req) {
+    private StringBuilder determineMethodsAllowed(HttpServletRequest req) {
 
         StringBuilder methodsAllowed = new StringBuilder();
-        boolean exists = true;
-        Object object = null;
-        try {
-            String path = getRelativePath(req);
 
-            object = dirContext.lookup(path);
-        } catch (NamingException e) {
-            exists = false;
-        }
+        WebResource resource = resources.getResource(getRelativePath(req));
 
-        if (!exists) {
+        if (!resource.exists()) {
             methodsAllowed.append("OPTIONS, MKCOL, PUT, LOCK");
             return methodsAllowed;
         }
@@ -2626,7 +2468,7 @@ public class WebdavServlet
             methodsAllowed.append(", PROPFIND");
         }
 
-        if (!(object instanceof DirContext)) {
+        if (resource.isFile()) {
             methodsAllowed.append(", PUT");
         }
 

Modified: tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java?rev=1401503&r1=1401502&r2=1401503&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java Tue Oct 23 22:38:16 2012
@@ -28,10 +28,8 @@ import java.net.JarURLConnection;
 import java.net.MalformedURLException;
 import java.net.URISyntaxException;
 import java.net.URL;
-import java.net.URLConnection;
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
@@ -44,10 +42,6 @@ import java.util.Set;
 import java.util.StringTokenizer;
 import java.util.concurrent.ConcurrentHashMap;
 
-import javax.naming.Binding;
-import javax.naming.NameNotFoundException;
-import javax.naming.NamingEnumeration;
-import javax.naming.NamingException;
 import javax.servlet.ServletContainerInitializer;
 import javax.servlet.ServletContext;
 import javax.servlet.annotation.HandlesTypes;
@@ -65,6 +59,8 @@ import org.apache.catalina.Pipeline;
 import org.apache.catalina.Server;
 import org.apache.catalina.Service;
 import org.apache.catalina.Valve;
+import org.apache.catalina.WebResource;
+import org.apache.catalina.WebResourceRoot;
 import org.apache.catalina.Wrapper;
 import org.apache.catalina.core.StandardContext;
 import org.apache.catalina.core.StandardHost;
@@ -79,9 +75,6 @@ import org.apache.catalina.util.ContextN
 import org.apache.catalina.util.Introspection;
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
-import org.apache.naming.resources.DirContextURLConnection;
-import org.apache.naming.resources.FileDirContext;
-import org.apache.naming.resources.ResourceAttributes;
 import org.apache.tomcat.JarScanner;
 import org.apache.tomcat.JarScannerCallback;
 import org.apache.tomcat.util.ExceptionUtils;
@@ -1181,43 +1174,12 @@ public class ContextConfig implements Li
         if  (!webXml.isMetadataComplete() || typeInitializerMap.size() > 0) {
             // Step 4. Process /WEB-INF/classes for annotations
             if (ok) {
-                // Hack required by Eclipse's "serve modules without
-                // publishing" feature since this backs WEB-INF/classes by
-                // multiple locations rather than one.
-                NamingEnumeration<Binding> listBindings = null;
-                try {
-                    try {
-                        listBindings = context.getResources().listBindings(
-                                "/WEB-INF/classes");
-                    } catch (NameNotFoundException ignore) {
-                        // Safe to ignore
-                    }
-                    while (listBindings != null &&
-                            listBindings.hasMoreElements()) {
-                        Binding binding = listBindings.nextElement();
-                        if (binding.getObject() instanceof FileDirContext) {
-                            File webInfClassDir = new File(
-                                    ((FileDirContext) binding.getObject()).getDocBase());
-                            processAnnotationsFile(webInfClassDir, webXml,
-                                    webXml.isMetadataComplete());
-                        } else {
-                            String resource =
-                                    "/WEB-INF/classes/" + binding.getName();
-                            try {
-                                URL url = sContext.getResource(resource);
-                                processAnnotationsUrl(url, webXml,
-                                        webXml.isMetadataComplete());
-                            } catch (MalformedURLException e) {
-                                log.error(sm.getString(
-                                        "contextConfig.webinfClassesUrl",
-                                        resource), e);
-                            }
-                        }
-                    }
-                } catch (NamingException e) {
-                    log.error(sm.getString(
-                            "contextConfig.webinfClassesUrl",
-                            "/WEB-INF/classes"), e);
+                WebResource[] webResources =
+                        context.getResources().listResources("/WEB-INF/classes");
+
+                for (WebResource webResource : webResources) {
+                    processAnnotationsWebResource(webResource, webXml,
+                            webXml.isMetadataComplete());
                 }
             }
 
@@ -1594,23 +1556,21 @@ public class ContextConfig implements Li
                     String entryName = jar.getEntryName();
                     while (entryName != null) {
                         if (entryName.startsWith("META-INF/resources/")) {
-                            context.addResourceJarUrl(url);
+                            context.getResources().createWebResourceSet(
+                                    WebResourceRoot.ResourceSetType.RESOURCE_JAR,
+                                    url, "", "META-INF/resources");
                             break;
                         }
                         jar.nextEntry();
                         entryName = jar.getEntryName();
                     }
                 } else if ("file".equals(url.getProtocol())) {
-                    FileDirContext fileDirContext = new FileDirContext();
-                    fileDirContext.setDocBase(new File(url.toURI()).getAbsolutePath());
-                    try {
-                        fileDirContext.lookup("META-INF/resources/");
-                        //lookup succeeded
-                        if(context instanceof StandardContext){
-                            ((StandardContext)context).addResourcesDirContext(fileDirContext);
-                        }
-                    } catch (NamingException e) {
-                        //not found, ignore
+                    File file = new File(url.toURI());
+                    File resources = new File(file, "META-INF/resources/");
+                    if (resources.isDirectory()) {
+                        context.getResources().createWebResourceSet(
+                                WebResourceRoot.ResourceSetType.RESOURCE_JAR,
+                                file.getAbsolutePath(), "", "");
                     }
                 }
             } catch (IOException ioe) {
@@ -1844,6 +1804,41 @@ public class ContextConfig implements Li
         }
     }
 
+    protected void processAnnotationsWebResource(WebResource webResource,
+            WebXml fragment, boolean handlesTypesOnly) {
+
+        if (webResource.isDirectory()) {
+            WebResource[] webResources =
+                    webResource.getWebResourceRoot().listResources(
+                            webResource.getWebappPath());
+            for (WebResource r : webResources) {
+                processAnnotationsWebResource(r, fragment, handlesTypesOnly);
+            }
+        } else if (webResource.isFile() &&
+                webResource.getName().endsWith(".class")) {
+            InputStream is = null;
+            try {
+                is = webResource.getInputStream();
+                processAnnotationsStream(is, fragment, handlesTypesOnly);
+            } catch (IOException e) {
+                log.error(sm.getString("contextConfig.inputStreamWebResource",
+                        webResource.getWebappPath()),e);
+            } catch (ClassFormatException e) {
+                log.error(sm.getString("contextConfig.inputStreamWebResource",
+                        webResource.getWebappPath()),e);
+            } finally {
+                if (is != null) {
+                    try {
+                        is.close();
+                    } catch (Throwable t) {
+                        ExceptionUtils.handleThrowable(t);
+                    }
+                }
+            }
+        }
+    }
+
+
     protected void processAnnotationsUrl(URL url, WebXml fragment,
             boolean handlesTypesOnly) {
         if (url == null) {
@@ -1851,8 +1846,6 @@ public class ContextConfig implements Li
             return;
         } else if ("jar".equals(url.getProtocol())) {
             processAnnotationsJar(url, fragment, handlesTypesOnly);
-        } else if ("jndi".equals(url.getProtocol())) {
-            processAnnotationsJndi(url, fragment, handlesTypesOnly);
         } else if ("file".equals(url.getProtocol())) {
             try {
                 processAnnotationsFile(
@@ -1915,61 +1908,6 @@ public class ContextConfig implements Li
     }
 
 
-    protected void processAnnotationsJndi(URL url, WebXml fragment,
-            boolean handlesTypesOnly) {
-        try {
-            URLConnection urlConn = url.openConnection();
-            DirContextURLConnection dcUrlConn;
-            if (!(urlConn instanceof DirContextURLConnection)) {
-                // This should never happen
-                sm.getString("contextConfig.jndiUrlNotDirContextConn", url);
-                return;
-            }
-
-            dcUrlConn = (DirContextURLConnection) urlConn;
-            dcUrlConn.setUseCaches(false);
-
-            String type = dcUrlConn.getHeaderField(ResourceAttributes.TYPE);
-            if (ResourceAttributes.COLLECTION_TYPE.equals(type)) {
-                // Collection
-                Enumeration<String> dirs = dcUrlConn.list();
-                while (dirs.hasMoreElements()) {
-                    String dir = dirs.nextElement();
-                    URL dirUrl = new URL(url.toString() + '/' + dir);
-                    processAnnotationsJndi(dirUrl, fragment, handlesTypesOnly);
-                }
-
-            } else {
-                // Single file
-                if (url.getPath().endsWith(".class")) {
-                    InputStream is = null;
-                    try {
-                        is = dcUrlConn.getInputStream();
-                        processAnnotationsStream(
-                                is, fragment, handlesTypesOnly);
-                    } catch (IOException e) {
-                        log.error(sm.getString("contextConfig.inputStreamJndi",
-                                url),e);
-                    } catch (ClassFormatException e) {
-                        log.error(sm.getString("contextConfig.inputStreamJndi",
-                                url),e);
-                    } finally {
-                        if (is != null) {
-                            try {
-                                is.close();
-                            } catch (Throwable t) {
-                                ExceptionUtils.handleThrowable(t);
-                            }
-                        }
-                    }
-                }
-            }
-        } catch (IOException e) {
-            log.error(sm.getString("contextConfig.jndiUrl", url), e);
-        }
-    }
-
-
     protected void processAnnotationsFile(File file, WebXml fragment,
             boolean handlesTypesOnly) {
 
@@ -2587,6 +2525,14 @@ for (String interfaceName : cacheEntry.g
             }
         }
 
+
+        @Override
+        public void scanWebInfClasses() {
+            // NO-OP. Fragments unpacked in WEB-INF classes are not handled,
+            // mainly because if there are multiple fragments there is no way to
+            // handle multiple web-fragment.xml files.
+        }
+
         public Map<String,WebXml> getFragments() {
             return fragments;
         }

Modified: tomcat/trunk/java/org/apache/catalina/startup/ContextRuleSet.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/ContextRuleSet.java?rev=1401503&r1=1401502&r2=1401503&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/ContextRuleSet.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/ContextRuleSet.java Tue Oct 23 22:38:16 2012
@@ -164,12 +164,37 @@ public class ContextRuleSet extends Rule
         digester.addRuleSet(new RealmRuleSet(prefix + "Context/"));
 
         digester.addObjectCreate(prefix + "Context/Resources",
-                                 "org.apache.naming.resources.FileDirContext",
+                                 "org.apache.catalina.webresources.StandardRoot",
                                  "className");
         digester.addSetProperties(prefix + "Context/Resources");
         digester.addSetNext(prefix + "Context/Resources",
                             "setResources",
-                            "javax.naming.directory.DirContext");
+                            "org.apache.catalina.WebResourceRoot");
+
+        digester.addObjectCreate(prefix + "Context/Resources/PreResources",
+                                 null, // MUST be specified in the element
+                                 "className");
+        digester.addSetProperties(prefix + "Context/Resources/PreResources");
+        digester.addSetNext(prefix + "Context/Resources/PreResources",
+                            "addPreResources",
+                            "org.apache.catalina.WebResourceSet");
+
+        digester.addObjectCreate(prefix + "Context/Resources/JarResources",
+                                 null, // MUST be specified in the element
+                                 "className");
+        digester.addSetProperties(prefix + "Context/Resources/JarResources");
+        digester.addSetNext(prefix + "Context/Resources/JarResources",
+                            "addJarResources",
+                            "org.apache.catalina.WebResourceSet");
+
+        digester.addObjectCreate(prefix + "Context/Resources/PostResources",
+                                 null, // MUST be specified in the element
+                                 "className");
+        digester.addSetProperties(prefix + "Context/Resources/PostResources");
+        digester.addSetNext(prefix + "Context/Resources/PostResources",
+                            "addPostResources",
+                            "org.apache.catalina.WebResourceSet");
+
 
         digester.addObjectCreate(prefix + "Context/ResourceLink",
                 "org.apache.catalina.deploy.ContextResourceLink");

Modified: tomcat/trunk/java/org/apache/catalina/startup/FailedContext.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/FailedContext.java?rev=1401503&r1=1401502&r2=1401503&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/FailedContext.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/FailedContext.java Tue Oct 23 22:38:16 2012
@@ -22,7 +22,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;
@@ -44,6 +43,7 @@ import org.apache.catalina.Manager;
 import org.apache.catalina.Pipeline;
 import org.apache.catalina.Realm;
 import org.apache.catalina.Valve;
+import org.apache.catalina.WebResourceRoot;
 import org.apache.catalina.Wrapper;
 import org.apache.catalina.connector.Request;
 import org.apache.catalina.connector.Response;
@@ -261,9 +261,9 @@ public class FailedContext extends Lifec
     public void setRealm(Realm realm) { /* NO-OP */ }
 
     @Override
-    public DirContext getResources() { return null; }
+    public WebResourceRoot getResources() { return null; }
     @Override
-    public void setResources(DirContext resources) { /* NO-OP */ }
+    public void setResources(WebResourceRoot resources) { /* NO-OP */ }
 
     @Override
     public void backgroundProcess() { /* NO-OP */ }
@@ -626,9 +626,6 @@ public class FailedContext extends Lifec
     public JspConfigDescriptor getJspConfigDescriptor() { return null; }
 
     @Override
-    public void addResourceJarUrl(URL url) { /* NO-OP */ }
-
-    @Override
     public void addServletContainerInitializer(ServletContainerInitializer sci,
             Set<Class<?>> classes) { /* NO-OP */ }
 
@@ -673,4 +670,11 @@ public class FailedContext extends Lifec
 
     @Override
     public File getCatalinaBase() { return null; }
+
+    @Override
+    public void setAddWebinfClassesResources(boolean addWebinfClassesResources) {
+        // NO-OP
+    }
+    @Override
+    public boolean getAddWebinfClassesResources() { return false; }
 }
\ No newline at end of file

Modified: tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties?rev=1401503&r1=1401502&r2=1401503&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties Tue Oct 23 22:38:16 2012
@@ -43,6 +43,7 @@ contextConfig.init=ContextConfig: Initia
 contextConfig.inputStreamFile=Unable to process file [{0}] for annotations
 contextConfig.inputStreamJar=Unable to process Jar entry [{0}] from Jar [{1}] for annotations
 contextConfig.inputStreamJndi=Unable to process resource element [{0}] for annotations
+contextConfig.inputStreamWebResource=Unable to process web resource [{0}] for annotations
 contextConfig.invalidSci=The ServletContentInitializer [{0}] could not be created
 contextConfig.jndiUrl=Unable to process JNDI URL [{0}] for annotations
 contextConfig.jndiUrlNotDirContextConn=The connection created for URL [{0}] was not a DirContextURLConnection

Modified: tomcat/trunk/java/org/apache/catalina/startup/TldConfig.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/TldConfig.java?rev=1401503&r1=1401502&r2=1401503&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/TldConfig.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/TldConfig.java Tue Oct 23 22:38:16 2012
@@ -59,8 +59,10 @@ public final class TldConfig  implements
 
     private static final String TLD_EXT = ".tld";
     private static final String WEB_INF = "/WEB-INF/";
+    private static final String WEB_INF_CLASSES = "/WEB-INF/classes/";
     private static final String WEB_INF_LIB = "/WEB-INF/lib/";
 
+
     // Names of JARs that are known not to contain any TLDs
     private static volatile Set<String> noTldJars = null;
 
@@ -255,7 +257,7 @@ public final class TldConfig  implements
         tldScanWebXml();
 
         // Stage 3a - TLDs under WEB-INF (not lib or classes)
-        tldScanResourcePaths(WEB_INF);
+        tldScanResourcePaths(WEB_INF, false);
 
         // Stages 3b & 4
         JarScanner jarScanner = context.getJarScanner();
@@ -295,6 +297,11 @@ public final class TldConfig  implements
                 tldScanDir(metaInf);
             }
         }
+
+        @Override
+        public void scanWebInfClasses() throws IOException {
+            tldScanResourcePaths(WEB_INF_CLASSES, true);
+        }
     }
 
     // -------------------------------------------------------- Private Methods
@@ -363,11 +370,12 @@ public final class TldConfig  implements
      *
      * Initially, rootPath equals /WEB-INF/. The /WEB-INF/classes and
      * /WEB-INF/lib sub-directories are excluded from the search, as per the
-     * JSP 2.0 spec.
+     * JSP 2.0 spec unless the JarScanner is configured to treat
+     * /WEB-INF/classes/ as an exploded JAR.
      *
      * Keep in sync with o.a.j.comiler.TldLocationsCache
      */
-    private void tldScanResourcePaths(String startPath) {
+    private void tldScanResourcePaths(String startPath, boolean webInfAsJar) {
 
         if (log.isTraceEnabled()) {
             log.trace(sm.getString("tldConfig.webinfScan", startPath));
@@ -382,7 +390,8 @@ public final class TldConfig  implements
                 String path = it.next();
                 if (!path.endsWith(TLD_EXT)
                         && (path.startsWith(WEB_INF_LIB)
-                                || path.startsWith("/WEB-INF/classes/"))) {
+                                || path.startsWith("/WEB-INF/classes/")
+                                   && !webInfAsJar)) {
                     continue;
                 }
                 if (path.endsWith(TLD_EXT)) {
@@ -407,7 +416,7 @@ public final class TldConfig  implements
                         }
                     }
                 } else {
-                    tldScanResourcePaths(path);
+                    tldScanResourcePaths(path, false);
                 }
             }
         }

Modified: tomcat/trunk/java/org/apache/catalina/util/ConcurrentDateFormat.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/util/ConcurrentDateFormat.java?rev=1401503&r1=1401502&r2=1401503&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/util/ConcurrentDateFormat.java (original)
+++ tomcat/trunk/java/org/apache/catalina/util/ConcurrentDateFormat.java Tue Oct 23 22:38:16 2012
@@ -35,6 +35,19 @@ public class ConcurrentDateFormat {
     private final TimeZone timezone;
     private final Queue<SimpleDateFormat> queue = new ConcurrentLinkedQueue<>();
 
+    public static final String RFC1123_DATE = "EEE, dd MMM yyyy HH:mm:ss zzz";
+    public static final TimeZone GMT = TimeZone.getTimeZone("GMT");
+
+    private static final ConcurrentDateFormat FORMAT_RFC1123;
+
+    static {
+        FORMAT_RFC1123 = new ConcurrentDateFormat(RFC1123_DATE, Locale.US, GMT);
+    }
+
+    public static String formatRfc1123(Date date) {
+        return FORMAT_RFC1123.format(date);
+    }
+
     public ConcurrentDateFormat(String format, Locale locale,
             TimeZone timezone) {
         this.format = format;

Modified: tomcat/trunk/java/org/apache/catalina/util/ExtensionValidator.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/util/ExtensionValidator.java?rev=1401503&r1=1401502&r2=1401503&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/util/ExtensionValidator.java (original)
+++ tomcat/trunk/java/org/apache/catalina/util/ExtensionValidator.java Tue Oct 23 22:38:16 2012
@@ -14,7 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.catalina.util;
 
 import java.io.File;
@@ -24,18 +23,13 @@ import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.Locale;
-import java.util.NoSuchElementException;
 import java.util.StringTokenizer;
 import java.util.jar.JarInputStream;
 import java.util.jar.Manifest;
 
-import javax.naming.Binding;
-import javax.naming.NamingEnumeration;
-import javax.naming.NamingException;
-import javax.naming.directory.DirContext;
-
 import org.apache.catalina.Context;
-import org.apache.naming.resources.Resource;
+import org.apache.catalina.WebResource;
+import org.apache.catalina.WebResourceRoot;
 import org.apache.tomcat.util.ExceptionUtils;
 import org.apache.tomcat.util.res.StringManager;
 
@@ -124,14 +118,14 @@ public final class ExtensionValidator {
      * <code>ManifestResorce<code> objects. These objects are then passed
      * to the validateManifestResources method for validation.
      *
-     * @param dirContext The JNDI root of the Web Application
-     * @param context The context from which the Logger and path to the
-     *                application
+     * @param resources The resources configured for this Web Application
+     * @param context   The context from which the Logger and path to the
+     *                  application
      *
      * @return true if all required extensions satisfied
      */
     public static synchronized boolean validateApplication(
-                                           DirContext dirContext,
+                                           WebResourceRoot resources,
                                            Context context)
                     throws IOException {
 
@@ -139,17 +133,14 @@ public final class ExtensionValidator {
         ArrayList<ManifestResource> appManifestResources = new ArrayList<>();
         // If the application context is null it does not exist and
         // therefore is not valid
-        if (dirContext == null) return false;
+        if (resources == null) return false;
         // Find the Manifest for the Web Application
         InputStream inputStream = null;
         try {
-            NamingEnumeration<Binding> wne =
-                dirContext.listBindings("/META-INF/");
-            Binding binding = wne.nextElement();
-            if (binding.getName().toUpperCase(Locale.ENGLISH).equals("MANIFEST.MF")) {
-                Resource resource = (Resource)dirContext.lookup
-                                    ("/META-INF/" + binding.getName());
-                inputStream = resource.streamContent();
+            WebResource resource =
+                    resources.getResource("/META-INF/MANIFEST.MF");
+            if (resource.isFile()) {
+                inputStream = resource.getInputStream();
                 Manifest manifest = new Manifest(inputStream);
                 inputStream.close();
                 inputStream = null;
@@ -158,10 +149,6 @@ public final class ExtensionValidator {
                     manifest, ManifestResource.WAR);
                 appManifestResources.add(mre);
             }
-        } catch (NamingException nex) {
-            // Application does not contain a MANIFEST.MF file
-        } catch (NoSuchElementException nse) {
-            // Application does not contain a MANIFEST.MF file
         } finally {
             if (inputStream != null) {
                 try {
@@ -172,35 +159,23 @@ public final class ExtensionValidator {
             }
         }
 
-        // Locate the Manifests for all bundled JARs
-        NamingEnumeration<Binding> ne = null;
         try {
-            ne = dirContext.listBindings("WEB-INF/lib/");
-            while ((ne != null) && ne.hasMoreElements()) {
-                Binding binding = ne.nextElement();
-                if (!binding.getName().toLowerCase(Locale.ENGLISH).endsWith(".jar")) {
-                    continue;
-                }
-                Object obj =
-                    dirContext.lookup("/WEB-INF/lib/" + binding.getName());
-                if (!(obj instanceof Resource)) {
-                    // Probably a directory named xxx.jar - ignore it
-                    continue;
-                }
-                Resource resource = (Resource) obj;
-                inputStream = resource.streamContent();
-                Manifest jmanifest = getManifest(inputStream);
-                if (jmanifest != null) {
-                    ManifestResource mre = new ManifestResource(
-                                                binding.getName(),
-                                                jmanifest,
-                                                ManifestResource.APPLICATION);
-                    appManifestResources.add(mre);
+            WebResource[] jars = resources.listResources("/WEB-INF/lib");
+            for (WebResource jar : jars) {
+                if (jar.getName().toLowerCase(Locale.ENGLISH).endsWith(".jar") &&
+                        jar.isFile()) {
+
+                    inputStream = jar.getInputStream();
+                    Manifest jmanifest = getManifest(inputStream);
+                    if (jmanifest != null) {
+                        ManifestResource mre = new ManifestResource(
+                                                    jar.getName(),
+                                                    jmanifest,
+                                                    ManifestResource.APPLICATION);
+                        appManifestResources.add(mre);
+                    }
                 }
             }
-        } catch (NamingException nex) {
-            // Jump out of the check for this application because it
-            // has no resources
         } finally {
             if (inputStream != null) {
                 try {

Modified: tomcat/trunk/java/org/apache/jasper/compiler/TldLocationsCache.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/compiler/TldLocationsCache.java?rev=1401503&r1=1401502&r2=1401503&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/jasper/compiler/TldLocationsCache.java (original)
+++ tomcat/trunk/java/org/apache/jasper/compiler/TldLocationsCache.java Tue Oct 23 22:38:16 2012
@@ -90,6 +90,7 @@ public class TldLocationsCache {
     public static final int NOROOT_REL_URI = 2;
 
     private static final String WEB_INF = "/WEB-INF/";
+    private static final String WEB_INF_CLASSES = "/WEB-INF/classes/";
     private static final String WEB_INF_LIB = "/WEB-INF/lib/";
     private static final String JAR_EXT = ".jar";
     private static final String TLD_EXT = ".tld";
@@ -237,7 +238,7 @@ public class TldLocationsCache {
         if (initialized) return;
         try {
             tldScanWebXml();
-            tldScanResourcePaths(WEB_INF);
+            tldScanResourcePaths(WEB_INF, false);
 
             JarScanner jarScanner = JarScannerFactory.getJarScanner(ctxt);
             if (jarScanner != null) {
@@ -267,6 +268,11 @@ public class TldLocationsCache {
                 tldScanDir(metaInf);
             }
         }
+
+        @Override
+        public void scanWebInfClasses() throws IOException {
+            tldScanResourcePaths(WEB_INF_CLASSES, true);
+        }
     }
 
     /*
@@ -336,12 +342,13 @@ public class TldLocationsCache {
      *
      * Initially, rootPath equals /WEB-INF/. The /WEB-INF/classes and
      * /WEB-INF/lib sub-directories are excluded from the search, as per the
-     * JSP 2.0 spec.
+     * JSP 2.0 spec unless the JarScanner is configured to treat
+     * /WEB-INF/classes/ as an exploded JAR.
      *
      * Keep code in sync with o.a.c.startup.TldConfig
      */
-    private void tldScanResourcePaths(String startPath)
-            throws Exception {
+    private void tldScanResourcePaths(String startPath, boolean webInfAsJar)
+            throws IOException {
 
         Set<String> dirList = ctxt.getResourcePaths(startPath);
         if (dirList != null) {
@@ -350,7 +357,8 @@ public class TldLocationsCache {
                 String path = it.next();
                 if (!path.endsWith(TLD_EXT)
                         && (path.startsWith(WEB_INF_LIB)
-                                || path.startsWith("/WEB-INF/classes/"))) {
+                                || path.startsWith("/WEB-INF/classes/")
+                                   && !webInfAsJar)) {
                     continue;
                 }
                 if (path.endsWith(TLD_EXT)) {
@@ -371,7 +379,7 @@ public class TldLocationsCache {
                         }
                     }
                 } else {
-                    tldScanResourcePaths(path);
+                    tldScanResourcePaths(path, false);
                 }
             }
         }

Modified: tomcat/trunk/java/org/apache/tomcat/JarScannerCallback.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/JarScannerCallback.java?rev=1401503&r1=1401502&r2=1401503&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/JarScannerCallback.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/JarScannerCallback.java Tue Oct 23 22:38:16 2012
@@ -14,22 +14,40 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-
 package org.apache.tomcat;
 
 import java.io.File;
 import java.io.IOException;
 import java.net.JarURLConnection;
 
+/**
+ * This interface is implemented by clients of the {@link JarScanner} to enable
+ * them to receive notification of a discovered JAR.
+ */
 public interface JarScannerCallback {
 
     /**
+     * A JAR was found (probably packaged in a WAR) and may be accessed for
+     * further processing via the provided URL connection.
      *
-     * @param urlConn
-     * @throws IOException
+     * @param urlConn   The connection to the identified JAR
      */
     public void scan(JarURLConnection urlConn) throws IOException;
 
-    public void scan(File file) throws IOException ;
+    /**
+     * A JAR was found (probably in an unpacked WAR or possibly elsewhere on the
+     * class path) and may be accessed for further processing via the provided
+     * file.
+     *
+     * @param file  The file for the identified JAR.
+     */
+    public void scan(File file) throws IOException;
 
+    /**
+     * A directory structure was found within the web application at
+     * /WEB-INF/classes that should be handled as an unpacked JAR. Note that all
+     * resource access must be via the ServletContext to ensure that any
+     * additional resources are visible.
+     */
+    public void scanWebInfClasses() throws IOException;
 }

Modified: tomcat/trunk/java/org/apache/tomcat/util/scan/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/scan/LocalStrings.properties?rev=1401503&r1=1401502&r2=1401503&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/scan/LocalStrings.properties (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/scan/LocalStrings.properties Tue Oct 23 22:38:16 2012
@@ -18,7 +18,8 @@ jarScan.classloaderStart=Scanning for JA
 jarScan.classloaderJarScan=Scanning JAR [{0}] from classpath
 jarScan.classloaderJarNoScan=Not scanning JAR [{0}] from classpath
 jarScan.jarUrlStart=Scanning JAR at URL [{0}]
-jarScan.webinflibFail=Failed to scan JAR [{0}] from WEB-INF/lib
-jarScan.webinflibStart=Scanning WEB-INF/lib for JARs
-jarScan.webinflibJarScan=Scanning JAR [{0}] from WEB-INF/lib
-jarScan.webinflibJarNoScan=Not scanning JAR [{0}] from WEB-INF/lib
+jarScan.webinfclassesFail=Failed to scan /WEB-INF/classes
+jarScan.webinflibFail=Failed to scan JAR [{0}] from /WEB-INF/lib
+jarScan.webinflibStart=Scanning /WEB-INF/lib for JARs
+jarScan.webinflibJarScan=Scanning JAR [{0}] from /WEB-INF/lib
+jarScan.webinflibJarNoScan=Not scanning JAR [{0}] from /WEB-INF/lib

Modified: tomcat/trunk/java/org/apache/tomcat/util/scan/StandardJarScanner.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/scan/StandardJarScanner.java?rev=1401503&r1=1401502&r2=1401503&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/scan/StandardJarScanner.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/scan/StandardJarScanner.java Tue Oct 23 22:38:16 2012
@@ -20,6 +20,7 @@ package org.apache.tomcat.util.scan;
 import java.io.File;
 import java.io.IOException;
 import java.net.JarURLConnection;
+import java.net.MalformedURLException;
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.net.URLClassLoader;
@@ -175,14 +176,31 @@ public class StandardJarScanner implemen
             }
         }
 
+        // Scan WEB-INF/classes
+        if (scanAllDirectories) {
+            try {
+                URL url = context.getResource("/WEB-INF/classes/META-INF");
+                if (url != null) {
+                    try {
+                        callback.scanWebInfClasses();
+                    } catch (IOException e) {
+                        log.warn(sm.getString("jarScan.webinfclassesFail"), e);
+                    }
+                }
+            } catch (MalformedURLException e) {
+                // Ignore
+            }
+        }
+
         // Scan the classpath
-        if (scanClassPath) {
+        if (scanClassPath && classloader != null) {
             if (log.isTraceEnabled()) {
                 log.trace(sm.getString("jarScan.classloaderStart"));
             }
 
-            ClassLoader loader =
-                Thread.currentThread().getContextClassLoader();
+            // No need to scan the web application class loader - we have
+            // already scanned WEB-INF/lib and WEB-INF/classes
+            ClassLoader loader = classloader.getParent();
 
             while (loader != null) {
                 if (loader instanceof URLClassLoader) {
@@ -215,7 +233,6 @@ public class StandardJarScanner implemen
                 }
                 loader = loader.getParent();
             }
-
         }
     }
 

Modified: tomcat/trunk/test/javax/el/TestCompositeELResolver.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/javax/el/TestCompositeELResolver.java?rev=1401503&r1=1401502&r2=1401503&view=diff
==============================================================================
--- tomcat/trunk/test/javax/el/TestCompositeELResolver.java (original)
+++ tomcat/trunk/test/javax/el/TestCompositeELResolver.java Tue Oct 23 22:38:16 2012
@@ -24,9 +24,11 @@ import static org.junit.Assert.assertEqu
 
 import org.junit.Test;
 
+import org.apache.catalina.WebResourceRoot;
 import org.apache.catalina.core.StandardContext;
 import org.apache.catalina.startup.Tomcat;
 import org.apache.catalina.startup.TomcatBaseTest;
+import org.apache.catalina.webresources.StandardRoot;
 import org.apache.tomcat.util.buf.ByteChunk;
 
 public class TestCompositeELResolver extends TomcatBaseTest {
@@ -42,7 +44,10 @@ public class TestCompositeELResolver ext
 
         // This test needs the JSTL libraries
         File lib = new File("webapps/examples/WEB-INF/lib");
-        ctxt.setAliases("/WEB-INF/lib=" + lib.getCanonicalPath());
+        ctxt.setResources(new StandardRoot(ctxt));
+        ctxt.getResources().createWebResourceSet(
+                WebResourceRoot.ResourceSetType.POST, lib.getAbsolutePath(),
+                "/WEB-INF/lib", "");
 
         tomcat.start();
 

Modified: tomcat/trunk/test/org/apache/catalina/core/TestStandardContextAliases.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/core/TestStandardContextAliases.java?rev=1401503&r1=1401502&r2=1401503&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/core/TestStandardContextAliases.java (original)
+++ tomcat/trunk/test/org/apache/catalina/core/TestStandardContextAliases.java Tue Oct 23 22:38:16 2012
@@ -32,8 +32,10 @@ import static org.junit.Assert.assertTru
 
 import org.junit.Test;
 
+import org.apache.catalina.WebResourceRoot;
 import org.apache.catalina.startup.Tomcat;
 import org.apache.catalina.startup.TomcatBaseTest;
+import org.apache.catalina.webresources.StandardRoot;
 import org.apache.tomcat.util.buf.ByteChunk;
 
 public class TestStandardContextAliases extends TomcatBaseTest {
@@ -47,7 +49,11 @@ public class TestStandardContextAliases 
             tomcat.addContext("", System.getProperty("java.io.tmpdir"));
 
         File lib = new File("webapps/examples/WEB-INF/lib");
-        ctx.setAliases("/WEB-INF/lib=" + lib.getCanonicalPath());
+        ctx.setResources(new StandardRoot(ctx));
+        ctx.getResources().createWebResourceSet(
+                WebResourceRoot.ResourceSetType.POST, lib.getAbsolutePath(),
+                "/WEB-INF/lib", "");
+
 
         Tomcat.addServlet(ctx, "test", new TestServlet());
         ctx.addServletMapping("/", "test");

Modified: tomcat/trunk/test/org/apache/catalina/loader/TestVirtualContext.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/loader/TestVirtualContext.java?rev=1401503&r1=1401502&r2=1401503&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/loader/TestVirtualContext.java (original)
+++ tomcat/trunk/test/org/apache/catalina/loader/TestVirtualContext.java Tue Oct 23 22:38:16 2012
@@ -31,11 +31,12 @@ import static org.junit.Assert.assertTru
 import org.junit.Assert;
 import org.junit.Test;
 
+import org.apache.catalina.WebResourceRoot;
 import org.apache.catalina.core.JreMemoryLeakPreventionListener;
 import org.apache.catalina.core.StandardContext;
 import org.apache.catalina.startup.Tomcat;
 import org.apache.catalina.startup.TomcatBaseTest;
-import org.apache.naming.resources.VirtualDirContext;
+import org.apache.catalina.webresources.StandardRoot;
 import org.apache.tomcat.util.buf.ByteChunk;
 import org.apache.tomcat.util.http.fileupload.FileUtils;
 import org.apache.tomcat.util.http.fileupload.IOUtils;
@@ -66,24 +67,38 @@ public class TestVirtualContext extends 
         StandardContext ctx = (StandardContext) tomcat.addWebapp(null, "/test",
             appDir.getAbsolutePath());
 
-        VirtualWebappLoader loader = new VirtualWebappLoader(ctx.getParentClassLoader());
-        loader.setVirtualClasspath(//
-            "test/webapp-3.0-virtual-webapp/target/classes;" + //
-                "test/webapp-3.0-virtual-library/target/classes;" + //
-                "test/webapp-3.0-virtual-webapp/src/main/webapp/WEB-INF/classes;" + //
+        ctx.setResources(new StandardRoot(ctx));
+        File f1 = new File("test/webapp-3.0-virtual-webapp/target/classes");
+        File f2 = new File("test/webapp-3.0-virtual-library/target/classes");
+        File f3 = new File(
+                "test/webapp-3.0-virtual-webapp/src/main/webapp/WEB-INF/classes");
+        File f4 = new File(
                 "test/webapp-3.0-virtual-webapp/src/main/webapp2/WEB-INF/classes");
-        ctx.setLoader(loader);
-
-        String extraMappings = "/=test/webapp-3.0-virtual-webapp/src/main/webapp2" + //
-            ",/other=test/webapp-3.0-virtual-webapp/src/main/misc" + //
-            ",/WEB-INF/classes=test/webapp-3.0-virtual-webapp/target/classes";
-        VirtualDirContext resources = new VirtualDirContext();
-        resources.setExtraResourcePaths(extraMappings);
-        ctx.setResources(resources);
+        File f5 = new File("test/webapp-3.0-virtual-webapp/src/main/misc");
+        File f6 = new File("test/webapp-3.0-virtual-webapp/src/main/webapp2");
+        ctx.getResources().createWebResourceSet(
+                WebResourceRoot.ResourceSetType.POST, f1.getAbsolutePath(),
+                "/WEB-INF/classes", "");
+        ctx.getResources().createWebResourceSet(
+                WebResourceRoot.ResourceSetType.POST, f2.getAbsolutePath(),
+                "/WEB-INF/classes", "");
+        ctx.getResources().createWebResourceSet(
+                WebResourceRoot.ResourceSetType.POST, f3.getAbsolutePath(),
+                "/WEB-INF/classes", "");
+        ctx.getResources().createWebResourceSet(
+                WebResourceRoot.ResourceSetType.POST, f4.getAbsolutePath(),
+                "/WEB-INF/classes", "");
+        ctx.getResources().createWebResourceSet(
+                WebResourceRoot.ResourceSetType.POST, f5.getAbsolutePath(),
+                "/other", "");
+        ctx.getResources().createWebResourceSet(
+                WebResourceRoot.ResourceSetType.POST, f6.getAbsolutePath(),
+                "", "");
 
         StandardJarScanner jarScanner = new StandardJarScanner();
         jarScanner.setScanAllDirectories(true);
         ctx.setJarScanner(jarScanner);
+        ctx.setAddWebinfClassesResources(true);
 
         tomcat.start();
 
@@ -261,11 +276,15 @@ public class TestVirtualContext extends 
         annotatedServletClassInputStream.close();
         annotatedServletClassOutputStream.close();
 
-        VirtualWebappLoader loader = new VirtualWebappLoader(ctx.getParentClassLoader());
-        loader.setVirtualClasspath("test/webapp-3.0-virtual-webapp/target/classes;" + //
-            "test/webapp-3.0-virtual-library/target/classes;" + //
-            additionWebInfClasses.getAbsolutePath());
-        ctx.setLoader(loader);
+        ctx.setResources(new StandardRoot(ctx));
+        File f1 = new File("test/webapp-3.0-virtual-webapp/target/classes");
+        File f2 = new File("test/webapp-3.0-virtual-library/target/classes");
+        ctx.getResources().createWebResourceSet(
+                WebResourceRoot.ResourceSetType.POST, f1.getAbsolutePath(),
+                "/WEB-INF/classes", "");
+        ctx.getResources().createWebResourceSet(
+                WebResourceRoot.ResourceSetType.POST, f2.getAbsolutePath(),
+                "/WEB-INF/classes", "");
 
         tomcat.start();
         // first test that without the setting on StandardContext the annotated
@@ -276,10 +295,17 @@ public class TestVirtualContext extends 
 
         // then test that if we configure StandardContext with the additional
         // path, the servlet is detected
-        // ctx.setAdditionalVirtualWebInfClasses(additionWebInfClasses.getAbsolutePath());
-        VirtualDirContext resources = new VirtualDirContext();
-        resources.setExtraResourcePaths("/WEB-INF/classes=" + additionWebInfClasses);
-        ctx.setResources(resources);
+        ctx.setResources(new StandardRoot(ctx));
+        ctx.getResources().createWebResourceSet(
+                WebResourceRoot.ResourceSetType.POST, f1.getAbsolutePath(),
+                "/WEB-INF/classes", "");
+        ctx.getResources().createWebResourceSet(
+                WebResourceRoot.ResourceSetType.POST, f2.getAbsolutePath(),
+                "/WEB-INF/classes", "");
+        ctx.getResources().createWebResourceSet(
+                WebResourceRoot.ResourceSetType.POST,
+                additionWebInfClasses.getAbsolutePath(),
+                "/WEB-INF/classes", "");
 
         tomcat.start();
         assertPageContains("/test/annotatedServlet", MyAnnotatedServlet.MESSAGE);

Modified: tomcat/trunk/test/org/apache/catalina/loader/TestVirtualWebappLoader.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/loader/TestVirtualWebappLoader.java?rev=1401503&r1=1401502&r2=1401503&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/loader/TestVirtualWebappLoader.java (original)
+++ tomcat/trunk/test/org/apache/catalina/loader/TestVirtualWebappLoader.java Tue Oct 23 22:38:16 2012
@@ -24,10 +24,11 @@ import static org.junit.Assert.assertNul
 
 import org.junit.Test;
 
+import org.apache.catalina.WebResourceRoot;
 import org.apache.catalina.core.StandardContext;
 import org.apache.catalina.startup.Tomcat;
 import org.apache.catalina.startup.TomcatBaseTest;
-import org.apache.naming.resources.FileDirContext;
+import org.apache.catalina.webresources.StandardRoot;
 
 public class TestVirtualWebappLoader extends TomcatBaseTest {
 
@@ -46,25 +47,31 @@ public class TestVirtualWebappLoader ext
         StandardContext ctx =
             (StandardContext)tomcat.addContext("",  appDir.getAbsolutePath());
 
-        VirtualWebappLoader loader = new VirtualWebappLoader();
+
+        WebappLoader loader = new WebappLoader();
 
         loader.setContext(ctx);
         ctx.setLoader(loader);
-        ctx.setResources(new FileDirContext());
+
+        ctx.setResources(new StandardRoot(ctx));
         ctx.resourcesStart();
-        File dir = new File("test/webapp-3.0-fragments/WEB-INF/lib");
-        loader.setVirtualClasspath(dir.getAbsolutePath() + "/*.jar");
+
+        File f1 = new File("test/webapp-3.0-fragments/WEB-INF/lib");
+        ctx.getResources().createWebResourceSet(
+                WebResourceRoot.ResourceSetType.POST, f1.getAbsolutePath(),
+                "/WEB-INF/lib", "");
+
         loader.start();
-        String[] repos = loader.getRepositories();
+        String[] repos = loader.getLoaderRepositories();
         assertEquals(2,repos.length);
         loader.stop();
         // ToDo: Why doesn't remove repositories?
-        repos = loader.getRepositories();
+        repos = loader.getLoaderRepositories();
         assertEquals(2, repos.length);
 
         // no leak
         loader.start();
-        repos = loader.getRepositories();
+        repos = loader.getLoaderRepositories();
         assertEquals(2,repos.length);
 
         // clear loader

Modified: tomcat/trunk/test/org/apache/catalina/mbeans/TestRegistration.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/mbeans/TestRegistration.java?rev=1401503&r1=1401502&r2=1401503&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/mbeans/TestRegistration.java (original)
+++ tomcat/trunk/test/org/apache/catalina/mbeans/TestRegistration.java Tue Oct 23 22:38:16 2012
@@ -96,7 +96,6 @@ public class TestRegistration extends To
         return new String[] {
             "Tomcat:j2eeType=WebModule,name=//" + host + context +
                 ",J2EEApplication=none,J2EEServer=none",
-            "Tomcat:type=Cache,host=" + host + ",context=" + context,
             "Tomcat:type=Loader,context=" + context + ",host=" + host,
             "Tomcat:type=Manager,context=" + context + ",host=" + host,
             "Tomcat:type=NamingResources,context=" + context +
@@ -107,6 +106,8 @@ public class TestRegistration extends To
                 ",host=" + host + ",name=StandardContextValve",
             "Tomcat:type=WebappClassLoader,context=" + context +
                 ",host=" + host,
+            "Tomcat:type=WebResourceRoot,context=" + context +
+                ",host=" + host,
         };
     }
 

Modified: tomcat/trunk/test/org/apache/catalina/startup/TestContextConfigAnnotation.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/startup/TestContextConfigAnnotation.java?rev=1401503&r1=1401502&r2=1401503&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/startup/TestContextConfigAnnotation.java (original)
+++ tomcat/trunk/test/org/apache/catalina/startup/TestContextConfigAnnotation.java Tue Oct 23 22:38:16 2012
@@ -343,10 +343,6 @@ public class TestContextConfigAnnotation
         public void addPropertyChangeListener(PropertyChangeListener l) {
         }
         @Override
-        public void addRepository(String repository) {}
-        @Override
-        public String[] findRepositories() { return null; }
-        @Override
         public boolean modified() { return false; }
         @Override
         public void removePropertyChangeListener(PropertyChangeListener l) {}

Modified: tomcat/trunk/test/org/apache/jasper/compiler/TestGenerator.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/jasper/compiler/TestGenerator.java?rev=1401503&r1=1401502&r2=1401503&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/jasper/compiler/TestGenerator.java (original)
+++ tomcat/trunk/test/org/apache/jasper/compiler/TestGenerator.java Tue Oct 23 22:38:16 2012
@@ -35,9 +35,11 @@ import static org.junit.Assert.assertTru
 
 import org.junit.Test;
 
+import org.apache.catalina.WebResourceRoot;
 import org.apache.catalina.core.StandardContext;
 import org.apache.catalina.startup.Tomcat;
 import org.apache.catalina.startup.TomcatBaseTest;
+import org.apache.catalina.webresources.StandardRoot;
 import org.apache.tomcat.util.buf.ByteChunk;
 
 public class TestGenerator extends TomcatBaseTest {
@@ -117,7 +119,10 @@ public class TestGenerator extends Tomca
 
         // This test needs the JSTL libraries
         File lib = new File("webapps/examples/WEB-INF/lib");
-        ctxt.setAliases("/WEB-INF/lib=" + lib.getCanonicalPath());
+        ctxt.setResources(new StandardRoot(ctxt));
+        ctxt.getResources().createWebResourceSet(
+                WebResourceRoot.ResourceSetType.POST, lib.getAbsolutePath(),
+                "/WEB-INF/lib", "");
 
         tomcat.start();
 

Modified: tomcat/trunk/test/org/apache/naming/resources/TestNamingContext.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/naming/resources/TestNamingContext.java?rev=1401503&r1=1401502&r2=1401503&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/naming/resources/TestNamingContext.java (original)
+++ tomcat/trunk/test/org/apache/naming/resources/TestNamingContext.java Tue Oct 23 22:38:16 2012
@@ -17,9 +17,7 @@
 package org.apache.naming.resources;
 
 import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.InputStream;
 import java.io.PrintWriter;
 
 import javax.naming.Binding;
@@ -43,7 +41,6 @@ import org.junit.Test;
 import org.apache.catalina.core.StandardContext;
 import org.apache.catalina.deploy.ContextEnvironment;
 import org.apache.catalina.deploy.ContextResource;
-import org.apache.catalina.startup.ExpandWar;
 import org.apache.catalina.startup.Tomcat;
 import org.apache.catalina.startup.TomcatBaseTest;
 import org.apache.tomcat.util.buf.ByteChunk;
@@ -95,137 +92,6 @@ public class TestNamingContext extends T
 
     }
 
-    @Test
-    public void testAliases() throws Exception {
-        // Some sample text
-        String foxText = "The quick brown fox jumps over the lazy dog";
-        String loremIpsum = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
-
-        // Set up a temporary docBase and some alternates that we can
-        // set up as aliases.
-        File tmpDir = new File(getTemporaryDirectory(),
-                               "tomcat-unit-test." + TestNamingContext.class.getName());
-
-        // Make sure we've got a clean slate
-        ExpandWar.delete(tmpDir);
-
-        File docBase = new File(tmpDir, "docBase");
-        File alternate1 = new File(tmpDir, "alternate1");
-        File alternate2 = new File(tmpDir, "alternate2");
-
-        // Register for clean-up
-        addDeleteOnTearDown(tmpDir);
-
-        if(!tmpDir.mkdirs())
-            throw new IOException("Could not create temp directory " + tmpDir);
-        if(!docBase.mkdir())
-            throw new IOException("Could not create temp directory " + docBase);
-        if(!alternate1.mkdir())
-            throw new IOException("Could not create temp directory " + alternate1);
-        if(!alternate2.mkdir())
-            throw new IOException("Could not create temp directory " + alternate2);
-
-        // Create a file in each alternate directory that we can attempt to access
-        FileOutputStream fos = new FileOutputStream(new File(alternate1, "test1.txt"));
-        try {
-            fos.write(foxText.getBytes("UTF-8"));
-            fos.flush();
-        } finally {
-            fos.close();
-        }
-
-        fos = new FileOutputStream(new File(alternate2, "test2.txt"));
-        try {
-            fos.write(loremIpsum.getBytes("UTF-8"));
-            fos.flush();
-        } finally {
-            fos.close();
-        }
-
-        // Finally, create the Context
-        FileDirContext ctx = new FileDirContext();
-        ctx.setDocBase(docBase.getCanonicalPath());
-        ctx.setAliases("/a1=" + alternate1.getCanonicalPath()
-                       +",/a2=" + alternate2.getCanonicalPath());
-
-        // Check first alias
-        Object file = ctx.lookup("/a1/test1.txt");
-
-        Assert.assertNotNull(file);
-        Assert.assertTrue(file instanceof Resource);
-
-        byte[] buffer = new byte[4096];
-        Resource res = (Resource)file;
-
-        InputStream is = res.streamContent();
-        int len;
-        try {
-            len = is.read(buffer);
-        } finally {
-            is.close();
-        }
-        String contents = new String(buffer, 0, len, "UTF-8");
-
-        assertEquals(foxText, contents);
-
-        // Check second alias
-        file = ctx.lookup("/a2/test2.txt");
-
-        Assert.assertNotNull(file);
-        Assert.assertTrue(file instanceof Resource);
-
-        res = (Resource)file;
-        is = res.streamContent();
-        try {
-            len = is.read(buffer);
-        } finally {
-            is.close();
-        }
-        contents = new String(buffer, 0, len, "UTF-8");
-
-        assertEquals(loremIpsum, contents);
-
-        // Test aliases with spaces around the separators
-        ctx.setAliases("   /a1= " + alternate1.getCanonicalPath()
-                       + "\n\n"
-                       +", /a2 =\n" + alternate2.getCanonicalPath()
-                       + ",");
-
-        // Check first alias
-        file = ctx.lookup("/a1/test1.txt");
-
-        Assert.assertNotNull(file);
-        Assert.assertTrue(file instanceof Resource);
-
-        res = (Resource)file;
-        is = res.streamContent();
-        try {
-            len = is.read(buffer);
-        } finally {
-            is.close();
-        }
-        contents = new String(buffer, 0, len, "UTF-8");
-
-        assertEquals(foxText, contents);
-
-        // Check second alias
-        file = ctx.lookup("/a2/test2.txt");
-
-        Assert.assertNotNull(file);
-        Assert.assertTrue(file instanceof Resource);
-
-        res = (Resource)file;
-        is = res.streamContent();
-        try {
-            len = is.read(buffer);
-        } finally {
-            is.close();
-        }
-        contents = new String(buffer, 0, len, "UTF-8");
-
-        assertEquals(loremIpsum, contents);
-    }
-
     public static final class Bug49994Servlet extends HttpServlet {
 
         private static final long serialVersionUID = 1L;

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1401503&r1=1401502&r2=1401503&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Tue Oct 23 22:38:16 2012
@@ -92,6 +92,12 @@
         Service. This removes the need to maintain two copies of the mappings
         for Servlets and Filters. (markt)
       </scode>
+      <add>
+        Implement a new Resources implementation that merges Aliases,
+        VirtualLoader, VirtualDirContext, JAR resources and external
+        repositories into a single framework rather than a separate one for each
+        feature. (markt) 
+      </add>
     </changelog>
   </subsection>
   <subsection name="Coyote">



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


Mime
View raw message