Author: markt Date: Sat Aug 15 12:07:42 2009 New Revision: 804462 URL: http://svn.apache.org/viewvc?rev=804462&view=rev Log: Apply Konstantin's new patch for https://issues.apache.org/bugzilla/show_bug.cgi?id=45403
Modified: tomcat/trunk/java/org/apache/catalina/loader/LocalStrings.properties tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java Modified: tomcat/trunk/java/org/apache/catalina/loader/LocalStrings.properties URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/loader/LocalStrings.properties?rev=804462&r1=804461&r2=804462&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/loader/LocalStrings.properties (original) +++ tomcat/trunk/java/org/apache/catalina/loader/LocalStrings.properties Sat Aug 15 12:07:42 2009 @@ -49,3 +49,5 @@ 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} Modified: tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java?rev=804462&r1=804461&r2=804462&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java (original) +++ tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java Sat Aug 15 12:07:42 2009 @@ -40,7 +40,6 @@ 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 @@ /** * 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 @@ 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 @@ } // 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; - - // 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()); - - if( log.isDebugEnabled()) - log.debug(sm.getString("webappLoader.jarDeploy", filename, - destFile.getAbsolutePath())); + 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; - Object obj = binding.getObject(); - - if (!(obj instanceof Resource)) - 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, ncPair.getName()); + + if( log.isDebugEnabled()) + log.debug(sm.getString("webappLoader.jarDeploy", filename, + destFile.getAbsolutePath())); + + // 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 ); } - } - } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org