Apply Konstantin's new patch for https://issues.apache.org/bugzilla/show_bug.cgi...
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Sat, 15 Aug 2009 12:07:42 +0000 (12:07 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Sat, 15 Aug 2009 12:07:42 +0000 (12:07 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@804462 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/loader/LocalStrings.properties
java/org/apache/catalina/loader/WebappLoader.java

index 1bc1b17..37ed504 100644 (file)
@@ -49,3 +49,5 @@ webappLoader.removeRepository=Removing repository {0}
 webappLoader.starting=Starting this Loader
 webappLoader.stopping=Stopping this Loader
 webappLoader.failModifiedCheck=Error tracking modifications
+webappLoader.copyFailure=Failed to copy resources
+webappLoader.namingFailure=Failed to access resource {0}
index 96fced9..4b3b179 100644 (file)
@@ -40,7 +40,6 @@ import java.util.jar.JarFile;
 import javax.management.MBeanRegistration;
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
-import javax.naming.Binding;
 import javax.naming.NameClassPair;
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
@@ -870,8 +869,9 @@ public class WebappLoader
     /**
      * Configure the repositories for our class loader, based on the
      * associated Context.
+     * @throws IOException 
      */
-    private void setRepositories() {
+    private void setRepositories() throws IOException {
 
         if (!(container instanceof Context))
             return;
@@ -925,7 +925,10 @@ public class WebappLoader
 
                 classRepository = new File(workDir, classesPath);
                 classRepository.mkdirs();
-                copyDir(classes, classRepository);
+                if (!copyDir(classes, classRepository)) {
+                    throw new IOException(
+                            sm.getString("webappLoader.copyFailure"));
+                }
 
             }
 
@@ -973,59 +976,69 @@ public class WebappLoader
             }
 
             // Looking up directory /WEB-INF/lib in the context
+            NamingEnumeration<NameClassPair> enumeration = null;
             try {
-                NamingEnumeration<Binding> enumeration =
-                    resources.listBindings(libPath);
-                while (enumeration.hasMoreElements()) {
-
-                    Binding binding = enumeration.nextElement();
-                    String filename = libPath + "/" + binding.getName();
-                    if (!filename.endsWith(".jar"))
-                        continue;
+                enumeration = libDir.list("");
+            } catch (NamingException e) {
+                IOException ioe = new IOException(sm.getString(
+                        "webappLoader.namingFailure", libPath));
+                ioe.initCause(e);
+                throw ioe;
+            }
+            while (enumeration.hasMoreElements()) {
+                NameClassPair ncPair = enumeration.nextElement();
+                String filename = libPath + "/" + ncPair.getName();
+                if (!filename.endsWith(".jar"))
+                    continue;
 
-                    // Copy JAR in the work directory, always (the JAR file
-                    // would get locked otherwise, which would make it
-                    // impossible to update it or remove it at runtime)
-                    File destFile = new File(destDir, binding.getName());
+                // Copy JAR in the work directory, always (the JAR file
+                // would get locked otherwise, which would make it
+                // impossible to update it or remove it at runtime)
+                File destFile = new File(destDir, ncPair.getName());
 
-                    if( log.isDebugEnabled())
-                    log.debug(sm.getString("webappLoader.jarDeploy", filename,
-                                     destFile.getAbsolutePath()));
+                if( log.isDebugEnabled())
+                log.debug(sm.getString("webappLoader.jarDeploy", filename,
+                                 destFile.getAbsolutePath()));
 
-                    Object obj = binding.getObject();
-                    
-                    if (!(obj instanceof Resource))
-                        continue;
+                // Bug 45403 - Explicitly call lookup() on the name to check
+                // that the resource is readable. We cannot use resources
+                // returned by listBindings(), because that lists all of them,
+                // but does not perform the necessary checks on each.
+                Object obj = null;
+                try {
+                    obj = libDir.lookup(ncPair.getName());
+                } catch (NamingException e) {
+                    IOException ioe = new IOException(sm.getString(
+                            "webappLoader.namingFailure", filename));
+                    ioe.initCause(e);
+                    throw ioe;
+                }
+                
+                if (!(obj instanceof Resource))
+                    continue;
                     
-                    Resource jarResource = (Resource) obj;
+                Resource jarResource = (Resource) obj;
                     
-                    if (copyJars) {
-                        if (!copy(jarResource.streamContent(),
-                                  new FileOutputStream(destFile)))
-                            continue;
+                if (copyJars) {
+                    if (!copy(jarResource.streamContent(),
+                              new FileOutputStream(destFile))) {
+                        throw new IOException(
+                                sm.getString("webappLoader.copyFailure"));
                     }
+                }
 
-                    try {
-                        JarFile jarFile = new JarFile(destFile);
-                        classLoader.addJar(filename, jarFile, destFile);
-                    } catch (Exception ex) {
-                        // Catch the exception if there is an empty jar file
-                        // Should ignore and continute loading other jar files 
-                        // in the dir
-                    }
-                    
-                    loaderRepositories.add( filename );
-
+                try {
+                    JarFile jarFile = new JarFile(destFile);
+                    classLoader.addJar(filename, jarFile, destFile);
+                } catch (Exception ex) {
+                    // Catch the exception if there is an empty jar file
+                    // Should ignore and continue loading other jar files 
+                    // in the dir
                 }
-            } catch (NamingException e) {
-                // Silent catch: it's valid that no /WEB-INF/lib directory
-                // exists
-            } catch (IOException e) {
-                e.printStackTrace();
+                    
+                loaderRepositories.add( filename );
             }
-
         }
-
     }