Remove redundant logic for uninstalling Tomcat's URL stream handler factory

Closes gh-8622
This commit is contained in:
Andy Wilkinson
2017-05-11 17:22:15 +01:00
parent 5810ae28d5
commit b71daac58a
15 changed files with 0 additions and 195 deletions

View File

@@ -16,19 +16,14 @@
package org.springframework.boot.autoconfigure.jersey;
import java.net.URL;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import org.apache.catalina.Context;
import org.apache.catalina.Wrapper;
import org.apache.catalina.webresources.TomcatURLStreamHandlerFactory;
import org.apache.tomcat.util.buf.UDecoder;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.servlet.ServletContainer;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -47,7 +42,6 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.util.ReflectionTestUtils;
import static org.assertj.core.api.Assertions.assertThat;
@@ -65,14 +59,6 @@ public class JerseyAutoConfigurationServletContainerTests {
@ClassRule
public static OutputCapture output = new OutputCapture();
@BeforeClass
@AfterClass
public static void uninstallUrlStreamHandlerFactory() {
ReflectionTestUtils.setField(TomcatURLStreamHandlerFactory.class, "instance",
null);
ReflectionTestUtils.setField(URL.class, "factory", null);
}
@Test
public void existingJerseyServletIsAmended() {
assertThat(output.toString())

View File

@@ -17,16 +17,12 @@
package org.springframework.boot.autoconfigure.security;
import java.io.IOException;
import java.net.URL;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.fasterxml.jackson.databind.module.SimpleModule;
import org.apache.catalina.webresources.TomcatURLStreamHandlerFactory;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
@@ -47,7 +43,6 @@ import org.springframework.context.annotation.Import;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -61,14 +56,6 @@ public class SecurityFilterAutoConfigurationEarlyInitializationTests {
// gh-4154
@BeforeClass
@AfterClass
public static void uninstallUrlStreamHandlerFactory() {
ReflectionTestUtils.setField(TomcatURLStreamHandlerFactory.class, "instance",
null);
ReflectionTestUtils.setField(URL.class, "factory", null);
}
@Test
public void testSecurityFilterDoesNotCauseEarlyInitialization() throws Exception {
AnnotationConfigServletWebServerApplicationContext context = new AnnotationConfigServletWebServerApplicationContext();

View File

@@ -17,15 +17,11 @@
package org.springframework.boot.autoconfigure.security.oauth2;
import java.net.URI;
import java.net.URL;
import java.util.Arrays;
import java.util.Base64;
import java.util.List;
import com.fasterxml.jackson.databind.JsonNode;
import org.apache.catalina.webresources.TomcatURLStreamHandlerFactory;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.aop.support.AopUtils;
@@ -123,14 +119,6 @@ public class OAuth2AutoConfigurationTests {
private AnnotationConfigServletWebServerApplicationContext context;
@BeforeClass
@AfterClass
public static void uninstallUrlStreamHandlerFactory() {
ReflectionTestUtils.setField(TomcatURLStreamHandlerFactory.class, "instance",
null);
ReflectionTestUtils.setField(URL.class, "factory", null);
}
@Test
public void testDefaultConfiguration() {
this.context = new AnnotationConfigServletWebServerApplicationContext();

View File

@@ -18,7 +18,6 @@ package org.springframework.boot.autoconfigure.web.servlet;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Locale;
@@ -34,13 +33,10 @@ import org.apache.catalina.Context;
import org.apache.catalina.Valve;
import org.apache.catalina.valves.AccessLogValve;
import org.apache.catalina.valves.RemoteIpValve;
import org.apache.catalina.webresources.TomcatURLStreamHandlerFactory;
import org.apache.coyote.AbstractProtocol;
import org.eclipse.jetty.server.NCSARequestLog;
import org.eclipse.jetty.server.RequestLog;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
@@ -59,7 +55,6 @@ import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFa
import org.springframework.boot.web.servlet.ServletContextInitializer;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.mock.env.MockEnvironment;
import org.springframework.test.util.ReflectionTestUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.anyBoolean;
@@ -90,14 +85,6 @@ public class DefaultServletWebServerFactoryCustomizerTests {
this.customizer = new DefaultServletWebServerFactoryCustomizer(this.properties);
}
@BeforeClass
@AfterClass
public static void uninstallUrlStreamHandlerFactory() {
ReflectionTestUtils.setField(TomcatURLStreamHandlerFactory.class, "instance",
null);
ReflectionTestUtils.setField(URL.class, "factory", null);
}
@Test
public void tomcatAccessLogIsDisabledByDefault() {
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();

View File

@@ -17,13 +17,10 @@
package org.springframework.boot.autoconfigure.web.servlet;
import java.net.URI;
import java.net.URL;
import javax.servlet.MultipartConfigElement;
import org.apache.catalina.webresources.TomcatURLStreamHandlerFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -80,14 +77,6 @@ public class MultipartAutoConfigurationTests {
}
}
@Before
@After
public void uninstallUrlStreamHandlerFactory() {
ReflectionTestUtils.setField(TomcatURLStreamHandlerFactory.class, "instance",
null);
ReflectionTestUtils.setField(URL.class, "factory", null);
}
@Test
public void webServerWithNothing() throws Exception {
this.context = new AnnotationConfigServletWebServerApplicationContext(

View File

@@ -16,14 +16,9 @@
package org.springframework.boot.autoconfigure.web.servlet;
import java.net.URL;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.apache.catalina.webresources.TomcatURLStreamHandlerFactory;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory;
@@ -35,7 +30,6 @@ import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebSe
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.util.ReflectionTestUtils;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
@@ -48,14 +42,6 @@ import static org.mockito.Mockito.verify;
*/
public class ServletWebServerServletContextListenerTests {
@BeforeClass
@AfterClass
public static void uninstallUrlStreamHandlerFactory() {
ReflectionTestUtils.setField(TomcatURLStreamHandlerFactory.class, "instance",
null);
ReflectionTestUtils.setField(URL.class, "factory", null);
}
@Test
public void registeredServletContextListenerBeanIsCalledByJetty() {
registeredServletContextListenerBeanIsCalled(JettyConfiguration.class);

View File

@@ -22,7 +22,6 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -33,10 +32,7 @@ import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import org.apache.catalina.webresources.TomcatURLStreamHandlerFactory;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.boot.SpringApplication;
@@ -55,7 +51,6 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.validation.BindException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.PostMapping;
@@ -86,14 +81,6 @@ public class BasicErrorControllerIntegrationTests {
}
}
@BeforeClass
@AfterClass
public static void uninstallUrlStreamHandlerFactory() {
ReflectionTestUtils.setField(TomcatURLStreamHandlerFactory.class, "instance",
null);
ReflectionTestUtils.setField(URL.class, "factory", null);
}
@Test
@SuppressWarnings("rawtypes")
public void testErrorForMachineClient() throws Exception {

View File

@@ -16,15 +16,10 @@
package org.springframework.boot.autoconfigure.websocket;
import java.net.URL;
import javax.websocket.server.ServerContainer;
import org.apache.catalina.webresources.TomcatURLStreamHandlerFactory;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory;
@@ -34,7 +29,6 @@ import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebSe
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.util.ReflectionTestUtils;
import static org.assertj.core.api.Assertions.assertThat;
@@ -59,14 +53,6 @@ public class WebSocketAutoConfigurationTests {
}
}
@BeforeClass
@AfterClass
public static void uninstallUrlStreamHandlerFactory() {
ReflectionTestUtils.setField(TomcatURLStreamHandlerFactory.class, "instance",
null);
ReflectionTestUtils.setField(URL.class, "factory", null);
}
@Test
public void tomcatServerContainerIsAvailableFromTheServletContext() {
serverContainerIsAvailableFromTheServletContext(TomcatConfiguration.class,

View File

@@ -17,7 +17,6 @@
package org.springframework.boot.autoconfigure.websocket;
import java.lang.reflect.Type;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
@@ -27,12 +26,9 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.catalina.webresources.TomcatURLStreamHandlerFactory;
import org.apache.tomcat.websocket.WsWebSocketContainer;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
@@ -101,14 +97,6 @@ public class WebSocketMessagingAutoConfigurationTests {
this.sockJsClient.stop();
}
@BeforeClass
@AfterClass
public static void uninstallUrlStreamHandlerFactory() {
ReflectionTestUtils.setField(TomcatURLStreamHandlerFactory.class, "instance",
null);
ReflectionTestUtils.setField(URL.class, "factory", null);
}
@Test
public void basicMessagingWithJsonResponse() throws Throwable {
Object result = performStompSubscription("/app/json");

View File

@@ -16,13 +16,9 @@
package org.springframework.boot.devtools.integrationtest;
import java.net.URL;
import java.util.Collection;
import java.util.Collections;
import org.apache.catalina.webresources.TomcatURLStreamHandlerFactory;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -52,7 +48,6 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.util.SocketUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -73,14 +68,6 @@ public class HttpTunnelIntegrationTests {
@Autowired
private Config config;
@BeforeClass
@AfterClass
public static void uninstallUrlStreamHandlerFactory() {
ReflectionTestUtils.setField(TomcatURLStreamHandlerFactory.class, "instance",
null);
ReflectionTestUtils.setField(URL.class, "factory", null);
}
@Test
public void httpServerDirect() throws Exception {
String url = "http://localhost:" + this.config.httpServerPort + "/hello";

View File

@@ -16,13 +16,8 @@
package org.springframework.boot.context.embedded;
import java.net.URL;
import org.apache.catalina.Context;
import org.apache.catalina.webresources.TomcatURLStreamHandlerFactory;
import org.apache.tomcat.util.http.LegacyCookieProcessor;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.boot.SpringApplication;
@@ -33,7 +28,6 @@ import org.springframework.boot.web.server.WebServerFactoryCustomizerBeanPostPro
import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.util.ReflectionTestUtils;
import static org.assertj.core.api.Assertions.assertThat;
@@ -44,14 +38,6 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
public class TomcatLegacyCookieProcessorExampleTests {
@BeforeClass
@AfterClass
public static void uninstallUrlStreamHandlerFactory() {
ReflectionTestUtils.setField(TomcatURLStreamHandlerFactory.class, "instance",
null);
ReflectionTestUtils.setField(URL.class, "factory", null);
}
@Test
public void cookieProcessorIsCustomized() {
ServletWebServerApplicationContext applicationContext = (ServletWebServerApplicationContext) new SpringApplication(

View File

@@ -16,13 +16,8 @@
package org.springframework.boot.test.context;
import java.net.URL;
import javax.servlet.ServletContext;
import org.apache.catalina.webresources.TomcatURLStreamHandlerFactory;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
@@ -33,7 +28,6 @@ import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.context.WebApplicationContext;
@@ -65,14 +59,6 @@ public abstract class AbstractSpringBootTestWebServerWebEnvironmentTests {
@Autowired
private TestRestTemplate restTemplate;
@BeforeClass
@AfterClass
public static void uninstallUrlStreamHandlerFactory() {
ReflectionTestUtils.setField(TomcatURLStreamHandlerFactory.class, "instance",
null);
ReflectionTestUtils.setField(URL.class, "factory", null);
}
public WebApplicationContext getContext() {
return this.context;
}

View File

@@ -16,12 +16,7 @@
package org.springframework.boot.web.reactive.server;
import java.net.URL;
import org.apache.catalina.webresources.TomcatURLStreamHandlerFactory;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -36,7 +31,6 @@ import org.springframework.http.MediaType;
import org.springframework.http.server.reactive.HttpHandler;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.util.SocketUtils;
import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.reactive.function.client.ClientResponse;
@@ -74,14 +68,6 @@ public abstract class AbstractReactiveWebServerFactoryTests {
}
}
@BeforeClass
@AfterClass
public static void uninstallUrlStreamHandlerFactory() {
ReflectionTestUtils.setField(TomcatURLStreamHandlerFactory.class, "instance",
null);
ReflectionTestUtils.setField(URL.class, "factory", null);
}
protected abstract AbstractReactiveWebServerFactory getFactory();
@Test

View File

@@ -17,13 +17,9 @@
package org.springframework.boot.web.servlet.context;
import java.net.URI;
import java.net.URL;
import java.nio.charset.Charset;
import org.apache.catalina.webresources.TomcatURLStreamHandlerFactory;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory;
@@ -42,7 +38,6 @@ import org.springframework.http.client.ClientHttpRequest;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.stereotype.Controller;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.util.StreamUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@@ -72,14 +67,6 @@ public class ServletWebServerMvcIntegrationTests {
}
}
@BeforeClass
@AfterClass
public static void uninstallUrlStreamHandlerFactory() {
ReflectionTestUtils.setField(TomcatURLStreamHandlerFactory.class, "instance",
null);
ReflectionTestUtils.setField(URL.class, "factory", null);
}
@Test
public void tomcat() throws Exception {
this.context = new AnnotationConfigServletWebServerApplicationContext(

View File

@@ -59,7 +59,6 @@ import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.catalina.webresources.TomcatURLStreamHandlerFactory;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.InputStreamFactory;
import org.apache.http.client.protocol.HttpClientContext;
@@ -73,9 +72,7 @@ import org.apache.http.ssl.TrustStrategy;
import org.apache.jasper.EmbeddedServletOptions;
import org.apache.jasper.servlet.JspServlet;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assume;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -140,14 +137,6 @@ public abstract class AbstractServletWebServerFactoryTests {
private final HttpClientContext httpClientContext = HttpClientContext.create();
@BeforeClass
@AfterClass
public static void uninstallUrlStreamHandlerFactory() {
ReflectionTestUtils.setField(TomcatURLStreamHandlerFactory.class, "instance",
null);
ReflectionTestUtils.setField(URL.class, "factory", null);
}
@After
public void tearDown() {
if (this.webServer != null) {