From: markt Date: Fri, 18 Feb 2011 21:44:13 +0000 (+0000) Subject: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=48870 X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=50d53228419ff87a4e2f5f05df928348becd1e6a;p=tomcat7.0 Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=48870 Re-factor to remove parallel arrays. Modify fix for 48863 to remove use of StringManager as it is not available in Bootstrap git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1072160 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/build.xml b/build.xml index a6dd3047a..a620aa20a 100644 --- a/build.xml +++ b/build.xml @@ -259,8 +259,7 @@ - - + diff --git a/java/org/apache/catalina/startup/Bootstrap.java b/java/org/apache/catalina/startup/Bootstrap.java index 770fde63d..6457dcef6 100644 --- a/java/org/apache/catalina/startup/Bootstrap.java +++ b/java/org/apache/catalina/startup/Bootstrap.java @@ -26,6 +26,7 @@ import java.lang.reflect.Method; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; +import java.util.List; import java.util.StringTokenizer; import javax.management.MBeanServer; @@ -34,6 +35,8 @@ import javax.management.ObjectName; import org.apache.catalina.Globals; import org.apache.catalina.security.SecurityClassLoad; +import org.apache.catalina.startup.ClassLoaderFactory.Repository; +import org.apache.catalina.startup.ClassLoaderFactory.RepositoryType; import org.apache.juli.logging.Log; import org.apache.juli.logging.LogFactory; @@ -113,8 +116,7 @@ public final class Bootstrap { if ((value == null) || (value.equals(""))) return parent; - ArrayList repositoryLocations = new ArrayList(); - ArrayList repositoryTypes = new ArrayList(); + List repositories = new ArrayList(); int i; StringTokenizer tokenizer = new StringTokenizer(value, ","); @@ -150,8 +152,8 @@ public final class Bootstrap { // Check for a JAR URL repository try { new URL(repository); - repositoryLocations.add(repository); - repositoryTypes.add(ClassLoaderFactory.IS_URL); + repositories.add( + new Repository(repository, RepositoryType.URL)); continue; } catch (MalformedURLException e) { // Ignore @@ -160,22 +162,19 @@ public final class Bootstrap { if (repository.endsWith("*.jar")) { repository = repository.substring (0, repository.length() - "*.jar".length()); - repositoryLocations.add(repository); - repositoryTypes.add(ClassLoaderFactory.IS_GLOB); + repositories.add( + new Repository(repository, RepositoryType.GLOB)); } else if (repository.endsWith(".jar")) { - repositoryLocations.add(repository); - repositoryTypes.add(ClassLoaderFactory.IS_JAR); + repositories.add( + new Repository(repository, RepositoryType.JAR)); } else { - repositoryLocations.add(repository); - repositoryTypes.add(ClassLoaderFactory.IS_DIR); + repositories.add( + new Repository(repository, RepositoryType.DIR)); } } - String[] locations = repositoryLocations.toArray(new String[0]); - Integer[] types = repositoryTypes.toArray(new Integer[0]); - ClassLoader classLoader = ClassLoaderFactory.createClassLoader - (locations, types, parent); + (repositories, parent); // Retrieving MBean server MBeanServer mBeanServer = null; diff --git a/java/org/apache/catalina/startup/ClassLoaderFactory.java b/java/org/apache/catalina/startup/ClassLoaderFactory.java index e498d3d75..84ed4a21a 100644 --- a/java/org/apache/catalina/startup/ClassLoaderFactory.java +++ b/java/org/apache/catalina/startup/ClassLoaderFactory.java @@ -24,13 +24,13 @@ import java.net.URL; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.LinkedHashSet; +import java.util.List; import java.util.Locale; import java.util.Set; import org.apache.catalina.loader.StandardClassLoader; import org.apache.juli.logging.Log; import org.apache.juli.logging.LogFactory; -import org.apache.tomcat.util.res.StringManager; /** @@ -57,14 +57,6 @@ public final class ClassLoaderFactory { private static final Log log = LogFactory.getLog(ClassLoaderFactory.class); - private static final StringManager sm = - StringManager.getManager(Constants.Package); - - protected static final Integer IS_DIR = Integer.valueOf(0); - protected static final Integer IS_JAR = Integer.valueOf(1); - protected static final Integer IS_GLOB = Integer.valueOf(2); - protected static final Integer IS_URL = Integer.valueOf(3); - // --------------------------------------------------------- Public Methods @@ -159,8 +151,7 @@ public final class ClassLoaderFactory { * * @exception Exception if an error occurs constructing the class loader */ - public static ClassLoader createClassLoader(String locations[], - Integer types[], + public static ClassLoader createClassLoader(List repositories, final ClassLoader parent) throws Exception { @@ -170,16 +161,15 @@ public final class ClassLoaderFactory { // Construct the "class path" for this class loader Set set = new LinkedHashSet(); - if (locations != null && types != null && locations.length == types.length) { - for (int i = 0; i < locations.length; i++) { - String location = locations[i]; - if ( types[i] == IS_URL ) { - URL url = new URL(location); + if (repositories != null) { + for (Repository repository : repositories) { + if (repository.getType() == RepositoryType.URL) { + URL url = new URL(repository.getLocation()); if (log.isDebugEnabled()) log.debug(" Including URL " + url); set.add(url); - } else if ( types[i] == IS_DIR ) { - File directory = new File(location); + } else if (repository.getType() == RepositoryType.DIR) { + File directory = new File(repository.getLocation()); directory = new File(directory.getCanonicalPath()); if (!directory.exists() || !directory.isDirectory() || !directory.canRead()) @@ -188,8 +178,8 @@ public final class ClassLoaderFactory { if (log.isDebugEnabled()) log.debug(" Including directory " + url); set.add(url); - } else if ( types[i] == IS_JAR ) { - File file=new File(location); + } else if (repository.getType() == RepositoryType.JAR) { + File file=new File(repository.getLocation()); file = new File(file.getCanonicalPath()); if (!file.exists() || !file.canRead()) continue; @@ -197,15 +187,15 @@ public final class ClassLoaderFactory { if (log.isDebugEnabled()) log.debug(" Including jar file " + url); set.add(url); - } else if ( types[i] == IS_GLOB ) { - File directory=new File(location); + } else if (repository.getType() == RepositoryType.GLOB) { + File directory=new File(repository.getLocation()); if (!directory.exists() || !directory.isDirectory() || !directory.canRead()) { - log.warn(sm.getString("classLoaderFactory.badDirectory", - directory.getAbsolutePath(), - Boolean.valueOf(directory.exists()), - Boolean.valueOf(directory.isDirectory()), - Boolean.valueOf(directory.canRead()))); + log.warn("Problem with directory [" + + directory.getAbsolutePath() + "], exists: [" + + directory.exists() + "], isDirectory: [" + + directory.isDirectory() + "], canRead: [" + + directory.canRead() + "]"); continue; } if (log.isDebugEnabled()) @@ -250,4 +240,28 @@ public final class ClassLoaderFactory { } + public static enum RepositoryType { + DIR, + GLOB, + JAR, + URL + } + + public static class Repository { + private String location; + private RepositoryType type; + + public Repository(String location, RepositoryType type) { + this.location = location; + this.type = type; + } + + public String getLocation() { + return location; + } + + public RepositoryType getType() { + return type; + } + } } diff --git a/java/org/apache/catalina/startup/LocalStrings.properties b/java/org/apache/catalina/startup/LocalStrings.properties index 3cab506b9..086e06b90 100644 --- a/java/org/apache/catalina/startup/LocalStrings.properties +++ b/java/org/apache/catalina/startup/LocalStrings.properties @@ -16,7 +16,6 @@ catalina.configFail=Unable to load server configuration from [{0}] catalina.shutdownHookFail=The shutdown hook experienced an error while trying to stop the server catalina.stopServer=No shutdown port configured. Shut down server through OS signal. Server not shut down. -classLoaderFactory.badDirectory=Problem with directory [{0}], exists: [{1}], isDirectory: [{2}], canRead: [{4}] contextConfig.altDDNotFound=alt-dd file {0} not found contextConfig.applicationUrl=Unable to determine URL for application web.xml contextConfig.applicationMissing=Missing application web.xml, using defaults only diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index aa4754f7e..2f8cab023 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -49,6 +49,9 @@ 48863: Better logging when specifying an invalid directory for a class loader. Based on a patch by Ralf Hauser. (markt) + + 48870: Refactor to remove use of parallel arrays. (markt) + Enhance the RemoteIpFilter and RemoteIpValve so that the modified remote address, remote host, protocol and server port may be used in an access