Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=49290
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Sat, 15 May 2010 22:52:18 +0000 (22:52 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Sat, 15 May 2010 22:52:18 +0000 (22:52 +0000)
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

java/org/apache/catalina/startup/ContextConfig.java

index 2e2b9ca..9419734 100644 (file)
@@ -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<WebXml> 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<WebXml> 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) {