Author: markt
Date: Mon Oct 3 15:57:07 2016
New Revision: 1763179
URL: http://svn.apache.org/viewvc?rev=1763179&view=rev
Log:
Further preparation for fixing BZ 60087.
With the war->jar conversion taking place in the WarURLStreamHandler, a URL
constructed from a String would have an external form that was not that same as
the original String.
Resolve this by moving the conversion of the war URL to a jar URL to the
WarURLConnection and add some unit tests to confirm the behavior is now as
expected.
Modified:
tomcat/trunk/java/org/apache/catalina/webresources/WarURLConnection.java
tomcat/trunk/java/org/apache/catalina/webresources/WarURLStreamHandler.java
tomcat/trunk/test/org/apache/catalina/webresources/TestWarURLStreamHandler.java
Modified:
tomcat/trunk/java/org/apache/catalina/webresources/WarURLConnection.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/webresources/WarURLConnection.java?rev=1763179&r1=1763178&r2=1763179&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/webresources/WarURLConnection.java
(original)
+++ tomcat/trunk/java/org/apache/catalina/webresources/WarURLConnection.java
Mon Oct 3 15:57:07 2016
@@ -25,31 +25,45 @@ import java.security.Permission;
public class WarURLConnection extends URLConnection {
- private final URLConnection innerJarUrlConnection;
+ private final URLConnection wrappedJarUrlConnection;
private boolean connected;
protected WarURLConnection(URL url) throws IOException {
super(url);
- URL innerJarUrl = new URL(url.getFile());
- innerJarUrlConnection = innerJarUrl.openConnection();
+
+ // 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);
+
+ wrappedJarUrlConnection = innerJarUrl.openConnection();
}
+
@Override
public void connect() throws IOException {
if (!connected) {
- innerJarUrlConnection.connect();
+ wrappedJarUrlConnection.connect();
connected = true;
}
}
+
@Override
public InputStream getInputStream() throws IOException {
connect();
- return innerJarUrlConnection.getInputStream();
+ return wrappedJarUrlConnection.getInputStream();
}
+
@Override
public Permission getPermission() throws IOException {
- return innerJarUrlConnection.getPermission();
+ return wrappedJarUrlConnection.getPermission();
}
}
Modified:
tomcat/trunk/java/org/apache/catalina/webresources/WarURLStreamHandler.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/webresources/WarURLStreamHandler.java?rev=1763179&r1=1763178&r2=1763179&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/webresources/WarURLStreamHandler.java
(original)
+++ tomcat/trunk/java/org/apache/catalina/webresources/WarURLStreamHandler.java
Mon Oct 3 15:57:07 2016
@@ -24,23 +24,6 @@ import java.net.URLStreamHandler;
public class WarURLStreamHandler extends URLStreamHandler {
@Override
- protected void parseURL(URL u, String spec, int start, int limit) {
- // Need to make this look like a JAR URL for the WAR file
- // Assumes that the spec is absolute and starts war:file:/...
-
- // Only the path needs to be changed
- String path = "jar:" + spec.substring(4);
- if (path.contains("*/")) {
- path = path.replaceFirst("\\*/", "!/");
- } else {
- path = path.replaceFirst("\\^/", "!/");
- }
-
- setURL(u, u.getProtocol(), "", -1, null, null,
- path, null, null);
- }
-
- @Override
protected URLConnection openConnection(URL u) throws IOException {
return new WarURLConnection(u);
}
Modified:
tomcat/trunk/test/org/apache/catalina/webresources/TestWarURLStreamHandler.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/webresources/TestWarURLStreamHandler.java?rev=1763179&r1=1763178&r2=1763179&view=diff
==============================================================================
---
tomcat/trunk/test/org/apache/catalina/webresources/TestWarURLStreamHandler.java
(original)
+++
tomcat/trunk/test/org/apache/catalina/webresources/TestWarURLStreamHandler.java
Mon Oct 3 15:57:07 2016
@@ -33,6 +33,35 @@ public class TestWarURLStreamHandler {
@Test
+ public void testUrlFileInJarInWar() throws Exception {
+ doTestUrl("jar:war:",
"*/WEB-INF/lib/test.jar!/META-INF/resources/index.html");
+ }
+
+
+ @Test
+ public void testUrlJarInWar() throws Exception {
+ doTestUrl("war:", "*/WEB-INF/lib/test.jar");
+ }
+
+
+ @Test
+ public void testUrlWar() throws Exception {
+ doTestUrl("", "");
+ }
+
+
+ private void doTestUrl(String prefix, String suffix) throws Exception {
+ File f = new File("test/webresources/war-url-connection.war");
+ String fileUrl = f.toURI().toURL().toString();
+
+ String urlString = prefix + fileUrl + suffix;
+ URL url = new URL(urlString);
+
+ Assert.assertEquals(urlString, url.toExternalForm());
+ }
+
+
+ @Test
public void testOldFormat() throws Exception {
File f = new File("test/webresources/war-url-connection.war");
String fileUrl = f.toURI().toURL().toString();
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]