From: markt Date: Sat, 15 May 2010 22:52:18 +0000 (+0000) Subject: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=49290 X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=b4a3e8c214f5d38536a8df53fda7a21227483100;p=tomcat7.0 Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=49290 Allow Tomcat to start when using a JarScanner with scanAllDirectories=true Patch by Larry Issacs (with minor tweaks) git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@944739 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/catalina/startup/ContextConfig.java b/java/org/apache/catalina/startup/ContextConfig.java index 2e2b9cae4..9419734d3 100644 --- a/java/org/apache/catalina/startup/ContextConfig.java +++ b/java/org/apache/catalina/startup/ContextConfig.java @@ -107,6 +107,9 @@ public class ContextConfig implements LifecycleListener { private static final Log log = LogFactory.getLog( ContextConfig.class ); + + private static final String SCI_LOCATION = + "META-INF/services/javax.servlet.ServletContainerInitializer"; // ----------------------------------------------------- Instance Variables @@ -1293,23 +1296,32 @@ public class ContextConfig Set fragments) { for (WebXml fragment : fragments) { - URL jarUrl = fragment.getURL(); + URL url = fragment.getURL(); JarFile jarFile = null; InputStream is = null; ServletContainerInitializer sci = null; try { - JarURLConnection conn = - (JarURLConnection) jarUrl.openConnection(); - jarFile = conn.getJarFile(); - ZipEntry entry = jarFile.getEntry( - "META-INF/services/javax.servlet.ServletContainerInitializer"); - if (entry != null) { - is = jarFile.getInputStream(entry); + if ("jar".equals(url.getProtocol())) { + JarURLConnection conn = + (JarURLConnection) url.openConnection(); + jarFile = conn.getJarFile(); + ZipEntry entry = jarFile.getEntry(SCI_LOCATION); + if (entry != null) { + is = jarFile.getInputStream(entry); + } + } else if ("file".equals(url.getProtocol())) { + String path = url.getPath(); + File file = new File(path, SCI_LOCATION); + if (file.exists()) { + is = new FileInputStream(file); + } + } + if (is != null) { sci = getServletContainerInitializer(is); } } catch (IOException ioe) { log.error(sm.getString( - "contextConfig.servletContainerInitializerFail", jarUrl, + "contextConfig.servletContainerInitializerFail", url, context.getPath())); return false; } finally { @@ -1412,18 +1424,21 @@ public class ContextConfig */ protected void processResourceJARs(Set fragments) { for (WebXml fragment : fragments) { - URL jarUrl = fragment.getURL(); + URL url = fragment.getURL(); JarFile jarFile = null; try { - JarURLConnection conn = - (JarURLConnection) jarUrl.openConnection(); - jarFile = conn.getJarFile(); - ZipEntry entry = jarFile.getEntry("META-INF/resources/"); - if (entry != null) { - context.addResourceJarUrl(jarUrl); + // Note: Ignore file URLs for now since only jar URLs will be accepted + if ("jar".equals(url.getProtocol())) { + JarURLConnection conn = + (JarURLConnection) url.openConnection(); + jarFile = conn.getJarFile(); + ZipEntry entry = jarFile.getEntry("META-INF/resources/"); + if (entry != null) { + context.addResourceJarUrl(url); + } } } catch (IOException ioe) { - log.error(sm.getString("contextConfig.resourceJarFail", jarUrl, + log.error(sm.getString("contextConfig.resourceJarFail", url, context.getPath())); } finally { if (jarFile != null) {