Merge branch '2.1.x'
This commit is contained in:
commit
b3abd25e22
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2018 the original author or authors.
|
* Copyright 2012-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -19,7 +19,6 @@ package org.springframework.boot.loader.jar;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.ref.SoftReference;
|
import java.lang.ref.SoftReference;
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
|
@ -58,20 +57,6 @@ public class Handler extends URLStreamHandler {
|
||||||
private static final String[] FALLBACK_HANDLERS = {
|
private static final String[] FALLBACK_HANDLERS = {
|
||||||
"sun.net.www.protocol.jar.Handler" };
|
"sun.net.www.protocol.jar.Handler" };
|
||||||
|
|
||||||
private static final Method OPEN_CONNECTION_METHOD;
|
|
||||||
|
|
||||||
static {
|
|
||||||
Method method = null;
|
|
||||||
try {
|
|
||||||
method = URLStreamHandler.class.getDeclaredMethod("openConnection",
|
|
||||||
URL.class);
|
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
// Swallow and ignore
|
|
||||||
}
|
|
||||||
OPEN_CONNECTION_METHOD = method;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static SoftReference<Map<File, JarFile>> rootFileCache;
|
private static SoftReference<Map<File, JarFile>> rootFileCache;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
@ -159,12 +144,7 @@ public class Handler extends URLStreamHandler {
|
||||||
|
|
||||||
private URLConnection openConnection(URLStreamHandler handler, URL url)
|
private URLConnection openConnection(URLStreamHandler handler, URL url)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
if (OPEN_CONNECTION_METHOD == null) {
|
return new URL(null, url.toExternalForm(), handler).openConnection();
|
||||||
throw new IllegalStateException(
|
|
||||||
"Unable to invoke fallback open connection method");
|
|
||||||
}
|
|
||||||
OPEN_CONNECTION_METHOD.setAccessible(true);
|
|
||||||
return (URLConnection) OPEN_CONNECTION_METHOD.invoke(handler, url);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2018 the original author or authors.
|
* Copyright 2012-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -16,10 +16,16 @@
|
||||||
|
|
||||||
package org.springframework.boot.loader.jar;
|
package org.springframework.boot.loader.jar;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
|
||||||
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.rules.TemporaryFolder;
|
||||||
|
|
||||||
|
import org.springframework.boot.loader.TestJarCreator;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
@ -30,6 +36,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class HandlerTests {
|
public class HandlerTests {
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||||
|
|
||||||
private final Handler handler = new Handler();
|
private final Handler handler = new Handler();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -170,6 +179,20 @@ public class HandlerTests {
|
||||||
"!/foo.txt?alpha");
|
"!/foo.txt?alpha");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void fallbackToJdksJarUrlStreamHandler() throws Exception {
|
||||||
|
File testJar = this.temporaryFolder.newFile("test.jar");
|
||||||
|
TestJarCreator.createTestJar(testJar);
|
||||||
|
URLConnection connection = new URL(null,
|
||||||
|
"jar:file:" + testJar.getAbsolutePath() + "!/nested.jar!/", this.handler)
|
||||||
|
.openConnection();
|
||||||
|
assertThat(connection).isInstanceOf(JarURLConnection.class);
|
||||||
|
URLConnection jdkConnection = new URL(null,
|
||||||
|
"jar:file:file:" + testJar.getAbsolutePath() + "!/nested.jar!/",
|
||||||
|
this.handler).openConnection();
|
||||||
|
assertThat(jdkConnection).isNotInstanceOf(JarURLConnection.class);
|
||||||
|
}
|
||||||
|
|
||||||
private void assertStandardAndCustomHandlerUrlsAreEqual(String context, String spec)
|
private void assertStandardAndCustomHandlerUrlsAreEqual(String context, String spec)
|
||||||
throws MalformedURLException {
|
throws MalformedURLException {
|
||||||
URL standardUrl = new URL(new URL("jar:" + context), spec);
|
URL standardUrl = new URL(new URL("jar:" + context), spec);
|
||||||
|
|
Loading…
Reference in New Issue