tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1763375 - in /tomcat/trunk: build.xml java/org/apache/catalina/webresources/war/WarURLConnection.java java/org/apache/tomcat/util/buf/UriUtil.java java/org/apache/tomcat/util/scan/JarFactory.java
Date Wed, 05 Oct 2016 09:40:55 GMT
Author: markt
Date: Wed Oct  5 09:40:54 2016
New Revision: 1763375

URL: http://svn.apache.org/viewvc?rev=1763375&view=rev
Log:
Add support for using 'war:file:...' URLs to refer to WAR files rather than 'jar:file:...'

Modified:
    tomcat/trunk/build.xml
    tomcat/trunk/java/org/apache/catalina/webresources/war/WarURLConnection.java
    tomcat/trunk/java/org/apache/tomcat/util/buf/UriUtil.java
    tomcat/trunk/java/org/apache/tomcat/util/scan/JarFactory.java

Modified: tomcat/trunk/build.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/build.xml?rev=1763375&r1=1763374&r2=1763375&view=diff
==============================================================================
--- tomcat/trunk/build.xml (original)
+++ tomcat/trunk/build.xml Wed Oct  5 09:40:54 2016
@@ -339,6 +339,7 @@
     <include name="org/apache/catalina/startup/Tool.*" />
     <include name="org/apache/catalina/security/SecurityClassLoad.*" />
     <include name="org/apache/catalina/webresources/war/**" />
+    <include name="org/apache/tomcat/util/buf/UriUtil.*" />
   </patternset>
 
   <patternset id="files.tomcat-juli">

Modified: tomcat/trunk/java/org/apache/catalina/webresources/war/WarURLConnection.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/webresources/war/WarURLConnection.java?rev=1763375&r1=1763374&r2=1763375&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/webresources/war/WarURLConnection.java (original)
+++ tomcat/trunk/java/org/apache/catalina/webresources/war/WarURLConnection.java Wed Oct 
5 09:40:54 2016
@@ -22,6 +22,8 @@ import java.net.URL;
 import java.net.URLConnection;
 import java.security.Permission;
 
+import org.apache.tomcat.util.buf.UriUtil;
+
 
 public class WarURLConnection extends URLConnection {
 
@@ -30,18 +32,7 @@ public class WarURLConnection extends UR
 
     protected WarURLConnection(URL url) throws IOException {
         super(url);
-
-        // Need to make this look like a JAR URL for the WAR file
-        // Assumes that the spec is absolute and starts war:file:/...
-        String file = url.getFile();
-        if (file.contains("*/")) {
-            file = file.replaceFirst("\\*/", "!/");
-        } else {
-            file = file.replaceFirst("\\^/", "!/");
-        }
-
-        URL innerJarUrl = new URL("jar", url.getHost(), url.getPort(), file);
-
+        URL innerJarUrl = UriUtil.warToJar(url);
         wrappedJarUrlConnection = innerJarUrl.openConnection();
     }
 

Modified: tomcat/trunk/java/org/apache/tomcat/util/buf/UriUtil.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/buf/UriUtil.java?rev=1763375&r1=1763374&r2=1763375&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/buf/UriUtil.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/buf/UriUtil.java Wed Oct  5 09:40:54 2016
@@ -128,4 +128,27 @@ public final class UriUtil {
         tmp = PATTERN_CARET.matcher(tmp).replaceAll("%5e/");
         return PATTERN_ASTERISK.matcher(tmp).replaceAll("%2a/");
     }
+
+
+    /**
+     * Convert a URL of the form <code>war:file:...</code> to
+     * <code>war:file:...</code>.
+     *
+     * @param warUrl The WAR URL to convert
+     *
+     * @return The equivalent JAR URL
+     *
+     * @throws MalformedURLException If the conversion fails
+     */
+    public static URL warToJar(URL warUrl) throws MalformedURLException {
+        // Assumes that the spec is absolute and starts war:file:/...
+        String file = warUrl.getFile();
+        if (file.contains("*/")) {
+            file = file.replaceFirst("\\*/", "!/");
+        } else {
+            file = file.replaceFirst("\\^/", "!/");
+        }
+
+        return new URL("jar", warUrl.getHost(), warUrl.getPort(), file);
+    }
 }

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=1763375&r1=1763374&r2=1763375&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/scan/JarFactory.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/scan/JarFactory.java Wed Oct  5 09:40:54 2016
@@ -21,6 +21,7 @@ import java.net.MalformedURLException;
 import java.net.URL;
 
 import org.apache.tomcat.Jar;
+import org.apache.tomcat.util.buf.UriUtil;
 
 /**
  * Provide a mechanism to obtain objects that implement {@link Jar}.
@@ -31,21 +32,26 @@ public class JarFactory {
         // Factory class. Hide public constructor.
     }
 
+
     public static Jar newInstance(URL url) throws IOException {
-        String jarUrl = url.toString();
-        if (jarUrl.startsWith("jar:file:")) {
-            if (jarUrl.endsWith("!/")) {
+        String urlString = url.toString();
+        if (urlString.startsWith("jar:file:")) {
+            if (urlString.endsWith("!/")) {
                 return new JarFileUrlJar(url, true);
             } else {
                 return new JarFileUrlNestedJar(url);
             }
-        } else if (jarUrl.startsWith("file:")) {
+        } else if (urlString.startsWith("war:file:")) {
+            URL jarUrl = UriUtil.warToJar(url);
+            return new JarFileUrlNestedJar(jarUrl);
+        } else if (urlString.startsWith("file:")) {
             return new JarFileUrlJar(url, false);
         } else {
             return new UrlJar(url);
         }
     }
 
+
     public static URL getJarEntryURL(URL baseUrl, String entryName)
             throws MalformedURLException {
 



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


Mime
View raw message