tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1526724 - in /tomcat/trunk/java/org/apache: jasper/servlet/ tomcat/util/descriptor/tld/ tomcat/util/scan/
Date Thu, 26 Sep 2013 22:09:59 GMT
Author: markt
Date: Thu Sep 26 22:09:58 2013
New Revision: 1526724

URL: http://svn.apache.org/r1526724
Log:
Fix regression caused by a combination of the TLD refactoring and the new resources implementation.
TLDs in JARs in packed WARs were not accessible. There were two parts to the fix:
- In TldScanner ensure that that the correct URL for the JAR containing the TLD was used
- In TldResourcePath ensure that the correct URL to the TLD was constructed from the JAR URL
and the path to the resource within the JAR

Modified:
    tomcat/trunk/java/org/apache/jasper/servlet/TldScanner.java
    tomcat/trunk/java/org/apache/tomcat/util/descriptor/tld/TldResourcePath.java
    tomcat/trunk/java/org/apache/tomcat/util/scan/FileUrlJar.java
    tomcat/trunk/java/org/apache/tomcat/util/scan/FileUrlNestedJar.java
    tomcat/trunk/java/org/apache/tomcat/util/scan/Jar.java
    tomcat/trunk/java/org/apache/tomcat/util/scan/JarFactory.java
    tomcat/trunk/java/org/apache/tomcat/util/scan/UrlJar.java

Modified: tomcat/trunk/java/org/apache/jasper/servlet/TldScanner.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/servlet/TldScanner.java?rev=1526724&r1=1526723&r2=1526724&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/jasper/servlet/TldScanner.java (original)
+++ tomcat/trunk/java/org/apache/jasper/servlet/TldScanner.java Thu Sep 26 22:09:58 2013
@@ -242,7 +242,7 @@ public class TldScanner {
             }
             boolean found = false;
             Jar jar = JarFactory.newInstance(urlConn.getURL());
