From 6c7289b8221e30558c4ed40f6a8205bfaf322ac6 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Tue, 5 Jun 2018 17:00:52 -0700 Subject: [PATCH] Allow META-INF/resources in WAR classes folder Update `TomcatResources` so that `META-INF/resources` folders in `src/main/resources` no longer fail with a "URI is not hierarchical" exception. Closes gh-13265 --- .../resources/META-INF/resources/favicon.ico | Bin 0 -> 2862 bytes .../embedded/tomcat/TomcatResources.java | 3 ++ .../embedded/tomcat/TomcatResourcesTests.java | 45 ++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 spring-boot-samples/spring-boot-sample-tomcat-jsp/src/main/resources/META-INF/resources/favicon.ico create mode 100644 spring-boot/src/test/java/org/springframework/boot/context/embedded/tomcat/TomcatResourcesTests.java diff --git a/spring-boot-samples/spring-boot-sample-tomcat-jsp/src/main/resources/META-INF/resources/favicon.ico b/spring-boot-samples/spring-boot-sample-tomcat-jsp/src/main/resources/META-INF/resources/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..fd306001dc2f8a4c1837118dd6f2c102b48e912b GIT binary patch literal 2862 zcmeHJeN2;Q5I@St070P&Dih>|O`JMFswf|J6A_&P3OcqSVZq6VI1sxD3)9NLb`5o? z)zs-0qeYoAB?8K7QN~I@WQvnbqE(xSSh3O0;KEm2Z}+|wWV*Px?7!{O-+On@J-_Fk z`!#u604uNt7Z(@uHZau+AQ*shpxhoZYypyKZ7}zS3>$zZJAkR|9)dT4wpumz8&_aEEJs?}B2U-HOBuER^0?q;l-CsRj$wscrYvt-9fnY8nZ1mPs$3p))I@;Uv>#eacwjc>LU&6%lq9ly{Gm?j4u+~w80aVjt!6c- zGI>yyZwDrA6tpPZiPr=j71N+cpHJKpFtn$Ec!?dD&HJG|+a21KJSa~X4K=IzU}}no zCWQ~xO2FJE24ib7=*#@Us1ee+d=N$Opr>5~hPo)wmUvOm63~dfz@UuMph$M4dkdj;p9h!?V!DTtxM`q@9}ODn+oIq@VT2>}=yIuVEEpXSoMuT}k zN@pa{8SIQf&?2QCHNn)c7+REG)Tagp^kR_4lOE<+UnV>D?L93E@oNfvb z$FjXt(57?*4X0HC@8s4J$s7khz;W;B~MP(kzb(0AXX%Y=5CNl)|qZ~q+yBy%Q>usM?G z3{TcFJY(n?;~5>7XR!qG33+n^a#lv>4B5)afXK~R6Nc2v_Q;9Md3DMNo1PQ9Bvr&D z`}#6leHkWoW~^g`12fNwadKi9rv(lXjvtR2GnsjhVb(Lu>+g1&0;V4ozRuyEZ%tC!yy=jRsY7wqHn zcD&nL&Qa6IqMV(_jvfEftoPm5*xDv0=FVOtT*Z^T>Afs%>Bhxd7H{-lIx$o7@4jcf zhopGM7tMEMRB_IlBP*TpMW9;ltdT4j#T-p?X*m6XE7lOc8v!;ST34sKqMGtySn^}Z zE)D9;agXcQyWw-O;i)>CXS<;~i@13c@nVTDHgEF4=B-{7`}{42_Oe`-^HcF;EL+P* z`c1&Kq3~SfEwsg>S#E{1KydzmYq$OWv}Hj=wg>qv>26VFj8_&c-v6G2EW! z-JW>Aei7b26@i8`k@&DF1|ObVhV*-g^+kXe_e|h=-uoe%^FQty$E~xqOM5-g+*yGS zo8!<>7matd%ka^~1blQU5g# z&BRA-sd(p9FkU}67TcA8H%iCjt>e@2w<{v-y^)W-x?JqNy5R}GH3|E#rD5OoEbP1a z3HIr?;J~dS?C+4{!0qi8?7;rpU(mV?`)?I;pvxi)!&crOp}?q)=T1hH!yqH!1E z{jU*C`^g_9uOj~yVGq@Iax>t42^y|$INxwO#SaH07ZA52nyHSoAHN|~5>62`1T~?W aaGX#^pmTp$Txig&n+EXD|Ie{6lRp5UY!=u6 literal 0 HcmV?d00001 diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatResources.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatResources.java index 98a23dbbbc..24ddbc3179 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatResources.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatResources.java @@ -59,6 +59,9 @@ abstract class TomcatResources { } addJar(jar); } + else if ("jar".equals(url.getProtocol())) { + addJar(url.toString()); + } else { addDir(new File(url.toURI()).getAbsolutePath(), url); } diff --git a/spring-boot/src/test/java/org/springframework/boot/context/embedded/tomcat/TomcatResourcesTests.java b/spring-boot/src/test/java/org/springframework/boot/context/embedded/tomcat/TomcatResourcesTests.java new file mode 100644 index 0000000000..4b5d2216c5 --- /dev/null +++ b/spring-boot/src/test/java/org/springframework/boot/context/embedded/tomcat/TomcatResourcesTests.java @@ -0,0 +1,45 @@ +/* + * Copyright 2012-2018 the original author or authors. + * + * Licensed 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.springframework.boot.context.embedded.tomcat; + +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +import org.apache.catalina.Context; +import org.junit.Test; + +import static org.mockito.Mockito.mock; + +/** + * Tests for {@link TomcatResources}. + * + * @author Phillip Webb + */ +public class TomcatResourcesTests { + + @Test + public void nonHierarchicalUri() throws Exception { + // gh-13265 + Context context = mock(Context.class); + TomcatResources resources = new TomcatResources.Tomcat8Resources(context); + List resourceJarUrls = new ArrayList(); + resourceJarUrls.add(new URL("jar:file:/opt/app/app.war!/WEB-INF/classes!/")); + resources.addResourceJars(resourceJarUrls); + } + +}