From 2e2fde0dcd0a2c13e46a759ea1fe30f180d3ee3d Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 12 Jun 2017 14:24:43 +0100 Subject: [PATCH] Stop using URLResource API that was deprecated in Undertow 1.4.16 Closes gh-9464 --- .../embedded/undertow/JarResourceManager.java | 2 +- ...dertowEmbeddedServletContainerFactory.java | 28 ++++++++++++------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/JarResourceManager.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/JarResourceManager.java index 040d4531da..b60063522f 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/JarResourceManager.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/JarResourceManager.java @@ -48,7 +48,7 @@ class JarResourceManager implements ResourceManager { public Resource getResource(String path) throws IOException { URL url = new URL("jar:file:" + this.jarPath + "!" + (path.startsWith("/") ? path : "/" + path)); - URLResource resource = new URLResource(url, url.openConnection(), path); + URLResource resource = new URLResource(url, path); if (resource.getContentLength() < 0) { return null; } diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactory.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactory.java index afa2eaf0c3..3a76ff9be6 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactory.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactory.java @@ -21,7 +21,6 @@ import java.io.IOException; import java.net.MalformedURLException; import java.net.Socket; import java.net.URL; -import java.net.URLConnection; import java.nio.charset.Charset; import java.security.KeyManagementException; import java.security.KeyStore; @@ -664,15 +663,9 @@ public class UndertowEmbeddedServletContainerFactory @Override public Resource getResource(String path) { for (URL url : this.metaInfResourceJarUrls) { - try { - URL resourceUrl = new URL(url + "META-INF/resources" + path); - URLConnection connection = resourceUrl.openConnection(); - if (connection.getContentLength() >= 0) { - return new URLResource(resourceUrl, connection, path); - } - } - catch (IOException ex) { - // Continue + URLResource resource = getMetaInfResource(url, path); + if (resource != null) { + return resource; } } return null; @@ -689,6 +682,21 @@ public class UndertowEmbeddedServletContainerFactory @Override public void removeResourceChangeListener(ResourceChangeListener listener) { + + } + + private URLResource getMetaInfResource(URL resourceJar, String path) { + try { + URL resourceUrl = new URL(resourceJar + "META-INF/resources" + path); + URLResource resource = new URLResource(resourceUrl, path); + if (resource.getContentLength() < 0) { + return null; + } + return resource; + } + catch (MalformedURLException ex) { + return null; + } } }