-            URL jarURL = urlConn.getJarFileURL();
+            URL jarURL = jar.getJarFileURL();
             try {
                 jar.nextEntry();
                 for (String entryName = jar.getEntryName();

Modified: tomcat/trunk/java/org/apache/tomcat/util/descriptor/tld/TldResourcePath.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/descriptor/tld/TldResourcePath.java?rev=1526724&r1=1526723&r2=1526724&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/descriptor/tld/TldResourcePath.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/descriptor/tld/TldResourcePath.java Thu Sep 26
22:09:58 2013
@@ -21,6 +21,8 @@ import java.io.InputStream;
 import java.net.URL;
 import java.util.Objects;
 
+import org.apache.tomcat.util.scan.JarFactory;
+
 /**
  * A TLD Resource Path as defined in JSP 7.3.2.
  * <p/>
@@ -104,8 +106,7 @@ public class TldResourcePath {
         if (entryName == null) {
             return url.openStream();
         } else {
-            // TODO: should this use the JarFactory abstraction?
-            URL entryUrl = new URL("jar:" + url.toExternalForm() + "!/" + entryName);
+            URL entryUrl = JarFactory.getJarEntryURL(url, entryName);
             return entryUrl.openStream();
         }
     }

Modified: tomcat/trunk/java/org/apache/tomcat/util/scan/FileUrlJar.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/scan/FileUrlJar.java?rev=1526724&r1=1526723&r2=1526724&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/scan/FileUrlJar.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/scan/FileUrlJar.java Thu Sep 26 22:09:58 2013
@@ -32,6 +32,7 @@ import java.util.zip.ZipEntry;
 public class FileUrlJar implements Jar {
 
     private final JarFile jarFile;
+    private final URL jarFileURL;
     private Enumeration<JarEntry> entries;
     private JarEntry entry = null;
 
@@ -39,8 +40,16 @@ public class FileUrlJar implements Jar {
         JarURLConnection jarConn = (JarURLConnection) url.openConnection();
         jarConn.setUseCaches(false);
         jarFile = jarConn.getJarFile();
+        jarFileURL = jarConn.getJarFileURL();
     }
 
+
+    @Override
+    public URL getJarFileURL() {
+        return jarFileURL;
+    }
+
+
     @Override
     public boolean entryExists(String name) {
         ZipEntry entry = jarFile.getEntry(name);

Modified: tomcat/trunk/java/org/apache/tomcat/util/scan/FileUrlNestedJar.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/scan/FileUrlNestedJar.java?rev=1526724&r1=1526723&r2=1526724&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/scan/FileUrlNestedJar.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/scan/FileUrlNestedJar.java Thu Sep 26 22:09:58
2013
@@ -31,12 +31,14 @@ import java.util.jar.JarFile;
  */
 public class FileUrlNestedJar implements Jar {
 
+    private final URL jarFileURL;
     private final JarFile warFile;
     private final JarEntry jarEntry;
     private NonClosingJarInputStream jarInputStream = null;
     private JarEntry entry = null;
 
     public FileUrlNestedJar(URL url) throws IOException {
+        jarFileURL = url;
         JarURLConnection jarConn = (JarURLConnection) url.openConnection();
         jarConn.setUseCaches(false);
         warFile = jarConn.getJarFile();
@@ -51,6 +53,13 @@ public class FileUrlNestedJar implements
 
 
     @Override
+    public URL getJarFileURL() {
+        return jarFileURL;
+    }
+
+
+
+    @Override
     public boolean entryExists(String name) throws IOException {
         JarEntry entry = jarInputStream.getNextJarEntry();
         while (entry != null) {

Modified: tomcat/trunk/java/org/apache/tomcat/util/scan/Jar.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/scan/Jar.java?rev=1526724&r1=1526723&r2=1526724&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/scan/Jar.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/scan/Jar.java Thu Sep 26 22:09:58 2013
@@ -18,6 +18,7 @@ package org.apache.tomcat.util.scan;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.URL;
 
 /**
  * Provides an abstraction for use by the various classes that need to scan
@@ -31,6 +32,11 @@ import java.io.InputStream;
 public interface Jar {
 
     /**
+     * Obtain the URL for accessing the JAR file.
+     */
+    URL getJarFileURL();
+
+    /**
      * Determines if a specific entry exists within the JAR.
      *
      * @param name  Entry to look for

Modified: tomcat/trunk/java/org/apache/tomcat/util/scan/JarFactory.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/scan/JarFactory.java?rev=1526724&r1=1526723&r2=1526724&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/scan/JarFactory.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/scan/JarFactory.java Thu Sep 26 22:09:58 2013
@@ -17,6 +17,7 @@
 package org.apache.tomcat.util.scan;
 
 import java.io.IOException;
+import java.net.MalformedURLException;
 import java.net.URL;
 
 /**
@@ -40,4 +41,19 @@ public class JarFactory {
             return new UrlJar(url);
         }
     }
+
+    public static URL getJarEntryURL(URL baseUrl, String entryName)
+            throws MalformedURLException {
+
+        String baseExternal = baseUrl.toExternalForm();
+
+        if (baseExternal.startsWith("jar")) {
+            // Assume this is pointing to a JAR file within a WAR. Java doesn't
+            // support jar:jar:file:... so switch to Tomcat's war:file:...
+            baseExternal = baseExternal.replaceFirst("^jar:", "war:");
+            baseExternal = baseExternal.replaceFirst("!/", "^/");
+        }
+
+        return new URL("jar:" + baseExternal + "!/" + entryName);
+    }
 }

Modified: tomcat/trunk/java/org/apache/tomcat/util/scan/UrlJar.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/scan/UrlJar.java?rev=1526724&r1=1526723&r2=1526724&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/scan/UrlJar.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/scan/UrlJar.java Thu Sep 26 22:09:58 2013
@@ -39,6 +39,11 @@ public class UrlJar implements Jar {
     }
 
     @Override
+    public URL getJarFileURL() {
+        return url;
+    }
+
+    @Override
     public boolean entryExists(String name) throws IOException {
         JarEntry entry = jarInputStream.getNextJarEntry();
         while (entry != null) {



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message