Improve performance of Tomcat 'jar:war:file' URLs
Update jar `Handler` fallback logic to directly support Tomcat 'jar:war:file' URLs. This commit allows contents to be accessed without the JDK needing to extracted the nested jar to the temporary folder. Closes gh-24553
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.boot.loaderapp;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.JarURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -33,7 +35,14 @@ public class LoaderTestApplication {
|
||||
@Bean
|
||||
public CommandLineRunner commandLineRunner(ServletContext servletContext) {
|
||||
return (args) -> {
|
||||
File temp = new File(System.getProperty("java.io.tmpdir"));
|
||||
URL resourceUrl = servletContext.getResource("webjars/jquery/3.5.0/jquery.js");
|
||||
JarURLConnection connection = (JarURLConnection) resourceUrl.openConnection();
|
||||
String jarName = connection.getJarFile().getName();
|
||||
System.out.println(">>>>> jar file " + jarName);
|
||||
if(jarName.contains(temp.getAbsolutePath())) {
|
||||
System.out.println(">>>>> jar written to temp");
|
||||
}
|
||||
byte[] resourceContent = FileCopyUtils.copyToByteArray(resourceUrl.openStream());
|
||||
URL directUrl = new URL(resourceUrl.toExternalForm());
|
||||
byte[] directContent = FileCopyUtils.copyToByteArray(directUrl.openStream());
|
||||
|
||||
@@ -59,8 +59,9 @@ class LoaderIntegrationTests {
|
||||
|
||||
@Test
|
||||
void readUrlsWithoutWarning() {
|
||||
System.out.println(output.toUtf8String());
|
||||
assertThat(output.toUtf8String()).contains(">>>>> 287649 BYTES from").doesNotContain("WARNING:")
|
||||
.doesNotContain("illegal");
|
||||
.doesNotContain("illegal").doesNotContain("jar written to temp");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user