From dev-return-203801-archive-asf-public=cust-asf.ponee.io@tomcat.apache.org Tue Nov 26 18:49:34 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id 4AAE818065D for ; Tue, 26 Nov 2019 19:49:34 +0100 (CET) Received: (qmail 80137 invoked by uid 500); 26 Nov 2019 18:49:33 -0000 Mailing-List: contact dev-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Developers List" Delivered-To: mailing list dev@tomcat.apache.org Received: (qmail 80126 invoked by uid 99); 26 Nov 2019 18:49:33 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 26 Nov 2019 18:49:33 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 8A9C48B690; Tue, 26 Nov 2019 18:49:32 +0000 (UTC) Date: Tue, 26 Nov 2019 18:49:32 +0000 To: "dev@tomcat.apache.org" Subject: [tomcat] branch master updated: Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=63964 Cached URLs MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <157479417229.28422.5001279427733953982@gitbox.apache.org> From: markt@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: tomcat X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: d760a78dda02772eeb2949cc756b8f3aa8e2c327 X-Git-Newrev: cd47ca9b7de1c048466e7e5c2c9bb59d04771249 X-Git-Rev: cd47ca9b7de1c048466e7e5c2c9bb59d04771249 X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated 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 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). -->
+ + + + 63964: 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) + + + --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org For additional commands, e-mail: dev-help@tomcat.apache.org