You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2019/11/26 18:49:32 UTC

[tomcat] branch master updated: Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=63964 Cached URLs

This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/master by this push:
     new cd47ca9  Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=63964 Cached URLs
cd47ca9 is described below

commit cd47ca9b7de1c048466e7e5c2c9bb59d04771249
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Tue Nov 26 18:49:07 2019 +0000

    Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=63964 Cached URLs
    
    Correct a regression in the static resource caching changes introduced
    to fix an issue with Jasper not showing updated JSOP files. URLs
    constructed from URLs obtained from the cache could not be used to
    access resources.
---
 .../catalina/webresources/CachedResource.java      | 12 ++++-
 .../catalina/webresources/TestCachedResource.java  | 52 ++++++++++++++++++++++
 webapps/docs/changelog.xml                         |  9 ++++
 3 files changed, 72 insertions(+), 1 deletion(-)

diff --git a/java/org/apache/catalina/webresources/CachedResource.java b/java/org/apache/catalina/webresources/CachedResource.java
index b1caf07..6b3e615 100644
--- a/java/org/apache/catalina/webresources/CachedResource.java
+++ b/java/org/apache/catalina/webresources/CachedResource.java
@@ -423,7 +423,17 @@ public class CachedResource implements WebResource {
 
         @Override
         protected URLConnection openConnection(URL u) throws IOException {
-            return new CachedResourceURLConnection(resourceURL, root, webAppPath, usesClassLoaderResources);
+            // This deliberately uses ==. If u isn't the URL object this
+            // URLStreamHandler was constructed for we do not want to use this
+            // URLStreamHandler to create a connection.
+            if (u == resourceURL) {
+                return new CachedResourceURLConnection(resourceURL, root, webAppPath, usesClassLoaderResources);
+            } else {
+                // The stream handler has been inherited by a URL that was
+                // constructed from a cache URL. We need to break that link.
+                URL constructedURL = new URL(u.toExternalForm());
+                return constructedURL.openConnection();
+            }
         }
     }
 
diff --git a/test/org/apache/catalina/webresources/TestCachedResource.java b/test/org/apache/catalina/webresources/TestCachedResource.java
new file mode 100644
index 0000000..e75819b
--- /dev/null
+++ b/test/org/apache/catalina/webresources/TestCachedResource.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.catalina.webresources;
+
+import java.io.File;
+import java.io.InputStream;
+import java.net.URL;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.catalina.Context;
+import org.apache.catalina.WebResourceRoot;
+import org.apache.catalina.startup.Tomcat;
+import org.apache.catalina.startup.TomcatBaseTest;
+
+public class TestCachedResource extends TomcatBaseTest {
+
+    // https://bz.apache.org/bugzilla/show_bug.cgi?id=63872
+    @Test
+    public void testUrlFileFromDirectory() throws Exception {
+
+        Tomcat tomcat = getTomcatInstance();
+        File docBase = new File("test/webresources/dir1");
+        Context ctx = tomcat.addWebapp("/test", docBase.getAbsolutePath());
+        tomcat.start();
+
+        WebResourceRoot root = ctx.getResources();
+
+        URL d1 = root.getResource("/d1").getURL();
+
+        URL d1f1 = new URL(d1, "d1-f1.txt");
+
+        try (InputStream is = d1f1.openStream()) {
+            Assert.assertNotNull(is);
+        }
+    }
+}
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index f1ece42..2375a3a 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -45,6 +45,15 @@
   issues do not "pop up" wrt. others).
 -->
 <section name="Tomcat 9.0.30 (markt)" rtext="in development">
+  <subsection name="Catalina">
+    <changelog>
+      <fix>
+        <bug>63964</bug>: Correct a regression in the static resource caching
+        changes introduced in 9.0.28. URLs constructed from URLs obtained from
+        the cache could not be used to access resources. (markt)
+      </fix>
+    </changelog>
+  </subsection>
   <subsection name="Coyote">
     <changelog>
       <fix>


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