diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfiguration.java index 77b6224432..0b582baaa4 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfiguration.java @@ -45,17 +45,17 @@ import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoCon import org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration; import org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration; import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration; -import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerProperties; +import org.springframework.boot.autoconfigure.web.ServletWebServerFactoryAutoConfiguration; import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration; import org.springframework.boot.bind.RelaxedPropertyResolver; -import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; -import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext; import org.springframework.boot.context.event.ApplicationFailedEvent; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.boot.web.filter.ApplicationContextHeaderFilter; +import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext; +import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext; +import org.springframework.boot.web.servlet.filter.ApplicationContextHeaderFilter; +import org.springframework.boot.web.servlet.server.ServletWebServerFactory; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationEvent; @@ -95,7 +95,7 @@ import org.springframework.web.servlet.DispatcherServlet; @ConditionalOnWebApplication(type = Type.SERVLET) @EnableConfigurationProperties(ManagementServerProperties.class) @AutoConfigureAfter({ PropertyPlaceholderAutoConfiguration.class, - EmbeddedServletContainerAutoConfiguration.class, WebMvcAutoConfiguration.class, + ServletWebServerFactoryAutoConfiguration.class, WebMvcAutoConfiguration.class, RepositoryRestMvcAutoConfiguration.class, HypermediaAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class }) public class EndpointWebMvcAutoConfiguration @@ -138,13 +138,13 @@ public class EndpointWebMvcAutoConfiguration .get(this.applicationContext.getEnvironment()); } if (managementPort == ManagementServerPort.DIFFERENT) { - if (this.applicationContext instanceof EmbeddedWebApplicationContext - && ((EmbeddedWebApplicationContext) this.applicationContext) - .getEmbeddedWebServer() != null) { + if (this.applicationContext instanceof ServletWebServerApplicationContext + && ((ServletWebServerApplicationContext) this.applicationContext) + .getWebServer() != null) { createChildManagementContext(); } else { - logger.warn("Could not start embedded management container on " + logger.warn("Could not start management web server on " + "different port (management endpoints are still available " + "through JMX)"); } @@ -166,31 +166,30 @@ public class EndpointWebMvcAutoConfiguration } private void createChildManagementContext() { - AnnotationConfigEmbeddedWebApplicationContext childContext = new AnnotationConfigEmbeddedWebApplicationContext(); + AnnotationConfigServletWebServerApplicationContext childContext = new AnnotationConfigServletWebServerApplicationContext(); childContext.setParent(this.applicationContext); childContext.setNamespace("management"); childContext.setId(this.applicationContext.getId() + ":management"); childContext.setClassLoader(this.applicationContext.getClassLoader()); childContext.register(EndpointWebMvcChildContextConfiguration.class, PropertyPlaceholderAutoConfiguration.class, - EmbeddedServletContainerAutoConfiguration.class, + ServletWebServerFactoryAutoConfiguration.class, DispatcherServletAutoConfiguration.class); - registerEmbeddedServletContainerFactory(childContext); + registerServletWebServerFactory(childContext); CloseManagementContextListener.addIfPossible(this.applicationContext, childContext); childContext.refresh(); managementContextResolver().setApplicationContext(childContext); } - private void registerEmbeddedServletContainerFactory( - AnnotationConfigEmbeddedWebApplicationContext childContext) { + private void registerServletWebServerFactory( + AnnotationConfigServletWebServerApplicationContext childContext) { try { ConfigurableListableBeanFactory beanFactory = childContext.getBeanFactory(); if (beanFactory instanceof BeanDefinitionRegistry) { BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory; - registry.registerBeanDefinition("embeddedServletContainerFactory", - new RootBeanDefinition( - determineEmbeddedServletContainerFactoryClass())); + registry.registerBeanDefinition("ServletWebServerFactory", + new RootBeanDefinition(determineServletWebServerFactoryClass())); } } catch (NoSuchBeanDefinitionException ex) { @@ -198,17 +197,17 @@ public class EndpointWebMvcAutoConfiguration } } - private Class determineEmbeddedServletContainerFactoryClass() + private Class determineServletWebServerFactoryClass() throws NoSuchBeanDefinitionException { - Class servletContainerFactoryClass = this.applicationContext - .getBean(EmbeddedServletContainerFactory.class).getClass(); - if (cannotBeInstantiated(servletContainerFactoryClass)) { - throw new FatalBeanException("EmbeddedServletContainerFactory implementation " - + servletContainerFactoryClass.getName() + " cannot be instantiated. " + Class factoryClass = this.applicationContext + .getBean(ServletWebServerFactory.class).getClass(); + if (cannotBeInstantiated(factoryClass)) { + throw new FatalBeanException("ServletWebServerFactory implementation " + + factoryClass.getName() + " cannot be instantiated. " + "To allow a separate management port to be used, a top-level class " + "or static inner class should be used instead"); } - return servletContainerFactoryClass; + return factoryClass; } private boolean cannotBeInstantiated(Class clazz) { diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcChildContextConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcChildContextConfiguration.java index 40ac3065be..82412eb642 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcChildContextConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcChildContextConfiguration.java @@ -40,17 +40,17 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.SearchStrategy; import org.springframework.boot.autoconfigure.hateoas.HypermediaHttpMessageConverterConfiguration; -import org.springframework.boot.autoconfigure.web.DefaultServletContainerCustomizer; +import org.springframework.boot.autoconfigure.web.DefaultServletWebServerFactoryCustomizer; import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration; import org.springframework.boot.autoconfigure.web.ErrorAttributes; import org.springframework.boot.autoconfigure.web.ServerProperties; -import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer; -import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer; -import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.EmbeddedWebServer; -import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory; -import org.springframework.boot.web.servlet.ErrorPage; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory; +import org.springframework.boot.web.server.ErrorPage; +import org.springframework.boot.web.server.WebServer; +import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory; +import org.springframework.boot.web.servlet.server.ServletWebServerFactory; +import org.springframework.boot.web.servlet.server.ServletWebServerFactoryCustomizer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @@ -69,7 +69,7 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc; /** * Configuration triggered from {@link EndpointWebMvcAutoConfiguration} when a new - * {@link EmbeddedWebServer} running on a different port is required. + * {@link WebServer} running on a different port is required. * * @author Dave Syer * @author Stephane Nicoll @@ -109,8 +109,8 @@ public class EndpointWebMvcChildContextConfiguration { } @Bean - public ServerCustomization serverCustomization() { - return new ServerCustomization(); + public ServerFactoryCustomization serverCustomization() { + return new ServerFactoryCustomization(); } @Bean @@ -171,19 +171,19 @@ public class EndpointWebMvcChildContextConfiguration { } - static class ServerCustomization - implements EmbeddedServletContainerCustomizer, Ordered { + static class ServerFactoryCustomization + implements ServletWebServerFactoryCustomizer, Ordered { @Autowired private ListableBeanFactory beanFactory; - // This needs to be lazily initialized because EmbeddedServletContainerCustomizer + // This needs to be lazily initialized because web server customizer // instances get their callback very early in the context lifecycle. private ManagementServerProperties managementServerProperties; private ServerProperties server; - private DefaultServletContainerCustomizer serverCustomizer; + private DefaultServletWebServerFactoryCustomizer serverCustomizer; @Override public int getOrder() { @@ -191,7 +191,7 @@ public class EndpointWebMvcChildContextConfiguration { } @Override - public void customize(ConfigurableEmbeddedServletContainer container) { + public void customize(ConfigurableServletWebServerFactory webServerFactory) { if (this.managementServerProperties == null) { this.managementServerProperties = BeanFactoryUtils .beanOfTypeIncludingAncestors(this.beanFactory, @@ -199,23 +199,23 @@ public class EndpointWebMvcChildContextConfiguration { this.server = BeanFactoryUtils.beanOfTypeIncludingAncestors( this.beanFactory, ServerProperties.class); this.serverCustomizer = BeanFactoryUtils.beanOfTypeIncludingAncestors( - this.beanFactory, DefaultServletContainerCustomizer.class); + this.beanFactory, DefaultServletWebServerFactoryCustomizer.class); } // Customize as per the parent context first (so e.g. the access logs go to // the same place) - this.serverCustomizer.customize(container); + this.serverCustomizer.customize(webServerFactory); // Then reset the error pages - container.setErrorPages(Collections.emptySet()); + webServerFactory.setErrorPages(Collections.emptySet()); // and the context path - container.setContextPath(""); + webServerFactory.setContextPath(""); // and add the management-specific bits - container.setPort(this.managementServerProperties.getPort()); + webServerFactory.setPort(this.managementServerProperties.getPort()); if (this.managementServerProperties.getSsl() != null) { - container.setSsl(this.managementServerProperties.getSsl()); + webServerFactory.setSsl(this.managementServerProperties.getSsl()); } - container.setServerHeader(this.server.getServerHeader()); - container.setAddress(this.managementServerProperties.getAddress()); - container.addErrorPages(new ErrorPage(this.server.getError().getPath())); + webServerFactory.setServerHeader(this.server.getServerHeader()); + webServerFactory.setAddress(this.managementServerProperties.getAddress()); + webServerFactory.addErrorPages(new ErrorPage(this.server.getError().getPath())); } } @@ -343,8 +343,8 @@ public class EndpointWebMvcChildContextConfiguration { } - static abstract class AccessLogCustomizer - implements EmbeddedServletContainerCustomizer, Ordered { + static abstract class AccessLogCustomizer + implements ServletWebServerFactoryCustomizer, Ordered { private final Class factoryClass; @@ -362,26 +362,26 @@ public class EndpointWebMvcChildContextConfiguration { } @Override - public void customize(ConfigurableEmbeddedServletContainer container) { - if (this.factoryClass.isInstance(container)) { - customize(this.factoryClass.cast(container)); + public void customize(ConfigurableServletWebServerFactory serverFactory) { + if (this.factoryClass.isInstance(serverFactory)) { + customize(this.factoryClass.cast(serverFactory)); } } - abstract void customize(T container); + abstract void customize(T webServerFactory); } static class TomcatAccessLogCustomizer - extends AccessLogCustomizer { + extends AccessLogCustomizer { TomcatAccessLogCustomizer() { - super(TomcatEmbeddedServletContainerFactory.class); + super(TomcatServletWebServerFactory.class); } @Override - public void customize(TomcatEmbeddedServletContainerFactory container) { - AccessLogValve accessLogValve = findAccessLogValve(container); + public void customize(TomcatServletWebServerFactory serverFactory) { + AccessLogValve accessLogValve = findAccessLogValve(serverFactory); if (accessLogValve == null) { return; } @@ -389,8 +389,8 @@ public class EndpointWebMvcChildContextConfiguration { } private AccessLogValve findAccessLogValve( - TomcatEmbeddedServletContainerFactory container) { - for (Valve engineValve : container.getEngineValves()) { + TomcatServletWebServerFactory serverFactory) { + for (Valve engineValve : serverFactory.getEngineValves()) { if (engineValve instanceof AccessLogValve) { return (AccessLogValve) engineValve; } @@ -401,15 +401,15 @@ public class EndpointWebMvcChildContextConfiguration { } static class UndertowAccessLogCustomizer - extends AccessLogCustomizer { + extends AccessLogCustomizer { UndertowAccessLogCustomizer() { - super(UndertowEmbeddedServletContainerFactory.class); + super(UndertowServletWebServerFactory.class); } @Override - public void customize(UndertowEmbeddedServletContainerFactory container) { - container.setAccessLogPrefix(customizePrefix(container.getAccessLogPrefix())); + public void customize(UndertowServletWebServerFactory serverFactory) { + serverFactory.setAccessLogPrefix(customizePrefix(serverFactory.getAccessLogPrefix())); } } diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/JolokiaAutoConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/JolokiaAutoConfiguration.java index 4e3233320e..c3945d4909 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/JolokiaAutoConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/JolokiaAutoConfiguration.java @@ -32,7 +32,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type; import org.springframework.boot.autoconfigure.condition.SpringBootCondition; -import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; +import org.springframework.boot.autoconfigure.web.ServletWebServerFactoryAutoConfiguration; import org.springframework.boot.bind.RelaxedPropertyResolver; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; @@ -66,7 +66,7 @@ import org.springframework.web.servlet.mvc.ServletWrappingController; @ConditionalOnClass({ AgentServlet.class, ServletWrappingController.class }) @Conditional(JolokiaCondition.class) @AutoConfigureBefore(ManagementWebSecurityAutoConfiguration.class) -@AutoConfigureAfter(EmbeddedServletContainerAutoConfiguration.class) +@AutoConfigureAfter(ServletWebServerFactoryAutoConfiguration.class) @EnableConfigurationProperties(JolokiaProperties.class) public class JolokiaAutoConfiguration { diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementServerProperties.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementServerProperties.java index b6bd2e036d..d530236be7 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementServerProperties.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementServerProperties.java @@ -25,9 +25,9 @@ import javax.servlet.http.HttpSession; import org.springframework.boot.autoconfigure.security.SecurityPrerequisite; import org.springframework.boot.autoconfigure.security.SecurityProperties; import org.springframework.boot.autoconfigure.web.ServerProperties; -import org.springframework.boot.context.embedded.Ssl; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.NestedConfigurationProperty; +import org.springframework.boot.web.server.Ssl; import org.springframework.util.Assert; import org.springframework.util.StringUtils; diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/TomcatPublicMetrics.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/TomcatPublicMetrics.java index 72b46e4ab1..166004f523 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/TomcatPublicMetrics.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/TomcatPublicMetrics.java @@ -28,9 +28,9 @@ import org.apache.catalina.session.ManagerBase; import org.springframework.beans.BeansException; import org.springframework.boot.actuate.metrics.Metric; -import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext; -import org.springframework.boot.context.embedded.EmbeddedWebServer; -import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer; +import org.springframework.boot.web.embedded.tomcat.TomcatWebServer; +import org.springframework.boot.web.server.WebServer; +import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; @@ -47,9 +47,9 @@ public class TomcatPublicMetrics implements PublicMetrics, ApplicationContextAwa @Override public Collection> metrics() { - if (this.applicationContext instanceof EmbeddedWebApplicationContext) { + if (this.applicationContext instanceof ServletWebServerApplicationContext) { Manager manager = getManager( - (EmbeddedWebApplicationContext) this.applicationContext); + (ServletWebServerApplicationContext) this.applicationContext); if (manager != null) { return metrics(manager); } @@ -57,16 +57,16 @@ public class TomcatPublicMetrics implements PublicMetrics, ApplicationContextAwa return Collections.emptySet(); } - private Manager getManager(EmbeddedWebApplicationContext applicationContext) { - EmbeddedWebServer embeddedWebServer = applicationContext.getEmbeddedWebServer(); - if (embeddedWebServer instanceof TomcatEmbeddedServletContainer) { - return getManager((TomcatEmbeddedServletContainer) embeddedWebServer); + private Manager getManager(ServletWebServerApplicationContext applicationContext) { + WebServer webServer = applicationContext.getWebServer(); + if (webServer instanceof TomcatWebServer) { + return getManager((TomcatWebServer) webServer); } return null; } - private Manager getManager(TomcatEmbeddedServletContainer servletContainer) { - for (Container container : servletContainer.getTomcat().getHost() + private Manager getManager(TomcatWebServer webServer) { + for (Container container : webServer.getTomcat().getHost() .findChildren()) { if (container instanceof Context) { return ((Context) container).getManager(); diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/BootCuriesHrefIntegrationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/BootCuriesHrefIntegrationTests.java index b85bc3ad25..8dc3f1bd6d 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/BootCuriesHrefIntegrationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/BootCuriesHrefIntegrationTests.java @@ -23,10 +23,10 @@ import net.minidev.json.JSONArray; import org.junit.After; import org.junit.Test; -import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; -import org.springframework.boot.context.embedded.ServerPortInfoApplicationContextInitializer; import org.springframework.boot.test.util.EnvironmentTestUtils; import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer; +import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext; import org.springframework.context.annotation.Configuration; import org.springframework.http.ResponseEntity; @@ -39,7 +39,7 @@ import static org.assertj.core.api.Assertions.assertThat; */ public class BootCuriesHrefIntegrationTests { - private AnnotationConfigEmbeddedWebApplicationContext context; + private AnnotationConfigServletWebServerApplicationContext context; @After public void closeContext() { @@ -110,7 +110,7 @@ public class BootCuriesHrefIntegrationTests { } private int load(String... properties) { - this.context = new AnnotationConfigEmbeddedWebApplicationContext(); + this.context = new AnnotationConfigServletWebServerApplicationContext(); this.context.setClassLoader(new ClassLoader(getClass().getClassLoader()) { @Override diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointMvcIntegrationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointMvcIntegrationTests.java index 1136d6b644..71a8f524d9 100755 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointMvcIntegrationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointMvcIntegrationTests.java @@ -42,14 +42,14 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration; -import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration; import org.springframework.boot.autoconfigure.web.HttpMessageConverters; +import org.springframework.boot.autoconfigure.web.ServletWebServerFactoryAutoConfiguration; import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration; -import org.springframework.boot.context.embedded.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @@ -152,7 +152,7 @@ public class EndpointMvcIntegrationTests { @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented - @Import({ EmbeddedServletContainerAutoConfiguration.class, + @Import({ ServletWebServerFactoryAutoConfiguration.class, DispatcherServletAutoConfiguration.class, WebMvcAutoConfiguration.class, JacksonAutoConfiguration.class, ErrorMvcAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class }) diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfigurationTests.java index f05a0b03fb..c284c6b055 100755 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfigurationTests.java @@ -56,23 +56,23 @@ import org.springframework.boot.actuate.endpoint.mvc.ShutdownMvcEndpoint; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration; -import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration; import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerProperties; +import org.springframework.boot.autoconfigure.web.ServletWebServerFactoryAutoConfiguration; import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration; -import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; -import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent; -import org.springframework.boot.context.embedded.EmbeddedWebServer; -import org.springframework.boot.context.embedded.EmbeddedWebServerException; -import org.springframework.boot.context.embedded.ServerPortInfoApplicationContextInitializer; -import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory; import org.springframework.boot.context.event.ApplicationFailedEvent; import org.springframework.boot.logging.LoggingSystem; import org.springframework.boot.test.util.EnvironmentTestUtils; import org.springframework.boot.testutil.Matched; +import org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory; +import org.springframework.boot.web.server.WebServer; +import org.springframework.boot.web.server.WebServerException; +import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext; +import org.springframework.boot.web.servlet.context.ServletWebServerInitializedEvent; +import org.springframework.boot.web.servlet.server.ServletWebServerFactory; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationListener; import org.springframework.context.ConfigurableApplicationContext; @@ -115,7 +115,7 @@ public class EndpointWebMvcAutoConfigurationTests { @Rule public ExpectedException thrown = ExpectedException.none(); - private final AnnotationConfigEmbeddedWebApplicationContext applicationContext = new AnnotationConfigEmbeddedWebApplicationContext(); + private final AnnotationConfigServletWebServerApplicationContext applicationContext = new AnnotationConfigServletWebServerApplicationContext(); private static ThreadLocal ports = new ThreadLocal<>(); @@ -185,10 +185,10 @@ public class EndpointWebMvcAutoConfigurationTests { } @Test - public void onDifferentPortWithSpecificContainer() throws Exception { + public void onDifferentPortWithSpecificServer() throws Exception { EnvironmentTestUtils.addEnvironment(this.applicationContext, "management.port=" + ports.get().management); - this.applicationContext.register(SpecificContainerConfig.class, RootConfig.class, + this.applicationContext.register(SpecificWebServerConfig.class, RootConfig.class, DifferentPortConfig.class, EndpointConfig.class, BaseConfiguration.class, EndpointWebMvcAutoConfiguration.class, ErrorMvcAutoConfiguration.class); this.applicationContext.refresh(); @@ -202,15 +202,13 @@ public class EndpointWebMvcAutoConfigurationTests { List interceptors = (List) ReflectionTestUtils.getField( managementContext.getBean(EndpointHandlerMapping.class), "interceptors"); assertThat(interceptors).hasSize(1); - EmbeddedServletContainerFactory parentContainerFactory = this.applicationContext - .getBean(EmbeddedServletContainerFactory.class); - EmbeddedServletContainerFactory managementContainerFactory = managementContext - .getBean(EmbeddedServletContainerFactory.class); - assertThat(parentContainerFactory) - .isInstanceOf(SpecificEmbeddedServletContainerFactory.class); - assertThat(managementContainerFactory) - .isInstanceOf(SpecificEmbeddedServletContainerFactory.class); - assertThat(managementContainerFactory).isNotSameAs(parentContainerFactory); + ServletWebServerFactory parentFactory = this.applicationContext + .getBean(ServletWebServerFactory.class); + ServletWebServerFactory managementFactory = managementContext + .getBean(ServletWebServerFactory.class); + assertThat(parentFactory).isInstanceOf(SpecificServletWebServerFactory.class); + assertThat(managementFactory).isInstanceOf(SpecificServletWebServerFactory.class); + assertThat(managementFactory).isNotSameAs(parentFactory); } @Test @@ -254,7 +252,7 @@ public class EndpointWebMvcAutoConfigurationTests { } @Test - public void onDifferentPortInServletContainer() throws Exception { + public void onDifferentPortInWebServer() throws Exception { EnvironmentTestUtils.addEnvironment(this.applicationContext, "management.port=" + ports.get().management); this.applicationContext.register(RootConfig.class, EndpointConfig.class, @@ -282,7 +280,7 @@ public class EndpointWebMvcAutoConfigurationTests { this.applicationContext); this.applicationContext.addApplicationListener(grabManagementPort); this.applicationContext.refresh(); - int managementPort = grabManagementPort.getServletContainer().getPort(); + int managementPort = grabManagementPort.getWebServer().getPort(); assertThat(managementPort).isNotEqualTo(ports.get().server); assertContent("/controller", ports.get().server, "controlleroutput"); assertContent("/endpoint", ports.get().server, null); @@ -348,7 +346,7 @@ public class EndpointWebMvcAutoConfigurationTests { this.applicationContext.register(RootConfig.class, EndpointConfig.class, BaseConfiguration.class, EndpointWebMvcAutoConfiguration.class, ErrorMvcAutoConfiguration.class); - this.thrown.expect(EmbeddedWebServerException.class); + this.thrown.expect(WebServerException.class); this.applicationContext.refresh(); } finally { @@ -363,7 +361,7 @@ public class EndpointWebMvcAutoConfigurationTests { this.applicationContext.register(RootConfig.class, EndpointConfig.class, PropertyPlaceholderAutoConfiguration.class, JacksonAutoConfiguration.class, - EmbeddedServletContainerAutoConfiguration.class, + ServletWebServerFactoryAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class, DispatcherServletAutoConfiguration.class, WebMvcAutoConfiguration.class, EndpointWebMvcAutoConfiguration.class, AuditAutoConfiguration.class); @@ -379,7 +377,7 @@ public class EndpointWebMvcAutoConfigurationTests { this.applicationContext.register(RootConfig.class, EndpointConfig.class, PropertyPlaceholderAutoConfiguration.class, JacksonAutoConfiguration.class, - EmbeddedServletContainerAutoConfiguration.class, + ServletWebServerFactoryAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class, DispatcherServletAutoConfiguration.class, WebMvcAutoConfiguration.class, EndpointWebMvcAutoConfiguration.class, AuditAutoConfiguration.class); @@ -590,7 +588,7 @@ public class EndpointWebMvcAutoConfigurationTests { public void tomcatManagementAccessLogUsesCustomPrefix() throws Exception { EnvironmentTestUtils.addEnvironment(this.applicationContext, "management.port=" + ports.get().management); - this.applicationContext.register(TomcatContainerConfig.class, RootConfig.class, + this.applicationContext.register(TomcatWebServerConfig.class, RootConfig.class, EndpointConfig.class, DifferentPortConfig.class, BaseConfiguration.class, EndpointWebMvcAutoConfiguration.class, ErrorMvcAutoConfiguration.class); EnvironmentTestUtils.addEnvironment(this.applicationContext, @@ -598,12 +596,11 @@ public class EndpointWebMvcAutoConfigurationTests { this.applicationContext.refresh(); ApplicationContext managementContext = this.applicationContext .getBean(ManagementContextResolver.class).getApplicationContext(); - EmbeddedServletContainerFactory servletContainerFactory = managementContext - .getBean(EmbeddedServletContainerFactory.class); - assertThat(servletContainerFactory) - .isInstanceOf(TomcatEmbeddedServletContainerFactory.class); + ServletWebServerFactory factory = managementContext + .getBean(ServletWebServerFactory.class); + assertThat(factory).isInstanceOf(TomcatServletWebServerFactory.class); AccessLogValve accessLogValve = findAccessLogValve( - ((TomcatEmbeddedServletContainerFactory) servletContainerFactory)); + ((TomcatServletWebServerFactory) factory)); assertThat(accessLogValve).isNotNull(); assertThat(accessLogValve.getPrefix()).isEqualTo("management_access_log"); } @@ -613,23 +610,22 @@ public class EndpointWebMvcAutoConfigurationTests { EnvironmentTestUtils.addEnvironment(this.applicationContext, "management.port=" + ports.get().management, "server.undertow.accesslog.enabled: true"); - this.applicationContext.register(UndertowContainerConfig.class, RootConfig.class, + this.applicationContext.register(UndertowWebServerConfig.class, RootConfig.class, EndpointConfig.class, DifferentPortConfig.class, BaseConfiguration.class, EndpointWebMvcAutoConfiguration.class, ErrorMvcAutoConfiguration.class); this.applicationContext.refresh(); ApplicationContext managementContext = this.applicationContext .getBean(ManagementContextResolver.class).getApplicationContext(); - EmbeddedServletContainerFactory servletContainerFactory = managementContext - .getBean(EmbeddedServletContainerFactory.class); - assertThat(servletContainerFactory) - .isInstanceOf(UndertowEmbeddedServletContainerFactory.class); - assertThat(((UndertowEmbeddedServletContainerFactory) servletContainerFactory) - .getAccessLogPrefix()).isEqualTo("management_access_log."); + ServletWebServerFactory factory = managementContext + .getBean(ServletWebServerFactory.class); + assertThat(factory).isInstanceOf(UndertowServletWebServerFactory.class); + assertThat(((UndertowServletWebServerFactory) factory).getAccessLogPrefix()) + .isEqualTo("management_access_log."); } private AccessLogValve findAccessLogValve( - TomcatEmbeddedServletContainerFactory container) { - for (Valve engineValve : container.getEngineValves()) { + TomcatServletWebServerFactory webServerFactory) { + for (Valve engineValve : webServerFactory.getEngineValves()) { if (engineValve instanceof AccessLogValve) { return (AccessLogValve) engineValve; } @@ -733,7 +729,7 @@ public class EndpointWebMvcAutoConfigurationTests { @Configuration @Import({ PropertyPlaceholderAutoConfiguration.class, - EmbeddedServletContainerAutoConfiguration.class, + ServletWebServerFactoryAutoConfiguration.class, JacksonAutoConfiguration.class, EndpointAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class, DispatcherServletAutoConfiguration.class, WebMvcAutoConfiguration.class, @@ -784,31 +780,31 @@ public class EndpointWebMvcAutoConfigurationTests { } @Configuration - public static class SpecificContainerConfig { + public static class SpecificWebServerConfig { @Bean - public SpecificEmbeddedServletContainerFactory embeddedServletContainerFactory() { - return new SpecificEmbeddedServletContainerFactory(); + public SpecificServletWebServerFactory webServerFactory() { + return new SpecificServletWebServerFactory(); } } @Configuration - public static class TomcatContainerConfig { + public static class TomcatWebServerConfig { @Bean - public TomcatEmbeddedServletContainerFactory embeddedServletContainerFactory() { - return new TomcatEmbeddedServletContainerFactory(); + public TomcatServletWebServerFactory webServerFactory() { + return new TomcatServletWebServerFactory(); } } @Configuration - public static class UndertowContainerConfig { + public static class UndertowWebServerConfig { @Bean - public UndertowEmbeddedServletContainerFactory embeddedServletContainerFactory() { - return new UndertowEmbeddedServletContainerFactory(); + public UndertowServletWebServerFactory webServerFactory() { + return new UndertowServletWebServerFactory(); } } @@ -879,31 +875,31 @@ public class EndpointWebMvcAutoConfigurationTests { } private static class GrabManagementPort - implements ApplicationListener { + implements ApplicationListener { private ApplicationContext rootContext; - private EmbeddedWebServer servletContainer; + private WebServer webServer; GrabManagementPort(ApplicationContext rootContext) { this.rootContext = rootContext; } @Override - public void onApplicationEvent(EmbeddedServletContainerInitializedEvent event) { + public void onApplicationEvent(ServletWebServerInitializedEvent event) { if (event.getApplicationContext() != this.rootContext) { - this.servletContainer = event.getEmbeddedWebServer(); + this.webServer = event.getWebServer(); } } - public EmbeddedWebServer getServletContainer() { - return this.servletContainer; + public WebServer getWebServer() { + return this.webServer; } } - private static class SpecificEmbeddedServletContainerFactory - extends TomcatEmbeddedServletContainerFactory { + private static class SpecificServletWebServerFactory + extends TomcatServletWebServerFactory { } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/JolokiaAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/JolokiaAutoConfigurationTests.java index 25488c7ceb..f9a647a05b 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/JolokiaAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/JolokiaAutoConfigurationTests.java @@ -30,12 +30,12 @@ import org.springframework.boot.actuate.endpoint.mvc.MvcEndpointSecurityIntercep import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration; import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration; -import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; -import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizerBeanPostProcessor; -import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.MockEmbeddedServletContainerFactory; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.test.util.EnvironmentTestUtils; +import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext; +import org.springframework.boot.web.servlet.server.MockServletWebServerFactory; +import org.springframework.boot.web.servlet.server.ServletWebServerFactory; +import org.springframework.boot.web.servlet.server.ServletWebServerFactoryCustomizerBeanPostProcessor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.web.servlet.MockMvc; @@ -53,21 +53,21 @@ import static org.assertj.core.api.Assertions.assertThat; */ public class JolokiaAutoConfigurationTests { - private AnnotationConfigEmbeddedWebApplicationContext context; + private AnnotationConfigServletWebServerApplicationContext context; @After public void close() { if (this.context != null) { this.context.close(); } - if (Config.containerFactory != null) { - Config.containerFactory = null; + if (Config.webServerFactory != null) { + Config.webServerFactory = null; } } @Test public void agentServletRegisteredWithAppContext() throws Exception { - this.context = new AnnotationConfigEmbeddedWebApplicationContext(); + this.context = new AnnotationConfigServletWebServerApplicationContext(); EnvironmentTestUtils.addEnvironment(this.context, "jolokia.config[key1]:value1", "jolokia.config[key2]:value2"); this.context.register(Config.class, WebMvcAutoConfiguration.class, @@ -80,7 +80,7 @@ public class JolokiaAutoConfigurationTests { @Test public void agentServletWithCustomPath() throws Exception { - this.context = new AnnotationConfigEmbeddedWebApplicationContext(); + this.context = new AnnotationConfigServletWebServerApplicationContext(); EnvironmentTestUtils.addEnvironment(this.context, "endpoints.jolokia.path=/foo/bar"); this.context.register(EndpointsConfig.class, WebMvcAutoConfiguration.class, @@ -112,7 +112,7 @@ public class JolokiaAutoConfigurationTests { } private void assertEndpointDisabled(String... pairs) { - this.context = new AnnotationConfigEmbeddedWebApplicationContext(); + this.context = new AnnotationConfigServletWebServerApplicationContext(); EnvironmentTestUtils.addEnvironment(this.context, pairs); this.context.register(Config.class, WebMvcAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class, @@ -123,7 +123,7 @@ public class JolokiaAutoConfigurationTests { } private void assertEndpointEnabled(String... pairs) { - this.context = new AnnotationConfigEmbeddedWebApplicationContext(); + this.context = new AnnotationConfigServletWebServerApplicationContext(); EnvironmentTestUtils.addEnvironment(this.context, pairs); this.context.register(Config.class, WebMvcAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class, @@ -151,19 +151,19 @@ public class JolokiaAutoConfigurationTests { @EnableConfigurationProperties protected static class Config { - protected static MockEmbeddedServletContainerFactory containerFactory = null; + protected static MockServletWebServerFactory webServerFactory = null; @Bean - public EmbeddedServletContainerFactory containerFactory() { - if (containerFactory == null) { - containerFactory = new MockEmbeddedServletContainerFactory(); + public ServletWebServerFactory webServerFactory() { + if (webServerFactory == null) { + webServerFactory = new MockServletWebServerFactory(); } - return containerFactory; + return webServerFactory; } @Bean - public EmbeddedServletContainerCustomizerBeanPostProcessor embeddedServletContainerCustomizerBeanPostProcessor() { - return new EmbeddedServletContainerCustomizerBeanPostProcessor(); + public ServletWebServerFactoryCustomizerBeanPostProcessor ServletWebServerCustomizerBeanPostProcessor() { + return new ServletWebServerFactoryCustomizerBeanPostProcessor(); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MinimalActuatorHypermediaApplication.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MinimalActuatorHypermediaApplication.java index 50b3a22b08..a18350b8fb 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MinimalActuatorHypermediaApplication.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/MinimalActuatorHypermediaApplication.java @@ -27,9 +27,9 @@ import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoCon import org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration; import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration; -import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration; import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration; +import org.springframework.boot.autoconfigure.web.ServletWebServerFactoryAutoConfiguration; import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration; import org.springframework.context.annotation.Configuration; @@ -43,7 +43,7 @@ import org.springframework.context.annotation.Configuration; @Retention(RetentionPolicy.RUNTIME) @Documented @Configuration -@ImportAutoConfiguration({ EmbeddedServletContainerAutoConfiguration.class, +@ImportAutoConfiguration({ ServletWebServerFactoryAutoConfiguration.class, DispatcherServletAutoConfiguration.class, JacksonAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class, WebMvcAutoConfiguration.class, HypermediaAutoConfiguration.class, EndpointAutoConfiguration.class, diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/PublicMetricsAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/PublicMetricsAutoConfigurationTests.java index ef8664a277..7dad671d84 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/PublicMetricsAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/PublicMetricsAutoConfigurationTests.java @@ -43,9 +43,9 @@ import org.springframework.boot.actuate.metrics.rich.RichGaugeReader; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvidersConfiguration; -import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; -import org.springframework.boot.context.embedded.MockEmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext; +import org.springframework.boot.web.servlet.server.MockServletWebServerFactory; import org.springframework.cache.CacheManager; import org.springframework.cache.concurrent.ConcurrentMapCacheManager; import org.springframework.context.ConfigurableApplicationContext; @@ -237,14 +237,13 @@ public class PublicMetricsAutoConfigurationTests { } private void loadWeb(Class... config) { - AnnotationConfigEmbeddedWebApplicationContext context = new AnnotationConfigEmbeddedWebApplicationContext(); + AnnotationConfigServletWebServerApplicationContext context = new AnnotationConfigServletWebServerApplicationContext(); if (config.length > 0) { context.register(config); } context.register(DataSourcePoolMetadataProvidersConfiguration.class, CacheStatisticsAutoConfiguration.class, - PublicMetricsAutoConfiguration.class, - MockEmbeddedServletContainerFactory.class); + PublicMetricsAutoConfiguration.class, MockServletWebServerFactory.class); context.refresh(); this.context = context; } @@ -346,8 +345,8 @@ public class PublicMetricsAutoConfigurationTests { static class TomcatConfiguration { @Bean - public TomcatEmbeddedServletContainerFactory containerFactory() { - TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory(); + public TomcatServletWebServerFactory webServerFactory() { + TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(); factory.setPort(SocketUtils.findAvailableTcpPort(40000)); return factory; } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/SkipSslVerificationHttpRequestFactoryTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/SkipSslVerificationHttpRequestFactoryTests.java index c46be09569..6c02dc18f4 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/SkipSslVerificationHttpRequestFactoryTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/cloudfoundry/SkipSslVerificationHttpRequestFactoryTests.java @@ -23,11 +23,11 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.springframework.boot.context.embedded.EmbeddedWebServer; -import org.springframework.boot.context.embedded.ExampleServlet; -import org.springframework.boot.context.embedded.Ssl; -import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.server.Ssl; +import org.springframework.boot.web.server.WebServer; import org.springframework.boot.web.servlet.ServletRegistrationBean; +import org.springframework.boot.web.servlet.server.ExampleServlet; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.client.ResourceAccessException; @@ -63,13 +63,12 @@ public class SkipSslVerificationHttpRequestFactoryTests { } private String getHttpsUrl() { - TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory( - 0); + TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(0); factory.setSsl(getSsl("password", "classpath:test.jks")); - EmbeddedWebServer container = factory.getEmbeddedServletContainer( + WebServer webServer = factory.getWebServer( new ServletRegistrationBean<>(new ExampleServlet(), "/hello")); - container.start(); - return "https://localhost:" + container.getPort() + "/hello"; + webServer.start(); + return "https://localhost:" + webServer.getPort() + "/hello"; } private Ssl getSsl(String keyPassword, String keyStore) { diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/TomcatPublicMetricsTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/TomcatPublicMetricsTests.java index c4d3d94c0a..e5e23bf48b 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/TomcatPublicMetricsTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/TomcatPublicMetricsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -21,8 +21,8 @@ import java.util.Iterator; import org.junit.Test; import org.springframework.boot.actuate.metrics.Metric; -import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; -import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.util.SocketUtils; @@ -39,7 +39,7 @@ public class TomcatPublicMetricsTests { @Test public void tomcatMetrics() throws Exception { - AnnotationConfigEmbeddedWebApplicationContext context = new AnnotationConfigEmbeddedWebApplicationContext( + AnnotationConfigServletWebServerApplicationContext context = new AnnotationConfigServletWebServerApplicationContext( Config.class); try { TomcatPublicMetrics tomcatMetrics = context @@ -58,8 +58,8 @@ public class TomcatPublicMetricsTests { static class Config { @Bean - public TomcatEmbeddedServletContainerFactory containerFactory() { - TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory(); + public TomcatServletWebServerFactory webServerFactory() { + TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(); factory.setPort(SocketUtils.findAvailableTcpPort(40000)); return factory; } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointServerContextPathIntegrationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointServerContextPathIntegrationTests.java index 461c31869e..df026566a7 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointServerContextPathIntegrationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointServerContextPathIntegrationTests.java @@ -23,10 +23,10 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.actuate.autoconfigure.MinimalActuatorHypermediaApplication; -import org.springframework.boot.context.embedded.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; import org.springframework.hateoas.ResourceSupport; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointServerServletPathIntegrationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointServerServletPathIntegrationTests.java index fde1350c50..735dbf8536 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointServerServletPathIntegrationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/HalBrowserMvcEndpointServerServletPathIntegrationTests.java @@ -23,10 +23,10 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.actuate.autoconfigure.MinimalActuatorHypermediaApplication; -import org.springframework.boot.context.embedded.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; import org.springframework.hateoas.ResourceSupport; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/EnableAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/EnableAutoConfiguration.java index 95fcaa4cf4..4253a81d3d 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/EnableAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/EnableAutoConfiguration.java @@ -26,8 +26,8 @@ import java.lang.annotation.Target; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.servlet.server.ServletWebServerFactory; import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @@ -38,8 +38,8 @@ import org.springframework.core.io.support.SpringFactoriesLoader; * configure beans that you are likely to need. Auto-configuration classes are usually * applied based on your classpath and what beans you have defined. For example, If you * have {@code tomcat-embedded.jar} on your classpath you are likely to want a - * {@link TomcatEmbeddedServletContainerFactory} (unless you have defined your own - * {@link EmbeddedServletContainerFactory} bean). + * {@link TomcatServletWebServerFactory} (unless you have defined your own + * {@link ServletWebServerFactory} bean). *

* Auto-configuration tries to be as intelligent as possible and will back-away as you * define more of your own configuration. You can always manually {@link #exclude()} any diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnWebApplicationCondition.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnWebApplicationCondition.java index c4af06d75b..7ed14e75cc 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnWebApplicationCondition.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnWebApplicationCondition.java @@ -19,7 +19,7 @@ package org.springframework.boot.autoconfigure.condition; import java.util.Map; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type; -import org.springframework.boot.context.ReactiveWebApplicationContext; +import org.springframework.boot.web.reactive.context.ReactiveWebApplicationContext; import org.springframework.context.annotation.Condition; import org.springframework.context.annotation.ConditionContext; import org.springframework.core.Ordered; diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/BasicErrorController.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/BasicErrorController.java index 688abdd2a1..a0181afcf7 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/BasicErrorController.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/BasicErrorController.java @@ -24,7 +24,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.boot.autoconfigure.web.ErrorProperties.IncludeStacktrace; -import org.springframework.boot.context.embedded.AbstractEmbeddedServletContainerFactory; +import org.springframework.boot.web.servlet.server.AbstractServletWebServerFactory; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -38,7 +38,7 @@ import org.springframework.web.servlet.ModelAndView; * Basic global error {@link Controller}, rendering {@link ErrorAttributes}. More specific * errors can be handled either using Spring MVC abstractions (e.g. * {@code @ExceptionHandler}) or by adding servlet - * {@link AbstractEmbeddedServletContainerFactory#setErrorPages container error pages}. + * {@link AbstractServletWebServerFactory#setErrorPages server error pages}. * * @author Dave Syer * @author Phillip Webb diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/DefaultServletContainerCustomizer.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/DefaultServletWebServerFactoryCustomizer.java similarity index 80% rename from spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/DefaultServletContainerCustomizer.java rename to spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/DefaultServletWebServerFactoryCustomizer.java index ab8f45d60f..fe60144fe3 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/DefaultServletContainerCustomizer.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/DefaultServletWebServerFactoryCustomizer.java @@ -43,19 +43,19 @@ import org.eclipse.jetty.server.handler.HandlerWrapper; import org.springframework.boot.autoconfigure.web.ServerProperties.Session; import org.springframework.boot.cloud.CloudPlatform; -import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer; -import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer; -import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizerBeanPostProcessor; -import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.InitParameterConfiguringServletContextInitializer; -import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.jetty.JettyServerCustomizer; -import org.springframework.boot.context.embedded.tomcat.TomcatConnectorCustomizer; -import org.springframework.boot.context.embedded.tomcat.TomcatContextCustomizer; -import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.undertow.UndertowBuilderCustomizer; -import org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory; +import org.springframework.boot.web.embedded.jetty.JettyServerCustomizer; +import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory; +import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer; +import org.springframework.boot.web.embedded.tomcat.TomcatContextCustomizer; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.embedded.undertow.UndertowBuilderCustomizer; +import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory; import org.springframework.boot.web.servlet.ServletContextInitializer; +import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory; +import org.springframework.boot.web.servlet.server.InitParameterConfiguringServletContextInitializer; +import org.springframework.boot.web.servlet.server.ServletWebServerFactory; +import org.springframework.boot.web.servlet.server.ServletWebServerFactoryCustomizer; +import org.springframework.boot.web.servlet.server.ServletWebServerFactoryCustomizerBeanPostProcessor; import org.springframework.context.EnvironmentAware; import org.springframework.core.Ordered; import org.springframework.core.env.Environment; @@ -63,26 +63,26 @@ import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; /** - * Customizer used by an {@link EmbeddedServletContainerFactory} when an - * {@link EmbeddedServletContainerCustomizerBeanPostProcessor} is active. + * Customizer used by an {@link ServletWebServerFactory} when an + * {@link ServletWebServerFactoryCustomizerBeanPostProcessor} is active. * * @author Brian Clozel * @author Stephane Nicoll * @since 2.0.0 */ -public class DefaultServletContainerCustomizer - implements EmbeddedServletContainerCustomizer, EnvironmentAware, Ordered { +public class DefaultServletWebServerFactoryCustomizer + implements ServletWebServerFactoryCustomizer, EnvironmentAware, Ordered { private final ServerProperties serverProperties; private Environment environment; - public DefaultServletContainerCustomizer(ServerProperties serverProperties) { + public DefaultServletWebServerFactoryCustomizer(ServerProperties serverProperties) { this.serverProperties = serverProperties; } public void setLoader(String value) { - // no op to support Tomcat running as a traditional container (not embedded) + // no op to support Tomcat running as a traditional server (not embedded) } @Override @@ -96,50 +96,50 @@ public class DefaultServletContainerCustomizer } @Override - public void customize(ConfigurableEmbeddedServletContainer container) { + public void customize(ConfigurableServletWebServerFactory factory) { if (this.serverProperties.getPort() != null) { - container.setPort(this.serverProperties.getPort()); + factory.setPort(this.serverProperties.getPort()); } if (this.serverProperties.getAddress() != null) { - container.setAddress(this.serverProperties.getAddress()); + factory.setAddress(this.serverProperties.getAddress()); } if (this.serverProperties.getServlet().getContextPath() != null) { - container.setContextPath(this.serverProperties.getServlet().getContextPath()); + factory.setContextPath(this.serverProperties.getServlet().getContextPath()); } if (this.serverProperties.getDisplayName() != null) { - container.setDisplayName(this.serverProperties.getDisplayName()); + factory.setDisplayName(this.serverProperties.getDisplayName()); } if (this.serverProperties.getSession().getTimeout() != null) { - container.setSessionTimeout(this.serverProperties.getSession().getTimeout()); + factory.setSessionTimeout(this.serverProperties.getSession().getTimeout()); } - container.setPersistSession(this.serverProperties.getSession().isPersistent()); - container.setSessionStoreDir(this.serverProperties.getSession().getStoreDir()); + factory.setPersistSession(this.serverProperties.getSession().isPersistent()); + factory.setSessionStoreDir(this.serverProperties.getSession().getStoreDir()); if (this.serverProperties.getSsl() != null) { - container.setSsl(this.serverProperties.getSsl()); + factory.setSsl(this.serverProperties.getSsl()); } if (this.serverProperties.getServlet() != null) { - container.setJsp(this.serverProperties.getServlet().getJsp()); + factory.setJsp(this.serverProperties.getServlet().getJsp()); } if (this.serverProperties.getCompression() != null) { - container.setCompression(this.serverProperties.getCompression()); + factory.setCompression(this.serverProperties.getCompression()); } - container.setServerHeader(this.serverProperties.getServerHeader()); - if (container instanceof TomcatEmbeddedServletContainerFactory) { + factory.setServerHeader(this.serverProperties.getServerHeader()); + if (factory instanceof TomcatServletWebServerFactory) { TomcatCustomizer.customizeTomcat(this.serverProperties, this.environment, - (TomcatEmbeddedServletContainerFactory) container); + (TomcatServletWebServerFactory) factory); } - if (container instanceof JettyEmbeddedServletContainerFactory) { + if (factory instanceof JettyServletWebServerFactory) { JettyCustomizer.customizeJetty(this.serverProperties, this.environment, - (JettyEmbeddedServletContainerFactory) container); + (JettyServletWebServerFactory) factory); } - if (container instanceof UndertowEmbeddedServletContainerFactory) { + if (factory instanceof UndertowServletWebServerFactory) { UndertowCustomizer.customizeUndertow(this.serverProperties, this.environment, - (UndertowEmbeddedServletContainerFactory) container); + (UndertowServletWebServerFactory) factory); } - container.addInitializers( + factory.addInitializers( new SessionConfiguringInitializer(this.serverProperties.getSession())); - container.addInitializers(new InitParameterConfiguringServletContextInitializer( + factory.addInitializers(new InitParameterConfiguringServletContextInitializer( this.serverProperties.getServlet().getContextParameters())); } @@ -216,7 +216,7 @@ public class DefaultServletContainerCustomizer private static class TomcatCustomizer { public static void customizeTomcat(ServerProperties serverProperties, - Environment environment, TomcatEmbeddedServletContainerFactory factory) { + Environment environment, TomcatServletWebServerFactory factory) { ServerProperties.Tomcat tomcatProperties = serverProperties.getTomcat(); if (tomcatProperties.getBasedir() != null) { @@ -266,8 +266,8 @@ public class DefaultServletContainerCustomizer } } - private static void customizeAcceptCount( - TomcatEmbeddedServletContainerFactory factory, final int acceptCount) { + private static void customizeAcceptCount(TomcatServletWebServerFactory factory, + final int acceptCount) { factory.addConnectorCustomizers(new TomcatConnectorCustomizer() { @Override @@ -282,8 +282,8 @@ public class DefaultServletContainerCustomizer }); } - private static void customizeMaxConnections( - TomcatEmbeddedServletContainerFactory factory, final int maxConnections) { + private static void customizeMaxConnections(TomcatServletWebServerFactory factory, + final int maxConnections) { factory.addConnectorCustomizers(new TomcatConnectorCustomizer() { @Override @@ -299,8 +299,7 @@ public class DefaultServletContainerCustomizer } private static void customizeConnectionTimeout( - TomcatEmbeddedServletContainerFactory factory, - final int connectionTimeout) { + TomcatServletWebServerFactory factory, final int connectionTimeout) { factory.addConnectorCustomizers(new TomcatConnectorCustomizer() { @Override @@ -316,7 +315,7 @@ public class DefaultServletContainerCustomizer } private static void customizeRemoteIpValve(ServerProperties properties, - Environment environment, TomcatEmbeddedServletContainerFactory factory) { + Environment environment, TomcatServletWebServerFactory factory) { String protocolHeader = properties.getTomcat().getProtocolHeader(); String remoteIpHeader = properties.getTomcat().getRemoteIpHeader(); // For back compatibility the valve is also enabled if protocol-header is set @@ -340,8 +339,8 @@ public class DefaultServletContainerCustomizer } @SuppressWarnings("rawtypes") - private static void customizeMaxThreads( - TomcatEmbeddedServletContainerFactory factory, final int maxThreads) { + private static void customizeMaxThreads(TomcatServletWebServerFactory factory, + final int maxThreads) { factory.addConnectorCustomizers(new TomcatConnectorCustomizer() { @Override public void customize(Connector connector) { @@ -357,8 +356,7 @@ public class DefaultServletContainerCustomizer } @SuppressWarnings("rawtypes") - private static void customizeMinThreads( - TomcatEmbeddedServletContainerFactory factory, + private static void customizeMinThreads(TomcatServletWebServerFactory factory, final int minSpareThreads) { factory.addConnectorCustomizers(new TomcatConnectorCustomizer() { @Override @@ -376,8 +374,7 @@ public class DefaultServletContainerCustomizer @SuppressWarnings("rawtypes") private static void customizeMaxHttpHeaderSize( - TomcatEmbeddedServletContainerFactory factory, - final int maxHttpHeaderSize) { + TomcatServletWebServerFactory factory, final int maxHttpHeaderSize) { factory.addConnectorCustomizers(new TomcatConnectorCustomizer() { @Override @@ -393,8 +390,7 @@ public class DefaultServletContainerCustomizer } private static void customizeMaxHttpPostSize( - TomcatEmbeddedServletContainerFactory factory, - final int maxHttpPostSize) { + TomcatServletWebServerFactory factory, final int maxHttpPostSize) { factory.addConnectorCustomizers(new TomcatConnectorCustomizer() { @Override @@ -406,7 +402,7 @@ public class DefaultServletContainerCustomizer } private static void customizeAccessLog(ServerProperties.Tomcat tomcatProperties, - TomcatEmbeddedServletContainerFactory factory) { + TomcatServletWebServerFactory factory) { AccessLogValve valve = new AccessLogValve(); valve.setPattern(tomcatProperties.getAccesslog().getPattern()); @@ -423,7 +419,7 @@ public class DefaultServletContainerCustomizer } private static void customizeRedirectContextRoot( - TomcatEmbeddedServletContainerFactory factory, + TomcatServletWebServerFactory factory, final boolean redirectContextRoot) { factory.addContextCustomizers(new TomcatContextCustomizer() { @@ -440,8 +436,7 @@ public class DefaultServletContainerCustomizer private static class UndertowCustomizer { protected static void customizeUndertow(final ServerProperties serverProperties, - Environment environment, - UndertowEmbeddedServletContainerFactory factory) { + Environment environment, UndertowServletWebServerFactory factory) { ServerProperties.Undertow undertowProperties = serverProperties.getUndertow(); ServerProperties.Undertow.Accesslog accesslogProperties = undertowProperties @@ -484,8 +479,7 @@ public class DefaultServletContainerCustomizer } private static void customizeConnectionTimeout( - UndertowEmbeddedServletContainerFactory factory, - final int connectionTimeout) { + UndertowServletWebServerFactory factory, final int connectionTimeout) { factory.addBuilderCustomizers(new UndertowBuilderCustomizer() { @Override public void customize(Undertow.Builder builder) { @@ -496,8 +490,7 @@ public class DefaultServletContainerCustomizer } private static void customizeMaxHttpHeaderSize( - UndertowEmbeddedServletContainerFactory factory, - final int maxHttpHeaderSize) { + UndertowServletWebServerFactory factory, final int maxHttpHeaderSize) { factory.addBuilderCustomizers(new UndertowBuilderCustomizer() { @Override @@ -510,8 +503,7 @@ public class DefaultServletContainerCustomizer } private static void customizeMaxHttpPostSize( - UndertowEmbeddedServletContainerFactory factory, - final long maxHttpPostSize) { + UndertowServletWebServerFactory factory, final long maxHttpPostSize) { factory.addBuilderCustomizers(new UndertowBuilderCustomizer() { @Override @@ -528,7 +520,7 @@ public class DefaultServletContainerCustomizer private static class JettyCustomizer { public static void customizeJetty(final ServerProperties serverProperties, - Environment environment, JettyEmbeddedServletContainerFactory factory) { + Environment environment, JettyServletWebServerFactory factory) { ServerProperties.Jetty jettyProperties = serverProperties.getJetty(); factory.setUseForwardHeaders( getOrDeduceUseForwardHeaders(serverProperties, environment)); @@ -553,8 +545,7 @@ public class DefaultServletContainerCustomizer } private static void customizeConnectionTimeout( - JettyEmbeddedServletContainerFactory factory, - final int connectionTimeout) { + JettyServletWebServerFactory factory, final int connectionTimeout) { factory.addServerCustomizers(new JettyServerCustomizer() { @Override @@ -572,8 +563,7 @@ public class DefaultServletContainerCustomizer } private static void customizeMaxHttpHeaderSize( - JettyEmbeddedServletContainerFactory factory, - final int maxHttpHeaderSize) { + JettyServletWebServerFactory factory, final int maxHttpHeaderSize) { factory.addServerCustomizers(new JettyServerCustomizer() { @Override @@ -619,8 +609,8 @@ public class DefaultServletContainerCustomizer }); } - private static void customizeMaxHttpPostSize( - JettyEmbeddedServletContainerFactory factory, final int maxHttpPostSize) { + private static void customizeMaxHttpPostSize(JettyServletWebServerFactory factory, + final int maxHttpPostSize) { factory.addServerCustomizers(new JettyServerCustomizer() { @Override diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/DispatcherServletAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/DispatcherServletAutoConfiguration.java index 1c799f4b22..26fa49ea5c 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/DispatcherServletAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/DispatcherServletAutoConfiguration.java @@ -53,7 +53,7 @@ import org.springframework.web.servlet.DispatcherServlet; /** * {@link EnableAutoConfiguration Auto-configuration} for the Spring * {@link DispatcherServlet}. Should work for a standalone application where an embedded - * servlet container is already present and also for a deployable application using + * web server is already present and also for a deployable application using * {@link SpringBootServletInitializer}. * * @author Phillip Webb @@ -65,7 +65,7 @@ import org.springframework.web.servlet.DispatcherServlet; @Configuration @ConditionalOnWebApplication(type = Type.SERVLET) @ConditionalOnClass(DispatcherServlet.class) -@AutoConfigureAfter(EmbeddedServletContainerAutoConfiguration.class) +@AutoConfigureAfter(ServletWebServerFactoryAutoConfiguration.class) @EnableConfigurationProperties(ServerProperties.class) public class DispatcherServletAutoConfiguration { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration.java index a0876816b6..33dfe63b6f 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration.java @@ -44,11 +44,11 @@ import org.springframework.boot.autoconfigure.condition.SearchStrategy; import org.springframework.boot.autoconfigure.condition.SpringBootCondition; import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider; import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProviders; -import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.boot.web.servlet.ErrorPage; -import org.springframework.boot.web.servlet.ErrorPageRegistrar; -import org.springframework.boot.web.servlet.ErrorPageRegistry; +import org.springframework.boot.web.server.ErrorPage; +import org.springframework.boot.web.server.ErrorPageRegistrar; +import org.springframework.boot.web.server.ErrorPageRegistry; +import org.springframework.boot.web.servlet.server.ServletWebServerFactoryCustomizer; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ConditionContext; @@ -296,8 +296,7 @@ public class ErrorMvcAutoConfiguration { } /** - * {@link EmbeddedServletContainerCustomizer} that configures the container's error - * pages. + * {@link ServletWebServerFactoryCustomizer} that configures the server's error pages. */ private static class ErrorPageCustomizer implements ErrorPageRegistrar, Ordered { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/HttpEncodingAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/HttpEncodingAutoConfiguration.java index 2e36f41231..9420031334 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/HttpEncodingAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/HttpEncodingAutoConfiguration.java @@ -22,10 +22,10 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.boot.autoconfigure.web.HttpEncodingProperties.Type; -import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer; -import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.boot.web.filter.OrderedCharacterEncodingFilter; +import org.springframework.boot.web.servlet.filter.OrderedCharacterEncodingFilter; +import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory; +import org.springframework.boot.web.servlet.server.ServletWebServerFactoryCustomizer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.Ordered; @@ -68,7 +68,7 @@ public class HttpEncodingAutoConfiguration { } private static class LocaleCharsetMappingsCustomizer - implements EmbeddedServletContainerCustomizer, Ordered { + implements ServletWebServerFactoryCustomizer, Ordered { private final HttpEncodingProperties properties; @@ -77,9 +77,9 @@ public class HttpEncodingAutoConfiguration { } @Override - public void customize(ConfigurableEmbeddedServletContainer container) { + public void customize(ConfigurableServletWebServerFactory webServerFactory) { if (this.properties.getMapping() != null) { - container.setLocaleCharsetMappings(this.properties.getMapping()); + webServerFactory.setLocaleCharsetMappings(this.properties.getMapping()); } } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/MultipartAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/MultipartAutoConfiguration.java index 9a5d03faaa..9bfd6065f3 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/MultipartAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/MultipartAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -23,8 +23,8 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext; import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.multipart.MultipartResolver; @@ -35,11 +35,11 @@ import org.springframework.web.servlet.DispatcherServlet; * {@link EnableAutoConfiguration Auto-configuration} for multi-part uploads. Adds a * {@link StandardServletMultipartResolver} if none is present, and adds a * {@link javax.servlet.MultipartConfigElement multipartConfigElement} if none is - * otherwise defined. The {@link EmbeddedWebApplicationContext} will associate the + * otherwise defined. The {@link ServletWebServerApplicationContext} will associate the * {@link MultipartConfigElement} bean to any {@link Servlet} beans. *

* The {@link javax.servlet.MultipartConfigElement} is a Servlet API that's used to - * configure how the container handles file uploads. By default + * configure how the server handles file uploads. By default * * @author Greg Turnquist * @author Josh Long diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java index 9162c7bfb9..6483d3bcfd 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java @@ -20,15 +20,20 @@ import java.io.File; import java.net.InetAddress; import java.nio.charset.Charset; import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Set; -import org.springframework.boot.context.embedded.Compression; -import org.springframework.boot.context.embedded.Servlet; -import org.springframework.boot.context.embedded.Ssl; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.DeprecatedConfigurationProperty; import org.springframework.boot.context.properties.NestedConfigurationProperty; +import org.springframework.boot.web.server.Compression; +import org.springframework.boot.web.server.Ssl; +import org.springframework.boot.web.servlet.server.Jsp; +import org.springframework.util.Assert; +import org.springframework.util.StringUtils; /** * {@link ConfigurationProperties} for a web server (e.g. port and path settings). @@ -82,8 +87,8 @@ public class ServerProperties { /** * Time in milliseconds that connectors will wait for another HTTP request before - * closing the connection. When not set, the connector's container-specific default - * will be used. Use a value of -1 to indicate no (i.e. infinite) timeout. + * closing the connection. When not set, the connector's server-specific default will + * be used. Use a value of -1 to indicate no (i.e. infinite) timeout. */ private Integer connectionTimeout; @@ -95,7 +100,6 @@ public class ServerProperties { @NestedConfigurationProperty private Compression compression = new Compression(); - @NestedConfigurationProperty private Servlet servlet = new Servlet(); private final Tomcat tomcat = new Tomcat(); @@ -204,6 +208,120 @@ public class ServerProperties { return this.undertow; } + /** + * Servlet properties. + */ + public class Servlet { + + /** + * ServletContext parameters. + */ + private final Map contextParameters = new HashMap<>(); + + /** + * Context path of the application. + */ + private String contextPath; + + /** + * Path of the main dispatcher servlet. + */ + private String path = "/"; + + @NestedConfigurationProperty + private Jsp jsp = new Jsp(); + + public String getContextPath() { + return this.contextPath; + } + + public void setContextPath(String contextPath) { + this.contextPath = cleanContextPath(contextPath); + } + + private String cleanContextPath(String contextPath) { + if (StringUtils.hasText(contextPath) && contextPath.endsWith("/")) { + return contextPath.substring(0, contextPath.length() - 1); + } + return contextPath; + } + + public String getPath() { + return this.path; + } + + public void setPath(String path) { + Assert.notNull(path, "Path must not be null"); + this.path = path; + } + + public Map getContextParameters() { + return this.contextParameters; + } + + public Jsp getJsp() { + return this.jsp; + } + + public void setJsp(Jsp jsp) { + this.jsp = jsp; + } + + public String getServletMapping() { + if (this.path.equals("") || this.path.equals("/")) { + return "/"; + } + if (this.path.contains("*")) { + return this.path; + } + if (this.path.endsWith("/")) { + return this.path + "*"; + } + return this.path + "/*"; + } + + public String getPath(String path) { + String prefix = getServletPrefix(); + if (!path.startsWith("/")) { + path = "/" + path; + } + return prefix + path; + } + + public String getServletPrefix() { + String result = this.path; + if (result.contains("*")) { + result = result.substring(0, result.indexOf("*")); + } + if (result.endsWith("/")) { + result = result.substring(0, result.length() - 1); + } + return result; + } + + public String[] getPathsArray(Collection paths) { + String[] result = new String[paths.size()]; + int i = 0; + for (String path : paths) { + result[i++] = getPath(path); + } + return result; + } + + public String[] getPathsArray(String[] paths) { + String[] result = new String[paths.length]; + int i = 0; + for (String path : paths) { + result[i++] = getPath(path); + } + return result; + } + + } + + /** + * Session properties. + */ public static class Session { /** @@ -264,6 +382,9 @@ public class ServerProperties { this.storeDir = storeDir; } + /** + * Cookie properties. + */ public static class Cookie { /** @@ -384,6 +505,9 @@ public class ServerProperties { } + /** + * Tomcat properties. + */ public static class Tomcat { /** @@ -615,6 +739,9 @@ public class ServerProperties { this.additionalTldSkipPatterns = additionalTldSkipPatterns; } + /** + * Tomcat access log properties. + */ public static class Accesslog { /** @@ -753,6 +880,9 @@ public class ServerProperties { } + /** + * Jetty properties. + */ public static class Jetty { /** @@ -796,6 +926,9 @@ public class ServerProperties { } + /** + * Undertow properties. + */ public static class Undertow { /** @@ -884,6 +1017,9 @@ public class ServerProperties { return this.accesslog; } + /** + * Undertow access log properties. + */ public static class Accesslog { /** diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/EmbeddedServletContainerAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServletWebServerFactoryAutoConfiguration.java similarity index 70% rename from spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/EmbeddedServletContainerAutoConfiguration.java rename to spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServletWebServerFactoryAutoConfiguration.java index b92e55b2c1..b533449b46 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/EmbeddedServletContainerAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServletWebServerFactoryAutoConfiguration.java @@ -38,14 +38,14 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type; import org.springframework.boot.autoconfigure.condition.SearchStrategy; -import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration.BeanPostProcessorsRegistrar; -import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizerBeanPostProcessor; -import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory; +import org.springframework.boot.autoconfigure.web.ServletWebServerFactoryAutoConfiguration.BeanPostProcessorsRegistrar; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.boot.web.servlet.ErrorPageRegistrarBeanPostProcessor; +import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory; +import org.springframework.boot.web.server.ErrorPageRegistrarBeanPostProcessor; +import org.springframework.boot.web.servlet.server.ServletWebServerFactory; +import org.springframework.boot.web.servlet.server.ServletWebServerFactoryCustomizerBeanPostProcessor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @@ -55,7 +55,7 @@ import org.springframework.core.type.AnnotationMetadata; import org.springframework.util.ObjectUtils; /** - * {@link EnableAutoConfiguration Auto-configuration} for an embedded servlet containers. + * {@link EnableAutoConfiguration Auto-configuration} for servlet web servers. * * @author Phillip Webb * @author Dave Syer @@ -68,13 +68,13 @@ import org.springframework.util.ObjectUtils; @ConditionalOnWebApplication(type = Type.SERVLET) @EnableConfigurationProperties(ServerProperties.class) @Import(BeanPostProcessorsRegistrar.class) -public class EmbeddedServletContainerAutoConfiguration { +public class ServletWebServerFactoryAutoConfiguration { @Bean @ConditionalOnMissingBean - public DefaultServletContainerCustomizer serverPropertiesServletContainerCustomizer( + public DefaultServletWebServerFactoryCustomizer serverPropertiesWebServerFactoryCustomizer( ServerProperties serverProperties) { - return new DefaultServletContainerCustomizer(serverProperties); + return new DefaultServletWebServerFactoryCustomizer(serverProperties); } /** @@ -82,12 +82,12 @@ public class EmbeddedServletContainerAutoConfiguration { */ @Configuration @ConditionalOnClass({ Servlet.class, Tomcat.class }) - @ConditionalOnMissingBean(value = EmbeddedServletContainerFactory.class, search = SearchStrategy.CURRENT) + @ConditionalOnMissingBean(value = ServletWebServerFactory.class, search = SearchStrategy.CURRENT) public static class EmbeddedTomcat { @Bean - public TomcatEmbeddedServletContainerFactory tomcatEmbeddedServletContainerFactory() { - return new TomcatEmbeddedServletContainerFactory(); + public TomcatServletWebServerFactory tomcatServletWebServerFactory() { + return new TomcatServletWebServerFactory(); } } @@ -98,12 +98,12 @@ public class EmbeddedServletContainerAutoConfiguration { @Configuration @ConditionalOnClass({ Servlet.class, Server.class, Loader.class, WebAppContext.class }) - @ConditionalOnMissingBean(value = EmbeddedServletContainerFactory.class, search = SearchStrategy.CURRENT) + @ConditionalOnMissingBean(value = ServletWebServerFactory.class, search = SearchStrategy.CURRENT) public static class EmbeddedJetty { @Bean - public JettyEmbeddedServletContainerFactory jettyEmbeddedServletContainerFactory() { - return new JettyEmbeddedServletContainerFactory(); + public JettyServletWebServerFactory JettyServletWebServerFactory() { + return new JettyServletWebServerFactory(); } } @@ -113,18 +113,18 @@ public class EmbeddedServletContainerAutoConfiguration { */ @Configuration @ConditionalOnClass({ Servlet.class, Undertow.class, SslClientAuthMode.class }) - @ConditionalOnMissingBean(value = EmbeddedServletContainerFactory.class, search = SearchStrategy.CURRENT) + @ConditionalOnMissingBean(value = ServletWebServerFactory.class, search = SearchStrategy.CURRENT) public static class EmbeddedUndertow { @Bean - public UndertowEmbeddedServletContainerFactory undertowEmbeddedServletContainerFactory() { - return new UndertowEmbeddedServletContainerFactory(); + public UndertowServletWebServerFactory undertowServletWebServerFactory() { + return new UndertowServletWebServerFactory(); } } /** - * Registers a {@link EmbeddedServletContainerCustomizerBeanPostProcessor}. Registered + * Registers a {@link ServletWebServerFactoryCustomizerBeanPostProcessor}. Registered * via {@link ImportBeanDefinitionRegistrar} for early registration. */ public static class BeanPostProcessorsRegistrar @@ -146,8 +146,8 @@ public class EmbeddedServletContainerAutoConfiguration { return; } registerSyntheticBeanIfMissing(registry, - "embeddedServletContainerCustomizerBeanPostProcessor", - EmbeddedServletContainerCustomizerBeanPostProcessor.class); + "ServletWebServerCustomizerBeanPostProcessor", + ServletWebServerFactoryCustomizerBeanPostProcessor.class); registerSyntheticBeanIfMissing(registry, "errorPageRegistrarBeanPostProcessor", ErrorPageRegistrarBeanPostProcessor.class); diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java index f642606bea..f51855a2d7 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java @@ -47,9 +47,9 @@ import org.springframework.boot.autoconfigure.validation.SpringValidator; import org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration; import org.springframework.boot.autoconfigure.web.ResourceProperties.Strategy; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.boot.web.filter.OrderedHiddenHttpMethodFilter; -import org.springframework.boot.web.filter.OrderedHttpPutFormContentFilter; -import org.springframework.boot.web.filter.OrderedRequestContextFilter; +import org.springframework.boot.web.servlet.filter.OrderedHiddenHttpMethodFilter; +import org.springframework.boot.web.servlet.filter.OrderedHttpPutFormContentFilter; +import org.springframework.boot.web.servlet.filter.OrderedRequestContextFilter; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/package-info.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/package-info.java index 2af71be199..21c64f848b 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/package-info.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2017 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. @@ -15,6 +15,6 @@ */ /** - * Auto-configuration for embedded servlet containers and Spring MVC. + * Auto-configuration for embedded web servers and Spring MVC. */ package org.springframework.boot.autoconfigure.web; diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webflux/DefaultReactiveWebServerCustomizer.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webflux/DefaultReactiveWebServerCustomizer.java index 025b2ad137..a7d51eabcd 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webflux/DefaultReactiveWebServerCustomizer.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webflux/DefaultReactiveWebServerCustomizer.java @@ -17,15 +17,15 @@ package org.springframework.boot.autoconfigure.webflux; import org.springframework.boot.autoconfigure.web.ServerProperties; -import org.springframework.boot.context.embedded.ConfigurableReactiveWebServer; -import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizerBeanPostProcessor; -import org.springframework.boot.context.embedded.ReactiveWebServerCustomizer; -import org.springframework.boot.context.embedded.ReactiveWebServerFactory; +import org.springframework.boot.web.reactive.server.ConfigurableReactiveWebServerFactory; +import org.springframework.boot.web.reactive.server.ReactiveWebServerCustomizer; +import org.springframework.boot.web.reactive.server.ReactiveWebServerFactory; +import org.springframework.boot.web.servlet.server.ServletWebServerFactoryCustomizerBeanPostProcessor; import org.springframework.core.Ordered; /** * Customizer used by an {@link ReactiveWebServerFactory} when an - * {@link EmbeddedServletContainerCustomizerBeanPostProcessor} is active. + * {@link ServletWebServerFactoryCustomizerBeanPostProcessor} is active. * * @author Brian Clozel * @since 2.0.0 @@ -45,7 +45,7 @@ public class DefaultReactiveWebServerCustomizer } @Override - public void customize(ConfigurableReactiveWebServer server) { + public void customize(ConfigurableReactiveWebServerFactory server) { if (this.serverProperties.getPort() != null) { server.setPort(this.serverProperties.getPort()); } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webflux/ReactiveWebServerAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webflux/ReactiveWebServerAutoConfiguration.java index 7a95fb4de6..1dc02598e6 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webflux/ReactiveWebServerAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webflux/ReactiveWebServerAutoConfiguration.java @@ -27,8 +27,8 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.boot.autoconfigure.web.ServerProperties; -import org.springframework.boot.context.embedded.ReactiveWebServerCustomizerBeanPostProcessor; import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.boot.web.reactive.server.ReactiveWebServerCustomizerBeanPostProcessor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webflux/ReactiveWebServerConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webflux/ReactiveWebServerConfiguration.java index f012daf93a..4fd3632333 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webflux/ReactiveWebServerConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webflux/ReactiveWebServerConfiguration.java @@ -21,11 +21,11 @@ import reactor.ipc.netty.http.server.HttpServer; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.context.embedded.ReactiveWebServerFactory; -import org.springframework.boot.context.embedded.jetty.JettyReactiveWebServerFactory; -import org.springframework.boot.context.embedded.reactor.ReactorNettyReactiveWebServerFactory; -import org.springframework.boot.context.embedded.tomcat.TomcatReactiveWebServerFactory; -import org.springframework.boot.context.embedded.undertow.UndertowReactiveWebServerFactory; +import org.springframework.boot.web.embedded.jetty.JettyReactiveWebServerFactory; +import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory; +import org.springframework.boot.web.embedded.tomcat.TomcatReactiveWebServerFactory; +import org.springframework.boot.web.embedded.undertow.UndertowReactiveWebServerFactory; +import org.springframework.boot.web.reactive.server.ReactiveWebServerFactory; import org.springframework.context.annotation.Bean; /** @@ -43,8 +43,8 @@ abstract class ReactiveWebServerConfiguration { static class ReactorNettyAutoConfiguration { @Bean - public ReactorNettyReactiveWebServerFactory reactorNettyReactiveWebServerFactory() { - return new ReactorNettyReactiveWebServerFactory(); + public NettyReactiveWebServerFactory NettyReactiveWebServerFactory() { + return new NettyReactiveWebServerFactory(); } } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webservices/WebServicesAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webservices/WebServicesAutoConfiguration.java index 9d8840cff3..6fb821538e 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webservices/WebServicesAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webservices/WebServicesAutoConfiguration.java @@ -24,7 +24,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type; -import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; +import org.springframework.boot.autoconfigure.web.ServletWebServerFactoryAutoConfiguration; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.context.ApplicationContext; @@ -46,7 +46,7 @@ import org.springframework.ws.transport.http.MessageDispatcherServlet; @ConditionalOnClass(MessageDispatcherServlet.class) @ConditionalOnMissingBean(WsConfigurationSupport.class) @EnableConfigurationProperties(WebServicesProperties.class) -@AutoConfigureAfter(EmbeddedServletContainerAutoConfiguration.class) +@AutoConfigureAfter(ServletWebServerFactoryAutoConfiguration.class) public class WebServicesAutoConfiguration { private final WebServicesProperties properties; diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/websocket/JettyWebSocketContainerCustomizer.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/websocket/JettyWebSocketContainerCustomizer.java index 9f4f16451f..463b0ce1db 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/websocket/JettyWebSocketContainerCustomizer.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/websocket/JettyWebSocketContainerCustomizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2017 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. @@ -22,10 +22,10 @@ import org.eclipse.jetty.webapp.WebAppContext; import org.eclipse.jetty.websocket.jsr356.server.ServerContainer; import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer; -import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory; +import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory; /** - * {@link WebSocketContainerCustomizer} for {@link JettyEmbeddedServletContainerFactory}. + * {@link WebSocketContainerCustomizer} for {@link JettyServletWebServerFactory}. * * @author Dave Syer * @author Phillip Webb @@ -33,11 +33,11 @@ import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletConta * @since 1.2.0 */ public class JettyWebSocketContainerCustomizer - extends WebSocketContainerCustomizer { + extends WebSocketContainerCustomizer { @Override - protected void doCustomize(JettyEmbeddedServletContainerFactory container) { - container.addConfigurations(new AbstractConfiguration() { + protected void doCustomize(JettyServletWebServerFactory factory) { + factory.addConfigurations(new AbstractConfiguration() { @Override public void configure(WebAppContext context) throws Exception { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/websocket/TomcatWebSocketContainerCustomizer.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/websocket/TomcatWebSocketContainerCustomizer.java index 35cbe69050..c0518aa485 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/websocket/TomcatWebSocketContainerCustomizer.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/websocket/TomcatWebSocketContainerCustomizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2017 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. @@ -21,13 +21,13 @@ import java.lang.reflect.Constructor; import org.apache.catalina.Context; import org.springframework.beans.BeanUtils; -import org.springframework.boot.context.embedded.tomcat.TomcatContextCustomizer; -import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; +import org.springframework.boot.web.embedded.tomcat.TomcatContextCustomizer; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; /** - * {@link WebSocketContainerCustomizer} for {@link TomcatEmbeddedServletContainerFactory}. + * {@link WebSocketContainerCustomizer} for {@link TomcatServletWebServerFactory}. * * @author Dave Syer * @author Phillip Webb @@ -35,7 +35,7 @@ import org.springframework.util.ReflectionUtils; * @since 1.2.0 */ public class TomcatWebSocketContainerCustomizer - extends WebSocketContainerCustomizer { + extends WebSocketContainerCustomizer { private static final String TOMCAT_7_LISTENER_TYPE = "org.apache.catalina.deploy.ApplicationListener"; @@ -44,12 +44,14 @@ public class TomcatWebSocketContainerCustomizer private static final String WS_LISTENER = "org.apache.tomcat.websocket.server.WsContextListener"; @Override - public void doCustomize(TomcatEmbeddedServletContainerFactory tomcatContainer) { - tomcatContainer.addContextCustomizers(new TomcatContextCustomizer() { + public void doCustomize(TomcatServletWebServerFactory factory) { + factory.addContextCustomizers(new TomcatContextCustomizer() { + @Override public void customize(Context context) { addListener(context, findListenerType()); } + }); } @@ -65,10 +67,9 @@ public class TomcatWebSocketContainerCustomizer } /** - * Instead of registering the WsSci directly as a ServletContainerInitializer, we use - * the ApplicationListener provided by Tomcat. Unfortunately the ApplicationListener - * class moved packages in Tomcat 8 and been deleted in 8.0.8 so we have to use - * reflection. + * Instead of registering directly as a ServletContainerInitializer, we use the + * ApplicationListener provided by Tomcat. Unfortunately the ApplicationListener class + * moved packages in Tomcat 8 and been deleted in 8.0.8 so we have to use reflection. * @param context the current context * @param listenerType the type of listener to add */ diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/websocket/UndertowWebSocketContainerCustomizer.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/websocket/UndertowWebSocketContainerCustomizer.java index 03100609cc..9093598a6e 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/websocket/UndertowWebSocketContainerCustomizer.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/websocket/UndertowWebSocketContainerCustomizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2017 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. @@ -19,23 +19,22 @@ package org.springframework.boot.autoconfigure.websocket; import io.undertow.servlet.api.DeploymentInfo; import io.undertow.websockets.jsr.WebSocketDeploymentInfo; -import org.springframework.boot.context.embedded.undertow.UndertowDeploymentInfoCustomizer; -import org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory; +import org.springframework.boot.web.embedded.undertow.UndertowDeploymentInfoCustomizer; +import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory; /** - * {@link WebSocketContainerCustomizer} for - * {@link UndertowEmbeddedServletContainerFactory}. + * {@link WebSocketContainerCustomizer} for {@link UndertowServletWebServerFactory}. * * @author Phillip Webb * @since 1.2.0 */ public class UndertowWebSocketContainerCustomizer - extends WebSocketContainerCustomizer { + extends WebSocketContainerCustomizer { @Override - protected void doCustomize(UndertowEmbeddedServletContainerFactory container) { + protected void doCustomize(UndertowServletWebServerFactory factory) { WebsocketDeploymentInfoCustomizer customizer = new WebsocketDeploymentInfoCustomizer(); - container.addDeploymentInfoCustomizers(customizer); + factory.addDeploymentInfoCustomizers(customizer); } private static class WebsocketDeploymentInfoCustomizer diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/websocket/WebSocketAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/websocket/WebSocketAutoConfiguration.java index f51b0f25d9..9747fdf9ab 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/websocket/WebSocketAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/websocket/WebSocketAutoConfiguration.java @@ -27,7 +27,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type; -import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; +import org.springframework.boot.autoconfigure.web.ServletWebServerFactoryAutoConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -36,16 +36,16 @@ import org.springframework.context.annotation.Configuration; * the appropriate WebSocket modules to be on the classpath. *

* If Tomcat's WebSocket support is detected on the classpath we add a customizer that - * installs the Tomcat Websocket initializer. In a non-embedded container it should - * already be there. + * installs the Tomcat Websocket initializer. In a non-embedded server it should already + * be there. *

* If Jetty's WebSocket support is detected on the classpath we add a configuration that - * configures the context with WebSocket support. In a non-embedded container it should + * configures the context with WebSocket support. In a non-embedded server it should * already be there. *

* If Undertow's WebSocket support is detected on the classpath we add a customizer that - * installs the Undertow Websocket DeploymentInfo Customizer. In a non-embedded container - * it should already be there. + * installs the Undertow Websocket DeploymentInfo Customizer. In a non-embedded server it + * should already be there. * * @author Dave Syer * @author Phillip Webb @@ -54,7 +54,7 @@ import org.springframework.context.annotation.Configuration; @Configuration @ConditionalOnClass({ Servlet.class, ServerContainer.class }) @ConditionalOnWebApplication(type = Type.SERVLET) -@AutoConfigureBefore(EmbeddedServletContainerAutoConfiguration.class) +@AutoConfigureBefore(ServletWebServerFactoryAutoConfiguration.class) public class WebSocketAutoConfiguration { @Configuration diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/websocket/WebSocketContainerCustomizer.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/websocket/WebSocketContainerCustomizer.java index 3440e0167d..1e2c007da0 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/websocket/WebSocketContainerCustomizer.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/websocket/WebSocketContainerCustomizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -16,24 +16,24 @@ package org.springframework.boot.autoconfigure.websocket; -import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer; -import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer; -import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; +import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory; +import org.springframework.boot.web.servlet.server.ServletWebServerFactory; +import org.springframework.boot.web.servlet.server.ServletWebServerFactoryCustomizer; import org.springframework.core.Ordered; import org.springframework.core.ResolvableType; /** - * {@link EmbeddedServletContainerCustomizer} to configure websockets for a given - * {@link EmbeddedServletContainerFactory}. + * {@link ServletWebServerFactoryCustomizer} to configure websockets for a given + * {@link ServletWebServerFactory}. * - * @param the embedded servlet container factory + * @param the {@link ServletWebServerFactory} * @author Dave Syer * @author Phillip Webb * @author Andy Wilkinson * @since 1.2.0 */ -public abstract class WebSocketContainerCustomizer - implements EmbeddedServletContainerCustomizer, Ordered { +public abstract class WebSocketContainerCustomizer + implements ServletWebServerFactoryCustomizer, Ordered { @Override public int getOrder() { @@ -42,17 +42,17 @@ public abstract class WebSocketContainerCustomizer getContainerType() { + protected Class getWebServerFactoryType() { return ResolvableType.forClass(WebSocketContainerCustomizer.class, getClass()) .resolveGeneric(); } - protected abstract void doCustomize(T container); + protected abstract void doCustomize(T factory); } diff --git a/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories b/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories index 0a3781fe3d..d9a3cff3f9 100644 --- a/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories +++ b/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories @@ -105,7 +105,7 @@ org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration, org.springframework.boot.autoconfigure.transaction.jta.JtaAutoConfiguration,\ org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration,\ org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration,\ -org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration,\ +org.springframework.boot.autoconfigure.web.ServletWebServerFactoryAutoConfiguration,\ org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration,\ org.springframework.boot.autoconfigure.web.HttpEncodingAutoConfiguration,\ org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration,\ diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationReproTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationReproTests.java index 5c58505e73..50a1cbfcfd 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationReproTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationReproTests.java @@ -20,7 +20,7 @@ import org.junit.After; import org.junit.Test; import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; +import org.springframework.boot.autoconfigure.web.ServletWebServerFactoryAutoConfiguration; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.ImportResource; @@ -48,7 +48,7 @@ public class AutoConfigurationReproTests { public void doesNotEarlyInitializeFactoryBeans() throws Exception { SpringApplication application = new SpringApplication(EarlyInitConfig.class, PropertySourcesPlaceholderConfigurer.class, - EmbeddedServletContainerAutoConfiguration.class); + ServletWebServerFactoryAutoConfiguration.class); this.context = application.run("--server.port=0"); String bean = (String) this.context.getBean("earlyInit"); assertThat(bean).isEqualTo("bucket"); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/admin/SpringApplicationAdminJmxAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/admin/SpringApplicationAdminJmxAutoConfigurationTests.java index 64efd3580a..068d8ddb19 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/admin/SpringApplicationAdminJmxAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/admin/SpringApplicationAdminJmxAutoConfigurationTests.java @@ -36,10 +36,10 @@ import org.springframework.boot.WebApplicationType; import org.springframework.boot.admin.SpringApplicationAdminMXBeanRegistrar; import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration; import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration; -import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; +import org.springframework.boot.autoconfigure.web.ServletWebServerFactoryAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext; import org.springframework.boot.test.util.EnvironmentTestUtils; +import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @@ -119,16 +119,16 @@ public class SpringApplicationAdminJmxAutoConfigurationTests { @Test public void registerWithSimpleWebApp() throws Exception { this.context = new SpringApplicationBuilder() - .sources(EmbeddedServletContainerAutoConfiguration.class, + .sources(ServletWebServerFactoryAutoConfiguration.class, DispatcherServletAutoConfiguration.class, JmxAutoConfiguration.class, SpringApplicationAdminJmxAutoConfiguration.class) .run("--" + ENABLE_ADMIN_PROP, "--server.port=0"); - assertThat(this.context).isInstanceOf(EmbeddedWebApplicationContext.class); + assertThat(this.context).isInstanceOf(ServletWebServerApplicationContext.class); assertThat(this.mBeanServer.getAttribute(createDefaultObjectName(), "EmbeddedWebApplication")).isEqualTo(Boolean.TRUE); - int expected = ((EmbeddedWebApplicationContext) this.context) - .getEmbeddedWebServer().getPort(); + int expected = ((ServletWebServerApplicationContext) this.context) + .getWebServer().getPort(); String actual = getProperty(createDefaultObjectName(), "local.server.port"); assertThat(actual).isEqualTo(String.valueOf(expected)); } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnNotWebApplicationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnNotWebApplicationTests.java index 4efcec4d90..08732af73f 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnNotWebApplicationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnNotWebApplicationTests.java @@ -21,8 +21,8 @@ import org.junit.Test; import reactor.core.publisher.Mono; import org.springframework.boot.autoconfigure.webflux.MockReactiveWebServerFactory; -import org.springframework.boot.context.GenericReactiveWebApplicationContext; -import org.springframework.boot.context.embedded.ReactiveWebServerFactory; +import org.springframework.boot.web.reactive.context.GenericReactiveWebApplicationContext; +import org.springframework.boot.web.reactive.server.ReactiveWebServerFactory; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnWebApplicationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnWebApplicationTests.java index 151446ae0f..843271f581 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnWebApplicationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnWebApplicationTests.java @@ -22,8 +22,8 @@ import reactor.core.publisher.Mono; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type; import org.springframework.boot.autoconfigure.webflux.MockReactiveWebServerFactory; -import org.springframework.boot.context.GenericReactiveWebApplicationContext; -import org.springframework.boot.context.embedded.ReactiveWebServerFactory; +import org.springframework.boot.web.reactive.context.GenericReactiveWebApplicationContext; +import org.springframework.boot.web.reactive.server.ReactiveWebServerFactory; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomFilterContextPathTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomFilterContextPathTests.java index 3fc0bcefab..1db72601fc 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomFilterContextPathTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomFilterContextPathTests.java @@ -34,7 +34,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; -import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; +import org.springframework.boot.autoconfigure.web.ServletWebServerFactoryAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; @@ -95,7 +95,7 @@ public class JerseyAutoConfigurationCustomFilterContextPathTests { @Retention(RetentionPolicy.RUNTIME) @Documented @Configuration - @Import({ EmbeddedServletContainerAutoConfiguration.class, + @Import({ ServletWebServerFactoryAutoConfiguration.class, JerseyAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class }) protected @interface MinimalWebConfiguration { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomFilterPathTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomFilterPathTests.java index 3fcb7e197d..3a85ea2872 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomFilterPathTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomFilterPathTests.java @@ -34,7 +34,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; -import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; +import org.springframework.boot.autoconfigure.web.ServletWebServerFactoryAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; @@ -94,7 +94,7 @@ public class JerseyAutoConfigurationCustomFilterPathTests { @Retention(RetentionPolicy.RUNTIME) @Documented @Configuration - @Import({ EmbeddedServletContainerAutoConfiguration.class, + @Import({ ServletWebServerFactoryAutoConfiguration.class, JerseyAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class }) protected @interface MinimalWebConfiguration { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomLoadOnStartupTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomLoadOnStartupTests.java index 2a68c84001..a51289eb90 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomLoadOnStartupTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomLoadOnStartupTests.java @@ -29,7 +29,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; -import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; +import org.springframework.boot.autoconfigure.web.ServletWebServerFactoryAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.context.ApplicationContext; @@ -73,7 +73,7 @@ public class JerseyAutoConfigurationCustomLoadOnStartupTests { @Retention(RetentionPolicy.RUNTIME) @Documented @Configuration - @Import({ EmbeddedServletContainerAutoConfiguration.class, + @Import({ ServletWebServerFactoryAutoConfiguration.class, JerseyAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class }) protected @interface MinimalWebConfiguration { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomObjectMapperProviderTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomObjectMapperProviderTests.java index 55f9239437..5abae76c98 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomObjectMapperProviderTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomObjectMapperProviderTests.java @@ -34,7 +34,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; -import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; +import org.springframework.boot.autoconfigure.web.ServletWebServerFactoryAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; @@ -121,7 +121,7 @@ public class JerseyAutoConfigurationCustomObjectMapperProviderTests { @Retention(RetentionPolicy.RUNTIME) @Documented @Configuration - @Import({ EmbeddedServletContainerAutoConfiguration.class, + @Import({ ServletWebServerFactoryAutoConfiguration.class, JacksonAutoConfiguration.class, JerseyAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class }) protected @interface MinimalWebConfiguration { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomServletContextPathTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomServletContextPathTests.java index eac5d84298..79c5a558b8 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomServletContextPathTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomServletContextPathTests.java @@ -34,7 +34,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; -import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; +import org.springframework.boot.autoconfigure.web.ServletWebServerFactoryAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; @@ -95,7 +95,7 @@ public class JerseyAutoConfigurationCustomServletContextPathTests { @Retention(RetentionPolicy.RUNTIME) @Documented @Configuration - @Import({ EmbeddedServletContainerAutoConfiguration.class, + @Import({ ServletWebServerFactoryAutoConfiguration.class, JerseyAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class }) protected @interface MinimalWebConfiguration { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomServletPathTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomServletPathTests.java index 0a49dc21ee..cf56d753a1 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomServletPathTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationCustomServletPathTests.java @@ -34,7 +34,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; -import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; +import org.springframework.boot.autoconfigure.web.ServletWebServerFactoryAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; @@ -95,7 +95,7 @@ public class JerseyAutoConfigurationCustomServletPathTests { @Retention(RetentionPolicy.RUNTIME) @Documented @Configuration - @Import({ EmbeddedServletContainerAutoConfiguration.class, + @Import({ ServletWebServerFactoryAutoConfiguration.class, JerseyAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class }) protected @interface MinimalWebConfiguration { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationDefaultFilterPathTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationDefaultFilterPathTests.java index 4c95867e53..0ecf3b14bb 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationDefaultFilterPathTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationDefaultFilterPathTests.java @@ -33,7 +33,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; -import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; +import org.springframework.boot.autoconfigure.web.ServletWebServerFactoryAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; @@ -92,7 +92,7 @@ public class JerseyAutoConfigurationDefaultFilterPathTests { @Retention(RetentionPolicy.RUNTIME) @Documented @Configuration - @Import({ EmbeddedServletContainerAutoConfiguration.class, + @Import({ ServletWebServerFactoryAutoConfiguration.class, JerseyAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class }) protected @interface MinimalWebConfiguration { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationDefaultServletPathTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationDefaultServletPathTests.java index 37c50119c7..75cdb90ed1 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationDefaultServletPathTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationDefaultServletPathTests.java @@ -33,7 +33,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; -import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; +import org.springframework.boot.autoconfigure.web.ServletWebServerFactoryAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; @@ -93,7 +93,7 @@ public class JerseyAutoConfigurationDefaultServletPathTests { @Retention(RetentionPolicy.RUNTIME) @Documented @Configuration - @Import({ EmbeddedServletContainerAutoConfiguration.class, + @Import({ ServletWebServerFactoryAutoConfiguration.class, JerseyAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class }) protected @interface MinimalWebConfiguration { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationObjectMapperProviderTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationObjectMapperProviderTests.java index e228351c64..a909a22171 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationObjectMapperProviderTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationObjectMapperProviderTests.java @@ -35,7 +35,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; -import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; +import org.springframework.boot.autoconfigure.web.ServletWebServerFactoryAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; @@ -132,7 +132,7 @@ public class JerseyAutoConfigurationObjectMapperProviderTests { @Retention(RetentionPolicy.RUNTIME) @Documented @Configuration - @Import({ EmbeddedServletContainerAutoConfiguration.class, + @Import({ ServletWebServerFactoryAutoConfiguration.class, JacksonAutoConfiguration.class, JerseyAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class }) protected @interface MinimalWebConfiguration { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationServletContainerTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationServletContainerTests.java index cfd4b4013c..47d8c784c6 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationServletContainerTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationServletContainerTests.java @@ -32,11 +32,11 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfigurationServletContainerTests.Application; -import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; -import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; +import org.springframework.boot.autoconfigure.web.ServletWebServerFactoryAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.rule.OutputCapture; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @@ -67,7 +67,7 @@ public class JerseyAutoConfigurationServletContainerTests { "Servlet " + Application.class.getName() + " was not registered"); } - @ImportAutoConfiguration({ EmbeddedServletContainerAutoConfiguration.class, + @ImportAutoConfiguration({ ServletWebServerFactoryAutoConfiguration.class, JerseyAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class }) @Import(ContainerConfiguration.class) @Path("/hello") @@ -91,8 +91,8 @@ public class JerseyAutoConfigurationServletContainerTests { public static class ContainerConfiguration { @Bean - public TomcatEmbeddedServletContainerFactory tomcat() { - return new TomcatEmbeddedServletContainerFactory() { + public TomcatServletWebServerFactory tomcat() { + return new TomcatServletWebServerFactory() { @Override protected void postProcessContext(Context context) { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationWithoutApplicationPathTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationWithoutApplicationPathTests.java index d401ea7b92..11df637c13 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationWithoutApplicationPathTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfigurationWithoutApplicationPathTests.java @@ -33,7 +33,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; -import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; +import org.springframework.boot.autoconfigure.web.ServletWebServerFactoryAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; @@ -92,7 +92,7 @@ public class JerseyAutoConfigurationWithoutApplicationPathTests { @Retention(RetentionPolicy.RUNTIME) @Documented @Configuration - @Import({ EmbeddedServletContainerAutoConfiguration.class, + @Import({ ServletWebServerFactoryAutoConfiguration.class, JerseyAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class }) protected @interface MinimalWebConfiguration { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfigurationIntegrationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfigurationIntegrationTests.java index 1ea124601d..63e597d5fc 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfigurationIntegrationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfigurationIntegrationTests.java @@ -32,11 +32,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration; -import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; -import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext; +import org.springframework.boot.autoconfigure.web.ServletWebServerFactoryAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.stereotype.Controller; @@ -58,13 +58,13 @@ import static org.assertj.core.api.Assertions.assertThat; public class MustacheAutoConfigurationIntegrationTests { @Autowired - private EmbeddedWebApplicationContext context; + private ServletWebServerApplicationContext context; private int port; @Before public void init() { - this.port = this.context.getEmbeddedWebServer().getPort(); + this.port = this.context.getWebServer().getPort(); } @Test @@ -112,7 +112,7 @@ public class MustacheAutoConfigurationIntegrationTests { @Retention(RetentionPolicy.RUNTIME) @Documented @Import({ MustacheAutoConfiguration.class, - EmbeddedServletContainerAutoConfiguration.class, + ServletWebServerFactoryAutoConfiguration.class, DispatcherServletAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class }) protected @interface MinimalWebConfiguration { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/web/MustacheWebIntegrationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/web/MustacheWebIntegrationTests.java index ac92adb02b..2cac7db294 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/web/MustacheWebIntegrationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/web/MustacheWebIntegrationTests.java @@ -37,11 +37,11 @@ import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoCon import org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration; import org.springframework.boot.autoconfigure.mustache.MustacheResourceTemplateLoader; import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration; -import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; -import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext; +import org.springframework.boot.autoconfigure.web.ServletWebServerFactoryAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @@ -64,13 +64,13 @@ import static org.assertj.core.api.Assertions.assertThat; public class MustacheWebIntegrationTests { @Autowired - private EmbeddedWebApplicationContext context; + private ServletWebServerApplicationContext context; private int port; @Before public void init() { - this.port = this.context.getEmbeddedWebServer().getPort(); + this.port = this.context.getWebServer().getPort(); } @Test @@ -138,7 +138,7 @@ public class MustacheWebIntegrationTests { @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented - @Import({ EmbeddedServletContainerAutoConfiguration.class, + @Import({ ServletWebServerFactoryAutoConfiguration.class, DispatcherServletAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class }) protected @interface MinimalWebConfiguration { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityFilterAutoConfigurationEarlyInitializationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityFilterAutoConfigurationEarlyInitializationTests.java index 9638ff488c..43356df742 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityFilterAutoConfigurationEarlyInitializationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityFilterAutoConfigurationEarlyInitializationTests.java @@ -33,10 +33,10 @@ import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration; import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration; import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration; -import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; -import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; import org.springframework.boot.test.util.EnvironmentTestUtils; import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @@ -58,13 +58,13 @@ public class SecurityFilterAutoConfigurationEarlyInitializationTests { @Test public void testSecurityFilterDoesNotCauseEarlyInitialization() throws Exception { - AnnotationConfigEmbeddedWebApplicationContext context = new AnnotationConfigEmbeddedWebApplicationContext(); + AnnotationConfigServletWebServerApplicationContext context = new AnnotationConfigServletWebServerApplicationContext(); try { EnvironmentTestUtils.addEnvironment(context, "server.port:0", "security.user.password:password"); context.register(Config.class); context.refresh(); - int port = context.getEmbeddedWebServer().getPort(); + int port = context.getWebServer().getPort(); new TestRestTemplate("user", "password") .getForEntity("http://localhost:" + port, Object.class); // If early initialization occurred a ConverterNotFoundException is thrown @@ -87,8 +87,8 @@ public class SecurityFilterAutoConfigurationEarlyInitializationTests { static class Config { @Bean - public TomcatEmbeddedServletContainerFactory containerFactory() { - TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory(); + public TomcatServletWebServerFactory webServerFactory() { + TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(); factory.setPort(0); return factory; } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SpringBootWebSecurityConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SpringBootWebSecurityConfigurationTests.java index 8e1d9f835a..4b5c830edc 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SpringBootWebSecurityConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SpringBootWebSecurityConfigurationTests.java @@ -32,9 +32,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration; -import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration; import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration; +import org.springframework.boot.autoconfigure.web.ServletWebServerFactoryAutoConfiguration; import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.context.ConfigurableApplicationContext; @@ -321,7 +321,7 @@ public class SpringBootWebSecurityConfigurationTests { @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented - @Import({ EmbeddedServletContainerAutoConfiguration.class, + @Import({ ServletWebServerFactoryAutoConfiguration.class, DispatcherServletAutoConfiguration.class, WebMvcAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class, ErrorMvcAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class }) diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/OAuth2AutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/OAuth2AutoConfigurationTests.java index acfb606ecc..f36f4ddfb7 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/OAuth2AutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/OAuth2AutoConfigurationTests.java @@ -34,10 +34,10 @@ import org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceS import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration; import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration; import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration; -import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; -import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; import org.springframework.boot.test.util.EnvironmentTestUtils; import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; @@ -116,11 +116,11 @@ public class OAuth2AutoConfigurationTests { private static final Class AUTHORIZATION_SERVER_CONFIG = OAuth2AuthorizationServerConfiguration.class; - private AnnotationConfigEmbeddedWebApplicationContext context; + private AnnotationConfigServletWebServerApplicationContext context; @Test public void testDefaultConfiguration() { - this.context = new AnnotationConfigEmbeddedWebApplicationContext(); + this.context = new AnnotationConfigServletWebServerApplicationContext(); this.context.register(AuthorizationAndResourceServerConfiguration.class, MinimalSecureWebApplication.class); this.context.refresh(); @@ -148,7 +148,7 @@ public class OAuth2AutoConfigurationTests { @Test public void methodSecurityExpressionHandlerIsConfiguredWithRoleHierarchyFromTheContext() { - this.context = new AnnotationConfigEmbeddedWebApplicationContext(); + this.context = new AnnotationConfigServletWebServerApplicationContext(); this.context.register(RoleHierarchyConfiguration.class, AuthorizationAndResourceServerConfiguration.class, MinimalSecureWebApplication.class); @@ -164,7 +164,7 @@ public class OAuth2AutoConfigurationTests { @Test public void methodSecurityExpressionHandlerIsConfiguredWithPermissionEvaluatorFromTheContext() { - this.context = new AnnotationConfigEmbeddedWebApplicationContext(); + this.context = new AnnotationConfigServletWebServerApplicationContext(); this.context.register(PermissionEvaluatorConfiguration.class, AuthorizationAndResourceServerConfiguration.class, MinimalSecureWebApplication.class); @@ -181,7 +181,7 @@ public class OAuth2AutoConfigurationTests { @Test public void testEnvironmentalOverrides() { - this.context = new AnnotationConfigEmbeddedWebApplicationContext(); + this.context = new AnnotationConfigServletWebServerApplicationContext(); EnvironmentTestUtils.addEnvironment(this.context, "security.oauth2.client.clientId:myclientid", "security.oauth2.client.clientSecret:mysecret", @@ -204,7 +204,7 @@ public class OAuth2AutoConfigurationTests { @Test public void testDisablingResourceServer() { - this.context = new AnnotationConfigEmbeddedWebApplicationContext(); + this.context = new AnnotationConfigServletWebServerApplicationContext(); this.context.register(AuthorizationServerConfiguration.class, MinimalSecureWebApplication.class); this.context.refresh(); @@ -214,7 +214,7 @@ public class OAuth2AutoConfigurationTests { @Test public void testClientIsNotResourceServer() { - this.context = new AnnotationConfigEmbeddedWebApplicationContext(); + this.context = new AnnotationConfigServletWebServerApplicationContext(); this.context.register(ClientConfiguration.class, MinimalSecureWebApplication.class); this.context.refresh(); @@ -226,7 +226,7 @@ public class OAuth2AutoConfigurationTests { @Test public void testCanUseClientCredentials() { - this.context = new AnnotationConfigEmbeddedWebApplicationContext(); + this.context = new AnnotationConfigServletWebServerApplicationContext(); this.context.register(TestSecurityConfiguration.class, MinimalSecureWebApplication.class); EnvironmentTestUtils.addEnvironment(this.context, @@ -241,7 +241,7 @@ public class OAuth2AutoConfigurationTests { @Test public void testCanUseClientCredentialsWithEnableOAuth2Client() { - this.context = new AnnotationConfigEmbeddedWebApplicationContext(); + this.context = new AnnotationConfigServletWebServerApplicationContext(); this.context.register(ClientConfiguration.class, MinimalSecureWebApplication.class); EnvironmentTestUtils.addEnvironment(this.context, @@ -274,7 +274,7 @@ public class OAuth2AutoConfigurationTests { @Test public void testDisablingAuthorizationServer() { - this.context = new AnnotationConfigEmbeddedWebApplicationContext(); + this.context = new AnnotationConfigServletWebServerApplicationContext(); this.context.register(ResourceServerConfiguration.class, MinimalSecureWebApplication.class); EnvironmentTestUtils.addEnvironment(this.context, @@ -288,7 +288,7 @@ public class OAuth2AutoConfigurationTests { @Test public void testResourceServerOverride() { - this.context = new AnnotationConfigEmbeddedWebApplicationContext(); + this.context = new AnnotationConfigServletWebServerApplicationContext(); this.context.register(AuthorizationAndResourceServerConfiguration.class, CustomResourceServer.class, MinimalSecureWebApplication.class); this.context.refresh(); @@ -301,7 +301,7 @@ public class OAuth2AutoConfigurationTests { @Test public void testAuthorizationServerOverride() { - this.context = new AnnotationConfigEmbeddedWebApplicationContext(); + this.context = new AnnotationConfigServletWebServerApplicationContext(); EnvironmentTestUtils.addEnvironment(this.context, "security.oauth2.resourceId:resource-id"); this.context.register(AuthorizationAndResourceServerConfiguration.class, @@ -321,7 +321,7 @@ public class OAuth2AutoConfigurationTests { @Test public void testDefaultPrePostSecurityAnnotations() { - this.context = new AnnotationConfigEmbeddedWebApplicationContext(); + this.context = new AnnotationConfigServletWebServerApplicationContext(); this.context.register(AuthorizationAndResourceServerConfiguration.class, MinimalSecureWebApplication.class); this.context.refresh(); @@ -339,7 +339,7 @@ public class OAuth2AutoConfigurationTests { @Test public void testClassicSecurityAnnotationOverride() { - this.context = new AnnotationConfigEmbeddedWebApplicationContext(); + this.context = new AnnotationConfigServletWebServerApplicationContext(); this.context.register(SecuredEnabledConfiguration.class, MinimalSecureWebApplication.class); this.context.refresh(); @@ -357,7 +357,7 @@ public class OAuth2AutoConfigurationTests { @Test public void testJsr250SecurityAnnotationOverride() { - this.context = new AnnotationConfigEmbeddedWebApplicationContext(); + this.context = new AnnotationConfigServletWebServerApplicationContext(); this.context.register(Jsr250EnabledConfiguration.class, MinimalSecureWebApplication.class); this.context.refresh(); @@ -375,7 +375,7 @@ public class OAuth2AutoConfigurationTests { @Test public void testMethodSecurityBackingOff() { - this.context = new AnnotationConfigEmbeddedWebApplicationContext(); + this.context = new AnnotationConfigServletWebServerApplicationContext(); this.context.register(CustomMethodSecurity.class, TestSecurityConfiguration.class, MinimalSecureWebApplication.class); this.context.refresh(); @@ -391,7 +391,7 @@ public class OAuth2AutoConfigurationTests { @Test public void resourceServerConditionWhenJwkConfigurationPresentShouldMatch() throws Exception { - this.context = new AnnotationConfigEmbeddedWebApplicationContext(); + this.context = new AnnotationConfigServletWebServerApplicationContext(); EnvironmentTestUtils.addEnvironment(this.context, "security.oauth2.resource.jwk.key-set-uri:http://my-auth-server/token_keys"); this.context.register(ResourceServerConfiguration.class, @@ -411,7 +411,7 @@ public class OAuth2AutoConfigurationTests { private void verifyAuthentication(ClientDetails config, HttpStatus finalStatus) { String baseUrl = "http://localhost:" - + this.context.getEmbeddedWebServer().getPort(); + + this.context.getWebServer().getPort(); TestRestTemplate rest = new TestRestTemplate(); // First, verify the web endpoint can't be reached assertEndpointUnauthorized(baseUrl, rest); @@ -573,8 +573,8 @@ public class OAuth2AutoConfigurationTests { protected static class UseFreePortEmbeddedContainerConfiguration { @Bean - TomcatEmbeddedServletContainerFactory containerFactory() { - return new TomcatEmbeddedServletContainerFactory(0); + TomcatServletWebServerFactory webServerFactory() { + return new TomcatServletWebServerFactory(0); } } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerTokenServicesConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerTokenServicesConfigurationTests.java index 72c5830b46..5e1e262581 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerTokenServicesConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerTokenServicesConfigurationTests.java @@ -35,10 +35,10 @@ import org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2RestO import org.springframework.boot.autoconfigure.social.FacebookAutoConfiguration; import org.springframework.boot.autoconfigure.social.SocialWebAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.MockEmbeddedServletContainerFactory; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.test.util.EnvironmentTestUtils; +import org.springframework.boot.web.servlet.server.MockServletWebServerFactory; +import org.springframework.boot.web.servlet.server.ServletWebServerFactory; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -317,8 +317,8 @@ public class ResourceServerTokenServicesConfigurationTests { protected static class ResourceNoClientConfiguration extends ResourceConfiguration { @Bean - public MockEmbeddedServletContainerFactory embeddedServletContainerFactory() { - return new MockEmbeddedServletContainerFactory(); + public MockServletWebServerFactory webServerFactory() { + return new MockServletWebServerFactory(); } } @@ -344,8 +344,8 @@ public class ResourceServerTokenServicesConfigurationTests { protected static class SocialResourceConfiguration extends ResourceConfiguration { @Bean - public EmbeddedServletContainerFactory embeddedServletContainerFactory() { - return mock(EmbeddedServletContainerFactory.class); + public ServletWebServerFactory webServerFactory() { + return mock(ServletWebServerFactory.class); } } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/UserInfoTokenServicesRefreshTokenTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/UserInfoTokenServicesRefreshTokenTests.java index 53ebea0f47..a043992f7f 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/UserInfoTokenServicesRefreshTokenTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/UserInfoTokenServicesRefreshTokenTests.java @@ -26,12 +26,12 @@ import org.junit.runner.RunWith; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration; -import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration; +import org.springframework.boot.autoconfigure.web.ServletWebServerFactoryAutoConfiguration; import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration; -import org.springframework.boot.context.embedded.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.web.server.LocalServerPort; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.http.HttpStatus; @@ -110,7 +110,7 @@ public class UserInfoTokenServicesRefreshTokenTests { } @Configuration - @Import({ EmbeddedServletContainerAutoConfiguration.class, + @Import({ ServletWebServerFactoryAutoConfiguration.class, DispatcherServletAutoConfiguration.class, WebMvcAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class }) diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/sso/MinimalSecureWebConfiguration.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/sso/MinimalSecureWebConfiguration.java index fa94acb4e9..1ae049429a 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/sso/MinimalSecureWebConfiguration.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/sso/MinimalSecureWebConfiguration.java @@ -25,9 +25,9 @@ import java.lang.annotation.Target; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration; import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration; -import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration; import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration; +import org.springframework.boot.autoconfigure.web.ServletWebServerFactoryAutoConfiguration; import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @@ -36,7 +36,7 @@ import org.springframework.context.annotation.Import; @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented -@Import({ EmbeddedServletContainerAutoConfiguration.class, +@Import({ ServletWebServerFactoryAutoConfiguration.class, DispatcherServletAutoConfiguration.class, WebMvcAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class, ErrorMvcAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class, SecurityAutoConfiguration.class }) diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerDirectMockMvcTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerDirectMockMvcTests.java index 6e0646cc7f..c9c0bde1c1 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerDirectMockMvcTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerDirectMockMvcTests.java @@ -124,7 +124,7 @@ public class BasicErrorControllerDirectMockMvcTests { @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented - @Import({ EmbeddedServletContainerAutoConfiguration.class, + @Import({ ServletWebServerFactoryAutoConfiguration.class, DispatcherServletAutoConfiguration.class, WebMvcAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class, ErrorMvcAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class }) diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerMockMvcTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerMockMvcTests.java index 2112c58ce6..921869a8ea 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerMockMvcTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerMockMvcTests.java @@ -100,7 +100,7 @@ public class BasicErrorControllerMockMvcTests { @Test public void testBindingExceptionForMachineClient() throws Exception { - // In a real container the response is carried over into the error dispatcher, but + // In a real server the response is carried over into the error dispatcher, but // in the mock a new one is created so we have to assert the status at this // intermediate point MvcResult result = this.mockMvc.perform(get("/bind")) @@ -125,8 +125,8 @@ public class BasicErrorControllerMockMvcTests { @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented - @Import({ EmbeddedServletContainerAutoConfiguration.EmbeddedTomcat.class, - EmbeddedServletContainerAutoConfiguration.class, + @Import({ ServletWebServerFactoryAutoConfiguration.EmbeddedTomcat.class, + ServletWebServerFactoryAutoConfiguration.class, DispatcherServletAutoConfiguration.class, WebMvcAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class, ErrorMvcAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class }) diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/DefaultErrorViewIntegrationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/DefaultErrorViewIntegrationTests.java index b050b94c86..19b6ad90cd 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/DefaultErrorViewIntegrationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/DefaultErrorViewIntegrationTests.java @@ -108,7 +108,7 @@ public class DefaultErrorViewIntegrationTests { @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented - @Import({ EmbeddedServletContainerAutoConfiguration.class, + @Import({ ServletWebServerFactoryAutoConfiguration.class, DispatcherServletAutoConfiguration.class, WebMvcAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class, ErrorMvcAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class }) diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/DefaultServletContainerCustomizerIntegrationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/DefaultServletWebServerFactoryCustomizerTests.java similarity index 53% rename from spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/DefaultServletContainerCustomizerIntegrationTests.java rename to spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/DefaultServletWebServerFactoryCustomizerTests.java index 515731c890..32b1d7df62 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/DefaultServletContainerCustomizerIntegrationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/DefaultServletWebServerFactoryCustomizerTests.java @@ -29,17 +29,17 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; -import org.springframework.boot.context.embedded.AbstractEmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; -import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer; -import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer; -import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizerBeanPostProcessor; -import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.test.util.EnvironmentTestUtils; +import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory; +import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext; +import org.springframework.boot.web.servlet.server.AbstractServletWebServerFactory; +import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory; +import org.springframework.boot.web.servlet.server.ServletWebServerFactory; +import org.springframework.boot.web.servlet.server.ServletWebServerFactoryCustomizer; +import org.springframework.boot.web.servlet.server.ServletWebServerFactoryCustomizerBeanPostProcessor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.util.ReflectionTestUtils; @@ -49,23 +49,23 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; /** - * Integration tests for {@link DefaultServletContainerCustomizer}. + * Integration tests for {@link DefaultServletWebServerFactoryCustomizer}. * * @author Dave Syer * @author Ivan Sopov */ -public class DefaultServletContainerCustomizerIntegrationTests { +public class DefaultServletWebServerFactoryCustomizerTests { - private static AbstractEmbeddedServletContainerFactory containerFactory; + private static AbstractServletWebServerFactory webServerFactory; @Rule public ExpectedException thrown = ExpectedException.none(); - private AnnotationConfigEmbeddedWebApplicationContext context; + private AnnotationConfigServletWebServerApplicationContext context; @Before public void init() { - containerFactory = mock(AbstractEmbeddedServletContainerFactory.class); + webServerFactory = mock(AbstractServletWebServerFactory.class); } @After @@ -85,20 +85,20 @@ public class DefaultServletContainerCustomizerIntegrationTests { @Test public void createFromConfigClass() throws Exception { - this.context = new AnnotationConfigEmbeddedWebApplicationContext(); + this.context = new AnnotationConfigServletWebServerApplicationContext(); this.context.register(Config.class, PropertyPlaceholderAutoConfiguration.class); EnvironmentTestUtils.addEnvironment(this.context, "server.port:9000"); this.context.refresh(); ServerProperties server = this.context.getBean(ServerProperties.class); assertThat(server).isNotNull(); assertThat(server.getPort().intValue()).isEqualTo(9000); - verify(containerFactory).setPort(9000); + verify(webServerFactory).setPort(9000); } @Test public void tomcatProperties() throws Exception { - containerFactory = mock(TomcatEmbeddedServletContainerFactory.class); - this.context = new AnnotationConfigEmbeddedWebApplicationContext(); + webServerFactory = mock(TomcatServletWebServerFactory.class); + this.context = new AnnotationConfigServletWebServerApplicationContext(); this.context.register(Config.class, PropertyPlaceholderAutoConfiguration.class); EnvironmentTestUtils.addEnvironment(this.context, "server.tomcat.basedir:target/foo", "server.port:9000"); @@ -106,49 +106,47 @@ public class DefaultServletContainerCustomizerIntegrationTests { ServerProperties server = this.context.getBean(ServerProperties.class); assertThat(server).isNotNull(); assertThat(server.getTomcat().getBasedir()).isEqualTo(new File("target/foo")); - verify(containerFactory).setPort(9000); + verify(webServerFactory).setPort(9000); } @Test - public void customizeWithJettyContainerFactory() throws Exception { - this.context = new AnnotationConfigEmbeddedWebApplicationContext(); - this.context.register(CustomJettyContainerConfig.class, + public void customizeWithJettyWebServerFactory() throws Exception { + this.context = new AnnotationConfigServletWebServerApplicationContext(); + this.context.register(CustomJettyWebServerConfig.class, PropertyPlaceholderAutoConfiguration.class); this.context.refresh(); - containerFactory = this.context - .getBean(AbstractEmbeddedServletContainerFactory.class); + webServerFactory = this.context.getBean(AbstractServletWebServerFactory.class); ServerProperties server = this.context.getBean(ServerProperties.class); assertThat(server).isNotNull(); - // The server.port environment property was not explicitly set so the container + // The server.port environment property was not explicitly set so the server // factory should take precedence... - assertThat(containerFactory.getPort()).isEqualTo(3000); + assertThat(webServerFactory.getPort()).isEqualTo(3000); } @Test - public void customizeWithUndertowContainerFactory() throws Exception { - this.context = new AnnotationConfigEmbeddedWebApplicationContext(); - this.context.register(CustomUndertowContainerConfig.class, + public void customizeWithUndertowWebServerFactory() throws Exception { + this.context = new AnnotationConfigServletWebServerApplicationContext(); + this.context.register(CustomUndertowWebServerConfig.class, PropertyPlaceholderAutoConfiguration.class); this.context.refresh(); - containerFactory = this.context - .getBean(AbstractEmbeddedServletContainerFactory.class); + webServerFactory = this.context.getBean(AbstractServletWebServerFactory.class); ServerProperties server = this.context.getBean(ServerProperties.class); assertThat(server).isNotNull(); - assertThat(containerFactory.getPort()).isEqualTo(3000); + assertThat(webServerFactory.getPort()).isEqualTo(3000); } @Test public void customizeTomcatWithCustomizer() throws Exception { - containerFactory = mock(TomcatEmbeddedServletContainerFactory.class); - this.context = new AnnotationConfigEmbeddedWebApplicationContext(); + webServerFactory = mock(TomcatServletWebServerFactory.class); + this.context = new AnnotationConfigServletWebServerApplicationContext(); this.context.register(Config.class, CustomizeConfig.class, PropertyPlaceholderAutoConfiguration.class); this.context.refresh(); ServerProperties server = this.context.getBean(ServerProperties.class); assertThat(server).isNotNull(); - // The server.port environment property was not explicitly set so the container + // The server.port environment property was not explicitly set so the server // customizer should take precedence... - verify(containerFactory).setPort(3000); + verify(webServerFactory).setPort(3000); } @Configuration @@ -156,55 +154,55 @@ public class DefaultServletContainerCustomizerIntegrationTests { protected static class Config { @Bean - public DefaultServletContainerCustomizer defaultServletContainerCustomizer( + public DefaultServletWebServerFactoryCustomizer defaultServletWebServerFactoryCustomizer( ServerProperties properties) { - return new DefaultServletContainerCustomizer(properties); + return new DefaultServletWebServerFactoryCustomizer(properties); } @Bean - public EmbeddedServletContainerFactory containerFactory() { - return DefaultServletContainerCustomizerIntegrationTests.containerFactory; + public ServletWebServerFactory webServerFactory() { + return DefaultServletWebServerFactoryCustomizerTests.webServerFactory; } @Bean - public EmbeddedServletContainerCustomizerBeanPostProcessor embeddedServletContainerCustomizerBeanPostProcessor() { - return new EmbeddedServletContainerCustomizerBeanPostProcessor(); + public ServletWebServerFactoryCustomizerBeanPostProcessor ServletWebServerCustomizerBeanPostProcessor() { + return new ServletWebServerFactoryCustomizerBeanPostProcessor(); } } @Configuration @EnableConfigurationProperties(ServerProperties.class) - protected static class CustomJettyContainerConfig { + protected static class CustomJettyWebServerConfig { @Bean - public EmbeddedServletContainerFactory containerFactory() { - JettyEmbeddedServletContainerFactory factory = new JettyEmbeddedServletContainerFactory(); + public ServletWebServerFactory webServerFactory() { + JettyServletWebServerFactory factory = new JettyServletWebServerFactory(); factory.setPort(3000); return factory; } @Bean - public EmbeddedServletContainerCustomizerBeanPostProcessor embeddedServletContainerCustomizerBeanPostProcessor() { - return new EmbeddedServletContainerCustomizerBeanPostProcessor(); + public ServletWebServerFactoryCustomizerBeanPostProcessor ServletWebServerCustomizerBeanPostProcessor() { + return new ServletWebServerFactoryCustomizerBeanPostProcessor(); } } @Configuration @EnableConfigurationProperties(ServerProperties.class) - protected static class CustomUndertowContainerConfig { + protected static class CustomUndertowWebServerConfig { @Bean - public EmbeddedServletContainerFactory containerFactory() { - UndertowEmbeddedServletContainerFactory factory = new UndertowEmbeddedServletContainerFactory(); + public ServletWebServerFactory webServerFactory() { + UndertowServletWebServerFactory factory = new UndertowServletWebServerFactory(); factory.setPort(3000); return factory; } @Bean - public EmbeddedServletContainerCustomizerBeanPostProcessor embeddedServletContainerCustomizerBeanPostProcessor() { - return new EmbeddedServletContainerCustomizerBeanPostProcessor(); + public ServletWebServerFactoryCustomizerBeanPostProcessor ServletWebServerCustomizerBeanPostProcessor() { + return new ServletWebServerFactoryCustomizerBeanPostProcessor(); } } @@ -213,12 +211,12 @@ public class DefaultServletContainerCustomizerIntegrationTests { protected static class CustomizeConfig { @Bean - public EmbeddedServletContainerCustomizer containerCustomizer() { - return new EmbeddedServletContainerCustomizer() { + public ServletWebServerFactoryCustomizer webServerFactoryCustomizer() { + return new ServletWebServerFactoryCustomizer() { @Override - public void customize(ConfigurableEmbeddedServletContainer container) { - container.setPort(3000); + public void customize(ConfigurableServletWebServerFactory serverFactory) { + serverFactory.setPort(3000); } }; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/FilterOrderingIntegrationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/FilterOrderingIntegrationTests.java index 386f964af6..366e1e83a2 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/FilterOrderingIntegrationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/FilterOrderingIntegrationTests.java @@ -28,13 +28,13 @@ import org.junit.Test; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration; import org.springframework.boot.autoconfigure.session.SessionAutoConfiguration; -import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; -import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizerBeanPostProcessor; -import org.springframework.boot.context.embedded.MockEmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.MockEmbeddedServletContainerFactory.RegisteredFilter; import org.springframework.boot.test.util.EnvironmentTestUtils; -import org.springframework.boot.web.filter.OrderedCharacterEncodingFilter; -import org.springframework.boot.web.filter.OrderedRequestContextFilter; +import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext; +import org.springframework.boot.web.servlet.filter.OrderedCharacterEncodingFilter; +import org.springframework.boot.web.servlet.filter.OrderedRequestContextFilter; +import org.springframework.boot.web.servlet.server.MockServletWebServerFactory; +import org.springframework.boot.web.servlet.server.MockServletWebServerFactory.RegisteredFilter; +import org.springframework.boot.web.servlet.server.ServletWebServerFactoryCustomizerBeanPostProcessor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.connection.RedisConnection; @@ -54,7 +54,7 @@ import static org.mockito.Mockito.mock; */ public class FilterOrderingIntegrationTests { - private AnnotationConfigEmbeddedWebApplicationContext context; + private AnnotationConfigServletWebServerApplicationContext context; @After public void cleanup() { @@ -67,7 +67,7 @@ public class FilterOrderingIntegrationTests { public void testFilterOrdering() { load(); List registeredFilters = this.context - .getBean(MockEmbeddedServletContainerFactory.class).getContainer() + .getBean(MockServletWebServerFactory.class).getWebServer() .getRegisteredFilters(); List filters = new ArrayList<>(registeredFilters.size()); for (RegisteredFilter registeredFilter : registeredFilters) { @@ -83,10 +83,10 @@ public class FilterOrderingIntegrationTests { } private void load() { - this.context = new AnnotationConfigEmbeddedWebApplicationContext(); + this.context = new AnnotationConfigServletWebServerApplicationContext(); EnvironmentTestUtils.addEnvironment(this.context, "spring.session.store-type=hash-map"); - this.context.register(MockEmbeddedServletContainerConfiguration.class, + this.context.register(MockWebServerConfiguration.class, TestRedisConfiguration.class, WebMvcAutoConfiguration.class, SecurityAutoConfiguration.class, SessionAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class, @@ -96,16 +96,16 @@ public class FilterOrderingIntegrationTests { } @Configuration - static class MockEmbeddedServletContainerConfiguration { + static class MockWebServerConfiguration { @Bean - public MockEmbeddedServletContainerFactory containerFactory() { - return new MockEmbeddedServletContainerFactory(); + public MockServletWebServerFactory webServerFactory() { + return new MockServletWebServerFactory(); } @Bean - public EmbeddedServletContainerCustomizerBeanPostProcessor embeddedServletContainerCustomizerBeanPostProcessor() { - return new EmbeddedServletContainerCustomizerBeanPostProcessor(); + public ServletWebServerFactoryCustomizerBeanPostProcessor ServletWebServerCustomizerBeanPostProcessor() { + return new ServletWebServerFactoryCustomizerBeanPostProcessor(); } } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/HttpEncodingAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/HttpEncodingAutoConfigurationTests.java index c6f4308b27..a4cd3a20d5 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/HttpEncodingAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/HttpEncodingAutoConfigurationTests.java @@ -30,12 +30,12 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.springframework.beans.factory.NoSuchBeanDefinitionException; -import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer; -import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizerBeanPostProcessor; -import org.springframework.boot.context.embedded.MockEmbeddedServletContainerFactory; import org.springframework.boot.test.util.EnvironmentTestUtils; -import org.springframework.boot.web.filter.OrderedHiddenHttpMethodFilter; -import org.springframework.boot.web.filter.OrderedHttpPutFormContentFilter; +import org.springframework.boot.web.servlet.filter.OrderedHiddenHttpMethodFilter; +import org.springframework.boot.web.servlet.filter.OrderedHttpPutFormContentFilter; +import org.springframework.boot.web.servlet.server.MockServletWebServerFactory; +import org.springframework.boot.web.servlet.server.ServletWebServerFactoryCustomizer; +import org.springframework.boot.web.servlet.server.ServletWebServerFactoryCustomizerBeanPostProcessor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.annotation.AnnotationAwareOrderComparator; @@ -145,10 +145,10 @@ public class HttpEncodingAutoConfigurationTests { @Test public void noLocaleCharsetMapping() { load(EmptyConfiguration.class); - Map beans = this.context - .getBeansOfType(EmbeddedServletContainerCustomizer.class); + Map beans = this.context + .getBeansOfType(ServletWebServerFactoryCustomizer.class); assertThat(beans.size()).isEqualTo(1); - assertThat(this.context.getBean(MockEmbeddedServletContainerFactory.class) + assertThat(this.context.getBean(MockServletWebServerFactory.class) .getLocaleCharsetMappings().size()).isEqualTo(0); } @@ -156,15 +156,15 @@ public class HttpEncodingAutoConfigurationTests { public void customLocaleCharsetMappings() { load(EmptyConfiguration.class, "spring.http.encoding.mapping.en:UTF-8", "spring.http.encoding.mapping.fr_FR:UTF-8"); - Map beans = this.context - .getBeansOfType(EmbeddedServletContainerCustomizer.class); + Map beans = this.context + .getBeansOfType(ServletWebServerFactoryCustomizer.class); assertThat(beans.size()).isEqualTo(1); - assertThat(this.context.getBean(MockEmbeddedServletContainerFactory.class) + assertThat(this.context.getBean(MockServletWebServerFactory.class) .getLocaleCharsetMappings().size()).isEqualTo(2); - assertThat(this.context.getBean(MockEmbeddedServletContainerFactory.class) + assertThat(this.context.getBean(MockServletWebServerFactory.class) .getLocaleCharsetMappings().get(Locale.ENGLISH)) .isEqualTo(Charset.forName("UTF-8")); - assertThat(this.context.getBean(MockEmbeddedServletContainerFactory.class) + assertThat(this.context.getBean(MockServletWebServerFactory.class) .getLocaleCharsetMappings().get(Locale.FRANCE)) .isEqualTo(Charset.forName("UTF-8")); } @@ -230,13 +230,13 @@ public class HttpEncodingAutoConfigurationTests { static class MinimalWebAutoConfiguration { @Bean - public MockEmbeddedServletContainerFactory mockEmbeddedServletContainerFactory() { - return new MockEmbeddedServletContainerFactory(); + public MockServletWebServerFactory MockServletWebServerFactory() { + return new MockServletWebServerFactory(); } @Bean - public EmbeddedServletContainerCustomizerBeanPostProcessor embeddedServletContainerCustomizerBeanPostProcessor() { - return new EmbeddedServletContainerCustomizerBeanPostProcessor(); + public ServletWebServerFactoryCustomizerBeanPostProcessor ServletWebServerCustomizerBeanPostProcessor() { + return new ServletWebServerFactoryCustomizerBeanPostProcessor(); } } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/MultipartAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/MultipartAutoConfigurationTests.java index 56e1f96d2d..f81e9abd3b 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/MultipartAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/MultipartAutoConfigurationTests.java @@ -23,18 +23,17 @@ import javax.servlet.MultipartConfigElement; import org.apache.catalina.webresources.TomcatURLStreamHandlerFactory; import org.junit.After; -import org.junit.AfterClass; -import org.junit.BeforeClass; +import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; -import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.test.util.EnvironmentTestUtils; +import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory; +import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @@ -68,7 +67,7 @@ import static org.mockito.Mockito.mock; */ public class MultipartAutoConfigurationTests { - private AnnotationConfigEmbeddedWebApplicationContext context; + private AnnotationConfigServletWebServerApplicationContext context; @Rule public ExpectedException thrown = ExpectedException.none(); @@ -80,18 +79,18 @@ public class MultipartAutoConfigurationTests { } } - @BeforeClass - @AfterClass - public static void uninstallUrlStreamHandlerFactory() { + @Before + @After + public void uninstallUrlStreamHandlerFactory() { ReflectionTestUtils.setField(TomcatURLStreamHandlerFactory.class, "instance", null); ReflectionTestUtils.setField(URL.class, "factory", null); } @Test - public void containerWithNothing() throws Exception { - this.context = new AnnotationConfigEmbeddedWebApplicationContext( - ContainerWithNothing.class, BaseConfiguration.class); + public void webServerWithNothing() throws Exception { + this.context = new AnnotationConfigServletWebServerApplicationContext( + WebServerWithNothing.class, BaseConfiguration.class); DispatcherServlet servlet = this.context.getBean(DispatcherServlet.class); verify404(); assertThat(servlet.getMultipartResolver()).isNotNull(); @@ -101,9 +100,9 @@ public class MultipartAutoConfigurationTests { } @Test - public void containerWithNoMultipartJettyConfiguration() { - this.context = new AnnotationConfigEmbeddedWebApplicationContext( - ContainerWithNoMultipartJetty.class, BaseConfiguration.class); + public void webServerWithNoMultipartJettyConfiguration() { + this.context = new AnnotationConfigServletWebServerApplicationContext( + WebServerWithNoMultipartJetty.class, BaseConfiguration.class); DispatcherServlet servlet = this.context.getBean(DispatcherServlet.class); assertThat(servlet.getMultipartResolver()).isNotNull(); assertThat(this.context.getBeansOfType(StandardServletMultipartResolver.class)) @@ -113,9 +112,9 @@ public class MultipartAutoConfigurationTests { } @Test - public void containerWithNoMultipartUndertowConfiguration() { - this.context = new AnnotationConfigEmbeddedWebApplicationContext( - ContainerWithNoMultipartUndertow.class, BaseConfiguration.class); + public void webServerWithNoMultipartUndertowConfiguration() { + this.context = new AnnotationConfigServletWebServerApplicationContext( + WebServerWithNoMultipartUndertow.class, BaseConfiguration.class); DispatcherServlet servlet = this.context.getBean(DispatcherServlet.class); verifyServletWorks(); assertThat(servlet.getMultipartResolver()).isNotNull(); @@ -125,9 +124,9 @@ public class MultipartAutoConfigurationTests { } @Test - public void containerWithNoMultipartTomcatConfiguration() { - this.context = new AnnotationConfigEmbeddedWebApplicationContext( - ContainerWithNoMultipartTomcat.class, BaseConfiguration.class); + public void webServerWithNoMultipartTomcatConfiguration() { + this.context = new AnnotationConfigServletWebServerApplicationContext( + WebServerWithNoMultipartTomcat.class, BaseConfiguration.class); DispatcherServlet servlet = this.context.getBean(DispatcherServlet.class); assertThat(servlet.getMultipartResolver()).isNull(); assertThat(this.context.getBeansOfType(StandardServletMultipartResolver.class)) @@ -137,9 +136,9 @@ public class MultipartAutoConfigurationTests { } @Test - public void containerWithAutomatedMultipartJettyConfiguration() { - this.context = new AnnotationConfigEmbeddedWebApplicationContext( - ContainerWithEverythingJetty.class, BaseConfiguration.class); + public void webServerWithAutomatedMultipartJettyConfiguration() { + this.context = new AnnotationConfigServletWebServerApplicationContext( + WebServerWithEverythingJetty.class, BaseConfiguration.class); this.context.getBean(MultipartConfigElement.class); assertThat(this.context.getBean(StandardServletMultipartResolver.class)).isSameAs( this.context.getBean(DispatcherServlet.class).getMultipartResolver()); @@ -147,11 +146,11 @@ public class MultipartAutoConfigurationTests { } @Test - public void containerWithAutomatedMultipartTomcatConfiguration() throws Exception { - this.context = new AnnotationConfigEmbeddedWebApplicationContext( - ContainerWithEverythingTomcat.class, BaseConfiguration.class); + public void webServerWithAutomatedMultipartTomcatConfiguration() throws Exception { + this.context = new AnnotationConfigServletWebServerApplicationContext( + WebServerWithEverythingTomcat.class, BaseConfiguration.class); new RestTemplate().getForObject( - "http://localhost:" + this.context.getEmbeddedWebServer().getPort() + "/", + "http://localhost:" + this.context.getWebServer().getPort() + "/", String.class); this.context.getBean(MultipartConfigElement.class); assertThat(this.context.getBean(StandardServletMultipartResolver.class)).isSameAs( @@ -160,9 +159,9 @@ public class MultipartAutoConfigurationTests { } @Test - public void containerWithAutomatedMultipartUndertowConfiguration() { - this.context = new AnnotationConfigEmbeddedWebApplicationContext( - ContainerWithEverythingUndertow.class, BaseConfiguration.class); + public void webServerWithAutomatedMultipartUndertowConfiguration() { + this.context = new AnnotationConfigServletWebServerApplicationContext( + WebServerWithEverythingUndertow.class, BaseConfiguration.class); this.context.getBean(MultipartConfigElement.class); verifyServletWorks(); assertThat(this.context.getBean(StandardServletMultipartResolver.class)).isSameAs( @@ -170,21 +169,21 @@ public class MultipartAutoConfigurationTests { } @Test - public void containerWithMultipartConfigDisabled() { - testContainerWithCustomMultipartConfigEnabledSetting("false", 0); + public void webServerWithMultipartConfigDisabled() { + testWebServerWithCustomMultipartConfigEnabledSetting("false", 0); } @Test - public void containerWithMultipartConfigEnabled() { - testContainerWithCustomMultipartConfigEnabledSetting("true", 1); + public void webServerWithMultipartConfigEnabled() { + testWebServerWithCustomMultipartConfigEnabledSetting("true", 1); } - private void testContainerWithCustomMultipartConfigEnabledSetting( + private void testWebServerWithCustomMultipartConfigEnabledSetting( final String propertyValue, int expectedNumberOfMultipartConfigElementBeans) { - this.context = new AnnotationConfigEmbeddedWebApplicationContext(); + this.context = new AnnotationConfigServletWebServerApplicationContext(); EnvironmentTestUtils.addEnvironment(this.context, "spring.http.multipart.enabled=" + propertyValue); - this.context.register(ContainerWithNoMultipartTomcat.class, + this.context.register(WebServerWithNoMultipartTomcat.class, BaseConfiguration.class); this.context.refresh(); this.context.getBean(MultipartProperties.class); @@ -193,9 +192,9 @@ public class MultipartAutoConfigurationTests { } @Test - public void containerWithCustomMultipartResolver() throws Exception { - this.context = new AnnotationConfigEmbeddedWebApplicationContext( - ContainerWithCustomMultipartResolver.class, BaseConfiguration.class); + public void webServerWithCustomMultipartResolver() throws Exception { + this.context = new AnnotationConfigServletWebServerApplicationContext( + WebServerWithCustomMultipartResolver.class, BaseConfiguration.class); MultipartResolver multipartResolver = this.context .getBean(MultipartResolver.class); assertThat(multipartResolver) @@ -204,10 +203,10 @@ public class MultipartAutoConfigurationTests { @Test public void configureResolveLazily() { - this.context = new AnnotationConfigEmbeddedWebApplicationContext(); + this.context = new AnnotationConfigServletWebServerApplicationContext(); EnvironmentTestUtils.addEnvironment(this.context, "spring.http.multipart.resolve-lazily=true"); - this.context.register(ContainerWithNothing.class, BaseConfiguration.class); + this.context.register(WebServerWithNothing.class, BaseConfiguration.class); this.context.refresh(); StandardServletMultipartResolver multipartResolver = this.context .getBean(StandardServletMultipartResolver.class); @@ -218,32 +217,32 @@ public class MultipartAutoConfigurationTests { private void verify404() throws Exception { HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(); - ClientHttpRequest request = requestFactory.createRequest( - new URI("http://localhost:" - + this.context.getEmbeddedWebServer().getPort() + "/"), - HttpMethod.GET); + ClientHttpRequest request = requestFactory + .createRequest( + new URI("http://localhost:" + + this.context.getWebServer().getPort() + "/"), + HttpMethod.GET); ClientHttpResponse response = request.execute(); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); } private void verifyServletWorks() { RestTemplate restTemplate = new RestTemplate(); - String url = "http://localhost:" + this.context.getEmbeddedWebServer().getPort() - + "/"; + String url = "http://localhost:" + this.context.getWebServer().getPort() + "/"; assertThat(restTemplate.getForObject(url, String.class)).isEqualTo("Hello"); } @Configuration - public static class ContainerWithNothing { + public static class WebServerWithNothing { } @Configuration - public static class ContainerWithNoMultipartJetty { + public static class WebServerWithNoMultipartJetty { @Bean - JettyEmbeddedServletContainerFactory containerFactory() { - return new JettyEmbeddedServletContainerFactory(); + JettyServletWebServerFactory webServerFactory() { + return new JettyServletWebServerFactory(); } @Bean @@ -254,11 +253,11 @@ public class MultipartAutoConfigurationTests { } @Configuration - public static class ContainerWithNoMultipartUndertow { + public static class WebServerWithNoMultipartUndertow { @Bean - UndertowEmbeddedServletContainerFactory containerFactory() { - return new UndertowEmbeddedServletContainerFactory(); + UndertowServletWebServerFactory webServerFactory() { + return new UndertowServletWebServerFactory(); } @Bean @@ -269,7 +268,7 @@ public class MultipartAutoConfigurationTests { } @Configuration - @Import({ EmbeddedServletContainerAutoConfiguration.class, + @Import({ ServletWebServerFactoryAutoConfiguration.class, DispatcherServletAutoConfiguration.class, MultipartAutoConfiguration.class }) @EnableConfigurationProperties(MultipartProperties.class) protected static class BaseConfiguration { @@ -284,11 +283,11 @@ public class MultipartAutoConfigurationTests { } @Configuration - public static class ContainerWithNoMultipartTomcat { + public static class WebServerWithNoMultipartTomcat { @Bean - TomcatEmbeddedServletContainerFactory containerFactory() { - return new TomcatEmbeddedServletContainerFactory(); + TomcatServletWebServerFactory webServerFactory() { + return new TomcatServletWebServerFactory(); } @Bean @@ -299,7 +298,7 @@ public class MultipartAutoConfigurationTests { } @Configuration - public static class ContainerWithEverythingJetty { + public static class WebServerWithEverythingJetty { @Bean MultipartConfigElement multipartConfigElement() { @@ -307,8 +306,8 @@ public class MultipartAutoConfigurationTests { } @Bean - JettyEmbeddedServletContainerFactory containerFactory() { - return new JettyEmbeddedServletContainerFactory(); + JettyServletWebServerFactory webServerFactory() { + return new JettyServletWebServerFactory(); } @Bean @@ -320,7 +319,7 @@ public class MultipartAutoConfigurationTests { @Configuration @EnableWebMvc - public static class ContainerWithEverythingTomcat { + public static class WebServerWithEverythingTomcat { @Bean MultipartConfigElement multipartConfigElement() { @@ -328,8 +327,8 @@ public class MultipartAutoConfigurationTests { } @Bean - TomcatEmbeddedServletContainerFactory containerFactory() { - return new TomcatEmbeddedServletContainerFactory(); + TomcatServletWebServerFactory webServerFactory() { + return new TomcatServletWebServerFactory(); } @Bean @@ -341,7 +340,7 @@ public class MultipartAutoConfigurationTests { @Configuration @EnableWebMvc - public static class ContainerWithEverythingUndertow { + public static class WebServerWithEverythingUndertow { @Bean MultipartConfigElement multipartConfigElement() { @@ -349,8 +348,8 @@ public class MultipartAutoConfigurationTests { } @Bean - UndertowEmbeddedServletContainerFactory containerFactory() { - return new UndertowEmbeddedServletContainerFactory(); + UndertowServletWebServerFactory webServerFactory() { + return new UndertowServletWebServerFactory(); } @Bean @@ -360,7 +359,7 @@ public class MultipartAutoConfigurationTests { } - public static class ContainerWithCustomMultipartResolver { + public static class WebServerWithCustomMultipartResolver { @Bean MultipartResolver multipartResolver() { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/RemappedErrorViewIntegrationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/RemappedErrorViewIntegrationTests.java index 78c599a388..269649d91d 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/RemappedErrorViewIntegrationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/RemappedErrorViewIntegrationTests.java @@ -21,13 +21,13 @@ import org.junit.runner.RunWith; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.context.embedded.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.boot.web.servlet.ErrorPage; -import org.springframework.boot.web.servlet.ErrorPageRegistrar; -import org.springframework.boot.web.servlet.ErrorPageRegistry; +import org.springframework.boot.web.server.ErrorPage; +import org.springframework.boot.web.server.ErrorPageRegistrar; +import org.springframework.boot.web.server.ErrorPageRegistry; +import org.springframework.boot.web.server.LocalServerPort; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.stereotype.Controller; @@ -71,7 +71,7 @@ public class RemappedErrorViewIntegrationTests { @Configuration @Import({ PropertyPlaceholderAutoConfiguration.class, WebMvcAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class, - EmbeddedServletContainerAutoConfiguration.class, + ServletWebServerFactoryAutoConfiguration.class, DispatcherServletAutoConfiguration.class, ErrorMvcAutoConfiguration.class }) @Controller public static class TestConfiguration implements ErrorPageRegistrar { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/DefaultServletContainerCustomizerTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesServletWebServerFactoryCustomizerTests.java similarity index 61% rename from spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/DefaultServletContainerCustomizerTests.java rename to spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesServletWebServerFactoryCustomizerTests.java index 3d894221c1..088269259e 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/DefaultServletContainerCustomizerTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesServletWebServerFactoryCustomizerTests.java @@ -39,13 +39,14 @@ import org.mockito.MockitoAnnotations; import org.springframework.beans.MutablePropertyValues; import org.springframework.boot.bind.RelaxedDataBinder; -import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer; -import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.tomcat.TomcatContextCustomizer; -import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer; -import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory; +import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory; +import org.springframework.boot.web.embedded.tomcat.TomcatContextCustomizer; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.embedded.tomcat.TomcatWebServer; +import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory; import org.springframework.boot.web.servlet.ServletContextInitializer; +import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory; +import org.springframework.boot.web.servlet.server.ServletWebServerFactoryCustomizer; import org.springframework.mock.env.MockEnvironment; import static org.assertj.core.api.Assertions.assertThat; @@ -58,84 +59,83 @@ import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; /** - * Tests for {@link DefaultServletContainerCustomizer}. + * Tests for {@link ServerProperties} {@link ServletWebServerFactoryCustomizer}. * * @author Brian Clozel */ -public class DefaultServletContainerCustomizerTests { +public class ServerPropertiesServletWebServerFactoryCustomizerTests { private final ServerProperties properties = new ServerProperties(); - private DefaultServletContainerCustomizer customizer; + private DefaultServletWebServerFactoryCustomizer customizer; @Before public void setup() throws Exception { MockitoAnnotations.initMocks(this); - this.customizer = new DefaultServletContainerCustomizer(this.properties); + this.customizer = new DefaultServletWebServerFactoryCustomizer(this.properties); } @Test public void tomcatAccessLogIsDisabledByDefault() { - TomcatEmbeddedServletContainerFactory tomcatContainer = new TomcatEmbeddedServletContainerFactory(); - this.customizer.customize(tomcatContainer); - assertThat(tomcatContainer.getEngineValves()).isEmpty(); + TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(); + this.customizer.customize(factory); + assertThat(factory.getEngineValves()).isEmpty(); } @Test public void tomcatAccessLogCanBeEnabled() { - TomcatEmbeddedServletContainerFactory tomcatContainer = new TomcatEmbeddedServletContainerFactory(); + TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(); Map map = new HashMap<>(); map.put("server.tomcat.accesslog.enabled", "true"); bindProperties(map); - this.customizer.customize(tomcatContainer); - assertThat(tomcatContainer.getEngineValves()).hasSize(1); - assertThat(tomcatContainer.getEngineValves()).first() - .isInstanceOf(AccessLogValve.class); + this.customizer.customize(factory); + assertThat(factory.getEngineValves()).hasSize(1); + assertThat(factory.getEngineValves()).first().isInstanceOf(AccessLogValve.class); } @Test public void tomcatAccessLogFileDateFormatByDefault() { - TomcatEmbeddedServletContainerFactory tomcatContainer = new TomcatEmbeddedServletContainerFactory(); + TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(); Map map = new HashMap(); map.put("server.tomcat.accesslog.enabled", "true"); bindProperties(map); - this.customizer.customize(tomcatContainer); - assertThat(((AccessLogValve) tomcatContainer.getEngineValves().iterator().next()) + this.customizer.customize(factory); + assertThat(((AccessLogValve) factory.getEngineValves().iterator().next()) .getFileDateFormat()).isEqualTo(".yyyy-MM-dd"); } @Test public void tomcatAccessLogFileDateFormatCanBeRedefined() { - TomcatEmbeddedServletContainerFactory tomcatContainer = new TomcatEmbeddedServletContainerFactory(); + TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(); Map map = new HashMap(); map.put("server.tomcat.accesslog.enabled", "true"); map.put("server.tomcat.accesslog.file-date-format", "yyyy-MM-dd.HH"); bindProperties(map); - this.customizer.customize(tomcatContainer); - assertThat(((AccessLogValve) tomcatContainer.getEngineValves().iterator().next()) + this.customizer.customize(factory); + assertThat(((AccessLogValve) factory.getEngineValves().iterator().next()) .getFileDateFormat()).isEqualTo("yyyy-MM-dd.HH"); } @Test public void tomcatAccessLogIsBufferedByDefault() { - TomcatEmbeddedServletContainerFactory tomcatContainer = new TomcatEmbeddedServletContainerFactory(); + TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(); Map map = new HashMap<>(); map.put("server.tomcat.accesslog.enabled", "true"); bindProperties(map); - this.customizer.customize(tomcatContainer); - assertThat(((AccessLogValve) tomcatContainer.getEngineValves().iterator().next()) + this.customizer.customize(factory); + assertThat(((AccessLogValve) factory.getEngineValves().iterator().next()) .isBuffered()).isTrue(); } @Test public void tomcatAccessLogBufferingCanBeDisabled() { - TomcatEmbeddedServletContainerFactory tomcatContainer = new TomcatEmbeddedServletContainerFactory(); + TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(); Map map = new HashMap<>(); map.put("server.tomcat.accesslog.enabled", "true"); map.put("server.tomcat.accesslog.buffered", "false"); bindProperties(map); - this.customizer.customize(tomcatContainer); - assertThat(((AccessLogValve) tomcatContainer.getEngineValves().iterator().next()) + this.customizer.customize(factory); + assertThat(((AccessLogValve) factory.getEngineValves().iterator().next()) .isBuffered()).isFalse(); } @@ -146,11 +146,10 @@ public class DefaultServletContainerCustomizerTests { bindProperties(map); ServerProperties.Tomcat tomcat = this.properties.getTomcat(); assertThat(tomcat.getRedirectContextRoot()).isEqualTo(false); - TomcatEmbeddedServletContainerFactory container = new TomcatEmbeddedServletContainerFactory(); - this.customizer.customize(container); + TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(); + this.customizer.customize(factory); Context context = mock(Context.class); - for (TomcatContextCustomizer customizer : container - .getTomcatContextCustomizers()) { + for (TomcatContextCustomizer customizer : factory.getTomcatContextCustomizers()) { customizer.customize(context); } verify(context).setMapperContextRootRedirectEnabled(false); @@ -158,24 +157,24 @@ public class DefaultServletContainerCustomizerTests { @Test public void testCustomizeTomcat() throws Exception { - ConfigurableEmbeddedServletContainer factory = mock( - ConfigurableEmbeddedServletContainer.class); + ConfigurableServletWebServerFactory factory = mock( + ConfigurableServletWebServerFactory.class); this.customizer.customize(factory); verify(factory, never()).setContextPath(""); } @Test public void testDefaultDisplayName() throws Exception { - ConfigurableEmbeddedServletContainer factory = mock( - ConfigurableEmbeddedServletContainer.class); + ConfigurableServletWebServerFactory factory = mock( + ConfigurableServletWebServerFactory.class); this.customizer.customize(factory); verify(factory).setDisplayName("application"); } @Test public void testCustomizeDisplayName() throws Exception { - ConfigurableEmbeddedServletContainer factory = mock( - ConfigurableEmbeddedServletContainer.class); + ConfigurableServletWebServerFactory factory = mock( + ConfigurableServletWebServerFactory.class); this.properties.setDisplayName("TestName"); this.customizer.customize(factory); verify(factory).setDisplayName("TestName"); @@ -194,8 +193,8 @@ public class DefaultServletContainerCustomizerTests { map.put("server.session.cookie.secure", "true"); map.put("server.session.cookie.max-age", "60"); bindProperties(map); - ConfigurableEmbeddedServletContainer factory = mock( - ConfigurableEmbeddedServletContainer.class); + ConfigurableServletWebServerFactory factory = mock( + ConfigurableServletWebServerFactory.class); ServletContext servletContext = mock(ServletContext.class); SessionCookieConfig sessionCookieConfig = mock(SessionCookieConfig.class); given(servletContext.getSessionCookieConfig()).willReturn(sessionCookieConfig); @@ -215,8 +214,8 @@ public class DefaultServletContainerCustomizerTests { @Test public void testCustomizeTomcatPort() throws Exception { - ConfigurableEmbeddedServletContainer factory = mock( - ConfigurableEmbeddedServletContainer.class); + ConfigurableServletWebServerFactory factory = mock( + ConfigurableServletWebServerFactory.class); this.properties.setPort(8080); this.customizer.customize(factory); verify(factory).setPort(8080); @@ -227,9 +226,9 @@ public class DefaultServletContainerCustomizerTests { Map map = new HashMap<>(); map.put("server.display-name", "MyBootApp"); bindProperties(map); - TomcatEmbeddedServletContainerFactory container = new TomcatEmbeddedServletContainerFactory(); - this.customizer.customize(container); - assertThat(container.getDisplayName()).isEqualTo("MyBootApp"); + TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(); + this.customizer.customize(factory); + assertThat(factory.getDisplayName()).isEqualTo("MyBootApp"); } @Test @@ -238,19 +237,17 @@ public class DefaultServletContainerCustomizerTests { map.put("server.tomcat.remote_ip_header", ""); map.put("server.tomcat.protocol_header", ""); bindProperties(map); - TomcatEmbeddedServletContainerFactory container = new TomcatEmbeddedServletContainerFactory(); - this.customizer.customize(container); - assertThat(container.getEngineValves()).isEmpty(); + TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(); + this.customizer.customize(factory); + assertThat(factory.getEngineValves()).isEmpty(); } @Test public void defaultTomcatBackgroundProcessorDelay() throws Exception { - TomcatEmbeddedServletContainerFactory container = new TomcatEmbeddedServletContainerFactory(); - this.customizer.customize(container); - assertThat( - ((TomcatEmbeddedServletContainer) container.getEmbeddedServletContainer()) - .getTomcat().getEngine().getBackgroundProcessorDelay()) - .isEqualTo(30); + TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(); + this.customizer.customize(factory); + assertThat(((TomcatWebServer) factory.getWebServer()).getTomcat().getEngine() + .getBackgroundProcessorDelay()).isEqualTo(30); } @Test @@ -258,12 +255,10 @@ public class DefaultServletContainerCustomizerTests { Map map = new HashMap<>(); map.put("server.tomcat.background-processor-delay", "5"); bindProperties(map); - TomcatEmbeddedServletContainerFactory container = new TomcatEmbeddedServletContainerFactory(); - this.customizer.customize(container); - assertThat( - ((TomcatEmbeddedServletContainer) container.getEmbeddedServletContainer()) - .getTomcat().getEngine().getBackgroundProcessorDelay()) - .isEqualTo(5); + TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(); + this.customizer.customize(factory); + assertThat(((TomcatWebServer) factory.getWebServer()).getTomcat().getEngine() + .getBackgroundProcessorDelay()).isEqualTo(5); } @Test @@ -290,10 +285,10 @@ public class DefaultServletContainerCustomizerTests { } private void testRemoteIpValveConfigured() { - TomcatEmbeddedServletContainerFactory container = new TomcatEmbeddedServletContainerFactory(); - this.customizer.customize(container); - assertThat(container.getEngineValves()).hasSize(1); - Valve valve = container.getEngineValves().iterator().next(); + TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(); + this.customizer.customize(factory); + assertThat(factory.getEngineValves()).hasSize(1); + Valve valve = factory.getEngineValves().iterator().next(); assertThat(valve).isInstanceOf(RemoteIpValve.class); RemoteIpValve remoteIpValve = (RemoteIpValve) valve; assertThat(remoteIpValve.getProtocolHeader()).isEqualTo("X-Forwarded-Proto"); @@ -318,10 +313,10 @@ public class DefaultServletContainerCustomizerTests { map.put("server.tomcat.port-header", "x-my-forward-port"); map.put("server.tomcat.protocol-header-https-value", "On"); bindProperties(map); - TomcatEmbeddedServletContainerFactory container = new TomcatEmbeddedServletContainerFactory(); - this.customizer.customize(container); - assertThat(container.getEngineValves()).hasSize(1); - Valve valve = container.getEngineValves().iterator().next(); + TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(); + this.customizer.customize(factory); + assertThat(factory.getEngineValves()).hasSize(1); + Valve valve = factory.getEngineValves().iterator().next(); assertThat(valve).isInstanceOf(RemoteIpValve.class); RemoteIpValve remoteIpValve = (RemoteIpValve) valve; assertThat(remoteIpValve.getProtocolHeader()).isEqualTo("x-my-protocol-header"); @@ -336,18 +331,16 @@ public class DefaultServletContainerCustomizerTests { Map map = new HashMap<>(); map.put("server.tomcat.accept-count", "10"); bindProperties(map); - TomcatEmbeddedServletContainerFactory container = new TomcatEmbeddedServletContainerFactory( - 0); - this.customizer.customize(container); - TomcatEmbeddedServletContainer embeddedContainer = (TomcatEmbeddedServletContainer) container - .getEmbeddedServletContainer(); - embeddedContainer.start(); + TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(0); + this.customizer.customize(factory); + TomcatWebServer embeddedfactory = (TomcatWebServer) factory.getWebServer(); + embeddedfactory.start(); try { - assertThat(((AbstractProtocol) embeddedContainer.getTomcat().getConnector() + assertThat(((AbstractProtocol) embeddedfactory.getTomcat().getConnector() .getProtocolHandler()).getBacklog()).isEqualTo(10); } finally { - embeddedContainer.stop(); + embeddedfactory.stop(); } } @@ -356,18 +349,16 @@ public class DefaultServletContainerCustomizerTests { Map map = new HashMap<>(); map.put("server.tomcat.max-connections", "5"); bindProperties(map); - TomcatEmbeddedServletContainerFactory container = new TomcatEmbeddedServletContainerFactory( - 0); - this.customizer.customize(container); - TomcatEmbeddedServletContainer embeddedContainer = (TomcatEmbeddedServletContainer) container - .getEmbeddedServletContainer(); - embeddedContainer.start(); + TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(0); + this.customizer.customize(factory); + TomcatWebServer embeddedfactory = (TomcatWebServer) factory.getWebServer(); + embeddedfactory.start(); try { - assertThat(((AbstractProtocol) embeddedContainer.getTomcat().getConnector() + assertThat(((AbstractProtocol) embeddedfactory.getTomcat().getConnector() .getProtocolHandler()).getMaxConnections()).isEqualTo(5); } finally { - embeddedContainer.stop(); + embeddedfactory.stop(); } } @@ -376,18 +367,16 @@ public class DefaultServletContainerCustomizerTests { Map map = new HashMap<>(); map.put("server.tomcat.max-http-post-size", "10000"); bindProperties(map); - TomcatEmbeddedServletContainerFactory container = new TomcatEmbeddedServletContainerFactory( - 0); - this.customizer.customize(container); - TomcatEmbeddedServletContainer embeddedContainer = (TomcatEmbeddedServletContainer) container - .getEmbeddedServletContainer(); - embeddedContainer.start(); + TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(0); + this.customizer.customize(factory); + TomcatWebServer embeddedfactory = (TomcatWebServer) factory.getWebServer(); + embeddedfactory.start(); try { - assertThat(embeddedContainer.getTomcat().getConnector().getMaxPostSize()) + assertThat(embeddedfactory.getTomcat().getConnector().getMaxPostSize()) .isEqualTo(10000); } finally { - embeddedContainer.stop(); + embeddedfactory.stop(); } } @@ -401,15 +390,15 @@ public class DefaultServletContainerCustomizerTests { map.put("server.undertow.accesslog.dir", "test-logs"); map.put("server.undertow.accesslog.rotate", "false"); bindProperties(map); - UndertowEmbeddedServletContainerFactory container = spy( - new UndertowEmbeddedServletContainerFactory()); - this.customizer.customize(container); - verify(container).setAccessLogEnabled(true); - verify(container).setAccessLogPattern("foo"); - verify(container).setAccessLogPrefix("test_log"); - verify(container).setAccessLogSuffix("txt"); - verify(container).setAccessLogDirectory(new File("test-logs")); - verify(container).setAccessLogRotate(false); + UndertowServletWebServerFactory factory = spy( + new UndertowServletWebServerFactory()); + this.customizer.customize(factory); + verify(factory).setAccessLogEnabled(true); + verify(factory).setAccessLogPattern("foo"); + verify(factory).setAccessLogPrefix("test_log"); + verify(factory).setAccessLogSuffix("txt"); + verify(factory).setAccessLogDirectory(new File("test-logs")); + verify(factory).setAccessLogRotate(false); } @Test @@ -438,63 +427,60 @@ public class DefaultServletContainerCustomizerTests { } private void testCustomTomcatTldSkip(String... expectedJars) { - TomcatEmbeddedServletContainerFactory container = new TomcatEmbeddedServletContainerFactory(); - this.customizer.customize(container); - assertThat(container.getTldSkipPatterns()).contains(expectedJars); - assertThat(container.getTldSkipPatterns()).contains("junit-*.jar", + TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(); + this.customizer.customize(factory); + assertThat(factory.getTldSkipPatterns()).contains(expectedJars); + assertThat(factory.getTldSkipPatterns()).contains("junit-*.jar", "spring-boot-*.jar"); } @Test public void defaultUseForwardHeadersUndertow() throws Exception { - UndertowEmbeddedServletContainerFactory container = spy( - new UndertowEmbeddedServletContainerFactory()); - this.customizer.customize(container); - verify(container).setUseForwardHeaders(false); + UndertowServletWebServerFactory factory = spy( + new UndertowServletWebServerFactory()); + this.customizer.customize(factory); + verify(factory).setUseForwardHeaders(false); } @Test public void setUseForwardHeadersUndertow() throws Exception { this.properties.setUseForwardHeaders(true); - UndertowEmbeddedServletContainerFactory container = spy( - new UndertowEmbeddedServletContainerFactory()); - this.customizer.customize(container); - verify(container).setUseForwardHeaders(true); + UndertowServletWebServerFactory factory = spy( + new UndertowServletWebServerFactory()); + this.customizer.customize(factory); + verify(factory).setUseForwardHeaders(true); } @Test public void deduceUseForwardHeadersUndertow() throws Exception { this.customizer.setEnvironment(new MockEnvironment().withProperty("DYNO", "-")); - UndertowEmbeddedServletContainerFactory container = spy( - new UndertowEmbeddedServletContainerFactory()); - this.customizer.customize(container); - verify(container).setUseForwardHeaders(true); + UndertowServletWebServerFactory factory = spy( + new UndertowServletWebServerFactory()); + this.customizer.customize(factory); + verify(factory).setUseForwardHeaders(true); } @Test public void defaultUseForwardHeadersJetty() throws Exception { - JettyEmbeddedServletContainerFactory container = spy( - new JettyEmbeddedServletContainerFactory()); - this.customizer.customize(container); - verify(container).setUseForwardHeaders(false); + JettyServletWebServerFactory factory = spy(new JettyServletWebServerFactory()); + this.customizer.customize(factory); + verify(factory).setUseForwardHeaders(false); } @Test public void setUseForwardHeadersJetty() throws Exception { this.properties.setUseForwardHeaders(true); - JettyEmbeddedServletContainerFactory container = spy( - new JettyEmbeddedServletContainerFactory()); - this.customizer.customize(container); - verify(container).setUseForwardHeaders(true); + JettyServletWebServerFactory factory = spy(new JettyServletWebServerFactory()); + this.customizer.customize(factory); + verify(factory).setUseForwardHeaders(true); } @Test public void deduceUseForwardHeadersJetty() throws Exception { this.customizer.setEnvironment(new MockEnvironment().withProperty("DYNO", "-")); - JettyEmbeddedServletContainerFactory container = spy( - new JettyEmbeddedServletContainerFactory()); - this.customizer.customize(container); - verify(container).setUseForwardHeaders(true); + JettyServletWebServerFactory factory = spy(new JettyServletWebServerFactory()); + this.customizer.customize(factory); + verify(factory).setUseForwardHeaders(true); } @Test @@ -502,24 +488,22 @@ public class DefaultServletContainerCustomizerTests { Map map = new HashMap<>(); map.put("server.session.store-dir", "myfolder"); bindProperties(map); - JettyEmbeddedServletContainerFactory container = spy( - new JettyEmbeddedServletContainerFactory()); - this.customizer.customize(container); - verify(container).setSessionStoreDir(new File("myfolder")); + JettyServletWebServerFactory factory = spy(new JettyServletWebServerFactory()); + this.customizer.customize(factory); + verify(factory).setSessionStoreDir(new File("myfolder")); } @Test public void skipNullElementsForUndertow() throws Exception { - UndertowEmbeddedServletContainerFactory container = mock( - UndertowEmbeddedServletContainerFactory.class); - this.customizer.customize(container); - verify(container, never()).setAccessLogEnabled(anyBoolean()); + UndertowServletWebServerFactory factory = mock( + UndertowServletWebServerFactory.class); + this.customizer.customize(factory); + verify(factory, never()).setAccessLogEnabled(anyBoolean()); } - private void triggerInitializers(ConfigurableEmbeddedServletContainer container, + private void triggerInitializers(ConfigurableServletWebServerFactory factory, ServletContext servletContext) throws ServletException { - verify(container, atLeastOnce()) - .addInitializers(this.initializersCaptor.capture()); + verify(factory, atLeastOnce()).addInitializers(this.initializersCaptor.capture()); for (Object initializers : this.initializersCaptor.getAllValues()) { if (initializers instanceof ServletContextInitializer) { ((ServletContextInitializer) initializers).onStartup(servletContext); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/EmbeddedServletContainerAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServletWebServerFactoryAutoConfigurationTests.java similarity index 68% rename from spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/EmbeddedServletContainerAutoConfigurationTests.java rename to spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServletWebServerFactoryAutoConfigurationTests.java index 660ed1feb2..0df182f1f5 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/EmbeddedServletContainerAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServletWebServerFactoryAutoConfigurationTests.java @@ -26,13 +26,13 @@ import org.junit.Test; import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; -import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; -import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer; -import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer; -import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.MockEmbeddedServletContainerFactory; import org.springframework.boot.test.util.EnvironmentTestUtils; import org.springframework.boot.web.servlet.ServletRegistrationBean; +import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext; +import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory; +import org.springframework.boot.web.servlet.server.MockServletWebServerFactory; +import org.springframework.boot.web.servlet.server.ServletWebServerFactory; +import org.springframework.boot.web.servlet.server.ServletWebServerFactoryCustomizer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @@ -44,31 +44,32 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.verify; /** - * Tests for {@link EmbeddedServletContainerAutoConfiguration}. + * Tests for {@link ServletWebServerFactoryAutoConfiguration}. * * @author Dave Syer + * @author Phillip Webb */ -public class EmbeddedServletContainerAutoConfigurationTests { +public class ServletWebServerFactoryAutoConfigurationTests { - private AnnotationConfigEmbeddedWebApplicationContext context; + private AnnotationConfigServletWebServerApplicationContext context; @Test public void createFromConfigClass() throws Exception { - this.context = new AnnotationConfigEmbeddedWebApplicationContext( + this.context = new AnnotationConfigServletWebServerApplicationContext( BaseConfiguration.class); verifyContext(); } @Test public void contextAlreadyHasDispatcherServletWithDefaultName() throws Exception { - this.context = new AnnotationConfigEmbeddedWebApplicationContext( + this.context = new AnnotationConfigServletWebServerApplicationContext( DispatcherServletConfiguration.class, BaseConfiguration.class); verifyContext(); } @Test public void contextAlreadyHasDispatcherServlet() throws Exception { - this.context = new AnnotationConfigEmbeddedWebApplicationContext( + this.context = new AnnotationConfigServletWebServerApplicationContext( SpringServletConfiguration.class, BaseConfiguration.class); verifyContext(); assertThat(this.context.getBeanNamesForType(DispatcherServlet.class).length) @@ -77,7 +78,7 @@ public class EmbeddedServletContainerAutoConfigurationTests { @Test public void contextAlreadyHasNonDispatcherServlet() throws Exception { - this.context = new AnnotationConfigEmbeddedWebApplicationContext( + this.context = new AnnotationConfigServletWebServerApplicationContext( NonSpringServletConfiguration.class, BaseConfiguration.class); verifyContext(); // the non default servlet is still registered assertThat(this.context.getBeanNamesForType(DispatcherServlet.class).length) @@ -86,7 +87,7 @@ public class EmbeddedServletContainerAutoConfigurationTests { @Test public void contextAlreadyHasNonServlet() throws Exception { - this.context = new AnnotationConfigEmbeddedWebApplicationContext( + this.context = new AnnotationConfigServletWebServerApplicationContext( NonServletConfiguration.class, BaseConfiguration.class); assertThat(this.context.getBeanNamesForType(DispatcherServlet.class).length) .isEqualTo(0); @@ -95,7 +96,7 @@ public class EmbeddedServletContainerAutoConfigurationTests { @Test public void contextAlreadyHasDispatcherServletAndRegistration() throws Exception { - this.context = new AnnotationConfigEmbeddedWebApplicationContext( + this.context = new AnnotationConfigServletWebServerApplicationContext( DispatcherServletWithRegistrationConfiguration.class, BaseConfiguration.class); verifyContext(); @@ -104,23 +105,23 @@ public class EmbeddedServletContainerAutoConfigurationTests { } @Test - public void containerHasNoServletContext() throws Exception { - this.context = new AnnotationConfigEmbeddedWebApplicationContext( - EnsureContainerHasNoServletContext.class, BaseConfiguration.class); + public void webServerHasNoServletContext() throws Exception { + this.context = new AnnotationConfigServletWebServerApplicationContext( + EnsureWebServerHasNoServletContext.class, BaseConfiguration.class); verifyContext(); } @Test - public void customizeContainerThroughCallback() throws Exception { - this.context = new AnnotationConfigEmbeddedWebApplicationContext( - CallbackEmbeddedContainerCustomizer.class, BaseConfiguration.class); + public void customizeWebServerFactoryThroughCallback() throws Exception { + this.context = new AnnotationConfigServletWebServerApplicationContext( + CallbackEmbeddedServerFactoryCustomizer.class, BaseConfiguration.class); verifyContext(); - assertThat(getContainerFactory().getPort()).isEqualTo(9000); + assertThat(getWebServerFactory().getPort()).isEqualTo(9000); } @Test public void initParametersAreConfiguredOnTheServletContext() { - this.context = new AnnotationConfigEmbeddedWebApplicationContext(); + this.context = new AnnotationConfigServletWebServerApplicationContext(); EnvironmentTestUtils.addEnvironment(this.context, "server.servlet.context-parameters.a:alpha", "server.servlet.context-parameters.b:bravo"); @@ -133,21 +134,20 @@ public class EmbeddedServletContainerAutoConfigurationTests { } private void verifyContext() { - MockEmbeddedServletContainerFactory containerFactory = getContainerFactory(); + MockServletWebServerFactory factory = getWebServerFactory(); Servlet servlet = this.context.getBean( DispatcherServletAutoConfiguration.DEFAULT_DISPATCHER_SERVLET_BEAN_NAME, Servlet.class); - verify(containerFactory.getServletContext()).addServlet("dispatcherServlet", - servlet); + verify(factory.getServletContext()).addServlet("dispatcherServlet", servlet); } - private MockEmbeddedServletContainerFactory getContainerFactory() { - return this.context.getBean(MockEmbeddedServletContainerFactory.class); + private MockServletWebServerFactory getWebServerFactory() { + return this.context.getBean(MockServletWebServerFactory.class); } @Configuration - @Import({ EmbeddedContainerConfiguration.class, - EmbeddedServletContainerAutoConfiguration.class, + @Import({ WebServerConfiguration.class, + ServletWebServerFactoryAutoConfiguration.class, DispatcherServletAutoConfiguration.class }) protected static class BaseConfiguration { @@ -155,11 +155,11 @@ public class EmbeddedServletContainerAutoConfigurationTests { @Configuration @ConditionalOnExpression("true") - public static class EmbeddedContainerConfiguration { + public static class WebServerConfiguration { @Bean - public EmbeddedServletContainerFactory containerFactory() { - return new MockEmbeddedServletContainerFactory(); + public ServletWebServerFactory webServerFactory() { + return new MockServletWebServerFactory(); } } @@ -225,14 +225,14 @@ public class EmbeddedServletContainerAutoConfigurationTests { } @Component - public static class EnsureContainerHasNoServletContext implements BeanPostProcessor { + public static class EnsureWebServerHasNoServletContext implements BeanPostProcessor { @Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { - if (bean instanceof ConfigurableEmbeddedServletContainer) { - MockEmbeddedServletContainerFactory containerFactory = (MockEmbeddedServletContainerFactory) bean; - assertThat(containerFactory.getServletContext()).isNull(); + if (bean instanceof ConfigurableServletWebServerFactory) { + MockServletWebServerFactory webServerFactory = (MockServletWebServerFactory) bean; + assertThat(webServerFactory.getServletContext()).isNull(); } return bean; } @@ -245,12 +245,12 @@ public class EmbeddedServletContainerAutoConfigurationTests { } @Component - public static class CallbackEmbeddedContainerCustomizer - implements EmbeddedServletContainerCustomizer { + public static class CallbackEmbeddedServerFactoryCustomizer + implements ServletWebServerFactoryCustomizer { @Override - public void customize(ConfigurableEmbeddedServletContainer container) { - container.setPort(9000); + public void customize(ConfigurableServletWebServerFactory serverFactory) { + serverFactory.setPort(9000); } } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/EmbeddedServletContainerServletContextListenerTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServletWebServerServletContextListenerTests.java similarity index 73% rename from spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/EmbeddedServletContainerServletContextListenerTests.java rename to spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServletWebServerServletContextListenerTests.java index d4e6489860..c4df9102ec 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/EmbeddedServletContainerServletContextListenerTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServletWebServerServletContextListenerTests.java @@ -21,13 +21,13 @@ import javax.servlet.ServletContextListener; import org.junit.Test; -import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; -import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.EmbeddedWebServer; -import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory; +import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory; +import org.springframework.boot.web.server.WebServer; import org.springframework.boot.web.servlet.ServletListenerRegistrationBean; +import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext; +import org.springframework.boot.web.servlet.server.ServletWebServerFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -36,11 +36,11 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; /** - * Tests for {@link EmbeddedWebServer}s driving {@link ServletContextListener}s correctly + * Tests for {@link WebServer}s driving {@link ServletContextListener}s correctly * * @author Andy Wilkinson */ -public class EmbeddedServletContainerServletContextListenerTests { +public class ServletWebServerServletContextListenerTests { @Test public void registeredServletContextListenerBeanIsCalledByJetty() { @@ -73,7 +73,7 @@ public class EmbeddedServletContainerServletContextListenerTests { } private void servletContextListenerBeanIsCalled(Class configuration) { - AnnotationConfigEmbeddedWebApplicationContext context = new AnnotationConfigEmbeddedWebApplicationContext( + AnnotationConfigServletWebServerApplicationContext context = new AnnotationConfigServletWebServerApplicationContext( ServletContextListenerBeanConfiguration.class, configuration); ServletContextListener servletContextListener = context .getBean("servletContextListener", ServletContextListener.class); @@ -82,7 +82,7 @@ public class EmbeddedServletContainerServletContextListenerTests { } private void registeredServletContextListenerBeanIsCalled(Class configuration) { - AnnotationConfigEmbeddedWebApplicationContext context = new AnnotationConfigEmbeddedWebApplicationContext( + AnnotationConfigServletWebServerApplicationContext context = new AnnotationConfigServletWebServerApplicationContext( ServletListenerRegistrationBeanConfiguration.class, configuration); ServletContextListener servletContextListener = (ServletContextListener) context .getBean("registration", ServletListenerRegistrationBean.class) @@ -95,8 +95,8 @@ public class EmbeddedServletContainerServletContextListenerTests { static class TomcatConfiguration { @Bean - public EmbeddedServletContainerFactory servletContainerFactory() { - return new TomcatEmbeddedServletContainerFactory(0); + public ServletWebServerFactory webServerFactory() { + return new TomcatServletWebServerFactory(0); } } @@ -105,8 +105,8 @@ public class EmbeddedServletContainerServletContextListenerTests { static class JettyConfiguration { @Bean - public EmbeddedServletContainerFactory servletContainerFactory() { - return new JettyEmbeddedServletContainerFactory(0); + public ServletWebServerFactory webServerFactory() { + return new JettyServletWebServerFactory(0); } } @@ -115,8 +115,8 @@ public class EmbeddedServletContainerServletContextListenerTests { static class UndertowConfiguration { @Bean - public EmbeddedServletContainerFactory servletContainerFactory() { - return new UndertowEmbeddedServletContainerFactory(0); + public ServletWebServerFactory webServerFactory() { + return new UndertowServletWebServerFactory(0); } } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfigurationTests.java index 1bcebe937d..8cc8540dc8 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfigurationTests.java @@ -42,12 +42,12 @@ import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoCon import org.springframework.boot.autoconfigure.validation.SpringValidator; import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter; import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration.WelcomePageHandlerMapping; -import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; -import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizerBeanPostProcessor; -import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.MockEmbeddedServletContainerFactory; import org.springframework.boot.test.util.EnvironmentTestUtils; -import org.springframework.boot.web.filter.OrderedHttpPutFormContentFilter; +import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext; +import org.springframework.boot.web.servlet.filter.OrderedHttpPutFormContentFilter; +import org.springframework.boot.web.servlet.server.MockServletWebServerFactory; +import org.springframework.boot.web.servlet.server.ServletWebServerFactory; +import org.springframework.boot.web.servlet.server.ServletWebServerFactoryCustomizerBeanPostProcessor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @@ -116,12 +116,12 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. */ public class WebMvcAutoConfigurationTests { - private static final MockEmbeddedServletContainerFactory containerFactory = new MockEmbeddedServletContainerFactory(); + private static final MockServletWebServerFactory webServerFactory = new MockServletWebServerFactory(); @Rule public ExpectedException thrown = ExpectedException.none(); - private AnnotationConfigEmbeddedWebApplicationContext context; + private AnnotationConfigServletWebServerApplicationContext context; @After public void close() { @@ -411,7 +411,7 @@ public class WebMvcAutoConfigurationTests { @Test public void overrideIgnoreDefaultModelOnRedirect() throws Exception { - this.context = new AnnotationConfigEmbeddedWebApplicationContext(); + this.context = new AnnotationConfigServletWebServerApplicationContext(); EnvironmentTestUtils.addEnvironment(this.context, "spring.mvc.ignore-default-model-on-redirect:false"); this.context.register(Config.class, WebMvcAutoConfiguration.class, @@ -708,7 +708,7 @@ public class WebMvcAutoConfigurationTests { } private void load(Class config, String... environment) { - this.context = new AnnotationConfigEmbeddedWebApplicationContext(); + this.context = new AnnotationConfigServletWebServerApplicationContext(); EnvironmentTestUtils.addEnvironment(this.context, environment); List> configClasses = new ArrayList<>(); if (config != null) { @@ -768,13 +768,13 @@ public class WebMvcAutoConfigurationTests { public static class Config { @Bean - public EmbeddedServletContainerFactory containerFactory() { - return containerFactory; + public ServletWebServerFactory webServerFactory() { + return webServerFactory; } @Bean - public EmbeddedServletContainerCustomizerBeanPostProcessor embeddedServletContainerCustomizerBeanPostProcessor() { - return new EmbeddedServletContainerCustomizerBeanPostProcessor(); + public ServletWebServerFactoryCustomizerBeanPostProcessor ServletWebServerCustomizerBeanPostProcessor() { + return new ServletWebServerFactoryCustomizerBeanPostProcessor(); } } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/webflux/DefaultReactiveWebServerCustomizerTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/webflux/DefaultReactiveWebServerCustomizerTests.java index 2a37439b0b..88c50c919d 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/webflux/DefaultReactiveWebServerCustomizerTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/webflux/DefaultReactiveWebServerCustomizerTests.java @@ -22,7 +22,7 @@ import org.junit.Before; import org.junit.Test; import org.springframework.boot.autoconfigure.web.ServerProperties; -import org.springframework.boot.context.embedded.ConfigurableReactiveWebServer; +import org.springframework.boot.web.reactive.server.ConfigurableReactiveWebServerFactory; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -45,7 +45,7 @@ public class DefaultReactiveWebServerCustomizerTests { @Test public void testCustomizeServerPort() throws Exception { - ConfigurableReactiveWebServer factory = mock(ConfigurableReactiveWebServer.class); + ConfigurableReactiveWebServerFactory factory = mock(ConfigurableReactiveWebServerFactory.class); this.properties.setPort(9000); this.customizer.customize(factory); verify(factory).setPort(9000); @@ -53,7 +53,7 @@ public class DefaultReactiveWebServerCustomizerTests { @Test public void testCustomizeServerAddress() throws Exception { - ConfigurableReactiveWebServer factory = mock(ConfigurableReactiveWebServer.class); + ConfigurableReactiveWebServerFactory factory = mock(ConfigurableReactiveWebServerFactory.class); InetAddress address = mock(InetAddress.class); this.properties.setAddress(address); this.customizer.customize(factory); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/webflux/HttpHandlerAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/webflux/HttpHandlerAutoConfigurationTests.java index f2a0b543c1..d87f96fb45 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/webflux/HttpHandlerAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/webflux/HttpHandlerAutoConfigurationTests.java @@ -20,8 +20,8 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.springframework.boot.context.GenericReactiveWebApplicationContext; import org.springframework.boot.test.util.EnvironmentTestUtils; +import org.springframework.boot.web.reactive.context.GenericReactiveWebApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/webflux/MockReactiveWebServerFactory.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/webflux/MockReactiveWebServerFactory.java index ce7164d0d0..6cbf51c3ce 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/webflux/MockReactiveWebServerFactory.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/webflux/MockReactiveWebServerFactory.java @@ -18,10 +18,10 @@ package org.springframework.boot.autoconfigure.webflux; import java.util.Map; -import org.springframework.boot.context.embedded.AbstractReactiveWebServerFactory; -import org.springframework.boot.context.embedded.EmbeddedWebServer; -import org.springframework.boot.context.embedded.EmbeddedWebServerException; -import org.springframework.boot.context.embedded.ReactiveWebServerFactory; +import org.springframework.boot.web.reactive.server.AbstractReactiveWebServerFactory; +import org.springframework.boot.web.reactive.server.ReactiveWebServerFactory; +import org.springframework.boot.web.server.WebServer; +import org.springframework.boot.web.server.WebServerException; import org.springframework.http.server.reactive.HttpHandler; import static org.mockito.Mockito.spy; @@ -36,13 +36,13 @@ public class MockReactiveWebServerFactory extends AbstractReactiveWebServerFacto private MockReactiveWebServer webServer; @Override - public EmbeddedWebServer getReactiveHttpServer(HttpHandler httpHandler) { + public WebServer getWebServer(HttpHandler httpHandler) { this.webServer = spy(new MockReactiveWebServer(httpHandler, getPort())); return this.webServer; } @Override - public EmbeddedWebServer getReactiveHttpServer(Map handlerMap) { + public WebServer getWebServer(Map handlerMap) { this.webServer = spy(new MockReactiveWebServer(handlerMap, getPort())); return this.webServer; } @@ -51,7 +51,7 @@ public class MockReactiveWebServerFactory extends AbstractReactiveWebServerFacto return this.webServer; } - public static class MockReactiveWebServer implements EmbeddedWebServer { + public static class MockReactiveWebServer implements WebServer { private final int port; @@ -78,12 +78,12 @@ public class MockReactiveWebServerFactory extends AbstractReactiveWebServerFacto } @Override - public void start() throws EmbeddedWebServerException { + public void start() throws WebServerException { } @Override - public void stop() throws EmbeddedWebServerException { + public void stop() throws WebServerException { } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/webflux/ReactiveWebServerAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/webflux/ReactiveWebServerAutoConfigurationTests.java index 4b19d5521e..abd89bdc22 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/webflux/ReactiveWebServerAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/webflux/ReactiveWebServerAutoConfigurationTests.java @@ -22,9 +22,9 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.mockito.Mockito; -import org.springframework.boot.context.embedded.EmbeddedReactiveWebApplicationContext; -import org.springframework.boot.context.embedded.ReactiveWebServerCustomizer; -import org.springframework.boot.context.embedded.ReactiveWebServerFactory; +import org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext; +import org.springframework.boot.web.reactive.server.ReactiveWebServerCustomizer; +import org.springframework.boot.web.reactive.server.ReactiveWebServerFactory; import org.springframework.context.ApplicationContextException; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -40,14 +40,14 @@ import static org.assertj.core.api.Assertions.assertThat; */ public class ReactiveWebServerAutoConfigurationTests { - private EmbeddedReactiveWebApplicationContext context; + private ReactiveWebServerApplicationContext context; @Rule public ExpectedException thrown = ExpectedException.none(); @Test public void createFromConfigClass() { - this.context = new EmbeddedReactiveWebApplicationContext(BaseConfiguration.class); + this.context = new ReactiveWebServerApplicationContext(BaseConfiguration.class); assertThat(this.context.getBeansOfType(ReactiveWebServerFactory.class)) .hasSize(1); assertThat(this.context.getBeansOfType(ReactiveWebServerCustomizer.class)) @@ -60,7 +60,7 @@ public class ReactiveWebServerAutoConfigurationTests { public void missingHttpHandler() { this.thrown.expect(ApplicationContextException.class); this.thrown.expectMessage(Matchers.containsString("missing HttpHandler bean")); - this.context = new EmbeddedReactiveWebApplicationContext( + this.context = new ReactiveWebServerApplicationContext( MissingHttpHandlerConfiguration.class); } @@ -69,13 +69,13 @@ public class ReactiveWebServerAutoConfigurationTests { this.thrown.expect(ApplicationContextException.class); this.thrown.expectMessage(Matchers.containsString( "multiple HttpHandler beans : httpHandler,additionalHttpHandler")); - this.context = new EmbeddedReactiveWebApplicationContext(BaseConfiguration.class, + this.context = new ReactiveWebServerApplicationContext(BaseConfiguration.class, TooManyHttpHandlers.class); } @Test public void customizeReactiveWebServer() { - this.context = new EmbeddedReactiveWebApplicationContext(BaseConfiguration.class, + this.context = new ReactiveWebServerApplicationContext(BaseConfiguration.class, ReactiveWebServerCustomization.class); MockReactiveWebServerFactory factory = this.context .getBean(MockReactiveWebServerFactory.class); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/webflux/WebFluxAnnotationAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/webflux/WebFluxAnnotationAutoConfigurationTests.java index 947dd90bfe..81cd86ee2b 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/webflux/WebFluxAnnotationAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/webflux/WebFluxAnnotationAutoConfigurationTests.java @@ -24,9 +24,9 @@ import org.junit.Test; import org.springframework.beans.DirectFieldAccessor; import org.springframework.boot.autoconfigure.validation.SpringValidator; -import org.springframework.boot.context.GenericReactiveWebApplicationContext; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.test.util.EnvironmentTestUtils; +import org.springframework.boot.web.reactive.context.GenericReactiveWebApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/websocket/WebSocketAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/websocket/WebSocketAutoConfigurationTests.java index 1ad3738297..3756c5d3d4 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/websocket/WebSocketAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/websocket/WebSocketAutoConfigurationTests.java @@ -27,11 +27,11 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; -import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizerBeanPostProcessor; -import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; +import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext; +import org.springframework.boot.web.servlet.server.ServletWebServerFactory; +import org.springframework.boot.web.servlet.server.ServletWebServerFactoryCustomizerBeanPostProcessor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.util.ReflectionTestUtils; @@ -45,11 +45,11 @@ import static org.assertj.core.api.Assertions.assertThat; */ public class WebSocketAutoConfigurationTests { - private AnnotationConfigEmbeddedWebApplicationContext context; + private AnnotationConfigServletWebServerApplicationContext context; @Before public void createContext() { - this.context = new AnnotationConfigEmbeddedWebApplicationContext(); + this.context = new AnnotationConfigServletWebServerApplicationContext(); } @After @@ -92,8 +92,8 @@ public class WebSocketAutoConfigurationTests { static class CommonConfiguration { @Bean - public EmbeddedServletContainerCustomizerBeanPostProcessor embeddedServletContainerCustomizerBeanPostProcessor() { - return new EmbeddedServletContainerCustomizerBeanPostProcessor(); + public ServletWebServerFactoryCustomizerBeanPostProcessor ServletWebServerCustomizerBeanPostProcessor() { + return new ServletWebServerFactoryCustomizerBeanPostProcessor(); } } @@ -102,10 +102,10 @@ public class WebSocketAutoConfigurationTests { static class TomcatConfiguration extends CommonConfiguration { @Bean - public EmbeddedServletContainerFactory servletContainerFactory() { - TomcatEmbeddedServletContainerFactory tomcatEmbeddedServletContainerFactory = new TomcatEmbeddedServletContainerFactory(); - tomcatEmbeddedServletContainerFactory.setPort(0); - return tomcatEmbeddedServletContainerFactory; + public ServletWebServerFactory webServerFactory() { + TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(); + factory.setPort(0); + return factory; } } @@ -114,10 +114,10 @@ public class WebSocketAutoConfigurationTests { static class JettyConfiguration extends CommonConfiguration { @Bean - public EmbeddedServletContainerFactory servletContainerFactory() { - JettyEmbeddedServletContainerFactory jettyEmbeddedServletContainerFactory = new JettyEmbeddedServletContainerFactory(); - jettyEmbeddedServletContainerFactory.setPort(0); - return jettyEmbeddedServletContainerFactory; + public ServletWebServerFactory webServerFactory() { + JettyServletWebServerFactory JettyServletWebServerFactory = new JettyServletWebServerFactory(); + JettyServletWebServerFactory.setPort(0); + return JettyServletWebServerFactory; } } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/websocket/WebSocketMessagingAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/websocket/WebSocketMessagingAutoConfigurationTests.java index 5adcabcfeb..54f2adbdec 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/websocket/WebSocketMessagingAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/websocket/WebSocketMessagingAutoConfigurationTests.java @@ -34,12 +34,12 @@ import org.junit.Test; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration; -import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; -import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; -import org.springframework.boot.context.embedded.ServerPortInfoApplicationContextInitializer; -import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; +import org.springframework.boot.autoconfigure.web.ServletWebServerFactoryAutoConfiguration; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.test.util.EnvironmentTestUtils; +import org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.messaging.converter.CompositeMessageConverter; @@ -78,7 +78,7 @@ import static org.junit.Assert.fail; */ public class WebSocketMessagingAutoConfigurationTests { - private AnnotationConfigEmbeddedWebApplicationContext context = new AnnotationConfigEmbeddedWebApplicationContext(); + private AnnotationConfigServletWebServerApplicationContext context = new AnnotationConfigServletWebServerApplicationContext(); private SockJsClient sockJsClient; @@ -208,7 +208,7 @@ public class WebSocketMessagingAutoConfigurationTests { @EnableConfigurationProperties @EnableWebSocketMessageBroker @ImportAutoConfiguration({ JacksonAutoConfiguration.class, - EmbeddedServletContainerAutoConfiguration.class, + ServletWebServerFactoryAutoConfiguration.class, WebSocketMessagingAutoConfiguration.class, DispatcherServletAutoConfiguration.class }) static class WebSocketMessagingConfiguration @@ -230,8 +230,8 @@ public class WebSocketMessagingAutoConfigurationTests { } @Bean - public TomcatEmbeddedServletContainerFactory tomcat() { - return new TomcatEmbeddedServletContainerFactory(0); + public TomcatServletWebServerFactory tomcat() { + return new TomcatServletWebServerFactory(0); } @Bean diff --git a/spring-boot-cli/samples/http.groovy b/spring-boot-cli/samples/http.groovy index f7ff3ef77e..af87329fda 100644 --- a/spring-boot-cli/samples/http.groovy +++ b/spring-boot-cli/samples/http.groovy @@ -16,7 +16,7 @@ class Example implements CommandLineRunner { } void run(String... args) { - def port = context.embeddedWebServer.port; + def port = context.webServer.port; def world = new RESTClient("http://localhost:" + port).get(path:"/").data.text print "Hello " + world } diff --git a/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfigurationTests.java b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfigurationTests.java index 6f5980d615..47de3d1c04 100644 --- a/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfigurationTests.java +++ b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfigurationTests.java @@ -33,10 +33,8 @@ import org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration; -import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; import org.springframework.boot.autoconfigure.web.ResourceProperties; -import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext; -import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer; +import org.springframework.boot.autoconfigure.web.ServletWebServerFactoryAutoConfiguration; import org.springframework.boot.devtools.classpath.ClassPathChangedEvent; import org.springframework.boot.devtools.classpath.ClassPathFileSystemWatcher; import org.springframework.boot.devtools.filewatch.ChangedFiles; @@ -45,6 +43,8 @@ import org.springframework.boot.devtools.restart.FailureHandler; import org.springframework.boot.devtools.restart.MockRestartInitializer; import org.springframework.boot.devtools.restart.MockRestarter; import org.springframework.boot.devtools.restart.Restarter; +import org.springframework.boot.web.embedded.tomcat.TomcatWebServer; +import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -243,8 +243,8 @@ public class LocalDevToolsAutoConfigurationTests { @Test public void devToolsSwitchesJspServletToDevelopmentMode() { this.context = initializeAndRun(Config.class); - TomcatEmbeddedServletContainer tomcatContainer = (TomcatEmbeddedServletContainer) ((EmbeddedWebApplicationContext) this.context) - .getEmbeddedWebServer(); + TomcatWebServer tomcatContainer = (TomcatWebServer) ((ServletWebServerApplicationContext) this.context) + .getWebServer(); Container context = tomcatContainer.getTomcat().getHost().findChildren()[0]; StandardWrapper jspServletWrapper = (StandardWrapper) context.findChild("jsp"); EmbeddedServletOptions options = (EmbeddedServletOptions) ReflectionTestUtils @@ -277,14 +277,14 @@ public class LocalDevToolsAutoConfigurationTests { } @Configuration - @Import({ EmbeddedServletContainerAutoConfiguration.class, + @Import({ ServletWebServerFactoryAutoConfiguration.class, LocalDevToolsAutoConfiguration.class, ThymeleafAutoConfiguration.class }) public static class Config { } @Configuration - @Import({ EmbeddedServletContainerAutoConfiguration.class, + @Import({ ServletWebServerFactoryAutoConfiguration.class, LocalDevToolsAutoConfiguration.class, ThymeleafAutoConfiguration.class }) public static class ConfigWithMockLiveReload { @@ -296,7 +296,7 @@ public class LocalDevToolsAutoConfigurationTests { } @Configuration - @Import({ EmbeddedServletContainerAutoConfiguration.class, + @Import({ ServletWebServerFactoryAutoConfiguration.class, LocalDevToolsAutoConfiguration.class, ResourceProperties.class }) public static class WebResourcesConfig { diff --git a/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/integrationtest/HttpTunnelIntegrationTests.java b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/integrationtest/HttpTunnelIntegrationTests.java index 2dea54063c..9fa46465d0 100644 --- a/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/integrationtest/HttpTunnelIntegrationTests.java +++ b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/integrationtest/HttpTunnelIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -23,8 +23,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; import org.springframework.boot.devtools.remote.server.AccessManager; import org.springframework.boot.devtools.remote.server.Dispatcher; import org.springframework.boot.devtools.remote.server.DispatcherFilter; @@ -42,6 +40,8 @@ import org.springframework.boot.devtools.tunnel.server.TargetServerConnection; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.servlet.server.ServletWebServerFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpStatus; @@ -95,8 +95,8 @@ public class HttpTunnelIntegrationTests { private int httpServerPort = SocketUtils.findAvailableTcpPort(); @Bean - public EmbeddedServletContainerFactory container() { - return new TomcatEmbeddedServletContainerFactory(this.httpServerPort); + public ServletWebServerFactory container() { + return new TomcatServletWebServerFactory(this.httpServerPort); } @Bean diff --git a/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/remote/client/RemoteClientConfigurationTests.java b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/remote/client/RemoteClientConfigurationTests.java index 9241e66d1e..22e6524564 100644 --- a/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/remote/client/RemoteClientConfigurationTests.java +++ b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/remote/client/RemoteClientConfigurationTests.java @@ -28,8 +28,6 @@ import org.junit.rules.ExpectedException; import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.NoSuchBeanDefinitionException; -import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; -import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; import org.springframework.boot.devtools.autoconfigure.OptionalLiveReloadServer; import org.springframework.boot.devtools.classpath.ClassPathChangedEvent; import org.springframework.boot.devtools.classpath.ClassPathFileSystemWatcher; @@ -43,6 +41,8 @@ import org.springframework.boot.devtools.restart.RestartScopeInitializer; import org.springframework.boot.devtools.tunnel.client.TunnelClient; import org.springframework.boot.test.rule.OutputCapture; import org.springframework.boot.test.util.EnvironmentTestUtils; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.server.ServerHttpRequest; @@ -71,7 +71,7 @@ public class RemoteClientConfigurationTests { @Rule public ExpectedException thrown = ExpectedException.none(); - private AnnotationConfigEmbeddedWebApplicationContext context; + private AnnotationConfigServletWebServerApplicationContext context; private static int remotePort = SocketUtils.findAvailableTcpPort(); @@ -149,7 +149,7 @@ public class RemoteClientConfigurationTests { } private void configure(String remoteUrl, boolean setSecret, String... pairs) { - this.context = new AnnotationConfigEmbeddedWebApplicationContext(); + this.context = new AnnotationConfigServletWebServerApplicationContext(); new RestartScopeInitializer().initialize(this.context); this.context.register(Config.class, RemoteClientConfiguration.class); String remoteUrlProperty = "remoteUrl:" + remoteUrl + ":" @@ -167,8 +167,8 @@ public class RemoteClientConfigurationTests { static class Config { @Bean - public TomcatEmbeddedServletContainerFactory tomcat() { - return new TomcatEmbeddedServletContainerFactory(remotePort); + public TomcatServletWebServerFactory tomcat() { + return new TomcatServletWebServerFactory(remotePort); } @Bean diff --git a/spring-boot-docs/src/main/java/org/springframework/boot/context/embedded/TomcatLegacyCookieProcessorExample.java b/spring-boot-docs/src/main/java/org/springframework/boot/context/embedded/TomcatLegacyCookieProcessorExample.java index 150f356f3e..67eb0c8c51 100644 --- a/spring-boot-docs/src/main/java/org/springframework/boot/context/embedded/TomcatLegacyCookieProcessorExample.java +++ b/spring-boot-docs/src/main/java/org/springframework/boot/context/embedded/TomcatLegacyCookieProcessorExample.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -19,8 +19,10 @@ package org.springframework.boot.context.embedded; import org.apache.catalina.Context; import org.apache.tomcat.util.http.LegacyCookieProcessor; -import org.springframework.boot.context.embedded.tomcat.TomcatContextCustomizer; -import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; +import org.springframework.boot.web.embedded.tomcat.TomcatContextCustomizer; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory; +import org.springframework.boot.web.servlet.server.ServletWebServerFactoryCustomizer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -33,20 +35,20 @@ public class TomcatLegacyCookieProcessorExample { /** * Configuration class that declares the required - * {@link EmbeddedServletContainerCustomizer}. + * {@link ServletWebServerFactoryCustomizer}. */ @Configuration static class LegacyCookieProcessorConfiguration { // tag::customizer[] @Bean - public EmbeddedServletContainerCustomizer cookieProcessorCustomizer() { - return new EmbeddedServletContainerCustomizer() { + public ServletWebServerFactoryCustomizer cookieProcessorCustomizer() { + return new ServletWebServerFactoryCustomizer() { @Override - public void customize(ConfigurableEmbeddedServletContainer container) { - if (container instanceof TomcatEmbeddedServletContainerFactory) { - ((TomcatEmbeddedServletContainerFactory) container) + public void customize(ConfigurableServletWebServerFactory serverFactory) { + if (serverFactory instanceof TomcatServletWebServerFactory) { + ((TomcatServletWebServerFactory) serverFactory) .addContextCustomizers(new TomcatContextCustomizer() { @Override diff --git a/spring-boot-docs/src/test/java/org/springframework/boot/context/embedded/TomcatLegacyCookieProcessorExampleTests.java b/spring-boot-docs/src/test/java/org/springframework/boot/context/embedded/TomcatLegacyCookieProcessorExampleTests.java index 3f4c8606ff..d5955da005 100644 --- a/spring-boot-docs/src/test/java/org/springframework/boot/context/embedded/TomcatLegacyCookieProcessorExampleTests.java +++ b/spring-boot-docs/src/test/java/org/springframework/boot/context/embedded/TomcatLegacyCookieProcessorExampleTests.java @@ -22,8 +22,10 @@ import org.junit.Test; import org.springframework.boot.SpringApplication; import org.springframework.boot.context.embedded.TomcatLegacyCookieProcessorExample.LegacyCookieProcessorConfiguration; -import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer; -import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.embedded.tomcat.TomcatWebServer; +import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext; +import org.springframework.boot.web.servlet.server.ServletWebServerFactoryCustomizerBeanPostProcessor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -38,10 +40,10 @@ public class TomcatLegacyCookieProcessorExampleTests { @Test public void cookieProcessorIsCustomized() { - EmbeddedWebApplicationContext applicationContext = (EmbeddedWebApplicationContext) new SpringApplication( + ServletWebServerApplicationContext applicationContext = (ServletWebServerApplicationContext) new SpringApplication( TestConfiguration.class, LegacyCookieProcessorConfiguration.class).run(); - Context context = (Context) ((TomcatEmbeddedServletContainer) applicationContext - .getEmbeddedWebServer()).getTomcat().getHost().findChildren()[0]; + Context context = (Context) ((TomcatWebServer) applicationContext + .getWebServer()).getTomcat().getHost().findChildren()[0]; assertThat(context.getCookieProcessor()) .isInstanceOf(LegacyCookieProcessor.class); } @@ -50,13 +52,13 @@ public class TomcatLegacyCookieProcessorExampleTests { static class TestConfiguration { @Bean - public TomcatEmbeddedServletContainerFactory tomcatFactory() { - return new TomcatEmbeddedServletContainerFactory(0); + public TomcatServletWebServerFactory tomcatFactory() { + return new TomcatServletWebServerFactory(0); } @Bean - public EmbeddedServletContainerCustomizerBeanPostProcessor postProcessor() { - return new EmbeddedServletContainerCustomizerBeanPostProcessor(); + public ServletWebServerFactoryCustomizerBeanPostProcessor postProcessor() { + return new ServletWebServerFactoryCustomizerBeanPostProcessor(); } } diff --git a/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/WarPackagingTests.java b/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/WarPackagingTests.java index 8e1918c4b3..3c5b41c429 100644 --- a/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/WarPackagingTests.java +++ b/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/java/org/springframework/boot/gradle/WarPackagingTests.java @@ -70,21 +70,21 @@ public class WarPackagingTests { @Test public void onlyTomcatIsPackagedInWebInfLibProvided() throws IOException { - checkWebInfEntriesForServletContainer("tomcat", + checkWebInfEntriesForWebServer("tomcat", TOMCAT_EXPECTED_IN_WEB_INF_LIB_PROVIDED); } @Test public void onlyJettyIsPackagedInWebInfLibProvided() throws IOException { - checkWebInfEntriesForServletContainer("jetty", + checkWebInfEntriesForWebServer("jetty", JETTY_EXPECTED_IN_WEB_INF_LIB_PROVIDED); } - private void checkWebInfEntriesForServletContainer(String servletContainer, + private void checkWebInfEntriesForWebServer(String webServer, Set expectedLibProvidedEntries) throws IOException { project.newBuild().forTasks("clean", "build") .withArguments("-PbootVersion=" + BOOT_VERSION, - "-PservletContainer=" + servletContainer) + "-PservletContainer=" + webServer) .run(); JarFile war = new JarFile("target/war-packaging/build/libs/war-packaging.war"); diff --git a/spring-boot-parent/pom.xml b/spring-boot-parent/pom.xml index 2d559cdbe9..f096a5a738 100644 --- a/spring-boot-parent/pom.xml +++ b/spring-boot-parent/pom.xml @@ -301,7 +301,7 @@ com.puppycrawl.tools checkstyle - 7.1.1 + 7.6 diff --git a/spring-boot-parent/src/checkstyle/checkstyle.xml b/spring-boot-parent/src/checkstyle/checkstyle.xml index c7f1dd1bd6..01aad59145 100644 --- a/spring-boot-parent/src/checkstyle/checkstyle.xml +++ b/spring-boot-parent/src/checkstyle/checkstyle.xml @@ -77,6 +77,10 @@ + + + + diff --git a/spring-boot-parent/src/checkstyle/import-control.xml b/spring-boot-parent/src/checkstyle/import-control.xml new file mode 100644 index 0000000000..d519b32ec6 --- /dev/null +++ b/spring-boot-parent/src/checkstyle/import-control.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationPortTests.java b/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationPortTests.java index 5a60ddf3d1..ea96355ed7 100644 --- a/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationPortTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationPortTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -22,10 +22,10 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.actuate.autoconfigure.LocalManagementPort; -import org.springframework.boot.context.embedded.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureManagementPortAndPathSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureManagementPortAndPathSampleActuatorApplicationTests.java index f38f73372e..43efe4cdb9 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureManagementPortAndPathSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureManagementPortAndPathSampleActuatorApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -24,10 +24,10 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.actuate.autoconfigure.LocalManagementPort; import org.springframework.boot.autoconfigure.security.SecurityProperties; -import org.springframework.boot.context.embedded.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementAddressActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementAddressActuatorApplicationTests.java index 1f6a188da7..0ea134ae89 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementAddressActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementAddressActuatorApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -22,10 +22,10 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.actuate.autoconfigure.LocalManagementPort; -import org.springframework.boot.context.embedded.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java index 6e50f52abb..030e7263b3 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -24,10 +24,10 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.actuate.autoconfigure.LocalManagementPort; import org.springframework.boot.autoconfigure.security.SecurityProperties; -import org.springframework.boot.context.embedded.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortSampleActuatorApplicationTests.java index fc7ed4bd3a..cdeb1e2107 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortSampleActuatorApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -24,10 +24,10 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.actuate.autoconfigure.LocalManagementPort; import org.springframework.boot.autoconfigure.security.SecurityProperties; -import org.springframework.boot.context.embedded.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; diff --git a/spring-boot-samples/spring-boot-sample-atmosphere/src/test/java/sample/atmosphere/SampleAtmosphereApplicationTests.java b/spring-boot-samples/spring-boot-sample-atmosphere/src/test/java/sample/atmosphere/SampleAtmosphereApplicationTests.java index ea4e3212f2..4e17f707d3 100644 --- a/spring-boot-samples/spring-boot-sample-atmosphere/src/test/java/sample/atmosphere/SampleAtmosphereApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-atmosphere/src/test/java/sample/atmosphere/SampleAtmosphereApplicationTests.java @@ -29,9 +29,9 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.context.embedded.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.web.server.LocalServerPort; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/spring-boot-samples/spring-boot-sample-jersey1/src/main/java/sample/jersey1/SampleJersey1Application.java b/spring-boot-samples/spring-boot-sample-jersey1/src/main/java/sample/jersey1/SampleJersey1Application.java index 8b4fdb5983..9a7cec432e 100644 --- a/spring-boot-samples/spring-boot-sample-jersey1/src/main/java/sample/jersey1/SampleJersey1Application.java +++ b/spring-boot-samples/spring-boot-sample-jersey1/src/main/java/sample/jersey1/SampleJersey1Application.java @@ -25,7 +25,7 @@ import com.sun.jersey.spi.container.servlet.ServletContainer; import org.springframework.boot.WebApplicationType; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; @@ -41,8 +41,8 @@ public class SampleJersey1Application { @Bean // Not needed if Spring Web MVC is also present on classpath - public TomcatEmbeddedServletContainerFactory tomcatEmbeddedServletContainerFactory() { - return new TomcatEmbeddedServletContainerFactory(); + public TomcatServletWebServerFactory webServerFactory() { + return new TomcatServletWebServerFactory(); } @Bean diff --git a/spring-boot-samples/spring-boot-sample-jetty-ssl/src/test/java/sample/jetty/ssl/SampleJettySslApplicationTests.java b/spring-boot-samples/spring-boot-sample-jetty-ssl/src/test/java/sample/jetty/ssl/SampleJettySslApplicationTests.java index ce9dc3a03c..a3c00bbe67 100644 --- a/spring-boot-samples/spring-boot-sample-jetty-ssl/src/test/java/sample/jetty/ssl/SampleJettySslApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-jetty-ssl/src/test/java/sample/jetty/ssl/SampleJettySslApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -19,11 +19,11 @@ package sample.jetty.ssl; import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.boot.context.embedded.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.boot.test.web.client.TestRestTemplate.HttpClientOption; +import org.springframework.boot.web.server.LocalServerPort; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; diff --git a/spring-boot-samples/spring-boot-sample-session-redis/src/test/java/sample/session/redis/SampleSessionRedisApplicationTests.java b/spring-boot-samples/spring-boot-sample-session-redis/src/test/java/sample/session/redis/SampleSessionRedisApplicationTests.java index 9cb3e27ddb..560e5d8590 100644 --- a/spring-boot-samples/spring-boot-sample-session-redis/src/test/java/sample/session/redis/SampleSessionRedisApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-session-redis/src/test/java/sample/session/redis/SampleSessionRedisApplicationTests.java @@ -21,7 +21,7 @@ import java.net.URI; import org.junit.Test; import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.context.embedded.ServerPortInfoApplicationContextInitializer; +import org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.data.redis.RedisConnectionFailureException; import org.springframework.http.HttpHeaders; diff --git a/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/main/java/sample/tomcat/multiconnector/SampleTomcatTwoConnectorsApplication.java b/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/main/java/sample/tomcat/multiconnector/SampleTomcatTwoConnectorsApplication.java index 220bd12dfb..255dba59f8 100644 --- a/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/main/java/sample/tomcat/multiconnector/SampleTomcatTwoConnectorsApplication.java +++ b/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/main/java/sample/tomcat/multiconnector/SampleTomcatTwoConnectorsApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2017 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. @@ -20,8 +20,8 @@ import org.apache.catalina.connector.Connector; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.servlet.server.ServletWebServerFactory; import org.springframework.context.annotation.Bean; import org.springframework.util.SocketUtils; @@ -40,8 +40,8 @@ public class SampleTomcatTwoConnectorsApplication { } @Bean - public EmbeddedServletContainerFactory servletContainer() { - TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory(); + public ServletWebServerFactory servletContainer() { + TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory(); tomcat.addAdditionalTomcatConnectors(createStandardConnector()); return tomcat; } diff --git a/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/test/java/sample/tomcat/multiconnector/SampleTomcatTwoConnectorsApplicationTests.java b/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/test/java/sample/tomcat/multiconnector/SampleTomcatTwoConnectorsApplicationTests.java index 199fda9c51..e72978ad98 100644 --- a/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/test/java/sample/tomcat/multiconnector/SampleTomcatTwoConnectorsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/test/java/sample/tomcat/multiconnector/SampleTomcatTwoConnectorsApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -31,9 +31,9 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.embedded.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.web.server.LocalServerPort; import org.springframework.context.ApplicationContext; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; diff --git a/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/NonAutoConfigurationSampleTomcatApplicationTests.java b/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/NonAutoConfigurationSampleTomcatApplicationTests.java index 1f3b60a83c..b20c6b33fc 100644 --- a/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/NonAutoConfigurationSampleTomcatApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/NonAutoConfigurationSampleTomcatApplicationTests.java @@ -25,7 +25,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration; -import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; +import org.springframework.boot.autoconfigure.web.ServletWebServerFactoryAutoConfiguration; import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration; import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; @@ -55,7 +55,7 @@ public class NonAutoConfigurationSampleTomcatApplicationTests { private TestRestTemplate restTemplate; @Configuration - @Import({ EmbeddedServletContainerAutoConfiguration.class, + @Import({ ServletWebServerFactoryAutoConfiguration.class, DispatcherServletAutoConfiguration.class, WebMvcAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class }) diff --git a/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/SampleTomcatApplicationTests.java b/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/SampleTomcatApplicationTests.java index 5055992802..c4b43aa29d 100644 --- a/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/SampleTomcatApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/SampleTomcatApplicationTests.java @@ -26,11 +26,11 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext; -import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.embedded.tomcat.TomcatWebServer; +import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext; import org.springframework.context.ApplicationContext; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; @@ -88,9 +88,9 @@ public class SampleTomcatApplicationTests { @Test public void testTimeout() throws Exception { - EmbeddedWebApplicationContext context = (EmbeddedWebApplicationContext) this.applicationContext; - TomcatEmbeddedServletContainer embeddedServletContainer = (TomcatEmbeddedServletContainer) context - .getEmbeddedWebServer(); + ServletWebServerApplicationContext context = (ServletWebServerApplicationContext) this.applicationContext; + TomcatWebServer embeddedServletContainer = (TomcatWebServer) context + .getWebServer(); ProtocolHandler protocolHandler = embeddedServletContainer.getTomcat() .getConnector().getProtocolHandler(); int timeout = ((AbstractProtocol) protocolHandler).getConnectionTimeout(); diff --git a/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/test/java/sample/groovytemplates/SampleGroovyTemplateApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/test/java/sample/groovytemplates/SampleGroovyTemplateApplicationTests.java index cf0fd812e3..aba12a26d7 100644 --- a/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/test/java/sample/groovytemplates/SampleGroovyTemplateApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/test/java/sample/groovytemplates/SampleGroovyTemplateApplicationTests.java @@ -22,10 +22,10 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.embedded.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; diff --git a/spring-boot-samples/spring-boot-sample-web-method-security/src/test/java/sample/security/method/SampleMethodSecurityApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-method-security/src/test/java/sample/security/method/SampleMethodSecurityApplicationTests.java index 695b23ec6f..ec34d73637 100644 --- a/spring-boot-samples/spring-boot-sample-web-method-security/src/test/java/sample/security/method/SampleMethodSecurityApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-method-security/src/test/java/sample/security/method/SampleMethodSecurityApplicationTests.java @@ -24,10 +24,10 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.embedded.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; diff --git a/spring-boot-samples/spring-boot-sample-web-secure-custom/src/test/java/sample/web/secure/custom/SampleWebSecureCustomApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-secure-custom/src/test/java/sample/web/secure/custom/SampleWebSecureCustomApplicationTests.java index 70d5ca2086..04a92dcc9e 100644 --- a/spring-boot-samples/spring-boot-sample-web-secure-custom/src/test/java/sample/web/secure/custom/SampleWebSecureCustomApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-secure-custom/src/test/java/sample/web/secure/custom/SampleWebSecureCustomApplicationTests.java @@ -24,10 +24,10 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.embedded.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; diff --git a/spring-boot-samples/spring-boot-sample-web-secure-github/src/test/java/sample/web/secure/github/SampleGithubApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-secure-github/src/test/java/sample/web/secure/github/SampleGithubApplicationTests.java index bd0bb89a7a..71bfabf28a 100644 --- a/spring-boot-samples/spring-boot-sample-web-secure-github/src/test/java/sample/web/secure/github/SampleGithubApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-secure-github/src/test/java/sample/web/secure/github/SampleGithubApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -22,10 +22,10 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.embedded.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; diff --git a/spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/test/java/sample/web/secure/jdbc/SampleWebSecureJdbcApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/test/java/sample/web/secure/jdbc/SampleWebSecureJdbcApplicationTests.java index 00b9109856..270b9c938c 100644 --- a/spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/test/java/sample/web/secure/jdbc/SampleWebSecureJdbcApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/test/java/sample/web/secure/jdbc/SampleWebSecureJdbcApplicationTests.java @@ -24,10 +24,10 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.embedded.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; diff --git a/spring-boot-samples/spring-boot-sample-web-secure/src/test/java/sample/web/secure/SampleSecureApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-secure/src/test/java/sample/web/secure/SampleSecureApplicationTests.java index 5eec9ec8c9..874e25c121 100644 --- a/spring-boot-samples/spring-boot-sample-web-secure/src/test/java/sample/web/secure/SampleSecureApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-secure/src/test/java/sample/web/secure/SampleSecureApplicationTests.java @@ -24,10 +24,10 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.embedded.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; diff --git a/spring-boot-samples/spring-boot-sample-web-ui/src/test/java/sample/web/ui/SampleWebUiApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-ui/src/test/java/sample/web/ui/SampleWebUiApplicationTests.java index d7b998ac66..9dcd2a8f21 100644 --- a/spring-boot-samples/spring-boot-sample-web-ui/src/test/java/sample/web/ui/SampleWebUiApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-ui/src/test/java/sample/web/ui/SampleWebUiApplicationTests.java @@ -22,10 +22,10 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.embedded.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; diff --git a/spring-boot-samples/spring-boot-sample-webservices/src/test/java/sample/webservices/SampleWsApplicationTests.java b/spring-boot-samples/spring-boot-sample-webservices/src/test/java/sample/webservices/SampleWsApplicationTests.java index 3807db7cb0..9168d151f7 100644 --- a/spring-boot-samples/spring-boot-sample-webservices/src/test/java/sample/webservices/SampleWsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-webservices/src/test/java/sample/webservices/SampleWsApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -26,10 +26,10 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.boot.context.embedded.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.rule.OutputCapture; +import org.springframework.boot.web.server.LocalServerPort; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.ws.client.core.WebServiceTemplate; diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/SampleWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/SampleWebSocketsApplicationTests.java index 6136a8e077..5ad375facb 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/SampleWebSocketsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/SampleWebSocketsApplicationTests.java @@ -32,9 +32,9 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.context.embedded.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.web.server.LocalServerPort; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/echo/CustomContainerWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/echo/CustomContainerWebSocketsApplicationTests.java index 3364dd9961..912391a1c0 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/echo/CustomContainerWebSocketsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/echo/CustomContainerWebSocketsApplicationTests.java @@ -34,10 +34,10 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory; +import org.springframework.boot.web.servlet.server.ServletWebServerFactory; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -95,8 +95,8 @@ public class CustomContainerWebSocketsApplicationTests { protected static class CustomContainerConfiguration { @Bean - public EmbeddedServletContainerFactory embeddedServletContainerFactory() { - return new JettyEmbeddedServletContainerFactory("/ws", PORT); + public ServletWebServerFactory webServerFactory() { + return new JettyServletWebServerFactory("/ws", PORT); } } diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/SampleWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/SampleWebSocketsApplicationTests.java index 0cff500d18..26c6776476 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/SampleWebSocketsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/SampleWebSocketsApplicationTests.java @@ -32,9 +32,9 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.context.embedded.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.web.server.LocalServerPort; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/echo/CustomContainerWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/echo/CustomContainerWebSocketsApplicationTests.java index 81155eeb23..ad99a63bbf 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/echo/CustomContainerWebSocketsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/echo/CustomContainerWebSocketsApplicationTests.java @@ -34,10 +34,10 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.servlet.server.ServletWebServerFactory; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -95,8 +95,8 @@ public class CustomContainerWebSocketsApplicationTests { protected static class CustomContainerConfiguration { @Bean - public EmbeddedServletContainerFactory embeddedServletContainerFactory() { - return new TomcatEmbeddedServletContainerFactory("/ws", PORT); + public ServletWebServerFactory webServerFactory() { + return new TomcatServletWebServerFactory("/ws", PORT); } } diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/SampleWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/SampleWebSocketsApplicationTests.java index 80d6032af0..6602535b97 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/SampleWebSocketsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/SampleWebSocketsApplicationTests.java @@ -32,9 +32,9 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.context.embedded.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.web.server.LocalServerPort; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/echo/CustomContainerWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/echo/CustomContainerWebSocketsApplicationTests.java index 8dedb17e0d..78d1e12cbf 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/echo/CustomContainerWebSocketsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/echo/CustomContainerWebSocketsApplicationTests.java @@ -34,10 +34,10 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory; +import org.springframework.boot.web.servlet.server.ServletWebServerFactory; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -95,8 +95,8 @@ public class CustomContainerWebSocketsApplicationTests { protected static class CustomContainerConfiguration { @Bean - public EmbeddedServletContainerFactory embeddedServletContainerFactory() { - return new UndertowEmbeddedServletContainerFactory("/ws", PORT); + public ServletWebServerFactory webServerFactory() { + return new UndertowServletWebServerFactory("/ws", PORT); } } diff --git a/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootContextLoader.java b/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootContextLoader.java index 6847c5162e..61ac10f6b0 100644 --- a/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootContextLoader.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootContextLoader.java @@ -28,9 +28,9 @@ import org.springframework.beans.BeanUtils; import org.springframework.boot.SpringApplication; import org.springframework.boot.WebApplicationType; import org.springframework.boot.bind.RelaxedPropertyResolver; -import org.springframework.boot.context.GenericReactiveWebApplicationContext; import org.springframework.boot.test.mock.web.SpringBootMockServletContext; import org.springframework.boot.test.util.EnvironmentTestUtils; +import org.springframework.boot.web.reactive.context.GenericReactiveWebApplicationContext; import org.springframework.boot.web.support.ServletContextApplicationContextInitializer; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextInitializer; @@ -66,8 +66,8 @@ import org.springframework.web.context.support.GenericWebApplicationContext; *

* The loader supports both standard {@link MergedContextConfiguration} as well as * {@link WebMergedContextConfiguration}. If {@link WebMergedContextConfiguration} is used - * the context will either use a mock servlet environment, or start the full embedded - * servlet container. + * the context will either use a mock servlet environment, or start the full embedded web + * server. *

* If {@code @ActiveProfiles} are provided in the test class they will be used to create * the application context. diff --git a/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootTest.java b/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootTest.java index a587b46803..a3198fb6f3 100644 --- a/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootTest.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootTest.java @@ -26,9 +26,9 @@ import java.lang.annotation.Target; import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.WebApplicationType; -import org.springframework.boot.context.ReactiveWebApplicationContext; -import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext; -import org.springframework.boot.context.embedded.LocalServerPort; +import org.springframework.boot.web.reactive.context.ReactiveWebApplicationContext; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Configuration; import org.springframework.core.annotation.AliasFor; @@ -53,11 +53,11 @@ import org.springframework.web.context.WebApplicationContext; *

  • Allows custom {@link Environment} properties to be defined using the * {@link #properties() properties attribute}.
  • *
  • Provides support for different {@link #webEnvironment() webEnvironment} modes, - * including the ability to start a fully running container listening on a + * including the ability to start a fully running web server listening on a * {@link WebEnvironment#DEFINED_PORT defined} or {@link WebEnvironment#RANDOM_PORT * random} port.
  • *
  • Registers a {@link org.springframework.boot.test.web.client.TestRestTemplate - * TestRestTemplate} bean for use in web tests that are using a fully running container. + * TestRestTemplate} bean for use in web tests that are using a fully running web server. *
  • * * @@ -149,8 +149,8 @@ public @interface SpringBootTest { } /** - * Return if the environment uses an {@link EmbeddedWebApplicationContext}. - * @return if an {@link EmbeddedWebApplicationContext} is used. + * Return if the environment uses an {@link ServletWebServerApplicationContext}. + * @return if an {@link ServletWebServerApplicationContext} is used. */ public boolean isEmbedded() { return this.embedded; diff --git a/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootTestContextCustomizer.java b/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootTestContextCustomizer.java index c7517d0c0e..54b51ca2fb 100644 --- a/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootTestContextCustomizer.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootTestContextCustomizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -22,11 +22,11 @@ import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.RootBeanDefinition; -import org.springframework.boot.context.embedded.AbstractConfigurableEmbeddedServletContainer; import org.springframework.boot.test.web.client.LocalHostUriTemplateHandler; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.boot.test.web.client.TestRestTemplate.HttpClientOption; import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.boot.web.servlet.server.AbstractConfigurableServletWebServerFactory; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.context.ConfigurableApplicationContext; @@ -106,9 +106,10 @@ class SpringBootTestContextCustomizer implements ContextCustomizer { private boolean isSslEnabled(ApplicationContext context) { try { - AbstractConfigurableEmbeddedServletContainer container = context - .getBean(AbstractConfigurableEmbeddedServletContainer.class); - return container.getSsl() != null && container.getSsl().isEnabled(); + AbstractConfigurableServletWebServerFactory webServerFactory = context + .getBean(AbstractConfigurableServletWebServerFactory.class); + return webServerFactory.getSsl() != null + && webServerFactory.getSsl().isEnabled(); } catch (NoSuchBeanDefinitionException ex) { return false; diff --git a/spring-boot-test/src/main/java/org/springframework/boot/test/web/reactive/WebTestClientContextCustomizer.java b/spring-boot-test/src/main/java/org/springframework/boot/test/web/reactive/WebTestClientContextCustomizer.java index 24bf10098c..24b49467d1 100644 --- a/spring-boot-test/src/main/java/org/springframework/boot/test/web/reactive/WebTestClientContextCustomizer.java +++ b/spring-boot-test/src/main/java/org/springframework/boot/test/web/reactive/WebTestClientContextCustomizer.java @@ -22,8 +22,8 @@ import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.RootBeanDefinition; -import org.springframework.boot.context.embedded.AbstractConfigurableReactiveWebServer; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.web.reactive.server.AbstractConfigurableReactiveWebServerFactory; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.context.ConfigurableApplicationContext; @@ -120,9 +120,9 @@ class WebTestClientContextCustomizer implements ContextCustomizer { private boolean isSslEnabled(ApplicationContext context) { try { - AbstractConfigurableReactiveWebServer container = context - .getBean(AbstractConfigurableReactiveWebServer.class); - return container.getSsl() != null && container.getSsl().isEnabled(); + AbstractConfigurableReactiveWebServerFactory webServerFactory = context + .getBean(AbstractConfigurableReactiveWebServerFactory.class); + return webServerFactory.getSsl() != null && webServerFactory.getSsl().isEnabled(); } catch (NoSuchBeanDefinitionException ex) { return false; diff --git a/spring-boot-test/src/test/java/org/springframework/boot/test/context/AbstractSpringBootTestEmbeddedReactiveWebEnvironmentTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/context/AbstractSpringBootTestEmbeddedReactiveWebEnvironmentTests.java index 75324b58af..ea52027e62 100644 --- a/spring-boot-test/src/test/java/org/springframework/boot/test/context/AbstractSpringBootTestEmbeddedReactiveWebEnvironmentTests.java +++ b/spring-boot-test/src/test/java/org/springframework/boot/test/context/AbstractSpringBootTestEmbeddedReactiveWebEnvironmentTests.java @@ -21,10 +21,10 @@ import reactor.core.publisher.Mono; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.context.ReactiveWebApplicationContext; -import org.springframework.boot.context.embedded.LocalServerPort; -import org.springframework.boot.context.embedded.ReactiveWebServerFactory; -import org.springframework.boot.context.embedded.tomcat.TomcatReactiveWebServerFactory; +import org.springframework.boot.web.embedded.tomcat.TomcatReactiveWebServerFactory; +import org.springframework.boot.web.reactive.context.ReactiveWebApplicationContext; +import org.springframework.boot.web.reactive.server.ReactiveWebServerFactory; +import org.springframework.boot.web.server.LocalServerPort; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; @@ -89,7 +89,7 @@ public abstract class AbstractSpringBootTestEmbeddedReactiveWebEnvironmentTests } @Bean - public ReactiveWebServerFactory embeddedReactiveContainer() { + public ReactiveWebServerFactory webServerFactory() { TomcatReactiveWebServerFactory factory = new TomcatReactiveWebServerFactory(); factory.setPort(this.port); return factory; diff --git a/spring-boot-test/src/test/java/org/springframework/boot/test/context/AbstractSpringBootTestEmbeddedServletWebEnvironmentTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/context/AbstractSpringBootTestWebServerWebEnvironmentTests.java similarity index 85% rename from spring-boot-test/src/test/java/org/springframework/boot/test/context/AbstractSpringBootTestEmbeddedServletWebEnvironmentTests.java rename to spring-boot-test/src/test/java/org/springframework/boot/test/context/AbstractSpringBootTestWebServerWebEnvironmentTests.java index 1b9d881cd4..11f95f7bd2 100644 --- a/spring-boot-test/src/test/java/org/springframework/boot/test/context/AbstractSpringBootTestEmbeddedServletWebEnvironmentTests.java +++ b/spring-boot-test/src/test/java/org/springframework/boot/test/context/AbstractSpringBootTestWebServerWebEnvironmentTests.java @@ -22,10 +22,10 @@ import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.LocalServerPort; -import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +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.web.bind.annotation.RequestMapping; @@ -37,13 +37,12 @@ import org.springframework.web.servlet.DispatcherServlet; import static org.assertj.core.api.Assertions.assertThat; /** - * Base class for {@link SpringBootTest} tests configured to start an embedded servlet - * container. + * Base class for {@link SpringBootTest} tests configured to start an embedded web server. * * @author Phillip Webb * @author Andy Wilkinson */ -public abstract class AbstractSpringBootTestEmbeddedServletWebEnvironmentTests { +public abstract class AbstractSpringBootTestWebServerWebEnvironmentTests { @LocalServerPort private int port = 0; @@ -104,8 +103,8 @@ public abstract class AbstractSpringBootTestEmbeddedServletWebEnvironmentTests { } @Bean - public EmbeddedServletContainerFactory embeddedServletContainer() { - TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory(); + public ServletWebServerFactory webServerFactory() { + TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(); factory.setPort(this.port); return factory; } diff --git a/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringBootTestTestRestTemplateDefinedByUser.java b/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringBootTestTestRestTemplateDefinedByUser.java index a1d53f849e..59151964b0 100644 --- a/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringBootTestTestRestTemplateDefinedByUser.java +++ b/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringBootTestTestRestTemplateDefinedByUser.java @@ -40,7 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat; @DirtiesContext @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "value=123" }) public class SpringBootTestTestRestTemplateDefinedByUser - extends AbstractSpringBootTestEmbeddedServletWebEnvironmentTests { + extends AbstractSpringBootTestWebServerWebEnvironmentTests { @Test public void restTemplateIsUserDefined() throws Exception { diff --git a/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringBootTestWebEnvironmentDefinedPortTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringBootTestWebEnvironmentDefinedPortTests.java index 0581ff3062..3f90c76951 100644 --- a/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringBootTestWebEnvironmentDefinedPortTests.java +++ b/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringBootTestWebEnvironmentDefinedPortTests.java @@ -36,7 +36,7 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc; @SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT, properties = { "server.port=0", "value=123" }) public class SpringBootTestWebEnvironmentDefinedPortTests - extends AbstractSpringBootTestEmbeddedServletWebEnvironmentTests { + extends AbstractSpringBootTestWebServerWebEnvironmentTests { @Configuration @EnableWebMvc diff --git a/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringBootTestWebEnvironmentRandomPortCustomPortTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringBootTestWebEnvironmentRandomPortCustomPortTests.java index bffe5b7965..397f159cac 100644 --- a/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringBootTestWebEnvironmentRandomPortCustomPortTests.java +++ b/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringBootTestWebEnvironmentRandomPortCustomPortTests.java @@ -20,7 +20,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.AbstractSpringBootTestEmbeddedServletWebEnvironmentTests.AbstractConfig; +import org.springframework.boot.test.context.AbstractSpringBootTestWebServerWebEnvironmentTests.AbstractConfig; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; diff --git a/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringBootTestWebEnvironmentRandomPortTests.java b/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringBootTestWebEnvironmentRandomPortTests.java index 8df6e065b9..3180007aa5 100644 --- a/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringBootTestWebEnvironmentRandomPortTests.java +++ b/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringBootTestWebEnvironmentRandomPortTests.java @@ -41,7 +41,7 @@ import static org.assertj.core.api.Assertions.assertThat; @DirtiesContext @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "value=123" }) public class SpringBootTestWebEnvironmentRandomPortTests - extends AbstractSpringBootTestEmbeddedServletWebEnvironmentTests { + extends AbstractSpringBootTestWebServerWebEnvironmentTests { @Test public void testRestTemplateShouldUseBuilder() throws Exception { diff --git a/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java b/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java index f0e45d26aa..d9ad22f5a4 100644 --- a/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java +++ b/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java @@ -171,8 +171,8 @@ public class SpringApplication { * The class name of application context that will be used by default for web * environments. */ - public static final String DEFAULT_WEB_CONTEXT_CLASS = "org.springframework." - + "boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext"; + public static final String DEFAULT_WEB_CONTEXT_CLASS = "org.springframework.boot." + + "web.servlet.context.AnnotationConfigServletWebServerApplicationContext"; private static final String[] WEB_ENVIRONMENT_CLASSES = { "javax.servlet.Servlet", "org.springframework.web.context.ConfigurableWebApplicationContext" }; @@ -182,7 +182,7 @@ public class SpringApplication { * environments. */ public static final String DEFAULT_REACTIVE_WEB_CONTEXT_CLASS = "org.springframework." - + "boot.context.embedded.EmbeddedReactiveWebApplicationContext"; + + "boot.web.reactive.context.ReactiveWebServerApplicationContext"; private static final String REACTIVE_WEB_ENVIRONMENT_CLASS = "org.springframework." + "web.reactive.DispatcherHandler"; diff --git a/spring-boot/src/main/java/org/springframework/boot/WebApplicationType.java b/spring-boot/src/main/java/org/springframework/boot/WebApplicationType.java index d1ee12f9aa..63e55d01fc 100644 --- a/spring-boot/src/main/java/org/springframework/boot/WebApplicationType.java +++ b/spring-boot/src/main/java/org/springframework/boot/WebApplicationType.java @@ -27,19 +27,19 @@ public enum WebApplicationType { /** * The application should not run as a web application and should not start an - * embedded web container. + * embedded web server. */ NONE, /** * The application should run as a servlet-based web application and should start an - * embedded servlet container. + * embedded servlet web server. */ SERVLET, /** * The application should run as a reactive web application and should start an - * embedded web container. + * embedded reactive web server. */ REACTIVE; diff --git a/spring-boot/src/main/java/org/springframework/boot/admin/SpringApplicationAdminMXBeanRegistrar.java b/spring-boot/src/main/java/org/springframework/boot/admin/SpringApplicationAdminMXBeanRegistrar.java index cc9caafdf2..b0972c2ef5 100644 --- a/spring-boot/src/main/java/org/springframework/boot/admin/SpringApplicationAdminMXBeanRegistrar.java +++ b/spring-boot/src/main/java/org/springframework/boot/admin/SpringApplicationAdminMXBeanRegistrar.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -28,8 +28,8 @@ import org.apache.commons.logging.LogFactory; import org.springframework.beans.BeansException; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; -import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext; import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationListener; @@ -111,7 +111,7 @@ public class SpringApplicationAdminMXBeanRegistrar @Override public boolean isEmbeddedWebApplication() { return (SpringApplicationAdminMXBeanRegistrar.this.applicationContext != null - && SpringApplicationAdminMXBeanRegistrar.this.applicationContext instanceof EmbeddedWebApplicationContext); + && SpringApplicationAdminMXBeanRegistrar.this.applicationContext instanceof ServletWebServerApplicationContext); } @Override diff --git a/spring-boot/src/main/java/org/springframework/boot/builder/SpringApplicationBuilder.java b/spring-boot/src/main/java/org/springframework/boot/builder/SpringApplicationBuilder.java index bc189681c4..e31086c81d 100644 --- a/spring-boot/src/main/java/org/springframework/boot/builder/SpringApplicationBuilder.java +++ b/spring-boot/src/main/java/org/springframework/boot/builder/SpringApplicationBuilder.java @@ -184,7 +184,7 @@ public class SpringApplicationBuilder { .additionalProfiles(this.additionalProfiles); child.parent = this; - // It's not possible if embedded containers are enabled to support web contexts as + // It's not possible if embedded web server are enabled to support web contexts as // parents because the servlets cannot be initialized at the right point in // lifecycle. web(false); diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/EmbeddedServletContainerFactory.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/EmbeddedServletContainerFactory.java deleted file mode 100644 index 57ff7ee5d8..0000000000 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/EmbeddedServletContainerFactory.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2012-2017 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; - -import org.apache.catalina.core.ApplicationContext; - -import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; -import org.springframework.boot.web.servlet.ServletContextInitializer; - -/** - * Factory interface that can be used to create {@link EmbeddedWebServer}s. - * Implementations are encouraged to extend - * {@link AbstractEmbeddedServletContainerFactory} when possible. - * - * @author Phillip Webb - * @see EmbeddedWebServer - * @see AbstractEmbeddedServletContainerFactory - * @see JettyEmbeddedServletContainerFactory - * @see TomcatEmbeddedServletContainerFactory - */ -@FunctionalInterface -public interface EmbeddedServletContainerFactory { - - /** - * Gets a new fully configured but paused {@link EmbeddedWebServer} instance. Clients - * should not be able to connect to the returned server until - * {@link EmbeddedWebServer#start()} is called (which happens when the - * {@link ApplicationContext} has been fully refreshed). - * @param initializers {@link ServletContextInitializer}s that should be applied as - * the container starts - * @return a fully configured and started {@link EmbeddedWebServer} - * @see EmbeddedWebServer#stop() - */ - EmbeddedWebServer getEmbeddedServletContainer( - ServletContextInitializer... initializers); - -} diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/EmbeddedWebServer.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/EmbeddedWebServer.java deleted file mode 100644 index d5c35b3784..0000000000 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/EmbeddedWebServer.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2012-2017 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; - -/** - * Simple interface that represents a fully configured embedded web server (for example - * Tomcat or Jetty). Allows the server to be {@link #start() started} and {@link #stop() - * stopped}. - *

    - * Instances of this class are usually obtained via a - * {@link EmbeddedServletContainerFactory}. - * - * @author Phillip Webb - * @author Dave Syer - * @see EmbeddedServletContainerFactory - */ -public interface EmbeddedWebServer { - - /** - * Starts the embedded web server. Calling this method on an already started container - * has no effect. - * @throws EmbeddedWebServerException if the container cannot be started - */ - void start() throws EmbeddedWebServerException; - - /** - * Stops the embedded web server. Calling this method on an already stopped container - * has no effect. - * @throws EmbeddedWebServerException if the container cannot be stopped - */ - void stop() throws EmbeddedWebServerException; - - /** - * Return the port this server is listening on. - * @return the port (or -1 if none) - */ - int getPort(); - -} diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/Servlet.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/Servlet.java deleted file mode 100644 index adf56f85f3..0000000000 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/Servlet.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright 2012-2017 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; - -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import org.springframework.boot.context.properties.NestedConfigurationProperty; -import org.springframework.util.Assert; -import org.springframework.util.StringUtils; - -/** - * Configuration for Servlet containers. - * - * @author Brian Clozel - * @since 2.0.0 - */ -public class Servlet { - - /** - * ServletContext parameters. - */ - private final Map contextParameters = new HashMap<>(); - - /** - * Context path of the application. - */ - private String contextPath; - - /** - * Path of the main dispatcher servlet. - */ - private String path = "/"; - - @NestedConfigurationProperty - private Jsp jsp = new Jsp(); - - public String getContextPath() { - return this.contextPath; - } - - public void setContextPath(String contextPath) { - this.contextPath = cleanContextPath(contextPath); - } - - private String cleanContextPath(String contextPath) { - if (StringUtils.hasText(contextPath) && contextPath.endsWith("/")) { - return contextPath.substring(0, contextPath.length() - 1); - } - return contextPath; - } - - public String getPath() { - return this.path; - } - - public void setPath(String path) { - Assert.notNull(path, "Path must not be null"); - this.path = path; - } - - public Map getContextParameters() { - return this.contextParameters; - } - - public Jsp getJsp() { - return this.jsp; - } - - public void setJsp(Jsp jsp) { - this.jsp = jsp; - } - - public String getServletMapping() { - if (this.path.equals("") || this.path.equals("/")) { - return "/"; - } - if (this.path.contains("*")) { - return this.path; - } - if (this.path.endsWith("/")) { - return this.path + "*"; - } - return this.path + "/*"; - } - - public String getPath(String path) { - String prefix = getServletPrefix(); - if (!path.startsWith("/")) { - path = "/" + path; - } - return prefix + path; - } - - public String getServletPrefix() { - String result = this.path; - if (result.contains("*")) { - result = result.substring(0, result.indexOf("*")); - } - if (result.endsWith("/")) { - result = result.substring(0, result.length() - 1); - } - return result; - } - - public String[] getPathsArray(Collection paths) { - String[] result = new String[paths.size()]; - int i = 0; - for (String path : paths) { - result[i++] = getPath(path); - } - return result; - } - - public String[] getPathsArray(String[] paths) { - String[] result = new String[paths.length]; - int i = 0; - for (String path : paths) { - result[i++] = getPath(path); - } - return result; - } - -} diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedServletContainer.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedServletContainer.java deleted file mode 100644 index 3984bbadb5..0000000000 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedServletContainer.java +++ /dev/null @@ -1,240 +0,0 @@ -/* - * Copyright 2012-2017 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.jetty; - -import java.net.BindException; -import java.util.List; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.eclipse.jetty.server.Connector; -import org.eclipse.jetty.server.Handler; -import org.eclipse.jetty.server.NetworkConnector; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.handler.HandlerCollection; -import org.eclipse.jetty.server.handler.HandlerWrapper; - -import org.springframework.boot.context.embedded.EmbeddedWebServer; -import org.springframework.boot.context.embedded.EmbeddedWebServerException; -import org.springframework.boot.context.embedded.PortInUseException; -import org.springframework.util.Assert; -import org.springframework.util.ReflectionUtils; -import org.springframework.util.StringUtils; - -/** - * {@link EmbeddedWebServer} that can be used to control an embedded Jetty server. Usually - * this class should be created using the {@link JettyEmbeddedServletContainerFactory} and - * not directly. - * - * @author Phillip Webb - * @author Dave Syer - * @author David Liu - * @author Eddú Meléndez - * @see JettyEmbeddedServletContainerFactory - */ -public class JettyEmbeddedServletContainer implements EmbeddedWebServer { - - private static final Log logger = LogFactory - .getLog(JettyEmbeddedServletContainer.class); - - private final Object monitor = new Object(); - - private final Server server; - - private final boolean autoStart; - - private Connector[] connectors; - - private volatile boolean started; - - /** - * Create a new {@link JettyEmbeddedServletContainer} instance. - * @param server the underlying Jetty server - */ - public JettyEmbeddedServletContainer(Server server) { - this(server, true); - } - - /** - * Create a new {@link JettyEmbeddedServletContainer} instance. - * @param server the underlying Jetty server - * @param autoStart if auto-starting the container - */ - public JettyEmbeddedServletContainer(Server server, boolean autoStart) { - this.autoStart = autoStart; - Assert.notNull(server, "Jetty Server must not be null"); - this.server = server; - initialize(); - } - - private void initialize() { - synchronized (this.monitor) { - try { - // Cache and clear the connectors to prevent requests being handled before - // the application context is ready - this.connectors = this.server.getConnectors(); - this.server.setConnectors(null); - - // Start the server so that the ServletContext is available - this.server.start(); - this.server.setStopAtShutdown(false); - } - catch (Exception ex) { - // Ensure process isn't left running - stopSilently(); - throw new EmbeddedWebServerException( - "Unable to start embedded Jetty servlet container", ex); - } - } - } - - private void stopSilently() { - try { - this.server.stop(); - } - catch (Exception ex) { - // Ignore - } - } - - @Override - public void start() throws EmbeddedWebServerException { - synchronized (this.monitor) { - if (this.started) { - return; - } - this.server.setConnectors(this.connectors); - if (!this.autoStart) { - return; - } - try { - this.server.start(); - for (Handler handler : this.server.getHandlers()) { - handleDeferredInitialize(handler); - } - Connector[] connectors = this.server.getConnectors(); - for (Connector connector : connectors) { - try { - connector.start(); - } - catch (BindException ex) { - if (connector instanceof NetworkConnector) { - throw new PortInUseException( - ((NetworkConnector) connector).getPort()); - } - throw ex; - } - } - this.started = true; - JettyEmbeddedServletContainer.logger - .info("Jetty started on port(s) " + getActualPortsDescription()); - } - catch (EmbeddedWebServerException ex) { - throw ex; - } - catch (Exception ex) { - throw new EmbeddedWebServerException( - "Unable to start embedded Jetty servlet container", ex); - } - } - } - - private String getActualPortsDescription() { - StringBuilder ports = new StringBuilder(); - for (Connector connector : this.server.getConnectors()) { - ports.append(ports.length() == 0 ? "" : ", "); - ports.append(getLocalPort(connector) + getProtocols(connector)); - } - return ports.toString(); - } - - private Integer getLocalPort(Connector connector) { - try { - // Jetty 9 internals are different, but the method name is the same - return (Integer) ReflectionUtils.invokeMethod( - ReflectionUtils.findMethod(connector.getClass(), "getLocalPort"), - connector); - } - catch (Exception ex) { - JettyEmbeddedServletContainer.logger - .info("could not determine port ( " + ex.getMessage() + ")"); - return 0; - } - } - - private String getProtocols(Connector connector) { - try { - List protocols = connector.getProtocols(); - return " (" + StringUtils.collectionToDelimitedString(protocols, ", ") + ")"; - } - catch (NoSuchMethodError ex) { - // Not available with Jetty 8 - return ""; - } - - } - - private void handleDeferredInitialize(Handler... handlers) throws Exception { - for (Handler handler : handlers) { - if (handler instanceof JettyEmbeddedWebAppContext) { - ((JettyEmbeddedWebAppContext) handler).deferredInitialize(); - } - else if (handler instanceof HandlerWrapper) { - handleDeferredInitialize(((HandlerWrapper) handler).getHandler()); - } - else if (handler instanceof HandlerCollection) { - handleDeferredInitialize(((HandlerCollection) handler).getHandlers()); - } - } - } - - @Override - public void stop() { - synchronized (this.monitor) { - this.started = false; - try { - this.server.stop(); - } - catch (InterruptedException ex) { - Thread.currentThread().interrupt(); - } - catch (Exception ex) { - throw new EmbeddedWebServerException( - "Unable to stop embedded Jetty servlet container", ex); - } - } - } - - @Override - public int getPort() { - Connector[] connectors = this.server.getConnectors(); - for (Connector connector : connectors) { - // Probably only one... - return getLocalPort(connector); - } - return 0; - } - - /** - * Returns access to the underlying Jetty Server. - * @return the Jetty server - */ - public Server getServer() { - return this.server; - } - -} diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/package-info.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/package-info.java deleted file mode 100644 index 541c5801ae..0000000000 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/package-info.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2012-2016 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. - */ - -/** - * Specialized {@link org.springframework.context.ApplicationContext} that supports - * embedded servlet containers. - * - * @see org.springframework.boot.context.embedded.EmbeddedServletContainerFactory - * @see org.springframework.boot.context.embedded.EmbeddedWebApplicationContext - */ -package org.springframework.boot.context.embedded; diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainer.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainer.java deleted file mode 100644 index 0cd8be5c1e..0000000000 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainer.java +++ /dev/null @@ -1,338 +0,0 @@ -/* - * Copyright 2012-2017 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.util.HashMap; -import java.util.Map; -import java.util.concurrent.atomic.AtomicInteger; - -import javax.naming.NamingException; - -import org.apache.catalina.Container; -import org.apache.catalina.Context; -import org.apache.catalina.Engine; -import org.apache.catalina.LifecycleException; -import org.apache.catalina.LifecycleState; -import org.apache.catalina.Service; -import org.apache.catalina.connector.Connector; -import org.apache.catalina.startup.Tomcat; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.naming.ContextBindings; - -import org.springframework.boot.context.embedded.EmbeddedWebServer; -import org.springframework.boot.context.embedded.EmbeddedWebServerException; -import org.springframework.util.Assert; - -/** - * {@link EmbeddedWebServer} that can be used to control an embedded Tomcat server. - * Usually this class should be created using the - * {@link TomcatEmbeddedServletContainerFactory} and not directly. - * - * @author Phillip Webb - * @author Dave Syer - * @see TomcatEmbeddedServletContainerFactory - */ -public class TomcatEmbeddedServletContainer implements EmbeddedWebServer { - - private static final Log logger = LogFactory - .getLog(TomcatEmbeddedServletContainer.class); - - private static final AtomicInteger containerCounter = new AtomicInteger(-1); - - private final Object monitor = new Object(); - - private final Map serviceConnectors = new HashMap<>(); - - private final Tomcat tomcat; - - private final boolean autoStart; - - private volatile boolean started; - - /** - * Create a new {@link TomcatEmbeddedServletContainer} instance. - * @param tomcat the underlying Tomcat server - */ - public TomcatEmbeddedServletContainer(Tomcat tomcat) { - this(tomcat, true); - } - - /** - * Create a new {@link TomcatEmbeddedServletContainer} instance. - * @param tomcat the underlying Tomcat server - * @param autoStart if the server should be started - */ - public TomcatEmbeddedServletContainer(Tomcat tomcat, boolean autoStart) { - Assert.notNull(tomcat, "Tomcat Server must not be null"); - this.tomcat = tomcat; - this.autoStart = autoStart; - initialize(); - } - - private void initialize() throws EmbeddedWebServerException { - TomcatEmbeddedServletContainer.logger - .info("Tomcat initialized with port(s): " + getPortsDescription(false)); - synchronized (this.monitor) { - try { - addInstanceIdToEngineName(); - try { - // Remove service connectors to that protocol binding doesn't happen - // yet - removeServiceConnectors(); - - // Start the server to trigger initialization listeners - this.tomcat.start(); - - // We can re-throw failure exception directly in the main thread - rethrowDeferredStartupExceptions(); - - Context context = findContext(); - try { - ContextBindings.bindClassLoader(context, context.getNamingToken(), - getClass().getClassLoader()); - } - catch (NamingException ex) { - // Naming is not enabled. Continue - } - - // Unlike Jetty, all Tomcat threads are daemon threads. We create a - // blocking non-daemon to stop immediate shutdown - startDaemonAwaitThread(); - } - catch (Exception ex) { - containerCounter.decrementAndGet(); - throw ex; - } - } - catch (Exception ex) { - throw new EmbeddedWebServerException("Unable to start embedded Tomcat", - ex); - } - } - } - - private Context findContext() { - for (Container child : this.tomcat.getHost().findChildren()) { - if (child instanceof Context) { - return (Context) child; - } - } - throw new IllegalStateException("The host does not contain a Context"); - } - - private void addInstanceIdToEngineName() { - int instanceId = containerCounter.incrementAndGet(); - if (instanceId > 0) { - Engine engine = this.tomcat.getEngine(); - engine.setName(engine.getName() + "-" + instanceId); - } - } - - private void removeServiceConnectors() { - for (Service service : this.tomcat.getServer().findServices()) { - Connector[] connectors = service.findConnectors().clone(); - this.serviceConnectors.put(service, connectors); - for (Connector connector : connectors) { - service.removeConnector(connector); - } - } - } - - private void rethrowDeferredStartupExceptions() throws Exception { - Container[] children = this.tomcat.getHost().findChildren(); - for (Container container : children) { - if (container instanceof TomcatEmbeddedContext) { - Exception exception = ((TomcatEmbeddedContext) container).getStarter() - .getStartUpException(); - if (exception != null) { - throw exception; - } - } - } - } - - private void startDaemonAwaitThread() { - Thread awaitThread = new Thread("container-" + (containerCounter.get())) { - - @Override - public void run() { - TomcatEmbeddedServletContainer.this.tomcat.getServer().await(); - } - - }; - awaitThread.setContextClassLoader(getClass().getClassLoader()); - awaitThread.setDaemon(false); - awaitThread.start(); - } - - @Override - public void start() throws EmbeddedWebServerException { - synchronized (this.monitor) { - if (this.started) { - return; - } - try { - addPreviouslyRemovedConnectors(); - Connector connector = this.tomcat.getConnector(); - if (connector != null && this.autoStart) { - startConnector(connector); - } - checkThatConnectorsHaveStarted(); - this.started = true; - TomcatEmbeddedServletContainer.logger - .info("Tomcat started on port(s): " + getPortsDescription(true)); - } - catch (ConnectorStartFailedException ex) { - stopSilently(); - throw ex; - } - catch (Exception ex) { - throw new EmbeddedWebServerException( - "Unable to start embedded Tomcat servlet container", ex); - } - finally { - Context context = findContext(); - ContextBindings.unbindClassLoader(context, context.getNamingToken(), - getClass().getClassLoader()); - } - } - } - - private void checkThatConnectorsHaveStarted() { - for (Connector connector : this.tomcat.getService().findConnectors()) { - if (LifecycleState.FAILED.equals(connector.getState())) { - throw new ConnectorStartFailedException(connector.getPort()); - } - } - } - - private void stopSilently() { - try { - stopTomcat(); - } - catch (LifecycleException ex) { - // Ignore - } - } - - private void stopTomcat() throws LifecycleException { - if (Thread.currentThread() - .getContextClassLoader() instanceof TomcatEmbeddedWebappClassLoader) { - Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); - } - this.tomcat.stop(); - } - - private void addPreviouslyRemovedConnectors() { - Service[] services = this.tomcat.getServer().findServices(); - for (Service service : services) { - Connector[] connectors = this.serviceConnectors.get(service); - if (connectors != null) { - for (Connector connector : connectors) { - service.addConnector(connector); - if (!this.autoStart) { - stopProtocolHandler(connector); - } - } - this.serviceConnectors.remove(service); - } - } - } - - private void stopProtocolHandler(Connector connector) { - try { - connector.getProtocolHandler().stop(); - } - catch (Exception ex) { - TomcatEmbeddedServletContainer.logger.error("Cannot pause connector: ", ex); - } - } - - private void startConnector(Connector connector) { - try { - for (Container child : this.tomcat.getHost().findChildren()) { - if (child instanceof TomcatEmbeddedContext) { - ((TomcatEmbeddedContext) child).deferredLoadOnStartup(); - } - } - } - catch (Exception ex) { - TomcatEmbeddedServletContainer.logger.error("Cannot start connector: ", ex); - throw new EmbeddedWebServerException( - "Unable to start embedded Tomcat connectors", ex); - } - } - - Map getServiceConnectors() { - return this.serviceConnectors; - } - - @Override - public void stop() throws EmbeddedWebServerException { - synchronized (this.monitor) { - boolean wasStarted = this.started; - try { - this.started = false; - try { - stopTomcat(); - this.tomcat.destroy(); - } - catch (LifecycleException ex) { - // swallow and continue - } - } - catch (Exception ex) { - throw new EmbeddedWebServerException("Unable to stop embedded Tomcat", - ex); - } - finally { - if (wasStarted) { - containerCounter.decrementAndGet(); - } - } - } - } - - private String getPortsDescription(boolean localPort) { - StringBuilder ports = new StringBuilder(); - for (Connector connector : this.tomcat.getService().findConnectors()) { - ports.append(ports.length() == 0 ? "" : " "); - int port = (localPort ? connector.getLocalPort() : connector.getPort()); - ports.append(port + " (" + connector.getScheme() + ")"); - } - return ports.toString(); - } - - @Override - public int getPort() { - Connector connector = this.tomcat.getConnector(); - if (connector != null) { - return connector.getLocalPort(); - } - return 0; - } - - /** - * Returns access to the underlying Tomcat server. - * @return the Tomcat server - */ - public Tomcat getTomcat() { - return this.tomcat; - } - -} diff --git a/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/ConnectorStartFailureAnalyzer.java b/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/ConnectorStartFailureAnalyzer.java index 18746bdf26..5a705c2fcf 100644 --- a/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/ConnectorStartFailureAnalyzer.java +++ b/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/ConnectorStartFailureAnalyzer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -16,9 +16,9 @@ package org.springframework.boot.diagnostics.analyzer; -import org.springframework.boot.context.embedded.tomcat.ConnectorStartFailedException; import org.springframework.boot.diagnostics.AbstractFailureAnalyzer; import org.springframework.boot.diagnostics.FailureAnalysis; +import org.springframework.boot.web.embedded.tomcat.ConnectorStartFailedException; /** * An {@link AbstractFailureAnalyzer} for {@link ConnectorStartFailedException}. diff --git a/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/PortInUseFailureAnalyzer.java b/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/PortInUseFailureAnalyzer.java index 15ac429c2a..2789a27dcc 100644 --- a/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/PortInUseFailureAnalyzer.java +++ b/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/PortInUseFailureAnalyzer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -16,9 +16,9 @@ package org.springframework.boot.diagnostics.analyzer; -import org.springframework.boot.context.embedded.PortInUseException; import org.springframework.boot.diagnostics.AbstractFailureAnalyzer; import org.springframework.boot.diagnostics.FailureAnalysis; +import org.springframework.boot.web.server.PortInUseException; /** * A {@code FailureAnalyzer} that performs analysis of failures caused by a @@ -31,7 +31,7 @@ class PortInUseFailureAnalyzer extends AbstractFailureAnalyzer { + implements ApplicationListener { private static final String DEFAULT_FILE_NAME = "application.port"; @@ -84,10 +84,10 @@ public class EmbeddedServerPortFileWriter } @Override - public void onApplicationEvent(EmbeddedServletContainerInitializedEvent event) { + public void onApplicationEvent(ServletWebServerInitializedEvent event) { File portFile = getPortFile(event.getApplicationContext()); try { - String port = String.valueOf(event.getEmbeddedWebServer().getPort()); + String port = String.valueOf(event.getWebServer().getPort()); createParentFolder(portFile); FileCopyUtils.copy(port.getBytes(), portFile); portFile.deleteOnExit(); @@ -104,7 +104,7 @@ public class EmbeddedServerPortFileWriter * @param applicationContext the source application context * @return the file that should be written */ - protected File getPortFile(EmbeddedWebApplicationContext applicationContext) { + protected File getPortFile(ServletWebServerApplicationContext applicationContext) { String contextName = applicationContext.getNamespace(); if (StringUtils.isEmpty(contextName)) { return this.file; diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/package-info.java b/spring-boot/src/main/java/org/springframework/boot/web/client/package-info.java similarity index 69% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/package-info.java rename to spring-boot/src/main/java/org/springframework/boot/web/client/package-info.java index 38f950d811..89bd54e23d 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/package-info.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/client/package-info.java @@ -15,9 +15,6 @@ */ /** - * Support for Tomcat {@link org.springframework.boot.context.embedded.EmbeddedWebServer - * EmbeddedServletContainers}. - * - * @see org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory + * Web client utilities. */ -package org.springframework.boot.context.embedded.tomcat; +package org.springframework.boot.web.client; diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/ServerPortInfoApplicationContextInitializer.java b/spring-boot/src/main/java/org/springframework/boot/web/context/ServerPortInfoApplicationContextInitializer.java similarity index 80% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/ServerPortInfoApplicationContextInitializer.java rename to spring-boot/src/main/java/org/springframework/boot/web/context/ServerPortInfoApplicationContextInitializer.java index 72e56fec74..ee13f5bddf 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/ServerPortInfoApplicationContextInitializer.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/context/ServerPortInfoApplicationContextInitializer.java @@ -14,12 +14,13 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded; +package org.springframework.boot.web.context; import java.util.HashMap; import java.util.Map; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.web.server.WebServer; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.ApplicationListener; @@ -32,20 +33,20 @@ import org.springframework.core.env.PropertySource; /** * {@link ApplicationContextInitializer} that sets {@link Environment} properties for the - * ports that {@link EmbeddedWebServer} servers are actually listening on. The property + * ports that {@link WebServer} servers are actually listening on. The property * {@literal "local.server.port"} can be injected directly into tests using * {@link Value @Value} or obtained via the {@link Environment}. *

    - * If the {@link EmbeddedWebApplicationContext} has a - * {@link EmbeddedWebApplicationContext#setNamespace(String) namespace} set, it will be - * used to construct the property name. For example, the "management" actuator context - * will have the property name {@literal "local.management.port"}. + * If the {@link WebServerInitializedEvent} has a + * {@link WebServerInitializedEvent#getServerId() server ID}, it will be used to construct + * the property name. For example, the "management" actuator context will have the + * property name {@literal "local.management.port"}. *

    * Properties are automatically propagated up to any parent context. * * @author Dave Syer * @author Phillip Webb - * @since 1.4.0 + * @since 2.0.0 */ public class ServerPortInfoApplicationContextInitializer implements ApplicationContextInitializer { @@ -53,11 +54,10 @@ public class ServerPortInfoApplicationContextInitializer @Override public void initialize(ConfigurableApplicationContext applicationContext) { applicationContext.addApplicationListener( - new ApplicationListener() { + new ApplicationListener() { @Override - public void onApplicationEvent( - EmbeddedWebServerInitializedEvent event) { + public void onApplicationEvent(WebServerInitializedEvent event) { ServerPortInfoApplicationContextInitializer.this .onApplicationEvent(event); } @@ -65,10 +65,10 @@ public class ServerPortInfoApplicationContextInitializer }); } - protected void onApplicationEvent(EmbeddedWebServerInitializedEvent event) { + protected void onApplicationEvent(WebServerInitializedEvent event) { String propertyName = "local." + event.getServerId() + ".port"; setPortProperty(event.getApplicationContext(), propertyName, - event.getEmbeddedWebServer().getPort()); + event.getWebServer().getPort()); } private void setPortProperty(ApplicationContext context, String propertyName, diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/EmbeddedWebServerInitializedEvent.java b/spring-boot/src/main/java/org/springframework/boot/web/context/WebServerInitializedEvent.java similarity index 57% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/EmbeddedWebServerInitializedEvent.java rename to spring-boot/src/main/java/org/springframework/boot/web/context/WebServerInitializedEvent.java index 348d5a610b..45fcfd6b5d 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/EmbeddedWebServerInitializedEvent.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/context/WebServerInitializedEvent.java @@ -14,57 +14,55 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded; +package org.springframework.boot.web.context; +import org.springframework.boot.web.server.WebServer; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationEvent; /** * Event to be published after the application context is refreshed and the - * {@link EmbeddedWebServer} is ready. Useful for obtaining the local port of a running - * server. + * {@link WebServer} is ready. Useful for obtaining the local port of a running server. * * @author Brian Clozel * @author Stephane Nicoll * @since 2.0.0 - * @see EmbeddedServletContainerInitializedEvent - * @see EmbeddedReactiveWebServerInitializedEvent */ @SuppressWarnings("serial") -public abstract class EmbeddedWebServerInitializedEvent extends ApplicationEvent { +public abstract class WebServerInitializedEvent extends ApplicationEvent { - protected EmbeddedWebServerInitializedEvent(EmbeddedWebServer source) { + protected WebServerInitializedEvent(WebServer source) { super(source); } /** - * Access the {@link EmbeddedWebServer}. + * Access the {@link WebServer}. * @return the embedded web server */ - public EmbeddedWebServer getEmbeddedWebServer() { + public WebServer getWebServer() { return getSource(); } /** - * Access the application context that the container was created in. Sometimes it is + * Access the application context that the server was created in. Sometimes it is * prudent to check that this matches expectations (like being equal to the current - * context) before acting on the server container itself. - * @return the applicationContext that the container was created from + * context) before acting on the server itself. + * @return the applicationContext that the server was created from */ public abstract ApplicationContext getApplicationContext(); /** - * Access the source of the event (an {@link EmbeddedWebServer}). + * Access the source of the event (an {@link WebServer}). * @return the embedded web server */ @Override - public EmbeddedWebServer getSource() { - return (EmbeddedWebServer) super.getSource(); + public WebServer getSource() { + return (WebServer) super.getSource(); } /** - * Access the {@link EmbeddedWebServer} Id used internally to differentiate - * application / management servers. + * Access the {@link WebServer} Id used internally to differentiate application / + * management servers. * @return the server internal Id */ public abstract String getServerId(); diff --git a/spring-boot/src/main/java/org/springframework/boot/web/context/package-info.java b/spring-boot/src/main/java/org/springframework/boot/web/context/package-info.java new file mode 100644 index 0000000000..0e16085d03 --- /dev/null +++ b/spring-boot/src/main/java/org/springframework/boot/web/context/package-info.java @@ -0,0 +1,21 @@ +/* + * Copyright 2012-2017 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. + */ + +/** + * Web integrations with Spring's {@link org.springframework.context.ApplicationContext + * ApplicationContext}. + */ +package org.springframework.boot.web.context; diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JasperInitializer.java b/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JasperInitializer.java similarity index 97% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JasperInitializer.java rename to spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JasperInitializer.java index 57847b15b6..ffab66fe00 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JasperInitializer.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JasperInitializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded.jetty; +package org.springframework.boot.web.embedded.jetty; import java.io.IOException; import java.io.InputStream; diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedErrorHandler.java b/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyEmbeddedErrorHandler.java similarity index 95% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedErrorHandler.java rename to spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyEmbeddedErrorHandler.java index 42f4ffafb5..9e1d4893ae 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedErrorHandler.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyEmbeddedErrorHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded.jetty; +package org.springframework.boot.web.embedded.jetty; import java.io.IOException; diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedWebAppContext.java b/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyEmbeddedWebAppContext.java similarity index 84% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedWebAppContext.java rename to spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyEmbeddedWebAppContext.java index c5c3234f10..7c4b6a2760 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedWebAppContext.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyEmbeddedWebAppContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2017 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. @@ -14,14 +14,14 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded.jetty; +package org.springframework.boot.web.embedded.jetty; import org.eclipse.jetty.servlet.ServletHandler; import org.eclipse.jetty.webapp.WebAppContext; /** - * Jetty {@link WebAppContext} used by {@link JettyEmbeddedServletContainer} to support - * deferred initialization. + * Jetty {@link WebAppContext} used by {@link JettyWebServer} to support deferred + * initialization. * * @author Phillip Webb */ diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyReactiveWebServerFactory.java b/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyReactiveWebServerFactory.java similarity index 87% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyReactiveWebServerFactory.java rename to spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyReactiveWebServerFactory.java index 8b68b357d1..ca57e24289 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyReactiveWebServerFactory.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyReactiveWebServerFactory.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded.jetty; +package org.springframework.boot.web.embedded.jetty; import java.net.InetSocketAddress; import java.util.Map; @@ -28,9 +28,9 @@ import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.util.thread.ThreadPool; -import org.springframework.boot.context.embedded.AbstractReactiveWebServerFactory; -import org.springframework.boot.context.embedded.EmbeddedWebServer; -import org.springframework.boot.context.embedded.ReactiveWebServerFactory; +import org.springframework.boot.web.reactive.server.AbstractReactiveWebServerFactory; +import org.springframework.boot.web.reactive.server.ReactiveWebServerFactory; +import org.springframework.boot.web.server.WebServer; import org.springframework.http.server.reactive.HttpHandler; import org.springframework.http.server.reactive.JettyHttpHandlerAdapter; @@ -38,6 +38,7 @@ import org.springframework.http.server.reactive.JettyHttpHandlerAdapter; * {@link ReactiveWebServerFactory} that can be used to create {@link JettyWebServer}s. * * @author Brian Clozel + * @since 2.0.0 */ public class JettyReactiveWebServerFactory extends AbstractReactiveWebServerFactory { @@ -54,14 +55,14 @@ public class JettyReactiveWebServerFactory extends AbstractReactiveWebServerFact private ThreadPool threadPool; /** - * Create a new {@link JettyEmbeddedServletContainerFactory} instance. + * Create a new {@link JettyServletWebServerFactory} instance. */ public JettyReactiveWebServerFactory() { super(); } /** - * Create a new {@link JettyEmbeddedServletContainerFactory} that listens for requests + * Create a new {@link JettyServletWebServerFactory} that listens for requests * using the specified port. * @param port the port to listen on */ @@ -70,14 +71,14 @@ public class JettyReactiveWebServerFactory extends AbstractReactiveWebServerFact } @Override - public EmbeddedWebServer getReactiveHttpServer(HttpHandler httpHandler) { + public WebServer getWebServer(HttpHandler httpHandler) { JettyHttpHandlerAdapter servlet = new JettyHttpHandlerAdapter(httpHandler); Server server = createJettyServer(servlet); return new JettyWebServer(server, getPort() >= 0); } @Override - public EmbeddedWebServer getReactiveHttpServer(Map handlerMap) { + public WebServer getWebServer(Map handlerMap) { JettyHttpHandlerAdapter servlet = new JettyHttpHandlerAdapter(handlerMap); Server server = createJettyServer(servlet); return new JettyWebServer(server, getPort() >= 0); diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyServerCustomizer.java b/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyServerCustomizer.java similarity index 89% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyServerCustomizer.java rename to spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyServerCustomizer.java index 0be413c83c..58b95fd9d5 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyServerCustomizer.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyServerCustomizer.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded.jetty; +package org.springframework.boot.web.embedded.jetty; import org.eclipse.jetty.server.Server; @@ -22,7 +22,8 @@ import org.eclipse.jetty.server.Server; * Callback interface that can be used to customize a Jetty {@link Server}. * * @author Dave Syer - * @see JettyEmbeddedServletContainerFactory + * @see JettyServletWebServerFactory + * @since 2.0.0 */ @FunctionalInterface public interface JettyServerCustomizer { diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedServletContainerFactory.java b/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactory.java similarity index 90% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedServletContainerFactory.java rename to spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactory.java index deeed9b243..69afdaa3c9 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedServletContainerFactory.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactory.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded.jetty; +package org.springframework.boot.web.embedded.jetty; import java.io.File; import java.io.IOException; @@ -64,16 +64,16 @@ import org.eclipse.jetty.webapp.AbstractConfiguration; import org.eclipse.jetty.webapp.Configuration; import org.eclipse.jetty.webapp.WebAppContext; -import org.springframework.boot.context.embedded.AbstractEmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.Compression; -import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.EmbeddedWebServer; -import org.springframework.boot.context.embedded.EmbeddedWebServerException; -import org.springframework.boot.context.embedded.MimeMappings; -import org.springframework.boot.context.embedded.Ssl; -import org.springframework.boot.context.embedded.Ssl.ClientAuth; -import org.springframework.boot.web.servlet.ErrorPage; +import org.springframework.boot.web.server.Compression; +import org.springframework.boot.web.server.ErrorPage; +import org.springframework.boot.web.server.MimeMappings; +import org.springframework.boot.web.server.Ssl; +import org.springframework.boot.web.server.Ssl.ClientAuth; +import org.springframework.boot.web.server.WebServer; +import org.springframework.boot.web.server.WebServerException; import org.springframework.boot.web.servlet.ServletContextInitializer; +import org.springframework.boot.web.servlet.server.AbstractServletWebServerFactory; +import org.springframework.boot.web.servlet.server.ServletWebServerFactory; import org.springframework.context.ResourceLoaderAware; import org.springframework.core.io.ResourceLoader; import org.springframework.util.Assert; @@ -82,12 +82,12 @@ import org.springframework.util.ResourceUtils; import org.springframework.util.StringUtils; /** - * {@link EmbeddedServletContainerFactory} that can be used to create - * {@link JettyEmbeddedServletContainer}s. Can be initialized using Spring's - * {@link ServletContextInitializer}s or Jetty {@link Configuration}s. + * {@link ServletWebServerFactory} that can be used to create a {@link JettyWebServer}. + * Can be initialized using Spring's {@link ServletContextInitializer}s or Jetty + * {@link Configuration}s. *

    - * Unless explicitly configured otherwise this factory will created containers that - * listens for HTTP requests on port 8080. + * Unless explicitly configured otherwise this factory will created servers that listens + * for HTTP requests on port 8080. * * @author Phillip Webb * @author Dave Syer @@ -96,12 +96,13 @@ import org.springframework.util.StringUtils; * @author Eddú Meléndez * @author Venil Noronha * @author Henri Kerola + * @since 2.0.0 * @see #setPort(int) * @see #setConfigurations(Collection) - * @see JettyEmbeddedServletContainer + * @see JettyWebServer */ -public class JettyEmbeddedServletContainerFactory - extends AbstractEmbeddedServletContainerFactory implements ResourceLoaderAware { +public class JettyServletWebServerFactory extends AbstractServletWebServerFactory + implements ResourceLoaderAware { private List configurations = new ArrayList<>(); @@ -124,34 +125,33 @@ public class JettyEmbeddedServletContainerFactory private ThreadPool threadPool; /** - * Create a new {@link JettyEmbeddedServletContainerFactory} instance. + * Create a new {@link JettyServletWebServerFactory} instance. */ - public JettyEmbeddedServletContainerFactory() { + public JettyServletWebServerFactory() { super(); } /** - * Create a new {@link JettyEmbeddedServletContainerFactory} that listens for requests - * using the specified port. + * Create a new {@link JettyServletWebServerFactory} that listens for requests using + * the specified port. * @param port the port to listen on */ - public JettyEmbeddedServletContainerFactory(int port) { + public JettyServletWebServerFactory(int port) { super(port); } /** - * Create a new {@link JettyEmbeddedServletContainerFactory} with the specified - * context path and port. + * Create a new {@link JettyServletWebServerFactory} with the specified context path + * and port. * @param contextPath the root context path * @param port the port to listen on */ - public JettyEmbeddedServletContainerFactory(String contextPath, int port) { + public JettyServletWebServerFactory(String contextPath, int port) { super(contextPath, port); } @Override - public EmbeddedWebServer getEmbeddedServletContainer( - ServletContextInitializer... initializers) { + public WebServer getWebServer(ServletContextInitializer... initializers) { JettyEmbeddedWebAppContext context = new JettyEmbeddedWebAppContext(); int port = (getPort() >= 0 ? getPort() : 0); InetSocketAddress address = new InetSocketAddress(getAddress(), port); @@ -172,7 +172,7 @@ public class JettyEmbeddedServletContainerFactory if (this.useForwardHeaders) { new ForwardHeadersCustomizer().customize(server); } - return getJettyEmbeddedServletContainer(server); + return getJettyWebServer(server); } private Server createServer(InetSocketAddress address) { @@ -292,7 +292,7 @@ public class JettyEmbeddedServletContainerFactory factory.setKeyStoreResource(Resource.newResource(url)); } catch (IOException ex) { - throw new EmbeddedWebServerException( + throw new WebServerException( "Could not find key store '" + ssl.getKeyStore() + "'", ex); } if (ssl.getKeyStoreType() != null) { @@ -313,7 +313,7 @@ public class JettyEmbeddedServletContainerFactory factory.setTrustStoreResource(Resource.newResource(url)); } catch (IOException ex) { - throw new EmbeddedWebServerException( + throw new WebServerException( "Could not find trust store '" + ssl.getTrustStore() + "'", ex); } } @@ -527,16 +527,14 @@ public class JettyEmbeddedServletContainerFactory } /** - * Factory method called to create the {@link JettyEmbeddedServletContainer} . - * Subclasses can override this method to return a different - * {@link JettyEmbeddedServletContainer} or apply additional processing to the Jetty - * server. + * Factory method called to create the {@link JettyWebServer} . Subclasses can + * override this method to return a different {@link JettyWebServer} or apply + * additional processing to the Jetty server. * @param server the Jetty server. - * @return a new {@link JettyEmbeddedServletContainer} instance + * @return a new {@link JettyWebServer} instance */ - protected JettyEmbeddedServletContainer getJettyEmbeddedServletContainer( - Server server) { - return new JettyEmbeddedServletContainer(server, getPort() >= 0); + protected JettyWebServer getJettyWebServer(Server server) { + return new JettyWebServer(server, getPort() >= 0); } @Override diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyWebServer.java b/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyWebServer.java similarity index 84% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyWebServer.java rename to spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyWebServer.java index 8c830f230f..f25bfe6fba 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyWebServer.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyWebServer.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded.jetty; +package org.springframework.boot.web.embedded.jetty; import java.net.BindException; import java.util.List; @@ -28,26 +28,25 @@ import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.handler.HandlerCollection; import org.eclipse.jetty.server.handler.HandlerWrapper; -import org.springframework.boot.context.embedded.EmbeddedWebServer; -import org.springframework.boot.context.embedded.EmbeddedWebServerException; -import org.springframework.boot.context.embedded.PortInUseException; +import org.springframework.boot.web.server.PortInUseException; +import org.springframework.boot.web.server.WebServer; +import org.springframework.boot.web.server.WebServerException; import org.springframework.util.Assert; import org.springframework.util.ReflectionUtils; import org.springframework.util.StringUtils; /** - * {@link EmbeddedWebServer} that can be used to control a Jetty web server. Usually this - * class should be created using the {@link JettyReactiveWebServerFactory} and not - * directly. + * {@link WebServer} that can be used to control a Jetty web server. * * @author Phillip Webb * @author Dave Syer * @author David Liu * @author Eddú Meléndez * @author Brian Clozel + * @since 2.0.0 * @see JettyReactiveWebServerFactory */ -public class JettyWebServer implements EmbeddedWebServer { +public class JettyWebServer implements WebServer { private static final Log logger = LogFactory.getLog(JettyWebServer.class); @@ -72,7 +71,7 @@ public class JettyWebServer implements EmbeddedWebServer { /** * Create a new {@link JettyWebServer} instance. * @param server the underlying Jetty server - * @param autoStart if auto-starting the container + * @param autoStart if auto-starting the server */ public JettyWebServer(Server server, boolean autoStart) { this.autoStart = autoStart; @@ -96,8 +95,8 @@ public class JettyWebServer implements EmbeddedWebServer { catch (Exception ex) { // Ensure process isn't left running stopSilently(); - throw new EmbeddedWebServerException( - "Unable to start embedded Jetty web server", ex); + throw new WebServerException("Unable to start embedded Jetty web server", + ex); } } } @@ -112,7 +111,7 @@ public class JettyWebServer implements EmbeddedWebServer { } @Override - public void start() throws EmbeddedWebServerException { + public void start() throws WebServerException { synchronized (this.monitor) { if (this.started) { return; @@ -143,12 +142,11 @@ public class JettyWebServer implements EmbeddedWebServer { JettyWebServer.logger .info("Jetty started on port(s) " + getActualPortsDescription()); } - catch (EmbeddedWebServerException ex) { + catch (WebServerException ex) { throw ex; } catch (Exception ex) { - throw new EmbeddedWebServerException( - "Unable to start embedded Jetty servlet container", ex); + throw new WebServerException("Unable to start embedded Jetty server", ex); } } } @@ -198,9 +196,6 @@ public class JettyWebServer implements EmbeddedWebServer { @Override public void stop() { synchronized (this.monitor) { - if (!this.started) { - return; - } this.started = false; try { this.server.stop(); @@ -209,8 +204,7 @@ public class JettyWebServer implements EmbeddedWebServer { Thread.currentThread().interrupt(); } catch (Exception ex) { - throw new EmbeddedWebServerException( - "Unable to stop embedded Jetty web server", ex); + throw new WebServerException("Unable to stop embedded Jetty server", ex); } } } diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/ServletContextInitializerConfiguration.java b/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/ServletContextInitializerConfiguration.java similarity index 95% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/ServletContextInitializerConfiguration.java rename to spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/ServletContextInitializerConfiguration.java index 4e61ed5fde..c50dfeec99 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/ServletContextInitializerConfiguration.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/ServletContextInitializerConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded.jetty; +package org.springframework.boot.web.embedded.jetty; import javax.servlet.ServletException; @@ -31,6 +31,7 @@ import org.springframework.util.Assert; * * @author Phillip Webb * @author Andy Wilkinson + * @since 2.0.0 */ public class ServletContextInitializerConfiguration extends AbstractConfiguration { diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/package-info.java b/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/package-info.java similarity index 68% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/package-info.java rename to spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/package-info.java index 1cc029ba69..619d159403 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/package-info.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/package-info.java @@ -15,9 +15,9 @@ */ /** - * Support for Undertow {@link org.springframework.boot.context.embedded.EmbeddedWebServer - * EmbeddedServletContainers}. + * Embedded reactive and servlet web server implementations backed by Jetty. * - * @see org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory + * @see org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory + * @see org.springframework.boot.web.embedded.jetty.JettyReactiveWebServerFactory */ -package org.springframework.boot.context.embedded.undertow; +package org.springframework.boot.web.embedded.jetty; diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/reactor/ReactorNettyReactiveWebServerFactory.java b/spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/NettyReactiveWebServerFactory.java similarity index 62% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/reactor/ReactorNettyReactiveWebServerFactory.java rename to spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/NettyReactiveWebServerFactory.java index 3d1a593cd5..4429a246ff 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/reactor/ReactorNettyReactiveWebServerFactory.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/NettyReactiveWebServerFactory.java @@ -14,48 +14,47 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded.reactor; +package org.springframework.boot.web.embedded.netty; import java.util.Map; import reactor.ipc.netty.http.server.HttpServer; -import org.springframework.boot.context.embedded.AbstractReactiveWebServerFactory; -import org.springframework.boot.context.embedded.EmbeddedWebServer; -import org.springframework.boot.context.embedded.ReactiveWebServerFactory; +import org.springframework.boot.web.reactive.server.AbstractReactiveWebServerFactory; +import org.springframework.boot.web.reactive.server.ReactiveWebServerFactory; +import org.springframework.boot.web.server.WebServer; import org.springframework.http.server.reactive.HttpHandler; import org.springframework.http.server.reactive.ReactorHttpHandlerAdapter; /** - * {@link ReactiveWebServerFactory} that can be used to create - * {@link ReactorNettyWebServer}s. + * {@link ReactiveWebServerFactory} that can be used to create {@link NettyWebServer}s. * * @author Brian Clozel + * @since 2.0.0 */ -public class ReactorNettyReactiveWebServerFactory - extends AbstractReactiveWebServerFactory { +public class NettyReactiveWebServerFactory extends AbstractReactiveWebServerFactory { - public ReactorNettyReactiveWebServerFactory() { + public NettyReactiveWebServerFactory() { } - public ReactorNettyReactiveWebServerFactory(int port) { + public NettyReactiveWebServerFactory(int port) { super(port); } @Override - public EmbeddedWebServer getReactiveHttpServer(HttpHandler httpHandler) { + public WebServer getWebServer(HttpHandler httpHandler) { HttpServer server = createHttpServer(); ReactorHttpHandlerAdapter handlerAdapter = new ReactorHttpHandlerAdapter( httpHandler); - return new ReactorNettyWebServer(server, handlerAdapter); + return new NettyWebServer(server, handlerAdapter); } @Override - public EmbeddedWebServer getReactiveHttpServer(Map handlerMap) { + public WebServer getWebServer(Map handlerMap) { HttpServer server = createHttpServer(); ReactorHttpHandlerAdapter handlerAdapter = new ReactorHttpHandlerAdapter( handlerMap); - return new ReactorNettyWebServer(server, handlerAdapter); + return new NettyWebServer(server, handlerAdapter); } private HttpServer createHttpServer() { diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/reactor/ReactorNettyWebServer.java b/spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/NettyWebServer.java similarity index 76% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/reactor/ReactorNettyWebServer.java rename to spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/NettyWebServer.java index 05f03a6f3f..7ef15b5753 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/reactor/ReactorNettyWebServer.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/NettyWebServer.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded.reactor; +package org.springframework.boot.web.embedded.netty; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicReference; @@ -23,18 +23,19 @@ import reactor.core.Loopback; import reactor.ipc.netty.NettyContext; import reactor.ipc.netty.http.server.HttpServer; -import org.springframework.boot.context.embedded.EmbeddedWebServer; -import org.springframework.boot.context.embedded.EmbeddedWebServerException; +import org.springframework.boot.web.server.WebServer; +import org.springframework.boot.web.server.WebServerException; import org.springframework.http.server.reactive.ReactorHttpHandlerAdapter; /** - * {@link EmbeddedWebServer} that can be used to control a Reactor Netty web server. - * Usually this class should be created using the - * {@link ReactorNettyReactiveWebServerFactory} and not directly. + * {@link WebServer} that can be used to control a Reactor Netty web server. Usually this + * class should be created using the {@link NettyReactiveWebServerFactory} and not + * directly. * * @author Brian Clozel + * @since 2.0.0 */ -public class ReactorNettyWebServer implements EmbeddedWebServer, Loopback { +public class NettyWebServer implements WebServer, Loopback { private static CountDownLatch latch = new CountDownLatch(1); @@ -44,7 +45,7 @@ public class ReactorNettyWebServer implements EmbeddedWebServer, Loopback { private AtomicReference nettyContext = new AtomicReference<>(); - public ReactorNettyWebServer(HttpServer reactorServer, + public NettyWebServer(HttpServer reactorServer, ReactorHttpHandlerAdapter handlerAdapter) { this.reactorServer = reactorServer; this.handlerAdapter = handlerAdapter; @@ -61,7 +62,7 @@ public class ReactorNettyWebServer implements EmbeddedWebServer, Loopback { } @Override - public void start() throws EmbeddedWebServerException { + public void start() throws WebServerException { if (this.nettyContext.get() == null) { this.nettyContext .set(this.reactorServer.newHandler(this.handlerAdapter).block()); @@ -75,7 +76,7 @@ public class ReactorNettyWebServer implements EmbeddedWebServer, Loopback { @Override public void run() { try { - ReactorNettyWebServer.latch.await(); + NettyWebServer.latch.await(); } catch (InterruptedException e) { } @@ -88,7 +89,7 @@ public class ReactorNettyWebServer implements EmbeddedWebServer, Loopback { } @Override - public void stop() throws EmbeddedWebServerException { + public void stop() throws WebServerException { NettyContext context = this.nettyContext.getAndSet(null); if (context != null) { context.dispose(); diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/package-info.java b/spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/package-info.java similarity index 70% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/package-info.java rename to spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/package-info.java index fce2d0b53b..428130e038 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/package-info.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/embedded/netty/package-info.java @@ -15,9 +15,8 @@ */ /** - * Support for Jetty {@link org.springframework.boot.context.embedded.EmbeddedWebServer - * EmbeddedServletContainers}. + * Embedded reactive web server implementation backed by Netty. * - * @see org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory + * @see org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory */ -package org.springframework.boot.context.embedded.jetty; +package org.springframework.boot.web.embedded.netty; diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/ConnectorStartFailedException.java b/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/ConnectorStartFailedException.java similarity index 84% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/ConnectorStartFailedException.java rename to spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/ConnectorStartFailedException.java index a1ee971e68..165c5ce2ea 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/ConnectorStartFailedException.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/ConnectorStartFailedException.java @@ -14,20 +14,20 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded.tomcat; +package org.springframework.boot.web.embedded.tomcat; import org.apache.catalina.connector.Connector; -import org.springframework.boot.context.embedded.EmbeddedWebServerException; +import org.springframework.boot.web.server.WebServerException; /** * A {@code ConnectorStartFailedException} is thrown when a Tomcat {@link Connector} fails * to start, for example due to a port clash or incorrect SSL configuration. * * @author Andy Wilkinson - * @since 1.4.1 + * @since 2.0.0 */ -public class ConnectorStartFailedException extends EmbeddedWebServerException { +public class ConnectorStartFailedException extends WebServerException { private final int port; diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/LazySessionIdGenerator.java b/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/LazySessionIdGenerator.java similarity index 90% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/LazySessionIdGenerator.java rename to spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/LazySessionIdGenerator.java index 956f13b62d..01e4045ded 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/LazySessionIdGenerator.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/LazySessionIdGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded.tomcat; +package org.springframework.boot.web.embedded.tomcat; import org.apache.catalina.LifecycleException; import org.apache.catalina.LifecycleState; diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/SkipPatternJarScanner.java b/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/SkipPatternJarScanner.java similarity index 97% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/SkipPatternJarScanner.java rename to spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/SkipPatternJarScanner.java index 0770d9556c..dbf7093a21 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/SkipPatternJarScanner.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/SkipPatternJarScanner.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded.tomcat; +package org.springframework.boot.web.embedded.tomcat; import java.util.Set; diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/SslStoreProviderUrlStreamHandlerFactory.java b/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/SslStoreProviderUrlStreamHandlerFactory.java similarity index 94% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/SslStoreProviderUrlStreamHandlerFactory.java rename to spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/SslStoreProviderUrlStreamHandlerFactory.java index 2539fa8e29..1ad438d212 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/SslStoreProviderUrlStreamHandlerFactory.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/SslStoreProviderUrlStreamHandlerFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded.tomcat; +package org.springframework.boot.web.embedded.tomcat; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -26,7 +26,7 @@ import java.net.URLStreamHandler; import java.net.URLStreamHandlerFactory; import java.security.KeyStore; -import org.springframework.boot.context.embedded.SslStoreProvider; +import org.springframework.boot.web.server.SslStoreProvider; /** * A {@link URLStreamHandlerFactory} that provides a {@link URLStreamHandler} for diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TldSkipPatterns.java b/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TldSkipPatterns.java similarity index 98% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TldSkipPatterns.java rename to spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TldSkipPatterns.java index 143556c98f..cb2014ff04 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TldSkipPatterns.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TldSkipPatterns.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded.tomcat; +package org.springframework.boot.web.embedded.tomcat; import java.util.Collections; import java.util.LinkedHashSet; diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatConnectorCustomizer.java b/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatConnectorCustomizer.java similarity index 90% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatConnectorCustomizer.java rename to spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatConnectorCustomizer.java index e049281d48..c6c8e84cc9 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatConnectorCustomizer.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatConnectorCustomizer.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded.tomcat; +package org.springframework.boot.web.embedded.tomcat; import org.apache.catalina.connector.Connector; @@ -22,7 +22,8 @@ import org.apache.catalina.connector.Connector; * Callback interface that can be used to customize a Tomcat {@link Connector}. * * @author Dave Syer - * @see TomcatEmbeddedServletContainerFactory + * @see TomcatServletWebServerFactory + * @since 2.0.0 */ @FunctionalInterface public interface TomcatConnectorCustomizer { diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatContextCustomizer.java b/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatContextCustomizer.java similarity index 89% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatContextCustomizer.java rename to spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatContextCustomizer.java index 1a7db6e97d..8207b95c96 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatContextCustomizer.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatContextCustomizer.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded.tomcat; +package org.springframework.boot.web.embedded.tomcat; import org.apache.catalina.Context; @@ -22,7 +22,8 @@ import org.apache.catalina.Context; * Callback interface that can be used to customize a Tomcat {@link Context}. * * @author Dave Syer - * @see TomcatEmbeddedServletContainerFactory + * @see TomcatServletWebServerFactory + * @since 2.0.0 */ @FunctionalInterface public interface TomcatContextCustomizer { diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedContext.java b/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatEmbeddedContext.java similarity index 93% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedContext.java rename to spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatEmbeddedContext.java index bbe49f25cb..95752b4dfd 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedContext.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatEmbeddedContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded.tomcat; +package org.springframework.boot.web.embedded.tomcat; import org.apache.catalina.Container; import org.apache.catalina.Manager; @@ -25,7 +25,7 @@ import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; /** - * Tomcat {@link StandardContext} used by {@link TomcatEmbeddedServletContainer} to + * Tomcat {@link StandardContext} used by {@link TomcatWebServer} to * support deferred initialization. * * @author Phillip Webb diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedWebappClassLoader.java b/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatEmbeddedWebappClassLoader.java similarity index 98% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedWebappClassLoader.java rename to spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatEmbeddedWebappClassLoader.java index a2b156001c..34e9e58f9e 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedWebappClassLoader.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatEmbeddedWebappClassLoader.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded.tomcat; +package org.springframework.boot.web.embedded.tomcat; import java.net.URL; @@ -29,6 +29,7 @@ import org.apache.commons.logging.LogFactory; * executable archives). * * @author Phillip Webb + * @since 2.0.0 */ public class TomcatEmbeddedWebappClassLoader extends WebappClassLoader { diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatErrorPage.java b/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatErrorPage.java similarity index 96% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatErrorPage.java rename to spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatErrorPage.java index bba05e9b88..8941598694 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatErrorPage.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatErrorPage.java @@ -14,14 +14,14 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded.tomcat; +package org.springframework.boot.web.embedded.tomcat; import java.lang.reflect.Method; import org.apache.catalina.Context; import org.springframework.beans.BeanUtils; -import org.springframework.boot.web.servlet.ErrorPage; +import org.springframework.boot.web.server.ErrorPage; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatReactiveWebServerFactory.java b/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatReactiveWebServerFactory.java similarity index 78% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatReactiveWebServerFactory.java rename to spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatReactiveWebServerFactory.java index 106226a1f6..2609fc7f59 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatReactiveWebServerFactory.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatReactiveWebServerFactory.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded.tomcat; +package org.springframework.boot.web.embedded.tomcat; import java.io.File; import java.util.Map; @@ -25,9 +25,9 @@ import org.apache.catalina.loader.WebappLoader; import org.apache.catalina.startup.Tomcat; import org.apache.coyote.AbstractProtocol; -import org.springframework.boot.context.embedded.AbstractReactiveWebServerFactory; -import org.springframework.boot.context.embedded.EmbeddedWebServer; -import org.springframework.boot.context.embedded.ReactiveWebServerFactory; +import org.springframework.boot.web.reactive.server.AbstractReactiveWebServerFactory; +import org.springframework.boot.web.reactive.server.ReactiveWebServerFactory; +import org.springframework.boot.web.server.WebServer; import org.springframework.http.server.reactive.HttpHandler; import org.springframework.http.server.reactive.TomcatHttpHandlerAdapter; import org.springframework.util.Assert; @@ -35,9 +35,10 @@ import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; /** - * {@link ReactiveWebServerFactory} that can be used to create {@link TomcatWebServer}s. + * {@link ReactiveWebServerFactory} that can be used to create a {@link TomcatWebServer}. * * @author Brian Clozel + * @since 2.0.0 */ public class TomcatReactiveWebServerFactory extends AbstractReactiveWebServerFactory { @@ -49,15 +50,15 @@ public class TomcatReactiveWebServerFactory extends AbstractReactiveWebServerFac private String protocol = DEFAULT_PROTOCOL; /** - * Create a new {@link TomcatEmbeddedServletContainerFactory} instance. + * Create a new {@link TomcatServletWebServerFactory} instance. */ public TomcatReactiveWebServerFactory() { super(); } /** - * Create a new {@link TomcatEmbeddedServletContainerFactory} that listens for - * requests using the specified port. + * Create a new {@link TomcatServletWebServerFactory} that listens for requests using + * the specified port. * @param port the port to listen on */ public TomcatReactiveWebServerFactory(int port) { @@ -65,7 +66,7 @@ public class TomcatReactiveWebServerFactory extends AbstractReactiveWebServerFac } @Override - public EmbeddedWebServer getReactiveHttpServer(HttpHandler httpHandler) { + public WebServer getWebServer(HttpHandler httpHandler) { Tomcat tomcatServer = createTomcatServer(); TomcatHttpHandlerAdapter servlet = new TomcatHttpHandlerAdapter(httpHandler); prepareContext(tomcatServer.getHost(), servlet); @@ -73,7 +74,7 @@ public class TomcatReactiveWebServerFactory extends AbstractReactiveWebServerFac } @Override - public EmbeddedWebServer getReactiveHttpServer(Map handlerMap) { + public WebServer getWebServer(Map handlerMap) { Tomcat tomcatServer = createTomcatServer(); TomcatHttpHandlerAdapter servlet = new TomcatHttpHandlerAdapter(handlerMap); prepareContext(tomcatServer.getHost(), servlet); @@ -131,16 +132,14 @@ public class TomcatReactiveWebServerFactory extends AbstractReactiveWebServerFac } /** - * Factory method called to create the {@link TomcatEmbeddedServletContainer}. - * Subclasses can override this method to return a different - * {@link TomcatEmbeddedServletContainer} or apply additional processing to the Tomcat - * server. + * Factory method called to create the {@link TomcatWebServer}. Subclasses can + * override this method to return a different {@link TomcatWebServer} or apply + * additional processing to the Tomcat server. * @param tomcat the Tomcat server. - * @return a new {@link TomcatEmbeddedServletContainer} instance + * @return a new {@link TomcatWebServer} instance */ - protected TomcatEmbeddedServletContainer getTomcatEmbeddedServletContainer( - Tomcat tomcat) { - return new TomcatEmbeddedServletContainer(tomcat, getPort() >= 0); + protected TomcatWebServer getTomcatWebServer(Tomcat tomcat) { + return new TomcatWebServer(tomcat, getPort() >= 0); } /** diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainerFactory.java b/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactory.java similarity index 92% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainerFactory.java rename to spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactory.java index 3147177262..2df46f7605 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainerFactory.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactory.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded.tomcat; +package org.springframework.boot.web.embedded.tomcat; import java.io.File; import java.io.FileNotFoundException; @@ -57,17 +57,16 @@ import org.apache.coyote.http11.AbstractHttp11Protocol; import org.apache.coyote.http11.Http11NioProtocol; import org.apache.tomcat.util.net.SSLHostConfig; -import org.springframework.boot.context.embedded.AbstractEmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.Compression; -import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.EmbeddedWebServer; -import org.springframework.boot.context.embedded.EmbeddedWebServerException; -import org.springframework.boot.context.embedded.MimeMappings; -import org.springframework.boot.context.embedded.Ssl; -import org.springframework.boot.context.embedded.Ssl.ClientAuth; -import org.springframework.boot.context.embedded.SslStoreProvider; -import org.springframework.boot.web.servlet.ErrorPage; +import org.springframework.boot.web.server.Compression; +import org.springframework.boot.web.server.ErrorPage; +import org.springframework.boot.web.server.MimeMappings; +import org.springframework.boot.web.server.Ssl; +import org.springframework.boot.web.server.Ssl.ClientAuth; +import org.springframework.boot.web.server.SslStoreProvider; +import org.springframework.boot.web.server.WebServer; +import org.springframework.boot.web.server.WebServerException; import org.springframework.boot.web.servlet.ServletContextInitializer; +import org.springframework.boot.web.servlet.server.AbstractServletWebServerFactory; import org.springframework.context.ResourceLoaderAware; import org.springframework.core.io.ResourceLoader; import org.springframework.util.Assert; @@ -76,8 +75,8 @@ import org.springframework.util.ResourceUtils; import org.springframework.util.StringUtils; /** - * {@link EmbeddedServletContainerFactory} that can be used to create - * {@link TomcatEmbeddedServletContainer}s. Can be initialized using Spring's + * {@link AbstractServletWebServerFactory} that can be used to create + * {@link TomcatWebServer}s. Can be initialized using Spring's * {@link ServletContextInitializer}s or Tomcat {@link LifecycleListener}s. *

    * Unless explicitly configured otherwise this factory will created containers that @@ -90,12 +89,13 @@ import org.springframework.util.StringUtils; * @author Andy Wilkinson * @author Eddú Meléndez * @author Christoffer Sawicki + * @since 2.0.0 * @see #setPort(int) * @see #setContextLifecycleListeners(Collection) - * @see TomcatEmbeddedServletContainer + * @see TomcatWebServer */ -public class TomcatEmbeddedServletContainerFactory - extends AbstractEmbeddedServletContainerFactory implements ResourceLoaderAware { +public class TomcatServletWebServerFactory extends AbstractServletWebServerFactory + implements ResourceLoaderAware { private static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8"); @@ -131,34 +131,33 @@ public class TomcatEmbeddedServletContainerFactory private int backgroundProcessorDelay; /** - * Create a new {@link TomcatEmbeddedServletContainerFactory} instance. + * Create a new {@link TomcatServletWebServerFactory} instance. */ - public TomcatEmbeddedServletContainerFactory() { + public TomcatServletWebServerFactory() { super(); } /** - * Create a new {@link TomcatEmbeddedServletContainerFactory} that listens for - * requests using the specified port. + * Create a new {@link TomcatServletWebServerFactory} that listens for requests using + * the specified port. * @param port the port to listen on */ - public TomcatEmbeddedServletContainerFactory(int port) { + public TomcatServletWebServerFactory(int port) { super(port); } /** - * Create a new {@link TomcatEmbeddedServletContainerFactory} with the specified - * context path and port. + * Create a new {@link TomcatServletWebServerFactory} with the specified context path + * and port. * @param contextPath the root context path * @param port the port to listen on */ - public TomcatEmbeddedServletContainerFactory(String contextPath, int port) { + public TomcatServletWebServerFactory(String contextPath, int port) { super(contextPath, port); } @Override - public EmbeddedWebServer getEmbeddedServletContainer( - ServletContextInitializer... initializers) { + public WebServer getWebServer(ServletContextInitializer... initializers) { Tomcat tomcat = new Tomcat(); File baseDir = (this.baseDirectory != null ? this.baseDirectory : createTempDir("tomcat")); @@ -173,7 +172,7 @@ public class TomcatEmbeddedServletContainerFactory tomcat.getService().addConnector(additionalConnector); } prepareContext(tomcat.getHost(), initializers); - return getTomcatEmbeddedServletContainer(tomcat); + return getTomcatWebServer(tomcat); } private void configureEngine(Engine engine) { @@ -223,7 +222,7 @@ public class TomcatEmbeddedServletContainerFactory } /** - * Override Tomcat's default locale mappings to align with other containers. See + * Override Tomcat's default locale mappings to align with other servers. See * {@code org.apache.catalina.util.CharsetMapperDefault.properties}. * @param context the context to reset */ @@ -416,8 +415,8 @@ public class TomcatEmbeddedServletContainerFactory protocol.setKeystoreFile(ResourceUtils.getURL(ssl.getKeyStore()).toString()); } catch (FileNotFoundException ex) { - throw new EmbeddedWebServerException( - "Could not load key store: " + ex.getMessage(), ex); + throw new WebServerException("Could not load key store: " + ex.getMessage(), + ex); } if (ssl.getKeyStoreType() != null) { protocol.setKeystoreType(ssl.getKeyStoreType()); @@ -435,7 +434,7 @@ public class TomcatEmbeddedServletContainerFactory ResourceUtils.getURL(ssl.getTrustStore()).toString()); } catch (FileNotFoundException ex) { - throw new EmbeddedWebServerException( + throw new WebServerException( "Could not load trust store: " + ex.getMessage(), ex); } } @@ -522,16 +521,14 @@ public class TomcatEmbeddedServletContainerFactory } /** - * Factory method called to create the {@link TomcatEmbeddedServletContainer}. - * Subclasses can override this method to return a different - * {@link TomcatEmbeddedServletContainer} or apply additional processing to the Tomcat - * server. + * Factory method called to create the {@link TomcatWebServer}. Subclasses can + * override this method to return a different {@link TomcatWebServer} or apply + * additional processing to the Tomcat server. * @param tomcat the Tomcat server. - * @return a new {@link TomcatEmbeddedServletContainer} instance + * @return a new {@link TomcatWebServer} instance */ - protected TomcatEmbeddedServletContainer getTomcatEmbeddedServletContainer( - Tomcat tomcat) { - return new TomcatEmbeddedServletContainer(tomcat, getPort() >= 0); + protected TomcatWebServer getTomcatWebServer(Tomcat tomcat) { + return new TomcatWebServer(tomcat, getPort() >= 0); } @Override diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatStarter.java b/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatStarter.java similarity index 94% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatStarter.java rename to spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatStarter.java index 433d96b063..6edf34e41d 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatStarter.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatStarter.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded.tomcat; +package org.springframework.boot.web.embedded.tomcat; import java.util.Set; @@ -33,7 +33,6 @@ import org.springframework.boot.web.servlet.ServletContextInitializer; * * @author Phillip Webb * @author Andy Wilkinson - * @since 1.2.1 */ class TomcatStarter implements ServletContainerInitializer { diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatWebServer.java b/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatWebServer.java similarity index 85% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatWebServer.java rename to spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatWebServer.java index 0e94284165..01bf46eb56 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatWebServer.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatWebServer.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded.tomcat; +package org.springframework.boot.web.embedded.tomcat; import java.util.HashMap; import java.util.Map; @@ -34,21 +34,20 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.naming.ContextBindings; -import org.springframework.boot.context.embedded.EmbeddedWebServer; -import org.springframework.boot.context.embedded.EmbeddedWebServerException; +import org.springframework.boot.web.server.WebServer; +import org.springframework.boot.web.server.WebServerException; import org.springframework.util.Assert; /** - * {@link EmbeddedWebServer} that can be used to control a Tomcat web server. Usually this - * class should be created using the {@link TomcatReactiveWebServerFactory} and not - * directly. + * {@link WebServer} that can be used to control a Tomcat web server. Usually this class + * should be created using the {@link TomcatReactiveWebServerFactory} and not directly. * * @author Brian Clozel + * @since 2.0.0 */ -public class TomcatWebServer implements EmbeddedWebServer { +public class TomcatWebServer implements WebServer { - private static final Log logger = LogFactory - .getLog(TomcatEmbeddedServletContainer.class); + private static final Log logger = LogFactory.getLog(TomcatWebServer.class); private static final AtomicInteger containerCounter = new AtomicInteger(-1); @@ -71,7 +70,7 @@ public class TomcatWebServer implements EmbeddedWebServer { } /** - * Create a new {@link TomcatEmbeddedServletContainer} instance. + * Create a new {@link TomcatWebServer} instance. * @param tomcat the underlying Tomcat server * @param autoStart if the server should be started */ @@ -82,7 +81,7 @@ public class TomcatWebServer implements EmbeddedWebServer { initialize(); } - private void initialize() throws EmbeddedWebServerException { + private void initialize() throws WebServerException { TomcatWebServer.logger .info("Tomcat initialized with port(s): " + getPortsDescription(false)); synchronized (this.monitor) { @@ -109,8 +108,7 @@ public class TomcatWebServer implements EmbeddedWebServer { startDaemonAwaitThread(); } catch (Exception ex) { - throw new EmbeddedWebServerException("Unable to start embedded Tomcat", - ex); + throw new WebServerException("Unable to start embedded Tomcat", ex); } } } @@ -157,7 +155,7 @@ public class TomcatWebServer implements EmbeddedWebServer { } @Override - public void start() throws EmbeddedWebServerException { + public void start() throws WebServerException { synchronized (this.monitor) { if (this.started) { return; @@ -178,8 +176,8 @@ public class TomcatWebServer implements EmbeddedWebServer { throw ex; } catch (Exception ex) { - throw new EmbeddedWebServerException( - "Unable to start embedded Tomcat server", ex); + throw new WebServerException("Unable to start embedded Tomcat server", + ex); } finally { Context context = findContext(); @@ -249,8 +247,8 @@ public class TomcatWebServer implements EmbeddedWebServer { } catch (Exception ex) { TomcatWebServer.logger.error("Cannot start connector: ", ex); - throw new EmbeddedWebServerException( - "Unable to start embedded Tomcat connectors", ex); + throw new WebServerException("Unable to start embedded Tomcat connectors", + ex); } } @@ -259,11 +257,9 @@ public class TomcatWebServer implements EmbeddedWebServer { } @Override - public void stop() throws EmbeddedWebServerException { + public void stop() throws WebServerException { synchronized (this.monitor) { - if (!this.started) { - return; - } + boolean wasStarted = this.started; try { this.started = false; try { @@ -275,11 +271,12 @@ public class TomcatWebServer implements EmbeddedWebServer { } } catch (Exception ex) { - throw new EmbeddedWebServerException("Unable to stop embedded Tomcat", - ex); + throw new WebServerException("Unable to stop embedded Tomcat", ex); } finally { - containerCounter.decrementAndGet(); + if (wasStarted) { + containerCounter.decrementAndGet(); + } } } } diff --git a/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/package-info.java b/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/package-info.java new file mode 100644 index 0000000000..4d8802250a --- /dev/null +++ b/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/package-info.java @@ -0,0 +1,23 @@ +/* + * Copyright 2012-2017 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. + */ + +/** + * Embedded reactive and servlet web server implementations backed by Tomcat. + * + * @see org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory + * @see org.springframework.boot.web.embedded.tomcat.TomcatReactiveWebServerFactory + */ +package org.springframework.boot.web.embedded.tomcat; diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/CompositeResourceManager.java b/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/CompositeResourceManager.java similarity index 97% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/CompositeResourceManager.java rename to spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/CompositeResourceManager.java index 661f78f65a..e286d3592c 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/CompositeResourceManager.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/CompositeResourceManager.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded.undertow; +package org.springframework.boot.web.embedded.undertow; import java.io.IOException; import java.util.Arrays; diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/FileSessionPersistence.java b/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/FileSessionPersistence.java similarity index 95% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/FileSessionPersistence.java rename to spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/FileSessionPersistence.java index fb0afe4f4c..d75f6988d7 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/FileSessionPersistence.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/FileSessionPersistence.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded.undertow; +package org.springframework.boot.web.embedded.undertow; import java.io.File; import java.io.FileInputStream; @@ -37,13 +37,12 @@ import org.springframework.core.ConfigurableObjectInputStream; * * @author Phillip Webb * @author Peter Leibiger - * @since 1.3.0 */ -public class FileSessionPersistence implements SessionPersistenceManager { +class FileSessionPersistence implements SessionPersistenceManager { private final File dir; - public FileSessionPersistence(File dir) { + FileSessionPersistence(File dir) { this.dir = dir; } 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/web/embedded/undertow/JarResourceManager.java similarity index 97% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/JarResourceManager.java rename to spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/JarResourceManager.java index 040d4531da..aa0513fa20 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/JarResourceManager.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/JarResourceManager.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded.undertow; +package org.springframework.boot.web.embedded.undertow; import java.io.File; import java.io.IOException; diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowBuilderCustomizer.java b/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowBuilderCustomizer.java similarity index 88% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowBuilderCustomizer.java rename to spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowBuilderCustomizer.java index 2500b155aa..fbeac4753b 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowBuilderCustomizer.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowBuilderCustomizer.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded.undertow; +package org.springframework.boot.web.embedded.undertow; import io.undertow.Undertow.Builder; @@ -22,8 +22,8 @@ import io.undertow.Undertow.Builder; * Callback interface that can be used to customize an Undertow {@link Builder}. * * @author Andy Wilkinson - * @since 1.2.0 - * @see UndertowEmbeddedServletContainerFactory + * @since 2.0.0 + * @see UndertowServletWebServerFactory */ @FunctionalInterface public interface UndertowBuilderCustomizer { diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowDeploymentInfoCustomizer.java b/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowDeploymentInfoCustomizer.java similarity index 89% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowDeploymentInfoCustomizer.java rename to spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowDeploymentInfoCustomizer.java index 36b10f0044..10bf430cca 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowDeploymentInfoCustomizer.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowDeploymentInfoCustomizer.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded.undertow; +package org.springframework.boot.web.embedded.undertow; import io.undertow.servlet.api.DeploymentInfo; @@ -22,8 +22,8 @@ import io.undertow.servlet.api.DeploymentInfo; * Callback interface that can be used to customize an Undertow {@link DeploymentInfo}. * * @author Phillip Webb - * @since 1.2.0 - * @see UndertowEmbeddedServletContainerFactory + * @since 2.0.0 + * @see UndertowServletWebServerFactory */ @FunctionalInterface public interface UndertowDeploymentInfoCustomizer { diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowReactiveWebServerFactory.java b/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowReactiveWebServerFactory.java similarity index 85% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowReactiveWebServerFactory.java rename to spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowReactiveWebServerFactory.java index 708d6a6ae6..dda9e836a6 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowReactiveWebServerFactory.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowReactiveWebServerFactory.java @@ -14,15 +14,15 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded.undertow; +package org.springframework.boot.web.embedded.undertow; import java.util.Map; import io.undertow.Undertow; -import org.springframework.boot.context.embedded.AbstractReactiveWebServerFactory; -import org.springframework.boot.context.embedded.EmbeddedWebServer; -import org.springframework.boot.context.embedded.ReactiveWebServerFactory; +import org.springframework.boot.web.reactive.server.AbstractReactiveWebServerFactory; +import org.springframework.boot.web.reactive.server.ReactiveWebServerFactory; +import org.springframework.boot.web.server.WebServer; import org.springframework.http.server.reactive.HttpHandler; import org.springframework.http.server.reactive.UndertowHttpHandlerAdapter; @@ -30,6 +30,7 @@ import org.springframework.http.server.reactive.UndertowHttpHandlerAdapter; * {@link ReactiveWebServerFactory} that can be used to create {@link UndertowWebServer}s. * * @author Brian Clozel + * @since 2.0.0 */ public class UndertowReactiveWebServerFactory extends AbstractReactiveWebServerFactory { @@ -57,7 +58,7 @@ public class UndertowReactiveWebServerFactory extends AbstractReactiveWebServerF } @Override - public EmbeddedWebServer getReactiveHttpServer(HttpHandler httpHandler) { + public WebServer getWebServer(HttpHandler httpHandler) { Undertow.Builder builder = createBuilder(getPort()); UndertowHttpHandlerAdapter handler = new UndertowHttpHandlerAdapter(httpHandler); builder.setHandler(handler); @@ -65,7 +66,7 @@ public class UndertowReactiveWebServerFactory extends AbstractReactiveWebServerF } @Override - public EmbeddedWebServer getReactiveHttpServer(Map handlerMap) { + public WebServer getWebServer(Map handlerMap) { Undertow.Builder builder = createBuilder(getPort()); UndertowHttpHandlerAdapter handler = new UndertowHttpHandlerAdapter(handlerMap); builder.setHandler(handler); diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainer.java b/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServer.java similarity index 88% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainer.java rename to spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServer.java index 130582bf49..64b8e6cb73 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainer.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServer.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded.undertow; +package org.springframework.boot.web.embedded.undertow; import java.lang.reflect.Field; import java.net.BindException; @@ -43,10 +43,10 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.xnio.channels.BoundChannel; -import org.springframework.boot.context.embedded.Compression; -import org.springframework.boot.context.embedded.EmbeddedWebServer; -import org.springframework.boot.context.embedded.EmbeddedWebServerException; -import org.springframework.boot.context.embedded.PortInUseException; +import org.springframework.boot.web.server.Compression; +import org.springframework.boot.web.server.PortInUseException; +import org.springframework.boot.web.server.WebServer; +import org.springframework.boot.web.server.WebServerException; import org.springframework.http.HttpHeaders; import org.springframework.util.MimeType; import org.springframework.util.MimeTypeUtils; @@ -54,21 +54,20 @@ import org.springframework.util.ReflectionUtils; import org.springframework.util.StringUtils; /** - * {@link EmbeddedWebServer} that can be used to control an embedded Undertow server. - * Typically this class should be created using - * {@link UndertowEmbeddedServletContainerFactory} and not directly. + * {@link WebServer} that can be used to control an embedded Undertow server. Typically + * this class should be created using {@link UndertowServletWebServerFactory} and not + * directly. * * @author Ivan Sopov * @author Andy Wilkinson * @author Eddú Meléndez * @author Christoph Dreis - * @since 1.2.0 - * @see UndertowEmbeddedServletContainerFactory + * @since 2.0.0 + * @see UndertowServletWebServerFactory */ -public class UndertowEmbeddedServletContainer implements EmbeddedWebServer { +public class UndertowServletWebServer implements WebServer { - private static final Log logger = LogFactory - .getLog(UndertowEmbeddedServletContainer.class); + private static final Log logger = LogFactory.getLog(UndertowServletWebServer.class); private final Object monitor = new Object(); @@ -91,20 +90,20 @@ public class UndertowEmbeddedServletContainer implements EmbeddedWebServer { private volatile boolean started = false; /** - * Create a new {@link UndertowEmbeddedServletContainer} instance. + * Create a new {@link UndertowServletWebServer} instance. * @param builder the builder * @param manager the deployment manager * @param contextPath the root context path * @param autoStart if the server should be started * @param compression compression configuration */ - public UndertowEmbeddedServletContainer(Builder builder, DeploymentManager manager, + public UndertowServletWebServer(Builder builder, DeploymentManager manager, String contextPath, boolean autoStart, Compression compression) { this(builder, manager, contextPath, false, autoStart, compression); } /** - * Create a new {@link UndertowEmbeddedServletContainer} instance. + * Create a new {@link UndertowServletWebServer} instance. * @param builder the builder * @param manager the deployment manager * @param contextPath the root context path @@ -112,7 +111,7 @@ public class UndertowEmbeddedServletContainer implements EmbeddedWebServer { * @param autoStart if the server should be started * @param compression compression configuration */ - public UndertowEmbeddedServletContainer(Builder builder, DeploymentManager manager, + public UndertowServletWebServer(Builder builder, DeploymentManager manager, String contextPath, boolean useForwardHeaders, boolean autoStart, Compression compression) { this(builder, manager, contextPath, useForwardHeaders, autoStart, compression, @@ -120,7 +119,7 @@ public class UndertowEmbeddedServletContainer implements EmbeddedWebServer { } /** - * Create a new {@link UndertowEmbeddedServletContainer} instance. + * Create a new {@link UndertowServletWebServer} instance. * @param builder the builder * @param manager the deployment manager * @param contextPath the root context path @@ -129,7 +128,7 @@ public class UndertowEmbeddedServletContainer implements EmbeddedWebServer { * @param compression compression configuration * @param serverHeader string to be used in HTTP header */ - public UndertowEmbeddedServletContainer(Builder builder, DeploymentManager manager, + public UndertowServletWebServer(Builder builder, DeploymentManager manager, String contextPath, boolean useForwardHeaders, boolean autoStart, Compression compression, String serverHeader) { this.builder = builder; @@ -142,7 +141,7 @@ public class UndertowEmbeddedServletContainer implements EmbeddedWebServer { } @Override - public void start() throws EmbeddedWebServerException { + public void start() throws WebServerException { synchronized (this.monitor) { if (this.started) { return; @@ -156,7 +155,7 @@ public class UndertowEmbeddedServletContainer implements EmbeddedWebServer { } this.undertow.start(); this.started = true; - UndertowEmbeddedServletContainer.logger + UndertowServletWebServer.logger .info("Undertow started on port(s) " + getPortsDescription()); } catch (Exception ex) { @@ -169,8 +168,7 @@ public class UndertowEmbeddedServletContainer implements EmbeddedWebServer { failedPorts.iterator().next().getNumber()); } } - throw new EmbeddedWebServerException("Unable to start embedded Undertow", - ex); + throw new WebServerException("Unable to start embedded Undertow", ex); } } } @@ -306,7 +304,7 @@ public class UndertowEmbeddedServletContainer implements EmbeddedWebServer { } @Override - public void stop() throws EmbeddedWebServerException { + public void stop() throws WebServerException { synchronized (this.monitor) { if (!this.started) { return; @@ -317,7 +315,7 @@ public class UndertowEmbeddedServletContainer implements EmbeddedWebServer { this.undertow.stop(); } catch (Exception ex) { - throw new EmbeddedWebServerException("Unable to stop undertow", ex); + throw new WebServerException("Unable to stop undertow", ex); } } } 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/web/embedded/undertow/UndertowServletWebServerFactory.java similarity index 90% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactory.java rename to spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServerFactory.java index 6c87135cf4..636738c6dd 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactory.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServerFactory.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded.undertow; +package org.springframework.boot.web.embedded.undertow; import java.io.File; import java.io.IOException; @@ -71,35 +71,35 @@ import org.xnio.SslClientAuthMode; import org.xnio.Xnio; import org.xnio.XnioWorker; -import org.springframework.boot.context.embedded.AbstractEmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.EmbeddedWebServer; -import org.springframework.boot.context.embedded.MimeMappings.Mapping; -import org.springframework.boot.context.embedded.Ssl; -import org.springframework.boot.context.embedded.Ssl.ClientAuth; -import org.springframework.boot.web.servlet.ErrorPage; +import org.springframework.boot.web.server.ErrorPage; +import org.springframework.boot.web.server.MimeMappings.Mapping; +import org.springframework.boot.web.server.Ssl; +import org.springframework.boot.web.server.Ssl.ClientAuth; +import org.springframework.boot.web.server.WebServer; import org.springframework.boot.web.servlet.ServletContextInitializer; +import org.springframework.boot.web.servlet.server.AbstractServletWebServerFactory; +import org.springframework.boot.web.servlet.server.ServletWebServerFactory; import org.springframework.context.ResourceLoaderAware; import org.springframework.core.io.ResourceLoader; import org.springframework.util.Assert; import org.springframework.util.ResourceUtils; /** - * {@link EmbeddedServletContainerFactory} that can be used to create - * {@link UndertowEmbeddedServletContainer}s. + * {@link ServletWebServerFactory} that can be used to create + * {@link UndertowServletWebServer}s. *

    - * Unless explicitly configured otherwise, the factory will create containers that listen - * for HTTP requests on port 8080. + * Unless explicitly configured otherwise, the factory will create servers that listen for + * HTTP requests on port 8080. * * @author Ivan Sopov * @author Andy Wilkinson * @author Marcos Barbero * @author Eddú Meléndez - * @since 1.2.0 - * @see UndertowEmbeddedServletContainer + * @since 2.0.0 + * @see UndertowServletWebServer */ -public class UndertowEmbeddedServletContainerFactory - extends AbstractEmbeddedServletContainerFactory implements ResourceLoaderAware { +public class UndertowServletWebServerFactory extends AbstractServletWebServerFactory + implements ResourceLoaderAware { private static final Set> NO_CLASSES = Collections.emptySet(); @@ -132,30 +132,30 @@ public class UndertowEmbeddedServletContainerFactory private boolean useForwardHeaders; /** - * Create a new {@link UndertowEmbeddedServletContainerFactory} instance. + * Create a new {@link UndertowServletWebServerFactory} instance. */ - public UndertowEmbeddedServletContainerFactory() { + public UndertowServletWebServerFactory() { super(); getJsp().setRegistered(false); } /** - * Create a new {@link UndertowEmbeddedServletContainerFactory} that listens for - * requests using the specified port. + * Create a new {@link UndertowServletWebServerFactory} that listens for requests + * using the specified port. * @param port the port to listen on */ - public UndertowEmbeddedServletContainerFactory(int port) { + public UndertowServletWebServerFactory(int port) { super(port); getJsp().setRegistered(false); } /** - * Create a new {@link UndertowEmbeddedServletContainerFactory} with the specified - * context path and port. + * Create a new {@link UndertowServletWebServerFactory} with the specified context + * path and port. * @param contextPath the root context path * @param port the port to listen on */ - public UndertowEmbeddedServletContainerFactory(String contextPath, int port) { + public UndertowServletWebServerFactory(String contextPath, int port) { super(contextPath, port); getJsp().setRegistered(false); } @@ -223,12 +223,11 @@ public class UndertowEmbeddedServletContainerFactory } @Override - public EmbeddedWebServer getEmbeddedServletContainer( - ServletContextInitializer... initializers) { + public WebServer getWebServer(ServletContextInitializer... initializers) { DeploymentManager manager = createDeploymentManager(initializers); int port = getPort(); Builder builder = createBuilder(port); - return getUndertowEmbeddedServletContainer(builder, manager, port); + return getUndertowWebServer(builder, manager, port); } private Builder createBuilder(int port) { @@ -539,18 +538,18 @@ public class UndertowEmbeddedServletContainerFactory } /** - * Factory method called to create the {@link UndertowEmbeddedServletContainer}. - * Subclasses can override this method to return a different - * {@link UndertowEmbeddedServletContainer} or apply additional processing to the - * {@link Builder} and {@link DeploymentManager} used to bootstrap Undertow + * Factory method called to create the {@link UndertowServletWebServer}. Subclasses + * can override this method to return a different {@link UndertowServletWebServer} or + * apply additional processing to the {@link Builder} and {@link DeploymentManager} + * used to bootstrap Undertow * @param builder the builder * @param manager the deployment manager * @param port the port that Undertow should listen on - * @return a new {@link UndertowEmbeddedServletContainer} instance + * @return a new {@link UndertowServletWebServer} instance */ - protected UndertowEmbeddedServletContainer getUndertowEmbeddedServletContainer( - Builder builder, DeploymentManager manager, int port) { - return new UndertowEmbeddedServletContainer(builder, manager, getContextPath(), + protected UndertowServletWebServer getUndertowWebServer(Builder builder, + DeploymentManager manager, int port) { + return new UndertowServletWebServer(builder, manager, getContextPath(), isUseForwardHeaders(), port >= 0, getCompression(), getServerHeader()); } diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowWebServer.java b/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowWebServer.java similarity index 87% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowWebServer.java rename to spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowWebServer.java index cd562aed05..104af8fe4b 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowWebServer.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowWebServer.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded.undertow; +package org.springframework.boot.web.embedded.undertow; import java.lang.reflect.Field; import java.net.BindException; @@ -28,27 +28,26 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.xnio.channels.BoundChannel; -import org.springframework.boot.context.embedded.EmbeddedWebServer; -import org.springframework.boot.context.embedded.EmbeddedWebServerException; -import org.springframework.boot.context.embedded.PortInUseException; +import org.springframework.boot.web.server.PortInUseException; +import org.springframework.boot.web.server.WebServer; +import org.springframework.boot.web.server.WebServerException; import org.springframework.util.ReflectionUtils; import org.springframework.util.StringUtils; /** - * {@link EmbeddedWebServer} that can be used to control a Jetty web server. Usually this - * class should be created using the {@link UndertowReactiveWebServerFactory} and not - * directly. + * {@link WebServer} that can be used to control a Undertow web server. Usually this class + * should be created using the {@link UndertowReactiveWebServerFactory} and not directly. * * @author Ivan Sopov * @author Andy Wilkinson * @author Eddú Meléndez * @author Christoph Dreis * @author Brian Clozel + * @since 2.0.0 */ -public class UndertowWebServer implements EmbeddedWebServer { +public class UndertowWebServer implements WebServer { - private static final Log logger = LogFactory - .getLog(UndertowEmbeddedServletContainer.class); + private static final Log logger = LogFactory.getLog(UndertowServletWebServer.class); private final Object monitor = new Object(); @@ -71,7 +70,7 @@ public class UndertowWebServer implements EmbeddedWebServer { } @Override - public void start() throws EmbeddedWebServerException { + public void start() throws WebServerException { synchronized (this.monitor) { if (this.started) { return; @@ -98,8 +97,7 @@ public class UndertowWebServer implements EmbeddedWebServer { failedPorts.iterator().next().getNumber()); } } - throw new EmbeddedWebServerException("Unable to start embedded Undertow", - ex); + throw new WebServerException("Unable to start embedded Undertow", ex); } } } @@ -191,7 +189,7 @@ public class UndertowWebServer implements EmbeddedWebServer { } @Override - public void stop() throws EmbeddedWebServerException { + public void stop() throws WebServerException { synchronized (this.monitor) { if (!this.started) { return; @@ -201,7 +199,7 @@ public class UndertowWebServer implements EmbeddedWebServer { this.undertow.stop(); } catch (Exception ex) { - throw new EmbeddedWebServerException("Unable to stop undertow", ex); + throw new WebServerException("Unable to stop undertow", ex); } } } diff --git a/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/package-info.java b/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/package-info.java new file mode 100644 index 0000000000..0b4f998638 --- /dev/null +++ b/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/package-info.java @@ -0,0 +1,23 @@ +/* + * Copyright 2012-2017 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. + */ + +/** + * Embedded reactive and servlet web server implementations backed by Undertow. + * + * @see org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory + * @see org.springframework.boot.web.embedded.undertow.UndertowReactiveWebServerFactory + */ +package org.springframework.boot.web.embedded.undertow; diff --git a/spring-boot/src/main/java/org/springframework/boot/context/GenericReactiveWebApplicationContext.java b/spring-boot/src/main/java/org/springframework/boot/web/reactive/context/GenericReactiveWebApplicationContext.java similarity index 95% rename from spring-boot/src/main/java/org/springframework/boot/context/GenericReactiveWebApplicationContext.java rename to spring-boot/src/main/java/org/springframework/boot/web/reactive/context/GenericReactiveWebApplicationContext.java index 8b06e4971b..a70578aaf7 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/GenericReactiveWebApplicationContext.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/reactive/context/GenericReactiveWebApplicationContext.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context; +package org.springframework.boot.web.reactive.context; import org.springframework.context.annotation.AnnotationConfigApplicationContext; diff --git a/spring-boot/src/main/java/org/springframework/boot/context/ReactiveWebApplicationContext.java b/spring-boot/src/main/java/org/springframework/boot/web/reactive/context/ReactiveWebApplicationContext.java similarity index 94% rename from spring-boot/src/main/java/org/springframework/boot/context/ReactiveWebApplicationContext.java rename to spring-boot/src/main/java/org/springframework/boot/web/reactive/context/ReactiveWebApplicationContext.java index 7ea904b92f..b4d526ec3d 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/ReactiveWebApplicationContext.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/reactive/context/ReactiveWebApplicationContext.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context; +package org.springframework.boot.web.reactive.context; import org.springframework.context.ApplicationContext; diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/EmbeddedReactiveWebApplicationContext.java b/spring-boot/src/main/java/org/springframework/boot/web/reactive/context/ReactiveWebServerApplicationContext.java similarity index 78% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/EmbeddedReactiveWebApplicationContext.java rename to spring-boot/src/main/java/org/springframework/boot/web/reactive/context/ReactiveWebServerApplicationContext.java index a469bf0af5..7f5bc03d4d 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/EmbeddedReactiveWebApplicationContext.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/reactive/context/ReactiveWebServerApplicationContext.java @@ -14,31 +14,32 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded; +package org.springframework.boot.web.reactive.context; import org.springframework.beans.BeansException; -import org.springframework.boot.context.GenericReactiveWebApplicationContext; +import org.springframework.boot.web.reactive.server.ReactiveWebServerFactory; +import org.springframework.boot.web.server.WebServer; import org.springframework.context.ApplicationContextException; import org.springframework.http.server.reactive.HttpHandler; import org.springframework.util.StringUtils; /** * A {@link GenericReactiveWebApplicationContext} that can be used to bootstrap itself - * from a contained embedded web server factory bean. + * from a contained {@link ReactiveWebServerFactory} bean. * * @author Brian Clozel * @since 2.0.0 */ -public class EmbeddedReactiveWebApplicationContext +public class ReactiveWebServerApplicationContext extends GenericReactiveWebApplicationContext { - private volatile EmbeddedWebServer embeddedWebServer; + private volatile WebServer webServer; - public EmbeddedReactiveWebApplicationContext() { + public ReactiveWebServerApplicationContext() { super(); } - public EmbeddedReactiveWebApplicationContext(Class... annotatedClasses) { + public ReactiveWebServerApplicationContext(Class... annotatedClasses) { super(annotatedClasses); } @@ -57,7 +58,7 @@ public class EmbeddedReactiveWebApplicationContext protected void onRefresh() { super.onRefresh(); try { - createEmbeddedServletContainer(); + createWebServer(); } catch (Throwable ex) { throw new ApplicationContextException("Unable to start reactive web server", @@ -68,10 +69,9 @@ public class EmbeddedReactiveWebApplicationContext @Override protected void finishRefresh() { super.finishRefresh(); - EmbeddedWebServer localServer = startReactiveWebServer(); + WebServer localServer = startReactiveWebServer(); if (localServer != null) { - publishEvent( - new EmbeddedReactiveWebServerInitializedEvent(localServer, this)); + publishEvent(new ReactiveWebServerInitializedEvent(localServer, this)); } } @@ -81,11 +81,10 @@ public class EmbeddedReactiveWebApplicationContext stopAndReleaseReactiveWebServer(); } - private void createEmbeddedServletContainer() { - EmbeddedWebServer localServer = this.embeddedWebServer; + private void createWebServer() { + WebServer localServer = this.webServer; if (localServer == null) { - this.embeddedWebServer = getReactiveWebServerFactory() - .getReactiveHttpServer(getHttpHandler()); + this.webServer = getWebServerFactory().getWebServer(getHttpHandler()); } initPropertySources(); } @@ -96,7 +95,7 @@ public class EmbeddedReactiveWebApplicationContext * context itself. * @return a {@link ReactiveWebServerFactory} (never {@code null}) */ - protected ReactiveWebServerFactory getReactiveWebServerFactory() { + protected ReactiveWebServerFactory getWebServerFactory() { // Use bean names so that we don't consider the hierarchy String[] beanNames = getBeanFactory() .getBeanNamesForType(ReactiveWebServerFactory.class); @@ -134,8 +133,8 @@ public class EmbeddedReactiveWebApplicationContext return getBeanFactory().getBean(beanNames[0], HttpHandler.class); } - private EmbeddedWebServer startReactiveWebServer() { - EmbeddedWebServer localServer = this.embeddedWebServer; + private WebServer startReactiveWebServer() { + WebServer localServer = this.webServer; if (localServer != null) { localServer.start(); } @@ -143,11 +142,11 @@ public class EmbeddedReactiveWebApplicationContext } private void stopAndReleaseReactiveWebServer() { - EmbeddedWebServer localServer = this.embeddedWebServer; + WebServer localServer = this.webServer; if (localServer != null) { try { localServer.stop(); - this.embeddedWebServer = null; + this.webServer = null; } catch (Exception ex) { throw new IllegalStateException(ex); diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/EmbeddedReactiveWebServerInitializedEvent.java b/spring-boot/src/main/java/org/springframework/boot/web/reactive/context/ReactiveWebServerInitializedEvent.java similarity index 55% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/EmbeddedReactiveWebServerInitializedEvent.java rename to spring-boot/src/main/java/org/springframework/boot/web/reactive/context/ReactiveWebServerInitializedEvent.java index e510afe3ae..c126e28fbc 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/EmbeddedReactiveWebServerInitializedEvent.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/reactive/context/ReactiveWebServerInitializedEvent.java @@ -14,30 +14,32 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded; +package org.springframework.boot.web.reactive.context; + +import org.springframework.boot.web.context.WebServerInitializedEvent; +import org.springframework.boot.web.server.WebServer; /** - * Event to be published after the {@link EmbeddedReactiveWebApplicationContext} is - * refreshed and the {@link EmbeddedWebServer} is ready. Useful for obtaining the local - * port of a running server. + * Event to be published after the {@link ReactiveWebServerApplicationContext} is + * refreshed and the {@link WebServer} is ready. Useful for obtaining the local port of a + * running server. * * @author Brian Clozel * @author Stephane Nicoll * @since 2.0.0 */ -public class EmbeddedReactiveWebServerInitializedEvent - extends EmbeddedWebServerInitializedEvent { +public class ReactiveWebServerInitializedEvent extends WebServerInitializedEvent { - private final EmbeddedReactiveWebApplicationContext applicationContext; + private final ReactiveWebServerApplicationContext applicationContext; - public EmbeddedReactiveWebServerInitializedEvent(EmbeddedWebServer source, - EmbeddedReactiveWebApplicationContext applicationContext) { + public ReactiveWebServerInitializedEvent(WebServer source, + ReactiveWebServerApplicationContext applicationContext) { super(source); this.applicationContext = applicationContext; } @Override - public EmbeddedReactiveWebApplicationContext getApplicationContext() { + public ReactiveWebServerApplicationContext getApplicationContext() { return this.applicationContext; } diff --git a/spring-boot/src/main/java/org/springframework/boot/web/reactive/context/package-info.java b/spring-boot/src/main/java/org/springframework/boot/web/reactive/context/package-info.java new file mode 100644 index 0000000000..ff9ca437a9 --- /dev/null +++ b/spring-boot/src/main/java/org/springframework/boot/web/reactive/context/package-info.java @@ -0,0 +1,21 @@ +/* + * Copyright 2012-2017 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. + */ + +/** + * Reactive based web integrations with Spring's + * {@link org.springframework.context.ApplicationContext ApplicationContext}. + */ +package org.springframework.boot.web.reactive.context; diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/AbstractConfigurableReactiveWebServer.java b/spring-boot/src/main/java/org/springframework/boot/web/reactive/server/AbstractConfigurableReactiveWebServerFactory.java similarity index 79% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/AbstractConfigurableReactiveWebServer.java rename to spring-boot/src/main/java/org/springframework/boot/web/reactive/server/AbstractConfigurableReactiveWebServerFactory.java index 1dd9db0312..8c43a39fe9 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/AbstractConfigurableReactiveWebServer.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/reactive/server/AbstractConfigurableReactiveWebServerFactory.java @@ -14,24 +14,27 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded; +package org.springframework.boot.web.reactive.server; import java.net.InetAddress; import java.util.Arrays; import java.util.LinkedHashSet; import java.util.Set; -import org.springframework.boot.web.servlet.ErrorPage; +import org.springframework.boot.web.server.Compression; +import org.springframework.boot.web.server.ErrorPage; +import org.springframework.boot.web.server.Ssl; +import org.springframework.boot.web.server.SslStoreProvider; import org.springframework.util.Assert; /** - * Abstract base class for {@link ConfigurableReactiveWebServer} implementations. + * Abstract base class for {@link ConfigurableReactiveWebServerFactory} implementations. * * @author Brian Clozel * @since 2.0.0 */ -public class AbstractConfigurableReactiveWebServer - implements ConfigurableReactiveWebServer { +public class AbstractConfigurableReactiveWebServerFactory + implements ConfigurableReactiveWebServerFactory { private int port = 8080; @@ -48,17 +51,17 @@ public class AbstractConfigurableReactiveWebServer private String serverHeader; /** - * Create a new {@link AbstractConfigurableReactiveWebServer} instance. + * Create a new {@link AbstractConfigurableReactiveWebServerFactory} instance. */ - public AbstractConfigurableReactiveWebServer() { + public AbstractConfigurableReactiveWebServerFactory() { } /** - * Create a new {@link AbstractConfigurableReactiveWebServer} instance with the + * Create a new {@link AbstractConfigurableReactiveWebServerFactory} instance with the * specified port. * @param port the port number for the reactive web server */ - public AbstractConfigurableReactiveWebServer(int port) { + public AbstractConfigurableReactiveWebServerFactory(int port) { this.port = port; } diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/AbstractReactiveWebServerFactory.java b/spring-boot/src/main/java/org/springframework/boot/web/reactive/server/AbstractReactiveWebServerFactory.java similarity index 83% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/AbstractReactiveWebServerFactory.java rename to spring-boot/src/main/java/org/springframework/boot/web/reactive/server/AbstractReactiveWebServerFactory.java index 7f3043643d..f2eab5ab07 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/AbstractReactiveWebServerFactory.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/reactive/server/AbstractReactiveWebServerFactory.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded; +package org.springframework.boot.web.reactive.server; import java.io.File; import java.io.IOException; @@ -22,6 +22,8 @@ import java.io.IOException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.boot.web.server.WebServerException; + /** * Abstract base class for {@link ReactiveWebServerFactory} implementations. * @@ -29,7 +31,7 @@ import org.apache.commons.logging.LogFactory; * @since 2.0.0 */ public abstract class AbstractReactiveWebServerFactory extends - AbstractConfigurableReactiveWebServer implements ReactiveWebServerFactory { + AbstractConfigurableReactiveWebServerFactory implements ReactiveWebServerFactory { protected final Log logger = LogFactory.getLog(getClass()); @@ -42,8 +44,8 @@ public abstract class AbstractReactiveWebServerFactory extends /** * Return the absolute temp dir for given web server. - * @param prefix servlet container name - * @return The temp dir for given servlet container. + * @param prefix server name + * @return The temp dir for given server. */ protected File createTempDir(String prefix) { try { @@ -54,7 +56,7 @@ public abstract class AbstractReactiveWebServerFactory extends return tempDir; } catch (IOException ex) { - throw new EmbeddedWebServerException( + throw new WebServerException( "Unable to create tempDir. java.io.tmpdir is set to " + System.getProperty("java.io.tmpdir"), ex); diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/ConfigurableReactiveWebServer.java b/spring-boot/src/main/java/org/springframework/boot/web/reactive/server/ConfigurableReactiveWebServerFactory.java similarity index 77% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/ConfigurableReactiveWebServer.java rename to spring-boot/src/main/java/org/springframework/boot/web/reactive/server/ConfigurableReactiveWebServerFactory.java index 716711cd61..7a9cfce539 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/ConfigurableReactiveWebServer.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/reactive/server/ConfigurableReactiveWebServerFactory.java @@ -14,7 +14,9 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded; +package org.springframework.boot.web.reactive.server; + +import org.springframework.boot.web.server.ConfigurableWebServerFactory; /** * Interface that represents customizations to a {@link ReactiveWebServerFactory}. @@ -22,6 +24,6 @@ package org.springframework.boot.context.embedded; * @author Brian Clozel * @since 2.0.0 */ -public interface ConfigurableReactiveWebServer extends ConfigurableEmbeddedWebServer { +public interface ConfigurableReactiveWebServerFactory extends ConfigurableWebServerFactory { } diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/ReactiveWebServerCustomizer.java b/spring-boot/src/main/java/org/springframework/boot/web/reactive/server/ReactiveWebServerCustomizer.java similarity index 75% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/ReactiveWebServerCustomizer.java rename to spring-boot/src/main/java/org/springframework/boot/web/reactive/server/ReactiveWebServerCustomizer.java index c35ea7f7fb..1db5b771d0 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/ReactiveWebServerCustomizer.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/reactive/server/ReactiveWebServerCustomizer.java @@ -14,11 +14,11 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded; +package org.springframework.boot.web.reactive.server; /** - * Strategy interface for customizing auto-configured embedded reactive servers. Any beans - * of this type will get a callback with the server factory before the server itself is + * Strategy interface for customizing auto-configured reactive web servers. Any beans of + * this type will get a callback with the server factory before the server itself is * started, so you can set the port, address, error pages etc. * @author Brian Clozel * @since 2.0.0 @@ -27,8 +27,8 @@ package org.springframework.boot.context.embedded; public interface ReactiveWebServerCustomizer { /** - * Customize the specified {@link ConfigurableReactiveWebServer}. + * Customize the specified {@link ConfigurableReactiveWebServerFactory}. * @param server the server to customize */ - void customize(ConfigurableReactiveWebServer server); + void customize(ConfigurableReactiveWebServerFactory server); } diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/ReactiveWebServerCustomizerBeanPostProcessor.java b/spring-boot/src/main/java/org/springframework/boot/web/reactive/server/ReactiveWebServerCustomizerBeanPostProcessor.java similarity index 91% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/ReactiveWebServerCustomizerBeanPostProcessor.java rename to spring-boot/src/main/java/org/springframework/boot/web/reactive/server/ReactiveWebServerCustomizerBeanPostProcessor.java index 1d11c10421..e3ae6504fc 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/ReactiveWebServerCustomizerBeanPostProcessor.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/reactive/server/ReactiveWebServerCustomizerBeanPostProcessor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded; +package org.springframework.boot.web.reactive.server; import java.util.ArrayList; import java.util.Collection; @@ -30,7 +30,7 @@ import org.springframework.core.annotation.AnnotationAwareOrderComparator; /** * {@link BeanPostProcessor} that applies all {@link ReactiveWebServerCustomizer}s from - * the bean factory to {@link ConfigurableReactiveWebServer} beans. + * the bean factory to {@link ConfigurableReactiveWebServerFactory} beans. * * @author Brian Clozel * @author Stephane Nicoll @@ -51,8 +51,8 @@ public class ReactiveWebServerCustomizerBeanPostProcessor @Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { - if (bean instanceof ConfigurableReactiveWebServer) { - postProcessBeforeInitialization((ConfigurableReactiveWebServer) bean); + if (bean instanceof ConfigurableReactiveWebServerFactory) { + postProcessBeforeInitialization((ConfigurableReactiveWebServerFactory) bean); } return bean; } @@ -63,7 +63,7 @@ public class ReactiveWebServerCustomizerBeanPostProcessor return bean; } - private void postProcessBeforeInitialization(ConfigurableReactiveWebServer bean) { + private void postProcessBeforeInitialization(ConfigurableReactiveWebServerFactory bean) { for (ReactiveWebServerCustomizer customizer : getCustomizers()) { customizer.customize(bean); } diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/ReactiveWebServerFactory.java b/spring-boot/src/main/java/org/springframework/boot/web/reactive/server/ReactiveWebServerFactory.java similarity index 55% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/ReactiveWebServerFactory.java rename to spring-boot/src/main/java/org/springframework/boot/web/reactive/server/ReactiveWebServerFactory.java index e796a90534..d9f00e8e19 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/ReactiveWebServerFactory.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/reactive/server/ReactiveWebServerFactory.java @@ -14,39 +14,39 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded; +package org.springframework.boot.web.reactive.server; import java.util.Map; -import org.springframework.context.ApplicationContext; +import org.springframework.boot.web.server.WebServer; import org.springframework.http.server.reactive.HttpHandler; /** - * Factory interface that can be used to create reactive {@link EmbeddedWebServer}s. + * Factory interface that can be used to create a reactive {@link WebServer}. * * @author Brian Clozel * @since 2.0.0 - * @see EmbeddedWebServer + * @see WebServer */ public interface ReactiveWebServerFactory { /** - * Gets a new fully configured but paused {@link EmbeddedWebServer} instance. Clients - * should not be able to connect to the returned server until - * {@link EmbeddedWebServer#start()} is called (which happens when the - * {@link ApplicationContext} has been fully refreshed). + * Gets a new fully configured but paused {@link WebServer} instance. Clients should + * not be able to connect to the returned server until {@link WebServer#start()} is + * called (which happens when the {@code ApplicationContext} has been fully + * refreshed). * @param httpHandler the HTTP handler in charge of processing requests - * @return a fully configured and started {@link EmbeddedWebServer} - * @see EmbeddedWebServer#stop() + * @return a fully configured and started {@link WebServer} + * @see WebServer#stop() */ - EmbeddedWebServer getReactiveHttpServer(HttpHandler httpHandler); + WebServer getWebServer(HttpHandler httpHandler); /** * Register a map of {@link HttpHandler}s, each to a specific context path. * @param handlerMap a map of context paths and the associated {@code HttpHandler} - * @return a fully configured and started {@link EmbeddedWebServer} - * @see EmbeddedWebServer#stop() + * @return a fully configured and started {@link WebServer} + * @see WebServer#stop() */ - EmbeddedWebServer getReactiveHttpServer(Map handlerMap); + WebServer getWebServer(Map handlerMap); } diff --git a/spring-boot/src/main/java/org/springframework/boot/web/reactive/server/package-info.java b/spring-boot/src/main/java/org/springframework/boot/web/reactive/server/package-info.java new file mode 100644 index 0000000000..92131c318f --- /dev/null +++ b/spring-boot/src/main/java/org/springframework/boot/web/reactive/server/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2017 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. + */ + +/** + * Reactive web server abstractions. + */ +package org.springframework.boot.web.reactive.server; diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/Compression.java b/spring-boot/src/main/java/org/springframework/boot/web/server/Compression.java similarity index 90% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/Compression.java rename to spring-boot/src/main/java/org/springframework/boot/web/server/Compression.java index 5a687bad98..8d64ccdc4c 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/Compression.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/server/Compression.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -14,14 +14,14 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded; +package org.springframework.boot.web.server; /** - * Simple container-independent abstraction for compression configuration. + * Simple server-independent abstraction for compression configuration. * * @author Ivan Sopov * @author Andy Wilkinson - * @since 1.3.0 + * @since 2.0.0 */ public class Compression { diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/ConfigurableEmbeddedWebServer.java b/spring-boot/src/main/java/org/springframework/boot/web/server/ConfigurableWebServerFactory.java similarity index 69% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/ConfigurableEmbeddedWebServer.java rename to spring-boot/src/main/java/org/springframework/boot/web/server/ConfigurableWebServerFactory.java index fab6f6e316..919111711b 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/ConfigurableEmbeddedWebServer.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/server/ConfigurableWebServerFactory.java @@ -14,26 +14,23 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded; +package org.springframework.boot.web.server; import java.net.InetAddress; import java.util.Set; -import org.springframework.boot.web.servlet.ErrorPage; -import org.springframework.boot.web.servlet.ErrorPageRegistry; - /** - * Interface that regroups common customizations to embedded server factories such as - * {@link EmbeddedServletContainerFactory} and {@link ReactiveWebServerFactory}. + * Simple interface that represents customizations to an web server factory. + * * @author Brian Clozel * @since 2.0.0 */ -public interface ConfigurableEmbeddedWebServer extends ErrorPageRegistry { +public interface ConfigurableWebServerFactory extends ErrorPageRegistry { /** - * Sets the port that the embedded servlet container should listen on. If not - * specified port '8080' will be used. Use port -1 to disable auto-start (i.e start - * the web application context but not have it listen to any port). + * Sets the port that the web server should listen on. If not specified port '8080' + * will be used. Use port -1 to disable auto-start (i.e start the web application + * context but not have it listen to any port). * @param port the port to set */ void setPort(int port); @@ -51,8 +48,7 @@ public interface ConfigurableEmbeddedWebServer extends ErrorPageRegistry { void setErrorPages(Set errorPages); /** - * Sets the SSL configuration that will be applied to the container's default - * connector. + * Sets the SSL configuration that will be applied to the server's default connector. * @param ssl the SSL configuration */ void setSsl(Ssl ssl); @@ -64,7 +60,7 @@ public interface ConfigurableEmbeddedWebServer extends ErrorPageRegistry { void setSslStoreProvider(SslStoreProvider sslStoreProvider); /** - * Sets the compression configuration that will be applied to the container's default + * Sets the compression configuration that will be applied to the server's default * connector. * @param compression the compression configuration */ diff --git a/spring-boot/src/main/java/org/springframework/boot/web/servlet/ErrorPage.java b/spring-boot/src/main/java/org/springframework/boot/web/server/ErrorPage.java similarity index 91% rename from spring-boot/src/main/java/org/springframework/boot/web/servlet/ErrorPage.java rename to spring-boot/src/main/java/org/springframework/boot/web/server/ErrorPage.java index 7a21ca77fc..6590e69c8b 100644 --- a/spring-boot/src/main/java/org/springframework/boot/web/servlet/ErrorPage.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/server/ErrorPage.java @@ -14,17 +14,17 @@ * limitations under the License. */ -package org.springframework.boot.web.servlet; +package org.springframework.boot.web.server; import org.springframework.http.HttpStatus; import org.springframework.util.ObjectUtils; /** - * Simple container-independent abstraction for servlet error pages. Roughly equivalent to - * the {@literal <error-page>} element traditionally found in web.xml. + * Simple server-independent abstraction for error pages. Roughly equivalent to the + * {@literal <error-page>} element traditionally found in web.xml. * * @author Dave Syer - * @since 1.4.0 + * @since 2.0.0 */ public class ErrorPage { @@ -54,7 +54,7 @@ public class ErrorPage { /** * The path to render (usually implemented as a forward), starting with "/". A custom - * controller or servlet path can be used, or if the container supports it, a template + * controller or servlet path can be used, or if the server supports it, a template * path (e.g. "/error.jsp"). * @return the path that will be rendered for this error */ diff --git a/spring-boot/src/main/java/org/springframework/boot/web/servlet/ErrorPageRegistrar.java b/spring-boot/src/main/java/org/springframework/boot/web/server/ErrorPageRegistrar.java similarity index 93% rename from spring-boot/src/main/java/org/springframework/boot/web/servlet/ErrorPageRegistrar.java rename to spring-boot/src/main/java/org/springframework/boot/web/server/ErrorPageRegistrar.java index 32edc311bf..c26ddc9eea 100644 --- a/spring-boot/src/main/java/org/springframework/boot/web/servlet/ErrorPageRegistrar.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/server/ErrorPageRegistrar.java @@ -14,13 +14,13 @@ * limitations under the License. */ -package org.springframework.boot.web.servlet; +package org.springframework.boot.web.server; /** * Interface to be implemented by types that register {@link ErrorPage ErrorPages}. * * @author Phillip Webb - * @since 1.4.0 + * @since 2.0.0 */ @FunctionalInterface public interface ErrorPageRegistrar { diff --git a/spring-boot/src/main/java/org/springframework/boot/web/servlet/ErrorPageRegistrarBeanPostProcessor.java b/spring-boot/src/main/java/org/springframework/boot/web/server/ErrorPageRegistrarBeanPostProcessor.java similarity index 97% rename from spring-boot/src/main/java/org/springframework/boot/web/servlet/ErrorPageRegistrarBeanPostProcessor.java rename to spring-boot/src/main/java/org/springframework/boot/web/server/ErrorPageRegistrarBeanPostProcessor.java index 3b3b96300a..186b3d6604 100644 --- a/spring-boot/src/main/java/org/springframework/boot/web/servlet/ErrorPageRegistrarBeanPostProcessor.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/server/ErrorPageRegistrarBeanPostProcessor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.web.servlet; +package org.springframework.boot.web.server; import java.util.ArrayList; import java.util.Collection; @@ -35,7 +35,7 @@ import org.springframework.util.Assert; * * @author Phillip Webb * @author Stephane Nicoll - * @since 1.4.0 + * @since 2.0.0 */ public class ErrorPageRegistrarBeanPostProcessor implements BeanPostProcessor, BeanFactoryAware { diff --git a/spring-boot/src/main/java/org/springframework/boot/web/servlet/ErrorPageRegistry.java b/spring-boot/src/main/java/org/springframework/boot/web/server/ErrorPageRegistry.java similarity index 93% rename from spring-boot/src/main/java/org/springframework/boot/web/servlet/ErrorPageRegistry.java rename to spring-boot/src/main/java/org/springframework/boot/web/server/ErrorPageRegistry.java index 4b019981d7..c6d3899cbf 100644 --- a/spring-boot/src/main/java/org/springframework/boot/web/servlet/ErrorPageRegistry.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/server/ErrorPageRegistry.java @@ -14,13 +14,13 @@ * limitations under the License. */ -package org.springframework.boot.web.servlet; +package org.springframework.boot.web.server; /** * Interface for a registry that holds {@link ErrorPage ErrorPages}. * * @author Phillip Webb - * @since 1.4.0 + * @since 2.0.0 */ @FunctionalInterface public interface ErrorPageRegistry { diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/LocalServerPort.java b/spring-boot/src/main/java/org/springframework/boot/web/server/LocalServerPort.java similarity index 91% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/LocalServerPort.java rename to spring-boot/src/main/java/org/springframework/boot/web/server/LocalServerPort.java index c7fbd21d27..fa27360f29 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/LocalServerPort.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/server/LocalServerPort.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded; +package org.springframework.boot.web.server; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; @@ -31,7 +31,7 @@ import org.springframework.beans.factory.annotation.Value; * * @author Anand Shah * @author Stephane Nicoll - * @since 1.4.0 + * @since 2.0.0 */ @Target({ ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE }) diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/MimeMappings.java b/spring-boot/src/main/java/org/springframework/boot/web/server/MimeMappings.java similarity index 97% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/MimeMappings.java rename to spring-boot/src/main/java/org/springframework/boot/web/server/MimeMappings.java index 06f2215663..68df3bf7eb 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/MimeMappings.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/server/MimeMappings.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded; +package org.springframework.boot.web.server; import java.util.Collection; import java.util.Collections; @@ -22,16 +22,16 @@ import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; -import org.springframework.boot.context.embedded.MimeMappings.Mapping; import org.springframework.util.Assert; /** - * Simple container-independent abstraction for servlet mime mappings. Roughly equivalent - * to the {@literal <mime-mapping>} element traditionally found in web.xml. + * Simple server-independent abstraction for mime mappings. Roughly equivalent to the + * {@literal <mime-mapping>} element traditionally found in web.xml. * * @author Phillip Webb + * @since 2.0.0 */ -public final class MimeMappings implements Iterable { +public final class MimeMappings implements Iterable { /** * Default mime mapping commonly used. diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/PortInUseException.java b/spring-boot/src/main/java/org/springframework/boot/web/server/PortInUseException.java similarity index 79% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/PortInUseException.java rename to spring-boot/src/main/java/org/springframework/boot/web/server/PortInUseException.java index 390ec96bdc..8f6fc108bd 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/PortInUseException.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/server/PortInUseException.java @@ -14,16 +14,16 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded; +package org.springframework.boot.web.server; /** - * A {@code PortInUseException} is thrown when an embedded servlet container fails to - * start due to a port already being in use. + * A {@code PortInUseException} is thrown when a web server fails to start due to a port + * already being in use. * * @author Andy Wilkinson - * @since 1.4.0 + * @since 2.0.0 */ -public class PortInUseException extends EmbeddedWebServerException { +public class PortInUseException extends WebServerException { private final int port; diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/Ssl.java b/spring-boot/src/main/java/org/springframework/boot/web/server/Ssl.java similarity index 96% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/Ssl.java rename to spring-boot/src/main/java/org/springframework/boot/web/server/Ssl.java index bde342cf0c..1e5ef70391 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/Ssl.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/server/Ssl.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -14,14 +14,14 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded; +package org.springframework.boot.web.server; /** - * Simple container-independent abstraction for SSL configuration. + * Simple server-independent abstraction for SSL configuration. * * @author Andy Wilkinson * @author Vladimir Tsanev - * @since 1.1.7 + * @since 2.0.0 */ public class Ssl { diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/SslStoreProvider.java b/spring-boot/src/main/java/org/springframework/boot/web/server/SslStoreProvider.java similarity index 83% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/SslStoreProvider.java rename to spring-boot/src/main/java/org/springframework/boot/web/server/SslStoreProvider.java index 476aa1f384..f7fc39a469 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/SslStoreProvider.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/server/SslStoreProvider.java @@ -14,16 +14,16 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded; +package org.springframework.boot.web.server; import java.security.KeyStore; /** - * Interface to provide SSL key stores for an {@link EmbeddedWebServer} to use. Can be - * used when file based key stores cannot be used. + * Interface to provide SSL key stores for an {@link WebServer} to use. Can be used when + * file based key stores cannot be used. * * @author Phillip Webb - * @since 1.4.0 + * @since 2.0.0 */ public interface SslStoreProvider { diff --git a/spring-boot/src/main/java/org/springframework/boot/web/server/WebServer.java b/spring-boot/src/main/java/org/springframework/boot/web/server/WebServer.java new file mode 100644 index 0000000000..33a95922a3 --- /dev/null +++ b/spring-boot/src/main/java/org/springframework/boot/web/server/WebServer.java @@ -0,0 +1,50 @@ +/* + * Copyright 2012-2017 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.web.server; + +/** + * Simple interface that represents a fully configured web server (for example Tomcat, + * Jetty, Netty). Allows the server to be {@link #start() started} and {@link #stop() + * stopped}. + * + * @author Phillip Webb + * @author Dave Syer + * @since 2.0.0 + */ +public interface WebServer { + + /** + * Starts the web server. Calling this method on an already started server has no + * effect. + * @throws WebServerException if the server cannot be started + */ + void start() throws WebServerException; + + /** + * Stops the web server. Calling this method on an already stopped server has no + * effect. + * @throws WebServerException if the server cannot be stopped + */ + void stop() throws WebServerException; + + /** + * Return the port this server is listening on. + * @return the port (or -1 if none) + */ + int getPort(); + +} diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/EmbeddedWebServerException.java b/spring-boot/src/main/java/org/springframework/boot/web/server/WebServerException.java similarity index 74% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/EmbeddedWebServerException.java rename to spring-boot/src/main/java/org/springframework/boot/web/server/WebServerException.java index 40d7cca29a..45ffaa715b 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/EmbeddedWebServerException.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/server/WebServerException.java @@ -14,17 +14,18 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded; +package org.springframework.boot.web.server; /** - * Exceptions thrown by an embedded servlet container. + * Exceptions thrown by an web server. * * @author Phillip Webb + * @since 2.0.0 */ @SuppressWarnings("serial") -public class EmbeddedWebServerException extends RuntimeException { +public class WebServerException extends RuntimeException { - public EmbeddedWebServerException(String message, Throwable cause) { + public WebServerException(String message, Throwable cause) { super(message, cause); } diff --git a/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletComponentRegisteringPostProcessor.java b/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletComponentRegisteringPostProcessor.java index 1d3448461d..4d9b41ff70 100644 --- a/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletComponentRegisteringPostProcessor.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletComponentRegisteringPostProcessor.java @@ -64,7 +64,7 @@ class ServletComponentRegisteringPostProcessor @Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { - if (isRunningInEmbeddedContainer()) { + if (isRunningInEmbeddedWebServer()) { ClassPathScanningCandidateComponentProvider componentProvider = createComponentProvider(); for (String packageToScan : this.packagesToScan) { scanPackage(componentProvider, packageToScan); @@ -86,7 +86,7 @@ class ServletComponentRegisteringPostProcessor } } - private boolean isRunningInEmbeddedContainer() { + private boolean isRunningInEmbeddedWebServer() { return this.applicationContext instanceof WebApplicationContext && ((WebApplicationContext) this.applicationContext) .getServletContext() == null; diff --git a/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletComponentScan.java b/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletComponentScan.java index 6659d233c1..4e76058c7e 100644 --- a/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletComponentScan.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletComponentScan.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -32,7 +32,7 @@ import org.springframework.core.annotation.AliasFor; /** * Enables scanning for Servlet components ({@link WebFilter filters}, {@link WebServlet * servlets}, and {@link WebListener listeners}). Scanning is only performed when using an - * embedded Servlet container. + * embedded web server. *

    * Typically, one of {@code value}, {@code basePackages}, or {@code basePackageClasses} * should be specified to control the packages to be scanned for components. In their diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/AnnotationConfigEmbeddedWebApplicationContext.java b/spring-boot/src/main/java/org/springframework/boot/web/servlet/context/AnnotationConfigServletWebServerApplicationContext.java similarity index 88% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/AnnotationConfigEmbeddedWebApplicationContext.java rename to spring-boot/src/main/java/org/springframework/boot/web/servlet/context/AnnotationConfigServletWebServerApplicationContext.java index 2d52ef0ea3..0b94b55b91 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/AnnotationConfigEmbeddedWebApplicationContext.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/servlet/context/AnnotationConfigServletWebServerApplicationContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2017 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded; +package org.springframework.boot.web.servlet.context; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.BeanNameGenerator; @@ -29,7 +29,7 @@ import org.springframework.util.Assert; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; /** - * {@link EmbeddedWebApplicationContext} that accepts annotated classes as input - in + * {@link ServletWebServerApplicationContext} that accepts annotated classes as input - in * particular {@link org.springframework.context.annotation.Configuration @Configuration} * -annotated classes, but also plain {@link Component @Component} classes and JSR-330 * compliant classes using {@code javax.inject} annotations. Allows for registering @@ -43,11 +43,11 @@ import org.springframework.web.context.support.AnnotationConfigWebApplicationCon * @author Phillip Webb * @see #register(Class...) * @see #scan(String...) - * @see EmbeddedWebApplicationContext + * @see ServletWebServerApplicationContext * @see AnnotationConfigWebApplicationContext */ -public class AnnotationConfigEmbeddedWebApplicationContext - extends EmbeddedWebApplicationContext { +public class AnnotationConfigServletWebServerApplicationContext + extends ServletWebServerApplicationContext { private final AnnotatedBeanDefinitionReader reader; @@ -58,34 +58,34 @@ public class AnnotationConfigEmbeddedWebApplicationContext private String[] basePackages; /** - * Create a new {@link AnnotationConfigEmbeddedWebApplicationContext} that needs to be + * Create a new {@link AnnotationConfigServletWebServerApplicationContext} that needs to be * populated through {@link #register} calls and then manually {@linkplain #refresh * refreshed}. */ - public AnnotationConfigEmbeddedWebApplicationContext() { + public AnnotationConfigServletWebServerApplicationContext() { this.reader = new AnnotatedBeanDefinitionReader(this); this.scanner = new ClassPathBeanDefinitionScanner(this); } /** - * Create a new {@link AnnotationConfigEmbeddedWebApplicationContext}, deriving bean + * Create a new {@link AnnotationConfigServletWebServerApplicationContext}, deriving bean * definitions from the given annotated classes and automatically refreshing the * context. * @param annotatedClasses one or more annotated classes, e.g. {@code @Configuration} * classes */ - public AnnotationConfigEmbeddedWebApplicationContext(Class... annotatedClasses) { + public AnnotationConfigServletWebServerApplicationContext(Class... annotatedClasses) { this(); register(annotatedClasses); refresh(); } /** - * Create a new {@link AnnotationConfigEmbeddedWebApplicationContext}, scanning for + * Create a new {@link AnnotationConfigServletWebServerApplicationContext}, scanning for * bean definitions in the given packages and automatically refreshing the context. * @param basePackages the packages to check for annotated classes */ - public AnnotationConfigEmbeddedWebApplicationContext(String... basePackages) { + public AnnotationConfigServletWebServerApplicationContext(String... basePackages) { this(); scan(basePackages); refresh(); diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/EmbeddedWebApplicationContext.java b/spring-boot/src/main/java/org/springframework/boot/web/servlet/context/ServletWebServerApplicationContext.java similarity index 72% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/EmbeddedWebApplicationContext.java rename to spring-boot/src/main/java/org/springframework/boot/web/servlet/context/ServletWebServerApplicationContext.java index b59f000338..03d92ad23e 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/EmbeddedWebApplicationContext.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/servlet/context/ServletWebServerApplicationContext.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded; +package org.springframework.boot.web.servlet.context; import java.util.Collection; import java.util.Collections; @@ -36,10 +36,12 @@ import org.apache.commons.logging.LogFactory; import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.config.Scope; +import org.springframework.boot.web.server.WebServer; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.boot.web.servlet.ServletContextInitializer; import org.springframework.boot.web.servlet.ServletContextInitializerBeans; import org.springframework.boot.web.servlet.ServletRegistrationBean; +import org.springframework.boot.web.servlet.server.ServletWebServerFactory; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextException; import org.springframework.core.io.Resource; @@ -55,20 +57,18 @@ import org.springframework.web.context.support.WebApplicationContextUtils; /** * A {@link WebApplicationContext} that can be used to bootstrap itself from a contained - * {@link EmbeddedServletContainerFactory} bean. + * {@link ServletWebServerFactory} bean. *

    - * This context will create, initialize and run an {@link EmbeddedWebServer} by searching - * for a single {@link EmbeddedServletContainerFactory} bean within the - * {@link ApplicationContext} itself. The {@link EmbeddedServletContainerFactory} is free - * to use standard Spring concepts (such as dependency injection, lifecycle callbacks and - * property placeholder variables). + * This context will create, initialize and run an {@link WebServer} by searching for a + * single {@link ServletWebServerFactory} bean within the {@link ApplicationContext} + * itself. The {@link ServletWebServerFactory} is free to use standard Spring concepts + * (such as dependency injection, lifecycle callbacks and property placeholder variables). *

    * In addition, any {@link Servlet} or {@link Filter} beans defined in the context will be - * automatically registered with the embedded Servlet container. In the case of a single - * Servlet bean, the '/' mapping will be used. If multiple Servlet beans are found then - * the lowercase bean name will be used as a mapping prefix. Any Servlet named - * 'dispatcherServlet' will always be mapped to '/'. Filter beans will be mapped to all - * URLs ('/*'). + * automatically registered with the web server. In the case of a single Servlet bean, the + * '/' mapping will be used. If multiple Servlet beans are found then the lowercase bean + * name will be used as a mapping prefix. Any Servlet named 'dispatcherServlet' will + * always be mapped to '/'. Filter beans will be mapped to all URLs ('/*'). *

    * For more advanced configuration, the context can instead define beans that implement * the {@link ServletContextInitializer} interface (most often @@ -77,19 +77,19 @@ import org.springframework.web.context.support.WebApplicationContextUtils; * automatic Servlet and Filter bean registration. *

    * Although this context can be used directly, most developers should consider using the - * {@link AnnotationConfigEmbeddedWebApplicationContext} or - * {@link XmlEmbeddedWebApplicationContext} variants. + * {@link AnnotationConfigServletWebServerApplicationContext} or + * {@link XmlServletWebServerApplicationContext} variants. * * @author Phillip Webb * @author Dave Syer - * @see AnnotationConfigEmbeddedWebApplicationContext - * @see XmlEmbeddedWebApplicationContext - * @see EmbeddedServletContainerFactory + * @see AnnotationConfigServletWebServerApplicationContext + * @see XmlServletWebServerApplicationContext + * @see ServletWebServerFactory */ -public class EmbeddedWebApplicationContext extends GenericWebApplicationContext { +public class ServletWebServerApplicationContext extends GenericWebApplicationContext { private static final Log logger = LogFactory - .getLog(EmbeddedWebApplicationContext.class); + .getLog(ServletWebServerApplicationContext.class); /** * Constant value for the DispatcherServlet bean name. A Servlet bean with this name @@ -99,7 +99,7 @@ public class EmbeddedWebApplicationContext extends GenericWebApplicationContext */ public static final String DISPATCHER_SERVLET_NAME = "dispatcherServlet"; - private volatile EmbeddedWebServer embeddedWebServer; + private volatile WebServer webServer; private ServletConfig servletConfig; @@ -122,7 +122,7 @@ public class EmbeddedWebApplicationContext extends GenericWebApplicationContext super.refresh(); } catch (RuntimeException ex) { - stopAndReleaseEmbeddedServletContainer(); + stopAndReleaseWebServer(); throw ex; } } @@ -131,41 +131,38 @@ public class EmbeddedWebApplicationContext extends GenericWebApplicationContext protected void onRefresh() { super.onRefresh(); try { - createEmbeddedServletContainer(); + createWebServer(); } catch (Throwable ex) { - throw new ApplicationContextException("Unable to start embedded container", - ex); + throw new ApplicationContextException("Unable to start web server", ex); } } @Override protected void finishRefresh() { super.finishRefresh(); - EmbeddedWebServer localContainer = startEmbeddedServletContainer(); - if (localContainer != null) { - publishEvent( - new EmbeddedServletContainerInitializedEvent(this, localContainer)); + WebServer webServer = startWebServer(); + if (webServer != null) { + publishEvent(new ServletWebServerInitializedEvent(this, webServer)); } } @Override protected void onClose() { super.onClose(); - stopAndReleaseEmbeddedServletContainer(); + stopAndReleaseWebServer(); } - private void createEmbeddedServletContainer() { - EmbeddedWebServer localContainer = this.embeddedWebServer; - ServletContext localServletContext = getServletContext(); - if (localContainer == null && localServletContext == null) { - EmbeddedServletContainerFactory containerFactory = getEmbeddedServletContainerFactory(); - this.embeddedWebServer = containerFactory - .getEmbeddedServletContainer(getSelfInitializer()); + private void createWebServer() { + WebServer webServer = this.webServer; + ServletContext servletContext = getServletContext(); + if (webServer == null && servletContext == null) { + ServletWebServerFactory factory = getWebServerFactory(); + this.webServer = factory.getWebServer(getSelfInitializer()); } - else if (localServletContext != null) { + else if (servletContext != null) { try { - getSelfInitializer().onStartup(localServletContext); + getSelfInitializer().onStartup(servletContext); } catch (ServletException ex) { throw new ApplicationContextException("Cannot initialize servlet context", @@ -176,35 +173,34 @@ public class EmbeddedWebApplicationContext extends GenericWebApplicationContext } /** - * Returns the {@link EmbeddedServletContainerFactory} that should be used to create - * the embedded servlet container. By default this method searches for a suitable bean - * in the context itself. - * @return a {@link EmbeddedServletContainerFactory} (never {@code null}) + * Returns the {@link ServletWebServerFactory} that should be used to create the + * embedded {@link WebServer}. By default this method searches for a suitable bean in + * the context itself. + * @return a {@link ServletWebServerFactory} (never {@code null}) */ - protected EmbeddedServletContainerFactory getEmbeddedServletContainerFactory() { + protected ServletWebServerFactory getWebServerFactory() { // Use bean names so that we don't consider the hierarchy String[] beanNames = getBeanFactory() - .getBeanNamesForType(EmbeddedServletContainerFactory.class); + .getBeanNamesForType(ServletWebServerFactory.class); if (beanNames.length == 0) { throw new ApplicationContextException( - "Unable to start EmbeddedWebApplicationContext due to missing " - + "EmbeddedServletContainerFactory bean."); + "Unable to start ServletWebServerApplicationContext due to missing " + + "ServletWebServerFactory bean."); } if (beanNames.length > 1) { throw new ApplicationContextException( - "Unable to start EmbeddedWebApplicationContext due to multiple " - + "EmbeddedServletContainerFactory beans : " + "Unable to start ServletWebServerApplicationContext due to multiple " + + "ServletWebServerFactory beans : " + StringUtils.arrayToCommaDelimitedString(beanNames)); } - return getBeanFactory().getBean(beanNames[0], - EmbeddedServletContainerFactory.class); + return getBeanFactory().getBean(beanNames[0], ServletWebServerFactory.class); } /** * Returns the {@link ServletContextInitializer} that will be used to complete the * setup of this {@link WebApplicationContext}. * @return the self initializer - * @see #prepareEmbeddedWebApplicationContext(ServletContext) + * @see #prepareWebApplicationContext(ServletContext) */ private org.springframework.boot.web.servlet.ServletContextInitializer getSelfInitializer() { return new ServletContextInitializer() { @@ -216,7 +212,7 @@ public class EmbeddedWebApplicationContext extends GenericWebApplicationContext } private void selfInitialize(ServletContext servletContext) throws ServletException { - prepareEmbeddedWebApplicationContext(servletContext); + prepareWebApplicationContext(servletContext); ConfigurableListableBeanFactory beanFactory = getBeanFactory(); ExistingWebApplicationScopes existingScopes = new ExistingWebApplicationScopes( beanFactory); @@ -232,7 +228,7 @@ public class EmbeddedWebApplicationContext extends GenericWebApplicationContext /** * Returns {@link ServletContextInitializer}s that should be used with the embedded - * Servlet context. By default this method will first attempt to find + * web server. By default this method will first attempt to find * {@link ServletContextInitializer}, {@link Servlet}, {@link Filter} and certain * {@link EventListener} beans. * @return the servlet initializer beans @@ -248,7 +244,7 @@ public class EmbeddedWebApplicationContext extends GenericWebApplicationContext * functionality usually provided by a {@link ContextLoaderListener}. * @param servletContext the operational servlet context */ - protected void prepareEmbeddedWebApplicationContext(ServletContext servletContext) { + protected void prepareWebApplicationContext(ServletContext servletContext) { Object rootContext = servletContext.getAttribute( WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); if (rootContext != null) { @@ -291,20 +287,20 @@ public class EmbeddedWebApplicationContext extends GenericWebApplicationContext } } - private EmbeddedWebServer startEmbeddedServletContainer() { - EmbeddedWebServer localContainer = this.embeddedWebServer; - if (localContainer != null) { - localContainer.start(); + private WebServer startWebServer() { + WebServer webServer = this.webServer; + if (webServer != null) { + webServer.start(); } - return localContainer; + return webServer; } - private void stopAndReleaseEmbeddedServletContainer() { - EmbeddedWebServer localContainer = this.embeddedWebServer; - if (localContainer != null) { + private void stopAndReleaseWebServer() { + WebServer webServer = this.webServer; + if (webServer != null) { try { - localContainer.stop(); - this.embeddedWebServer = null; + webServer.stop(); + this.webServer = null; } catch (Exception ex) { throw new IllegalStateException(ex); @@ -341,12 +337,12 @@ public class EmbeddedWebApplicationContext extends GenericWebApplicationContext } /** - * Returns the {@link EmbeddedWebServer} that was created by the context or - * {@code null} if the container has not yet been created. - * @return the embedded servlet container + * Returns the {@link WebServer} that was created by the context or {@code null} if + * the server has not yet been created. + * @return the embedded web server */ - public EmbeddedWebServer getEmbeddedWebServer() { - return this.embeddedWebServer; + public WebServer getWebServer() { + return this.webServer; } /** diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/EmbeddedServletContainerInitializedEvent.java b/spring-boot/src/main/java/org/springframework/boot/web/servlet/context/ServletWebServerInitializedEvent.java similarity index 57% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/EmbeddedServletContainerInitializedEvent.java rename to spring-boot/src/main/java/org/springframework/boot/web/servlet/context/ServletWebServerInitializedEvent.java index 5b758d5d5e..83a6c98d3d 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/EmbeddedServletContainerInitializedEvent.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/servlet/context/ServletWebServerInitializedEvent.java @@ -14,14 +14,16 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded; +package org.springframework.boot.web.servlet.context; +import org.springframework.boot.web.context.WebServerInitializedEvent; +import org.springframework.boot.web.server.WebServer; import org.springframework.util.StringUtils; /** - * Event to be published after the {@link EmbeddedWebApplicationContext} is refreshed and - * the {@link EmbeddedWebServer} is ready. Useful for obtaining the local port of a - * running server. + * Event to be published after the {@link ServletWebServerApplicationContext} is refreshed + * and the {@link WebServer} is ready. Useful for obtaining the local port of a running + * server. * *

    * Normally it will have been started, but listeners are free to inspect the server and @@ -30,25 +32,24 @@ import org.springframework.util.StringUtils; * @author Dave Syer */ @SuppressWarnings("serial") -public class EmbeddedServletContainerInitializedEvent - extends EmbeddedWebServerInitializedEvent { +public class ServletWebServerInitializedEvent extends WebServerInitializedEvent { - private final EmbeddedWebApplicationContext applicationContext; + private final ServletWebServerApplicationContext applicationContext; - public EmbeddedServletContainerInitializedEvent( - EmbeddedWebApplicationContext applicationContext, EmbeddedWebServer source) { + public ServletWebServerInitializedEvent( + ServletWebServerApplicationContext applicationContext, WebServer source) { super(source); this.applicationContext = applicationContext; } /** - * Access the application context that the container was created in. Sometimes it is + * Access the application context that the server was created in. Sometimes it is * prudent to check that this matches expectations (like being equal to the current - * context) before acting on the server container itself. - * @return the applicationContext that the container was created from + * context) before acting on the server server itself. + * @return the applicationContext that the server was created from */ @Override - public EmbeddedWebApplicationContext getApplicationContext() { + public ServletWebServerApplicationContext getApplicationContext() { return this.applicationContext; } diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/WebApplicationContextServletContextAwareProcessor.java b/spring-boot/src/main/java/org/springframework/boot/web/servlet/context/WebApplicationContextServletContextAwareProcessor.java similarity index 94% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/WebApplicationContextServletContextAwareProcessor.java rename to spring-boot/src/main/java/org/springframework/boot/web/servlet/context/WebApplicationContextServletContextAwareProcessor.java index c59b651e62..2acc7be9bb 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/WebApplicationContextServletContextAwareProcessor.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/servlet/context/WebApplicationContextServletContextAwareProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2017 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded; +package org.springframework.boot.web.servlet.context; import javax.servlet.ServletConfig; import javax.servlet.ServletContext; diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/XmlEmbeddedWebApplicationContext.java b/spring-boot/src/main/java/org/springframework/boot/web/servlet/context/XmlServletWebServerApplicationContext.java similarity index 75% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/XmlEmbeddedWebApplicationContext.java rename to spring-boot/src/main/java/org/springframework/boot/web/servlet/context/XmlServletWebServerApplicationContext.java index a21d7daa97..f21599782f 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/XmlEmbeddedWebApplicationContext.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/servlet/context/XmlServletWebServerApplicationContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2017 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded; +package org.springframework.boot.web.servlet.context; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; import org.springframework.core.env.ConfigurableEnvironment; @@ -23,7 +23,7 @@ import org.springframework.core.io.Resource; import org.springframework.web.context.support.XmlWebApplicationContext; /** - * {@link EmbeddedWebApplicationContext} which takes its configuration from XML documents, + * {@link ServletWebServerApplicationContext} which takes its configuration from XML documents, * understood by an {@link org.springframework.beans.factory.xml.XmlBeanDefinitionReader}. *

    * Note: In case of multiple config locations, later bean definitions will override ones @@ -33,49 +33,49 @@ import org.springframework.web.context.support.XmlWebApplicationContext; * @author Phillip Webb * @see #setNamespace * @see #setConfigLocations - * @see EmbeddedWebApplicationContext + * @see ServletWebServerApplicationContext * @see XmlWebApplicationContext */ -public class XmlEmbeddedWebApplicationContext extends EmbeddedWebApplicationContext { +public class XmlServletWebServerApplicationContext extends ServletWebServerApplicationContext { private final XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this); /** - * Create a new {@link XmlEmbeddedWebApplicationContext} that needs to be + * Create a new {@link XmlServletWebServerApplicationContext} that needs to be * {@linkplain #load loaded} and then manually {@link #refresh refreshed}. */ - public XmlEmbeddedWebApplicationContext() { + public XmlServletWebServerApplicationContext() { this.reader.setEnvironment(this.getEnvironment()); } /** - * Create a new {@link XmlEmbeddedWebApplicationContext}, loading bean definitions - * from the given resources and automatically refreshing the context. + * Create a new {@link XmlServletWebServerApplicationContext}, loading bean definitions from + * the given resources and automatically refreshing the context. * @param resources the resources to load from */ - public XmlEmbeddedWebApplicationContext(Resource... resources) { + public XmlServletWebServerApplicationContext(Resource... resources) { load(resources); refresh(); } /** - * Create a new {@link XmlEmbeddedWebApplicationContext}, loading bean definitions - * from the given resource locations and automatically refreshing the context. + * Create a new {@link XmlServletWebServerApplicationContext}, loading bean definitions from + * the given resource locations and automatically refreshing the context. * @param resourceLocations the resources to load from */ - public XmlEmbeddedWebApplicationContext(String... resourceLocations) { + public XmlServletWebServerApplicationContext(String... resourceLocations) { load(resourceLocations); refresh(); } /** - * Create a new {@link XmlEmbeddedWebApplicationContext}, loading bean definitions - * from the given resource locations and automatically refreshing the context. + * Create a new {@link XmlServletWebServerApplicationContext}, loading bean definitions from + * the given resource locations and automatically refreshing the context. * @param relativeClass class whose package will be used as a prefix when loading each * specified resource name * @param resourceNames relatively-qualified names of resources to load */ - public XmlEmbeddedWebApplicationContext(Class relativeClass, + public XmlServletWebServerApplicationContext(Class relativeClass, String... resourceNames) { load(relativeClass, resourceNames); refresh(); diff --git a/spring-boot/src/main/java/org/springframework/boot/web/servlet/context/package-info.java b/spring-boot/src/main/java/org/springframework/boot/web/servlet/context/package-info.java new file mode 100644 index 0000000000..ea175fb3a9 --- /dev/null +++ b/spring-boot/src/main/java/org/springframework/boot/web/servlet/context/package-info.java @@ -0,0 +1,21 @@ +/* + * Copyright 2012-2017 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. + */ + +/** + * Servlet based web integrations with Spring's + * {@link org.springframework.web.context.WebApplicationContext WebApplicationContext}. + */ +package org.springframework.boot.web.servlet.context; diff --git a/spring-boot/src/main/java/org/springframework/boot/web/filter/ApplicationContextHeaderFilter.java b/spring-boot/src/main/java/org/springframework/boot/web/servlet/filter/ApplicationContextHeaderFilter.java similarity index 93% rename from spring-boot/src/main/java/org/springframework/boot/web/filter/ApplicationContextHeaderFilter.java rename to spring-boot/src/main/java/org/springframework/boot/web/servlet/filter/ApplicationContextHeaderFilter.java index 56b06180b4..799f60f0f2 100644 --- a/spring-boot/src/main/java/org/springframework/boot/web/filter/ApplicationContextHeaderFilter.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/servlet/filter/ApplicationContextHeaderFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.web.filter; +package org.springframework.boot.web.servlet.filter; import java.io.IOException; @@ -32,7 +32,7 @@ import org.springframework.web.filter.OncePerRequestFilter; * * @author Phillip Webb * @author Venil Noronha - * @since 1.4.0 + * @since 2.0.0 */ public class ApplicationContextHeaderFilter extends OncePerRequestFilter { diff --git a/spring-boot/src/main/java/org/springframework/boot/web/filter/OrderedCharacterEncodingFilter.java b/spring-boot/src/main/java/org/springframework/boot/web/servlet/filter/OrderedCharacterEncodingFilter.java similarity index 90% rename from spring-boot/src/main/java/org/springframework/boot/web/filter/OrderedCharacterEncodingFilter.java rename to spring-boot/src/main/java/org/springframework/boot/web/servlet/filter/OrderedCharacterEncodingFilter.java index 3597d9efe2..982aabd414 100644 --- a/spring-boot/src/main/java/org/springframework/boot/web/filter/OrderedCharacterEncodingFilter.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/servlet/filter/OrderedCharacterEncodingFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.web.filter; +package org.springframework.boot.web.servlet.filter; import org.springframework.core.Ordered; import org.springframework.web.filter.CharacterEncodingFilter; @@ -23,7 +23,7 @@ import org.springframework.web.filter.CharacterEncodingFilter; * {@link CharacterEncodingFilter} that also implements {@link Ordered}. * * @author Phillip Webb - * @since 1.4.0 + * @since 2.0.0 */ public class OrderedCharacterEncodingFilter extends CharacterEncodingFilter implements Ordered { diff --git a/spring-boot/src/main/java/org/springframework/boot/web/filter/OrderedHiddenHttpMethodFilter.java b/spring-boot/src/main/java/org/springframework/boot/web/servlet/filter/OrderedHiddenHttpMethodFilter.java similarity index 91% rename from spring-boot/src/main/java/org/springframework/boot/web/filter/OrderedHiddenHttpMethodFilter.java rename to spring-boot/src/main/java/org/springframework/boot/web/servlet/filter/OrderedHiddenHttpMethodFilter.java index 2089654fac..cfff394593 100644 --- a/spring-boot/src/main/java/org/springframework/boot/web/filter/OrderedHiddenHttpMethodFilter.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/servlet/filter/OrderedHiddenHttpMethodFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.web.filter; +package org.springframework.boot.web.servlet.filter; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.core.Ordered; @@ -24,7 +24,7 @@ import org.springframework.web.filter.HiddenHttpMethodFilter; * {@link HiddenHttpMethodFilter} that also implements {@link Ordered}. * * @author Phillip Webb - * @since 1.4.0 + * @since 2.0.0 */ public class OrderedHiddenHttpMethodFilter extends HiddenHttpMethodFilter implements Ordered { diff --git a/spring-boot/src/main/java/org/springframework/boot/web/filter/OrderedHttpPutFormContentFilter.java b/spring-boot/src/main/java/org/springframework/boot/web/servlet/filter/OrderedHttpPutFormContentFilter.java similarity index 91% rename from spring-boot/src/main/java/org/springframework/boot/web/filter/OrderedHttpPutFormContentFilter.java rename to spring-boot/src/main/java/org/springframework/boot/web/servlet/filter/OrderedHttpPutFormContentFilter.java index bb2bf3ab3d..e3ca4fa9a6 100644 --- a/spring-boot/src/main/java/org/springframework/boot/web/filter/OrderedHttpPutFormContentFilter.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/servlet/filter/OrderedHttpPutFormContentFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.web.filter; +package org.springframework.boot.web.servlet.filter; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.core.Ordered; @@ -24,7 +24,7 @@ import org.springframework.web.filter.HttpPutFormContentFilter; * {@link HttpPutFormContentFilter} that also implements {@link Ordered}. * * @author Joao Pedro Evangelista - * @since 1.4.0 + * @since 2.0.0 */ public class OrderedHttpPutFormContentFilter extends HttpPutFormContentFilter implements Ordered { diff --git a/spring-boot/src/main/java/org/springframework/boot/web/filter/OrderedRequestContextFilter.java b/spring-boot/src/main/java/org/springframework/boot/web/servlet/filter/OrderedRequestContextFilter.java similarity index 91% rename from spring-boot/src/main/java/org/springframework/boot/web/filter/OrderedRequestContextFilter.java rename to spring-boot/src/main/java/org/springframework/boot/web/servlet/filter/OrderedRequestContextFilter.java index ae853a0817..f2e13e7142 100644 --- a/spring-boot/src/main/java/org/springframework/boot/web/filter/OrderedRequestContextFilter.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/servlet/filter/OrderedRequestContextFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.web.filter; +package org.springframework.boot.web.servlet.filter; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.core.Ordered; @@ -24,7 +24,7 @@ import org.springframework.web.filter.RequestContextFilter; * {@link RequestContextFilter} that also implements {@link Ordered}. * * @author Phillip Webb - * @since 1.4.0 + * @since 2.0.0 */ public class OrderedRequestContextFilter extends RequestContextFilter implements Ordered { diff --git a/spring-boot/src/main/java/org/springframework/boot/web/filter/package-info.java b/spring-boot/src/main/java/org/springframework/boot/web/servlet/filter/package-info.java similarity index 85% rename from spring-boot/src/main/java/org/springframework/boot/web/filter/package-info.java rename to spring-boot/src/main/java/org/springframework/boot/web/servlet/filter/package-info.java index ed8d21092c..cfcb3a069b 100644 --- a/spring-boot/src/main/java/org/springframework/boot/web/filter/package-info.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/servlet/filter/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -17,4 +17,4 @@ /** * Spring Boot specific {@link javax.servlet.Filter} implementations. */ -package org.springframework.boot.web.filter; +package org.springframework.boot.web.servlet.filter; diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/AbstractConfigurableEmbeddedServletContainer.java b/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/AbstractConfigurableServletWebServerFactory.java similarity index 84% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/AbstractConfigurableEmbeddedServletContainer.java rename to spring-boot/src/main/java/org/springframework/boot/web/servlet/server/AbstractConfigurableServletWebServerFactory.java index a6d32682f8..07b9b5be3b 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/AbstractConfigurableEmbeddedServletContainer.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/AbstractConfigurableServletWebServerFactory.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded; +package org.springframework.boot.web.servlet.server; import java.io.File; import java.net.InetAddress; @@ -29,13 +29,17 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; -import org.springframework.boot.web.servlet.ErrorPage; +import org.springframework.boot.web.server.Compression; +import org.springframework.boot.web.server.ErrorPage; +import org.springframework.boot.web.server.MimeMappings; +import org.springframework.boot.web.server.Ssl; +import org.springframework.boot.web.server.SslStoreProvider; import org.springframework.boot.web.servlet.ServletContextInitializer; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; /** - * Abstract base class for {@link ConfigurableEmbeddedServletContainer} implementations. + * Abstract base class for {@link ConfigurableServletWebServerFactory} implementations. * * @author Phillip Webb * @author Dave Syer @@ -44,10 +48,11 @@ import org.springframework.util.ClassUtils; * @author Ivan Sopov * @author Eddú Meléndez * @author Brian Clozel - * @see AbstractEmbeddedServletContainerFactory + * @since 2.0.0 + * @see AbstractServletWebServerFactory */ -public abstract class AbstractConfigurableEmbeddedServletContainer - implements ConfigurableEmbeddedServletContainer { +public abstract class AbstractConfigurableServletWebServerFactory + implements ConfigurableServletWebServerFactory { private static final int DEFAULT_SESSION_TIMEOUT = (int) TimeUnit.MINUTES .toSeconds(30); @@ -89,27 +94,27 @@ public abstract class AbstractConfigurableEmbeddedServletContainer private Map localeCharsetMappings = new HashMap<>(); /** - * Create a new {@link AbstractConfigurableEmbeddedServletContainer} instance. + * Create a new {@link AbstractConfigurableServletWebServerFactory} instance. */ - public AbstractConfigurableEmbeddedServletContainer() { + public AbstractConfigurableServletWebServerFactory() { } /** - * Create a new {@link AbstractConfigurableEmbeddedServletContainer} instance with the + * Create a new {@link AbstractConfigurableServletWebServerFactory} instance with the * specified port. - * @param port the port number for the embedded servlet container + * @param port the port number for the web server */ - public AbstractConfigurableEmbeddedServletContainer(int port) { + public AbstractConfigurableServletWebServerFactory(int port) { this.port = port; } /** - * Create a new {@link AbstractConfigurableEmbeddedServletContainer} instance with the + * Create a new {@link AbstractConfigurableServletWebServerFactory} instance with the * specified context path and port. - * @param contextPath the context path for the embedded servlet container - * @param port the port number for the embedded servlet container + * @param contextPath the context path for the web server + * @param port the port number for the web server */ - public AbstractConfigurableEmbeddedServletContainer(String contextPath, int port) { + public AbstractConfigurableServletWebServerFactory(String contextPath, int port) { checkContextPath(contextPath); this.contextPath = contextPath; this.port = port; @@ -136,8 +141,8 @@ public abstract class AbstractConfigurableEmbeddedServletContainer } /** - * Returns the context path for the embedded servlet container. The path will start - * with "/" and not end with "/". The root context is represented by an empty string. + * Returns the context path for the web server. The path will start with "/" and not + * end with "/". The root context is represented by an empty string. * @return the context path */ public String getContextPath() { @@ -159,7 +164,7 @@ public abstract class AbstractConfigurableEmbeddedServletContainer } /** - * The port that the embedded server listens on. + * The port that the web server server listens on. * @return the port */ public int getPort() { @@ -172,7 +177,7 @@ public abstract class AbstractConfigurableEmbeddedServletContainer } /** - * Return the address that the embedded container binds to. + * Return the address that the web server binds to. * @return the address */ public InetAddress getAddress() { @@ -365,9 +370,8 @@ public abstract class AbstractConfigurableEmbeddedServletContainer } /** - * Returns whether or not the JSP servlet should be registered with the embedded - * container. - * @return {@code true} if the container should be registered, otherwise {@code false} + * Returns whether or not the JSP servlet should be registered with the web server. + * @return {@code true} if the servlet should be registered, otherwise {@code false} */ protected boolean shouldRegisterJspServlet() { return this.jsp != null && this.jsp.getRegistered() && ClassUtils diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactory.java b/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactory.java similarity index 90% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactory.java rename to spring-boot/src/main/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactory.java index 7eb55655ad..a506b0de95 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactory.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactory.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded; +package org.springframework.boot.web.servlet.server; import java.io.File; import java.io.IOException; @@ -33,32 +33,33 @@ import org.apache.commons.logging.LogFactory; import org.springframework.boot.ApplicationHome; import org.springframework.boot.ApplicationTemp; +import org.springframework.boot.web.server.WebServerException; import org.springframework.util.Assert; /** - * Abstract base class for {@link EmbeddedServletContainerFactory} implementations. + * Abstract base class for {@link ServletWebServerFactory} implementations. * * @author Phillip Webb * @author Dave Syer + * @since 2.0.0 */ -public abstract class AbstractEmbeddedServletContainerFactory - extends AbstractConfigurableEmbeddedServletContainer - implements EmbeddedServletContainerFactory { +public abstract class AbstractServletWebServerFactory extends + AbstractConfigurableServletWebServerFactory implements ServletWebServerFactory { protected final Log logger = LogFactory.getLog(getClass()); private static final String[] COMMON_DOC_ROOTS = { "src/main/webapp", "public", "static" }; - public AbstractEmbeddedServletContainerFactory() { + public AbstractServletWebServerFactory() { super(); } - public AbstractEmbeddedServletContainerFactory(int port) { + public AbstractServletWebServerFactory(int port) { super(port); } - public AbstractEmbeddedServletContainerFactory(String contextPath, int port) { + public AbstractServletWebServerFactory(String contextPath, int port) { super(contextPath, port); } @@ -236,9 +237,9 @@ public abstract class AbstractEmbeddedServletContainerFactory } /** - * Returns the absolute temp dir for given servlet container. - * @param prefix servlet container name - * @return The temp dir for given servlet container. + * Returns the absolute temp dir for given server. + * @param prefix server name + * @return The temp dir for given server. */ protected File createTempDir(String prefix) { try { @@ -249,7 +250,7 @@ public abstract class AbstractEmbeddedServletContainerFactory return tempDir; } catch (IOException ex) { - throw new EmbeddedWebServerException( + throw new WebServerException( "Unable to create tempDir. java.io.tmpdir is set to " + System.getProperty("java.io.tmpdir"), ex); diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/ConfigurableEmbeddedServletContainer.java b/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/ConfigurableServletWebServerFactory.java similarity index 79% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/ConfigurableEmbeddedServletContainer.java rename to spring-boot/src/main/java/org/springframework/boot/web/servlet/server/ConfigurableServletWebServerFactory.java index fb1bff1f28..9208a8b3c3 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/ConfigurableEmbeddedServletContainer.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/ConfigurableServletWebServerFactory.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded; +package org.springframework.boot.web.servlet.server; import java.io.File; import java.nio.charset.Charset; @@ -23,34 +23,35 @@ import java.util.Locale; import java.util.Map; import java.util.concurrent.TimeUnit; +import org.springframework.boot.web.server.ConfigurableWebServerFactory; +import org.springframework.boot.web.server.MimeMappings; import org.springframework.boot.web.servlet.ServletContextInitializer; /** - * Simple interface that represents customizations to an - * {@link EmbeddedServletContainerFactory}. + * Simple interface that represents customizations to an {@link ServletWebServerFactory}. * * @author Dave Syer * @author Andy Wilkinson * @author Stephane Nicoll * @author Eddú Meléndez * @author Brian Clozel - * @see EmbeddedServletContainerFactory - * @see EmbeddedServletContainerCustomizer + * @since 2.0.0 + * @see ServletWebServerFactory + * @see ServletWebServerFactoryCustomizer */ -public interface ConfigurableEmbeddedServletContainer - extends ConfigurableEmbeddedWebServer { +public interface ConfigurableServletWebServerFactory + extends ConfigurableWebServerFactory { /** - * Sets the context path for the embedded servlet container. The context should start - * with a "/" character but not end with a "/" character. The default context path can - * be specified using an empty string. + * Sets the context path for the web server. The context should start with a "/" + * character but not end with a "/" character. The default context path can be + * specified using an empty string. * @param contextPath the contextPath to set */ void setContextPath(String contextPath); /** - * Sets the display name of the application deployed in the embedded servlet - * container. + * Sets the display name of the application deployed in the web server. * @param displayName the displayName to set * @since 1.3.0 */ @@ -106,7 +107,7 @@ public interface ConfigurableEmbeddedServletContainer /** * Sets {@link ServletContextInitializer} that should be applied in addition to - * {@link EmbeddedServletContainerFactory#getEmbeddedServletContainer(ServletContextInitializer...)} + * {@link ServletWebServerFactory#getWebServer(ServletContextInitializer...)} * parameters. This method will replace any previously set or added initializers. * @param initializers the initializers to set * @see #addInitializers @@ -115,8 +116,7 @@ public interface ConfigurableEmbeddedServletContainer /** * Add {@link ServletContextInitializer}s to those that should be applied in addition - * to - * {@link EmbeddedServletContainerFactory#getEmbeddedServletContainer(ServletContextInitializer...)} + * to {@link ServletWebServerFactory#getWebServer(ServletContextInitializer...)} * parameters. * @param initializers the initializers to add * @see #setInitializers @@ -124,7 +124,7 @@ public interface ConfigurableEmbeddedServletContainer void addInitializers(ServletContextInitializer... initializers); /** - * Sets the configuration that will be applied to the container's JSP servlet. + * Sets the configuration that will be applied to the server's JSP servlet. * @param jsp the JSP servlet configuration */ void setJsp(Jsp jsp); diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/InitParameterConfiguringServletContextInitializer.java b/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/InitParameterConfiguringServletContextInitializer.java similarity index 92% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/InitParameterConfiguringServletContextInitializer.java rename to spring-boot/src/main/java/org/springframework/boot/web/servlet/server/InitParameterConfiguringServletContextInitializer.java index ad757713d5..a4734c1bec 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/InitParameterConfiguringServletContextInitializer.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/InitParameterConfiguringServletContextInitializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded; +package org.springframework.boot.web.servlet.server; import java.util.Map; import java.util.Map.Entry; @@ -29,7 +29,7 @@ import org.springframework.boot.web.servlet.ServletContextInitializer; * {@code ServletContext}. * * @author Andy Wilkinson - * @since 1.2.0 + * @since 2.0.0 * @see ServletContext#setInitParameter(String, String) */ public class InitParameterConfiguringServletContextInitializer diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/Jsp.java b/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/Jsp.java similarity index 93% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/Jsp.java rename to spring-boot/src/main/java/org/springframework/boot/web/servlet/server/Jsp.java index 0c8f1e4eeb..ff435bd758 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/Jsp.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/Jsp.java @@ -14,13 +14,13 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded; +package org.springframework.boot.web.servlet.server; import java.util.HashMap; import java.util.Map; /** - * Configuration for the container's JSP servlet. + * Configuration for the server's JSP servlet. * * @author Andy Wilkinson * @since 2.0.0 @@ -41,8 +41,7 @@ public class Jsp { private Map initParameters = new HashMap<>(); /** - * Whether or not the JSP servlet should be registered with the embedded servlet - * container. + * Whether or not the JSP servlet should be registered with the web server. */ private boolean registered = true; diff --git a/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/ServletWebServerFactory.java b/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/ServletWebServerFactory.java new file mode 100644 index 0000000000..5aba860d32 --- /dev/null +++ b/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/ServletWebServerFactory.java @@ -0,0 +1,46 @@ +/* + * Copyright 2012-2017 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.web.servlet.server; + +import org.apache.catalina.core.ApplicationContext; + +import org.springframework.boot.web.server.WebServer; +import org.springframework.boot.web.servlet.ServletContextInitializer; + +/** + * Factory interface that can be used to create a {@link WebServer}. + * + * @author Phillip Webb + * @see WebServer + * @since 2.0.0 + */ +@FunctionalInterface +public interface ServletWebServerFactory { + + /** + * Gets a new fully configured but paused {@link WebServer} instance. Clients should + * not be able to connect to the returned server until {@link WebServer#start()} is + * called (which happens when the {@link ApplicationContext} has been fully + * refreshed). + * @param initializers {@link ServletContextInitializer}s that should be applied as + * the server starts + * @return a fully configured and started {@link WebServer} + * @see WebServer#stop() + */ + WebServer getWebServer(ServletContextInitializer... initializers); + +} diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/EmbeddedServletContainerCustomizer.java b/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/ServletWebServerFactoryCustomizer.java similarity index 60% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/EmbeddedServletContainerCustomizer.java rename to spring-boot/src/main/java/org/springframework/boot/web/servlet/server/ServletWebServerFactoryCustomizer.java index 3ea0ce4c67..8cc6f8fb3f 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/EmbeddedServletContainerCustomizer.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/ServletWebServerFactoryCustomizer.java @@ -14,31 +14,32 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded; +package org.springframework.boot.web.servlet.server; import org.springframework.beans.factory.config.BeanPostProcessor; /** - * Strategy interface for customizing auto-configured embedded servlet containers. Any - * beans of this type will get a callback with the container factory before the container - * itself is started, so you can set the port, address, error pages etc. + * Strategy interface for customizing auto-configured web server factory. Any beans of + * this type will get a callback with the server factory before the server itself is + * started, so you can set the port, address, error pages etc. *

    * Beware: calls to this interface are usually made from a - * {@link EmbeddedServletContainerCustomizerBeanPostProcessor} which is a + * {@link ServletWebServerFactoryCustomizerBeanPostProcessor} which is a * {@link BeanPostProcessor} (so called very early in the ApplicationContext lifecycle). * It might be safer to lookup dependencies lazily in the enclosing BeanFactory rather * than injecting them with {@code @Autowired}. * * @author Dave Syer - * @see EmbeddedServletContainerCustomizerBeanPostProcessor + * @since 2.0.0 + * @see ServletWebServerFactoryCustomizerBeanPostProcessor */ @FunctionalInterface -public interface EmbeddedServletContainerCustomizer { +public interface ServletWebServerFactoryCustomizer { /** - * Customize the specified {@link ConfigurableEmbeddedServletContainer}. - * @param container the container to customize + * Customize the specified {@link ConfigurableServletWebServerFactory}. + * @param serverFactory the server factory to customize */ - void customize(ConfigurableEmbeddedServletContainer container); + void customize(ConfigurableServletWebServerFactory serverFactory); } diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/EmbeddedServletContainerCustomizerBeanPostProcessor.java b/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/ServletWebServerFactoryCustomizerBeanPostProcessor.java similarity index 70% rename from spring-boot/src/main/java/org/springframework/boot/context/embedded/EmbeddedServletContainerCustomizerBeanPostProcessor.java rename to spring-boot/src/main/java/org/springframework/boot/web/servlet/server/ServletWebServerFactoryCustomizerBeanPostProcessor.java index a897623dfd..046983b76f 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/EmbeddedServletContainerCustomizerBeanPostProcessor.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/ServletWebServerFactoryCustomizerBeanPostProcessor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded; +package org.springframework.boot.web.servlet.server; import java.util.ArrayList; import java.util.Collection; @@ -30,24 +30,25 @@ import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.util.Assert; /** - * {@link BeanPostProcessor} that applies all {@link EmbeddedServletContainerCustomizer}s - * from the bean factory to {@link ConfigurableEmbeddedServletContainer} beans. + * {@link BeanPostProcessor} that applies all {@link ServletWebServerFactoryCustomizer}s + * from the bean factory to {@link ConfigurableServletWebServerFactory} beans. * * @author Dave Syer * @author Phillip Webb * @author Stephane Nicoll + * @since 2.0.0 */ -public class EmbeddedServletContainerCustomizerBeanPostProcessor +public class ServletWebServerFactoryCustomizerBeanPostProcessor implements BeanPostProcessor, BeanFactoryAware { private ListableBeanFactory beanFactory; - private List customizers; + private List customizers; @Override public void setBeanFactory(BeanFactory beanFactory) { Assert.isInstanceOf(ListableBeanFactory.class, beanFactory, - "EmbeddedServletContainerCustomizerBeanPostProcessor can only be used " + "ServletWebServerFactoryCustomizerBeanPostProcessor can only be used " + "with a ListableBeanFactory"); this.beanFactory = (ListableBeanFactory) beanFactory; } @@ -55,8 +56,8 @@ public class EmbeddedServletContainerCustomizerBeanPostProcessor @Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { - if (bean instanceof ConfigurableEmbeddedServletContainer) { - postProcessBeforeInitialization((ConfigurableEmbeddedServletContainer) bean); + if (bean instanceof ConfigurableServletWebServerFactory) { + postProcessBeforeInitialization((ConfigurableServletWebServerFactory) bean); } return bean; } @@ -68,17 +69,18 @@ public class EmbeddedServletContainerCustomizerBeanPostProcessor } private void postProcessBeforeInitialization( - ConfigurableEmbeddedServletContainer bean) { - for (EmbeddedServletContainerCustomizer customizer : getCustomizers()) { + ConfigurableServletWebServerFactory bean) { + for (ServletWebServerFactoryCustomizer customizer : getCustomizers()) { customizer.customize(bean); } } - private Collection getCustomizers() { + private Collection getCustomizers() { if (this.customizers == null) { // Look up does not include the parent context - this.customizers = new ArrayList<>(this.beanFactory.getBeansOfType( - EmbeddedServletContainerCustomizer.class, false, false).values()); + this.customizers = new ArrayList<>(this.beanFactory + .getBeansOfType(ServletWebServerFactoryCustomizer.class, false, false) + .values()); Collections.sort(this.customizers, AnnotationAwareOrderComparator.INSTANCE); this.customizers = Collections.unmodifiableList(this.customizers); } diff --git a/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/package-info.java b/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/package-info.java new file mode 100644 index 0000000000..7b4cb6535e --- /dev/null +++ b/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2012-2017 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. + */ + +/** + * Servlet web server abstractions. + */ +package org.springframework.boot.web.servlet.server; diff --git a/spring-boot/src/main/java/org/springframework/boot/web/support/ErrorPageFilter.java b/spring-boot/src/main/java/org/springframework/boot/web/support/ErrorPageFilter.java index 717f635beb..3ec6cab9b8 100644 --- a/spring-boot/src/main/java/org/springframework/boot/web/support/ErrorPageFilter.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/support/ErrorPageFilter.java @@ -33,9 +33,9 @@ import javax.servlet.http.HttpServletResponseWrapper; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.boot.web.servlet.ErrorPage; -import org.springframework.boot.web.servlet.ErrorPageRegistrar; -import org.springframework.boot.web.servlet.ErrorPageRegistry; +import org.springframework.boot.web.server.ErrorPage; +import org.springframework.boot.web.server.ErrorPageRegistrar; +import org.springframework.boot.web.server.ErrorPageRegistry; import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; import org.springframework.web.filter.OncePerRequestFilter; @@ -45,10 +45,10 @@ import org.springframework.web.util.NestedServletException; * A Servlet {@link Filter} that provides an {@link ErrorPageRegistry} for non-embedded * applications (i.e. deployed WAR files). It registers error pages and handles * application errors by filtering requests and forwarding to the error pages instead of - * letting the container handle them. Error pages are a feature of the servlet spec but - * there is no Java API for registering them in the spec. This filter works around that by + * letting the server handle them. Error pages are a feature of the servlet spec but there + * is no Java API for registering them in the spec. This filter works around that by * accepting error page registrations from Spring Boot's {@link ErrorPageRegistrar} (any - * beans of that type in the context will be applied to this container). + * beans of that type in the context will be applied to this server). * * @author Dave Syer * @author Phillip Webb diff --git a/spring-boot/src/main/java/org/springframework/boot/web/support/SpringBootServletInitializer.java b/spring-boot/src/main/java/org/springframework/boot/web/support/SpringBootServletInitializer.java index 717cd102c1..d9321dfdd0 100644 --- a/spring-boot/src/main/java/org/springframework/boot/web/support/SpringBootServletInitializer.java +++ b/spring-boot/src/main/java/org/springframework/boot/web/support/SpringBootServletInitializer.java @@ -28,8 +28,8 @@ import org.apache.commons.logging.LogFactory; import org.springframework.boot.SpringApplication; import org.springframework.boot.builder.ParentContextApplicationContextInitializer; import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; import org.springframework.boot.web.servlet.ServletContextInitializer; +import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Configuration; import org.springframework.core.annotation.AnnotationUtils; @@ -41,8 +41,7 @@ import org.springframework.web.context.WebApplicationContext; /** * An opinionated {@link WebApplicationInitializer} to run a {@link SpringApplication} * from a traditional WAR deployment. Binds {@link Servlet}, {@link Filter} and - * {@link ServletContextInitializer} beans from the application context to the servlet - * container. + * {@link ServletContextInitializer} beans from the application context to the server. *

    * To configure the application either override the * {@link #configure(SpringApplicationBuilder)} method (calling @@ -53,7 +52,7 @@ import org.springframework.web.context.WebApplicationContext; * order. *

    * Note that a WebApplicationInitializer is only needed if you are building a war file and - * deploying it. If you prefer to run an embedded container then you won't need this at + * deploying it. If you prefer to run an embedded web server then you won't need this at * all. * * @author Dave Syer @@ -70,8 +69,7 @@ public abstract class SpringBootServletInitializer implements WebApplicationInit /** * Set if the {@link ErrorPageFilter} should be registered. Set to {@code false} if - * error page mappings should be handled via the Servlet container and not Spring - * Boot. + * error page mappings should be handled via the server and not Spring Boot. * @param registerErrorPageFilter if the {@link ErrorPageFilter} should be registered. */ protected final void setRegisterErrorPageFilter(boolean registerErrorPageFilter) { @@ -114,7 +112,7 @@ public abstract class SpringBootServletInitializer implements WebApplicationInit builder.initializers( new ServletContextApplicationContextInitializer(servletContext)); builder.listeners(new ServletContextApplicationListener(servletContext)); - builder.contextClass(AnnotationConfigEmbeddedWebApplicationContext.class); + builder.contextClass(AnnotationConfigServletWebServerApplicationContext.class); builder = configure(builder); SpringApplication application = builder.build(); if (application.getSources().isEmpty() && AnnotationUtils diff --git a/spring-boot/src/main/resources/META-INF/spring.factories b/spring-boot/src/main/resources/META-INF/spring.factories index 2563865d9b..be922ea469 100644 --- a/spring-boot/src/main/resources/META-INF/spring.factories +++ b/spring-boot/src/main/resources/META-INF/spring.factories @@ -12,7 +12,7 @@ org.springframework.context.ApplicationContextInitializer=\ org.springframework.boot.context.ConfigurationWarningsApplicationContextInitializer,\ org.springframework.boot.context.ContextIdApplicationContextInitializer,\ org.springframework.boot.context.config.DelegatingApplicationContextInitializer,\ -org.springframework.boot.context.embedded.ServerPortInfoApplicationContextInitializer +org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer # Application Listeners org.springframework.context.ApplicationListener=\ diff --git a/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java b/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java index 2824d64b70..ac230eddc7 100644 --- a/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java @@ -43,15 +43,15 @@ import org.springframework.beans.CachedIntrospectionResults; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.BeanNameGenerator; import org.springframework.beans.factory.support.DefaultBeanNameGenerator; -import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; -import org.springframework.boot.context.embedded.EmbeddedReactiveWebApplicationContext; -import org.springframework.boot.context.embedded.reactor.ReactorNettyReactiveWebServerFactory; -import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent; import org.springframework.boot.context.event.ApplicationPreparedEvent; import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.boot.context.event.ApplicationStartingEvent; import org.springframework.boot.testutil.InternalOutputCapture; +import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext; +import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationContextInitializer; @@ -398,7 +398,7 @@ public class SpringApplicationTests { application.setWebApplicationType(WebApplicationType.SERVLET); this.context = application.run(); assertThat(this.context) - .isInstanceOf(AnnotationConfigEmbeddedWebApplicationContext.class); + .isInstanceOf(AnnotationConfigServletWebServerApplicationContext.class); } @Test @@ -407,8 +407,7 @@ public class SpringApplicationTests { ExampleReactiveWebConfig.class); application.setWebApplicationType(WebApplicationType.REACTIVE); this.context = application.run(); - assertThat(this.context) - .isInstanceOf(EmbeddedReactiveWebApplicationContext.class); + assertThat(this.context).isInstanceOf(ReactiveWebServerApplicationContext.class); } @Test @@ -1027,8 +1026,8 @@ public class SpringApplicationTests { static class ExampleWebConfig { @Bean - public TomcatEmbeddedServletContainerFactory container() { - return new TomcatEmbeddedServletContainerFactory(0); + public TomcatServletWebServerFactory webServer() { + return new TomcatServletWebServerFactory(0); } } @@ -1037,8 +1036,8 @@ public class SpringApplicationTests { static class ExampleReactiveWebConfig { @Bean - public ReactorNettyReactiveWebServerFactory webServerFactory() { - return new ReactorNettyReactiveWebServerFactory(0); + public NettyReactiveWebServerFactory webServerFactory() { + return new NettyReactiveWebServerFactory(0); } @Bean diff --git a/spring-boot/src/test/java/org/springframework/boot/diagnostics/FailureAnalyzersIntegrationTests.java b/spring-boot/src/test/java/org/springframework/boot/diagnostics/FailureAnalyzersIntegrationTests.java index 7da7e32b35..2511bdeabf 100644 --- a/spring-boot/src/test/java/org/springframework/boot/diagnostics/FailureAnalyzersIntegrationTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/diagnostics/FailureAnalyzersIntegrationTests.java @@ -23,8 +23,8 @@ import org.junit.Test; import org.springframework.boot.WebApplicationType; import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.context.embedded.PortInUseException; import org.springframework.boot.testutil.InternalOutputCapture; +import org.springframework.boot.web.server.PortInUseException; import org.springframework.context.annotation.Configuration; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-boot/src/test/java/org/springframework/boot/system/EmbeddedServerPortFileWriterTests.java b/spring-boot/src/test/java/org/springframework/boot/system/EmbeddedServerPortFileWriterTests.java index a06c1a7089..ef76a8c0e4 100644 --- a/spring-boot/src/test/java/org/springframework/boot/system/EmbeddedServerPortFileWriterTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/system/EmbeddedServerPortFileWriterTests.java @@ -27,9 +27,9 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; -import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent; -import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext; -import org.springframework.boot.context.embedded.EmbeddedWebServer; +import org.springframework.boot.web.server.WebServer; +import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext; +import org.springframework.boot.web.servlet.context.ServletWebServerInitializedEvent; import org.springframework.util.FileCopyUtils; import org.springframework.util.StringUtils; @@ -117,13 +117,13 @@ public class EmbeddedServerPortFileWriterTests { assertThat(collectFileNames(file.getParentFile())).contains(managementFile); } - private EmbeddedServletContainerInitializedEvent mockEvent(String name, int port) { - EmbeddedWebApplicationContext applicationContext = mock( - EmbeddedWebApplicationContext.class); - EmbeddedWebServer source = mock(EmbeddedWebServer.class); + private ServletWebServerInitializedEvent mockEvent(String name, int port) { + ServletWebServerApplicationContext applicationContext = mock( + ServletWebServerApplicationContext.class); + WebServer source = mock(WebServer.class); given(applicationContext.getNamespace()).willReturn(name); given(source.getPort()).willReturn(port); - EmbeddedServletContainerInitializedEvent event = new EmbeddedServletContainerInitializedEvent( + ServletWebServerInitializedEvent event = new ServletWebServerInitializedEvent( applicationContext, source); return event; } diff --git a/spring-boot/src/test/java/org/springframework/boot/context/embedded/jetty/JettyReactiveWebServerFactoryTests.java b/spring-boot/src/test/java/org/springframework/boot/web/embedded/jetty/JettyReactiveWebServerFactoryTests.java similarity index 80% rename from spring-boot/src/test/java/org/springframework/boot/context/embedded/jetty/JettyReactiveWebServerFactoryTests.java rename to spring-boot/src/test/java/org/springframework/boot/web/embedded/jetty/JettyReactiveWebServerFactoryTests.java index cd7aee33c4..3d1eaecd84 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/embedded/jetty/JettyReactiveWebServerFactoryTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/web/embedded/jetty/JettyReactiveWebServerFactoryTests.java @@ -14,10 +14,10 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded.jetty; +package org.springframework.boot.web.embedded.jetty; -import org.springframework.boot.context.embedded.AbstractReactiveWebServerFactory; -import org.springframework.boot.context.embedded.AbstractReactiveWebServerFactoryTests; +import org.springframework.boot.web.reactive.server.AbstractReactiveWebServerFactory; +import org.springframework.boot.web.reactive.server.AbstractReactiveWebServerFactoryTests; /** * Tests for {@link JettyReactiveWebServerFactory} and {@link JettyWebServer}. diff --git a/spring-boot/src/test/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedServletContainerFactoryTests.java b/spring-boot/src/test/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactoryTests.java similarity index 69% rename from spring-boot/src/test/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedServletContainerFactoryTests.java rename to spring-boot/src/test/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactoryTests.java index 0b27598762..d2d0160a6d 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedServletContainerFactoryTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactoryTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded.jetty; +package org.springframework.boot.web.embedded.jetty; import java.io.IOException; import java.nio.charset.Charset; @@ -42,12 +42,12 @@ import org.eclipse.jetty.webapp.WebAppContext; import org.junit.Test; import org.mockito.InOrder; -import org.springframework.boot.context.embedded.AbstractEmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.AbstractEmbeddedServletContainerFactoryTests; -import org.springframework.boot.context.embedded.Compression; -import org.springframework.boot.context.embedded.PortInUseException; -import org.springframework.boot.context.embedded.Ssl; +import org.springframework.boot.web.server.Compression; +import org.springframework.boot.web.server.PortInUseException; +import org.springframework.boot.web.server.Ssl; import org.springframework.boot.web.servlet.ServletRegistrationBean; +import org.springframework.boot.web.servlet.server.AbstractServletWebServerFactory; +import org.springframework.boot.web.servlet.server.AbstractServletWebServerFactoryTests; import org.springframework.http.HttpHeaders; import static org.assertj.core.api.Assertions.assertThat; @@ -56,32 +56,31 @@ import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.mock; /** - * Tests for {@link JettyEmbeddedServletContainerFactory} and - * {@link JettyEmbeddedServletContainer}. + * Tests for {@link JettyServletWebServerFactory}. * * @author Phillip Webb * @author Dave Syer * @author Andy Wilkinson * @author Henri Kerola */ -public class JettyEmbeddedServletContainerFactoryTests - extends AbstractEmbeddedServletContainerFactoryTests { +public class JettyServletWebServerFactoryTests + extends AbstractServletWebServerFactoryTests { @Override - protected JettyEmbeddedServletContainerFactory getFactory() { - return new JettyEmbeddedServletContainerFactory(0); + protected JettyServletWebServerFactory getFactory() { + return new JettyServletWebServerFactory(0); } @Test public void jettyConfigurations() throws Exception { - JettyEmbeddedServletContainerFactory factory = getFactory(); + JettyServletWebServerFactory factory = getFactory(); Configuration[] configurations = new Configuration[4]; for (int i = 0; i < configurations.length; i++) { configurations[i] = mock(Configuration.class); } factory.setConfigurations(Arrays.asList(configurations[0], configurations[1])); factory.addConfigurations(configurations[2], configurations[3]); - this.container = factory.getEmbeddedServletContainer(); + this.webServer = factory.getWebServer(); InOrder ordered = inOrder((Object[]) configurations); for (Configuration configuration : configurations) { ordered.verify(configuration).configure(any(WebAppContext.class)); @@ -90,14 +89,14 @@ public class JettyEmbeddedServletContainerFactoryTests @Test public void jettyCustomizations() throws Exception { - JettyEmbeddedServletContainerFactory factory = getFactory(); + JettyServletWebServerFactory factory = getFactory(); JettyServerCustomizer[] configurations = new JettyServerCustomizer[4]; for (int i = 0; i < configurations.length; i++) { configurations[i] = mock(JettyServerCustomizer.class); } factory.setServerCustomizers(Arrays.asList(configurations[0], configurations[1])); factory.addServerCustomizers(configurations[2], configurations[3]); - this.container = factory.getEmbeddedServletContainer(); + this.webServer = factory.getWebServer(); InOrder ordered = inOrder((Object[]) configurations); for (JettyServerCustomizer configuration : configurations) { ordered.verify(configuration).customize(any(Server.class)); @@ -106,14 +105,14 @@ public class JettyEmbeddedServletContainerFactoryTests @Test public void sessionTimeout() throws Exception { - JettyEmbeddedServletContainerFactory factory = getFactory(); + JettyServletWebServerFactory factory = getFactory(); factory.setSessionTimeout(10); assertTimeout(factory, 10); } @Test public void sessionTimeoutInMins() throws Exception { - JettyEmbeddedServletContainerFactory factory = getFactory(); + JettyServletWebServerFactory factory = getFactory(); factory.setSessionTimeout(1, TimeUnit.MINUTES); assertTimeout(factory, 60); } @@ -126,14 +125,14 @@ public class JettyEmbeddedServletContainerFactoryTests ssl.setKeyPassword("password"); ssl.setCiphers(new String[] { "ALPHA", "BRAVO", "CHARLIE" }); - JettyEmbeddedServletContainerFactory factory = getFactory(); + JettyServletWebServerFactory factory = getFactory(); factory.setSsl(ssl); - this.container = factory.getEmbeddedServletContainer(); - this.container.start(); + this.webServer = factory.getWebServer(); + this.webServer.start(); - JettyEmbeddedServletContainer jettyContainer = (JettyEmbeddedServletContainer) this.container; - ServerConnector connector = (ServerConnector) jettyContainer.getServer() + JettyWebServer jettyWebServer = (JettyWebServer) this.webServer; + ServerConnector connector = (ServerConnector) jettyWebServer.getServer() .getConnectors()[0]; SslConnectionFactory connectionFactory = connector .getConnectionFactory(SslConnectionFactory.class); @@ -145,18 +144,16 @@ public class JettyEmbeddedServletContainerFactoryTests @Test public void stopCalledWithoutStart() throws Exception { - JettyEmbeddedServletContainerFactory factory = getFactory(); - this.container = factory - .getEmbeddedServletContainer(exampleServletRegistration()); - this.container.stop(); - Server server = ((JettyEmbeddedServletContainer) this.container).getServer(); + JettyServletWebServerFactory factory = getFactory(); + this.webServer = factory.getWebServer(exampleServletRegistration()); + this.webServer.stop(); + Server server = ((JettyWebServer) this.webServer).getServer(); assertThat(server.isStopped()).isTrue(); } @Override - protected void addConnector(final int port, - AbstractEmbeddedServletContainerFactory factory) { - ((JettyEmbeddedServletContainerFactory) factory) + protected void addConnector(int port, AbstractServletWebServerFactory factory) { + ((JettyServletWebServerFactory) factory) .addServerCustomizers(new JettyServerCustomizer() { @Override @@ -178,14 +175,14 @@ public class JettyEmbeddedServletContainerFactoryTests ssl.setCiphers(new String[] { "ALPHA", "BRAVO", "CHARLIE" }); ssl.setEnabledProtocols(new String[] { "TLSv1.1", "TLSv1.2" }); - JettyEmbeddedServletContainerFactory factory = getFactory(); + JettyServletWebServerFactory factory = getFactory(); factory.setSsl(ssl); - this.container = factory.getEmbeddedServletContainer(); - this.container.start(); + this.webServer = factory.getWebServer(); + this.webServer.start(); - JettyEmbeddedServletContainer jettyContainer = (JettyEmbeddedServletContainer) this.container; - ServerConnector connector = (ServerConnector) jettyContainer.getServer() + JettyWebServer jettyWebServer = (JettyWebServer) this.webServer; + ServerConnector connector = (ServerConnector) jettyWebServer.getServer() .getConnectors()[0]; SslConnectionFactory connectionFactory = connector .getConnectionFactory(SslConnectionFactory.class); @@ -203,14 +200,14 @@ public class JettyEmbeddedServletContainerFactoryTests ssl.setCiphers(new String[] { "ALPHA", "BRAVO", "CHARLIE" }); ssl.setEnabledProtocols(new String[] { "TLSv1.1" }); - JettyEmbeddedServletContainerFactory factory = getFactory(); + JettyServletWebServerFactory factory = getFactory(); factory.setSsl(ssl); - this.container = factory.getEmbeddedServletContainer(); - this.container.start(); + this.webServer = factory.getWebServer(); + this.webServer.start(); - JettyEmbeddedServletContainer jettyContainer = (JettyEmbeddedServletContainer) this.container; - ServerConnector connector = (ServerConnector) jettyContainer.getServer() + JettyWebServer jettyWebServer = (JettyWebServer) this.webServer; + ServerConnector connector = (ServerConnector) jettyWebServer.getServer() .getConnectors()[0]; SslConnectionFactory connectionFactory = connector .getConnectionFactory(SslConnectionFactory.class); @@ -219,11 +216,10 @@ public class JettyEmbeddedServletContainerFactoryTests .isEqualTo(new String[] { "TLSv1.1" }); } - private void assertTimeout(JettyEmbeddedServletContainerFactory factory, - int expected) { - this.container = factory.getEmbeddedServletContainer(); - JettyEmbeddedServletContainer jettyContainer = (JettyEmbeddedServletContainer) this.container; - Handler[] handlers = jettyContainer.getServer() + private void assertTimeout(JettyServletWebServerFactory factory, int expected) { + this.webServer = factory.getWebServer(); + JettyWebServer jettyWebServer = (JettyWebServer) this.webServer; + Handler[] handlers = jettyWebServer.getServer() .getChildHandlersByClass(WebAppContext.class); WebAppContext webAppContext = (WebAppContext) handlers[0]; int actual = webAppContext.getSessionHandler().getMaxInactiveInterval(); @@ -232,7 +228,7 @@ public class JettyEmbeddedServletContainerFactoryTests @Test public void wrappedHandlers() throws Exception { - JettyEmbeddedServletContainerFactory factory = getFactory(); + JettyServletWebServerFactory factory = getFactory(); factory.setServerCustomizers(Arrays.asList(new JettyServerCustomizer() { @Override public void customize(Server server) { @@ -244,9 +240,8 @@ public class JettyEmbeddedServletContainerFactoryTests server.setHandler(collection); } })); - this.container = factory - .getEmbeddedServletContainer(exampleServletRegistration()); - this.container.start(); + this.webServer = factory.getWebServer(exampleServletRegistration()); + this.webServer.start(); assertThat(getResponse(getLocalUrl("/hello"))).isEqualTo("Hello World"); } @@ -257,29 +252,27 @@ public class JettyEmbeddedServletContainerFactoryTests @Test public void useForwardHeaders() throws Exception { - JettyEmbeddedServletContainerFactory factory = getFactory(); + JettyServletWebServerFactory factory = getFactory(); factory.setUseForwardHeaders(true); assertForwardHeaderIsUsed(factory); } @Test public void defaultThreadPool() throws Exception { - JettyEmbeddedServletContainerFactory factory = getFactory(); + JettyServletWebServerFactory factory = getFactory(); factory.setThreadPool(null); assertThat(factory.getThreadPool()).isNull(); - JettyEmbeddedServletContainer servletContainer = (JettyEmbeddedServletContainer) factory - .getEmbeddedServletContainer(); - assertThat(servletContainer.getServer().getThreadPool()).isNotNull(); + JettyWebServer jettyWebServer = (JettyWebServer) factory.getWebServer(); + assertThat(jettyWebServer.getServer().getThreadPool()).isNotNull(); } @Test public void customThreadPool() throws Exception { - JettyEmbeddedServletContainerFactory factory = getFactory(); + JettyServletWebServerFactory factory = getFactory(); ThreadPool threadPool = mock(ThreadPool.class); factory.setThreadPool(threadPool); - JettyEmbeddedServletContainer servletContainer = (JettyEmbeddedServletContainer) factory - .getEmbeddedServletContainer(); - assertThat(servletContainer.getServer().getThreadPool()).isSameAs(threadPool); + JettyWebServer jettyWebServer = (JettyWebServer) factory.getWebServer(); + assertThat(jettyWebServer.getServer().getThreadPool()).isSameAs(threadPool); } @Override @@ -290,7 +283,7 @@ public class JettyEmbeddedServletContainerFactoryTests char[] chars = new char[contentSize]; Arrays.fill(chars, 'F'); final String testContent = new String(chars); - AbstractEmbeddedServletContainerFactory factory = getFactory(); + AbstractServletWebServerFactory factory = getFactory(); Compression compression = new Compression(); compression.setEnabled(true); if (mimeTypes != null) { @@ -300,8 +293,8 @@ public class JettyEmbeddedServletContainerFactoryTests compression.setExcludedUserAgents(excludedUserAgents); } factory.setCompression(compression); - this.container = factory.getEmbeddedServletContainer( - new ServletRegistrationBean(new HttpServlet() { + this.webServer = factory + .getWebServer(new ServletRegistrationBean(new HttpServlet() { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { @@ -310,13 +303,13 @@ public class JettyEmbeddedServletContainerFactoryTests resp.getWriter().print(testContent); } }, "/test.txt")); - this.container.start(); + this.webServer.start(); return testContent; } @Override protected JspServlet getJspServlet() throws Exception { - WebAppContext context = (WebAppContext) ((JettyEmbeddedServletContainer) this.container) + WebAppContext context = (WebAppContext) ((JettyWebServer) this.webServer) .getServer().getHandler(); ServletHolder holder = context.getServletHandler().getServlet("jsp"); if (holder == null) { @@ -328,14 +321,14 @@ public class JettyEmbeddedServletContainerFactoryTests @Override protected Map getActualMimeMappings() { - WebAppContext context = (WebAppContext) ((JettyEmbeddedServletContainer) this.container) + WebAppContext context = (WebAppContext) ((JettyWebServer) this.webServer) .getServer().getHandler(); return context.getMimeTypes().getMimeMap(); } @Override protected Charset getCharset(Locale locale) { - WebAppContext context = (WebAppContext) ((JettyEmbeddedServletContainer) this.container) + WebAppContext context = (WebAppContext) ((JettyWebServer) this.webServer) .getServer().getHandler(); String charsetName = context.getLocaleEncoding(locale); return (charsetName != null) ? Charset.forName(charsetName) : null; diff --git a/spring-boot/src/test/java/org/springframework/boot/context/embedded/reactor/ReactorNettyReactiveWebServerFactoryTests.java b/spring-boot/src/test/java/org/springframework/boot/web/embedded/netty/NettyReactiveWebServerFactoryTests.java similarity index 64% rename from spring-boot/src/test/java/org/springframework/boot/context/embedded/reactor/ReactorNettyReactiveWebServerFactoryTests.java rename to spring-boot/src/test/java/org/springframework/boot/web/embedded/netty/NettyReactiveWebServerFactoryTests.java index 979106c3c2..7040c3c661 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/embedded/reactor/ReactorNettyReactiveWebServerFactoryTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/web/embedded/netty/NettyReactiveWebServerFactoryTests.java @@ -14,23 +14,22 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded.reactor; +package org.springframework.boot.web.embedded.netty; -import org.springframework.boot.context.embedded.AbstractReactiveWebServerFactory; -import org.springframework.boot.context.embedded.AbstractReactiveWebServerFactoryTests; +import org.springframework.boot.web.reactive.server.AbstractReactiveWebServerFactory; +import org.springframework.boot.web.reactive.server.AbstractReactiveWebServerFactoryTests; /** - * Tests for {@link ReactorNettyReactiveWebServerFactory} and - * {@link ReactorNettyWebServer}. + * Tests for {@link NettyReactiveWebServerFactory}. * * @author Brian Clozel */ -public class ReactorNettyReactiveWebServerFactoryTests +public class NettyReactiveWebServerFactoryTests extends AbstractReactiveWebServerFactoryTests { @Override protected AbstractReactiveWebServerFactory getFactory() { - return new ReactorNettyReactiveWebServerFactory(0); + return new NettyReactiveWebServerFactory(0); } } diff --git a/spring-boot/src/test/java/org/springframework/boot/context/embedded/tomcat/TomcatReactiveWebServerFactoryTests.java b/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/TomcatReactiveWebServerFactoryTests.java similarity index 74% rename from spring-boot/src/test/java/org/springframework/boot/context/embedded/tomcat/TomcatReactiveWebServerFactoryTests.java rename to spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/TomcatReactiveWebServerFactoryTests.java index cb2beb6059..093e1cab7e 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/embedded/tomcat/TomcatReactiveWebServerFactoryTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/TomcatReactiveWebServerFactoryTests.java @@ -14,13 +14,13 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded.tomcat; +package org.springframework.boot.web.embedded.tomcat; -import org.springframework.boot.context.embedded.AbstractReactiveWebServerFactory; -import org.springframework.boot.context.embedded.AbstractReactiveWebServerFactoryTests; +import org.springframework.boot.web.reactive.server.AbstractReactiveWebServerFactory; +import org.springframework.boot.web.reactive.server.AbstractReactiveWebServerFactoryTests; /** - * Tests for {@link TomcatReactiveWebServerFactory} and {@link TomcatWebServer}. + * Tests for {@link TomcatReactiveWebServerFactory}. * * @author Brian Clozel */ diff --git a/spring-boot/src/test/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainerFactoryTests.java b/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactoryTests.java similarity index 67% rename from spring-boot/src/test/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainerFactoryTests.java rename to spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactoryTests.java index c63b31e8b9..8dd392b801 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainerFactoryTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactoryTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded.tomcat; +package org.springframework.boot.web.embedded.tomcat; import java.io.File; import java.io.IOException; @@ -48,11 +48,11 @@ import org.junit.Rule; import org.junit.Test; import org.mockito.InOrder; -import org.springframework.boot.context.embedded.AbstractEmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.AbstractEmbeddedServletContainerFactoryTests; -import org.springframework.boot.context.embedded.EmbeddedWebServerException; -import org.springframework.boot.context.embedded.Ssl; import org.springframework.boot.testutil.InternalOutputCapture; +import org.springframework.boot.web.server.Ssl; +import org.springframework.boot.web.server.WebServerException; +import org.springframework.boot.web.servlet.server.AbstractServletWebServerFactory; +import org.springframework.boot.web.servlet.server.AbstractServletWebServerFactoryTests; import org.springframework.test.util.ReflectionTestUtils; import org.springframework.util.SocketUtils; @@ -65,22 +65,21 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; /** - * Tests for {@link TomcatEmbeddedServletContainerFactory} and - * {@link TomcatEmbeddedServletContainer}. + * Tests for {@link TomcatServletWebServerFactory}. * * @author Phillip Webb * @author Dave Syer * @author Stephane Nicoll */ -public class TomcatEmbeddedServletContainerFactoryTests - extends AbstractEmbeddedServletContainerFactoryTests { +public class TomcatServletWebServerFactoryTests + extends AbstractServletWebServerFactoryTests { @Rule public InternalOutputCapture outputCapture = new InternalOutputCapture(); @Override - protected TomcatEmbeddedServletContainerFactory getFactory() { - return new TomcatEmbeddedServletContainerFactory(0); + protected TomcatServletWebServerFactory getFactory() { + return new TomcatServletWebServerFactory(0); } @After @@ -91,31 +90,29 @@ public class TomcatEmbeddedServletContainerFactoryTests // JMX MBean names clash if you get more than one Engine with the same name... @Test public void tomcatEngineNames() throws Exception { - TomcatEmbeddedServletContainerFactory factory = getFactory(); - this.container = factory.getEmbeddedServletContainer(); + TomcatServletWebServerFactory factory = getFactory(); + this.webServer = factory.getWebServer(); factory.setPort(SocketUtils.findAvailableTcpPort(40000)); - TomcatEmbeddedServletContainer container2 = (TomcatEmbeddedServletContainer) factory - .getEmbeddedServletContainer(); - + TomcatWebServer tomcatWebServer = (TomcatWebServer) factory.getWebServer(); // Make sure that the names are different - String firstContainerName = ((TomcatEmbeddedServletContainer) this.container) - .getTomcat().getEngine().getName(); - String secondContainerName = container2.getTomcat().getEngine().getName(); - assertThat(firstContainerName).as("Tomcat engines must have different names") - .isNotEqualTo(secondContainerName); - container2.stop(); + String firstName = ((TomcatWebServer) this.webServer).getTomcat().getEngine() + .getName(); + String secondName = tomcatWebServer.getTomcat().getEngine().getName(); + assertThat(firstName).as("Tomcat engines must have different names") + .isNotEqualTo(secondName); + tomcatWebServer.stop(); } @Test public void tomcatListeners() throws Exception { - TomcatEmbeddedServletContainerFactory factory = getFactory(); + TomcatServletWebServerFactory factory = getFactory(); LifecycleListener[] listeners = new LifecycleListener[4]; for (int i = 0; i < listeners.length; i++) { listeners[i] = mock(LifecycleListener.class); } factory.setContextLifecycleListeners(Arrays.asList(listeners[0], listeners[1])); factory.addContextLifecycleListeners(listeners[2], listeners[3]); - this.container = factory.getEmbeddedServletContainer(); + this.webServer = factory.getWebServer(); InOrder ordered = inOrder((Object[]) listeners); for (LifecycleListener listener : listeners) { ordered.verify(listener).lifecycleEvent(any(LifecycleEvent.class)); @@ -124,14 +121,14 @@ public class TomcatEmbeddedServletContainerFactoryTests @Test public void tomcatCustomizers() throws Exception { - TomcatEmbeddedServletContainerFactory factory = getFactory(); + TomcatServletWebServerFactory factory = getFactory(); TomcatContextCustomizer[] listeners = new TomcatContextCustomizer[4]; for (int i = 0; i < listeners.length; i++) { listeners[i] = mock(TomcatContextCustomizer.class); } factory.setTomcatContextCustomizers(Arrays.asList(listeners[0], listeners[1])); factory.addContextCustomizers(listeners[2], listeners[3]); - this.container = factory.getEmbeddedServletContainer(); + this.webServer = factory.getWebServer(); InOrder ordered = inOrder((Object[]) listeners); for (TomcatContextCustomizer listener : listeners) { ordered.verify(listener).customize(any(Context.class)); @@ -140,14 +137,14 @@ public class TomcatEmbeddedServletContainerFactoryTests @Test public void tomcatConnectorCustomizers() throws Exception { - TomcatEmbeddedServletContainerFactory factory = getFactory(); + TomcatServletWebServerFactory factory = getFactory(); TomcatConnectorCustomizer[] listeners = new TomcatConnectorCustomizer[4]; for (int i = 0; i < listeners.length; i++) { listeners[i] = mock(TomcatConnectorCustomizer.class); } factory.setTomcatConnectorCustomizers(Arrays.asList(listeners[0], listeners[1])); factory.addConnectorCustomizers(listeners[2], listeners[3]); - this.container = factory.getEmbeddedServletContainer(); + this.webServer = factory.getWebServer(); InOrder ordered = inOrder((Object[]) listeners); for (TomcatConnectorCustomizer listener : listeners) { ordered.verify(listener).customize(any(Connector.class)); @@ -156,7 +153,7 @@ public class TomcatEmbeddedServletContainerFactoryTests @Test public void tomcatAdditionalConnectors() throws Exception { - TomcatEmbeddedServletContainerFactory factory = getFactory(); + TomcatServletWebServerFactory factory = getFactory(); Connector[] listeners = new Connector[4]; for (int i = 0; i < listeners.length; i++) { Connector connector = mock(Connector.class); @@ -164,8 +161,8 @@ public class TomcatEmbeddedServletContainerFactoryTests listeners[i] = connector; } factory.addAdditionalTomcatConnectors(listeners); - this.container = factory.getEmbeddedServletContainer(); - Map connectors = ((TomcatEmbeddedServletContainer) this.container) + this.webServer = factory.getWebServer(); + Map connectors = ((TomcatWebServer) this.webServer) .getServiceConnectors(); assertThat(connectors.values().iterator().next().length) .isEqualTo(listeners.length + 1); @@ -173,7 +170,7 @@ public class TomcatEmbeddedServletContainerFactoryTests @Test public void addNullAdditionalConnectorThrows() { - TomcatEmbeddedServletContainerFactory factory = getFactory(); + TomcatServletWebServerFactory factory = getFactory(); this.thrown.expect(IllegalArgumentException.class); this.thrown.expectMessage("Connectors must not be null"); factory.addAdditionalTomcatConnectors((Connector[]) null); @@ -181,37 +178,37 @@ public class TomcatEmbeddedServletContainerFactoryTests @Test public void sessionTimeout() throws Exception { - TomcatEmbeddedServletContainerFactory factory = getFactory(); + TomcatServletWebServerFactory factory = getFactory(); factory.setSessionTimeout(10); assertTimeout(factory, 1); } @Test public void sessionTimeoutInMins() throws Exception { - TomcatEmbeddedServletContainerFactory factory = getFactory(); + TomcatServletWebServerFactory factory = getFactory(); factory.setSessionTimeout(1, TimeUnit.MINUTES); assertTimeout(factory, 1); } @Test public void noSessionTimeout() throws Exception { - TomcatEmbeddedServletContainerFactory factory = getFactory(); + TomcatServletWebServerFactory factory = getFactory(); factory.setSessionTimeout(0); assertTimeout(factory, -1); } @Test public void valve() throws Exception { - TomcatEmbeddedServletContainerFactory factory = getFactory(); + TomcatServletWebServerFactory factory = getFactory(); Valve valve = mock(Valve.class); factory.addContextValves(valve); - this.container = factory.getEmbeddedServletContainer(); + this.webServer = factory.getWebServer(); verify(valve).setNext(any(Valve.class)); } @Test public void setNullTomcatContextCustomizersThrows() { - TomcatEmbeddedServletContainerFactory factory = getFactory(); + TomcatServletWebServerFactory factory = getFactory(); this.thrown.expect(IllegalArgumentException.class); this.thrown.expectMessage("TomcatContextCustomizers must not be null"); factory.setTomcatContextCustomizers(null); @@ -219,7 +216,7 @@ public class TomcatEmbeddedServletContainerFactoryTests @Test public void addNullContextCustomizersThrows() { - TomcatEmbeddedServletContainerFactory factory = getFactory(); + TomcatServletWebServerFactory factory = getFactory(); this.thrown.expect(IllegalArgumentException.class); this.thrown.expectMessage("TomcatContextCustomizers must not be null"); factory.addContextCustomizers((TomcatContextCustomizer[]) null); @@ -227,7 +224,7 @@ public class TomcatEmbeddedServletContainerFactoryTests @Test public void setNullTomcatConnectorCustomizersThrows() { - TomcatEmbeddedServletContainerFactory factory = getFactory(); + TomcatServletWebServerFactory factory = getFactory(); this.thrown.expect(IllegalArgumentException.class); this.thrown.expectMessage("TomcatConnectorCustomizers must not be null"); factory.setTomcatConnectorCustomizers(null); @@ -235,7 +232,7 @@ public class TomcatEmbeddedServletContainerFactoryTests @Test public void addNullConnectorCustomizersThrows() { - TomcatEmbeddedServletContainerFactory factory = getFactory(); + TomcatServletWebServerFactory factory = getFactory(); this.thrown.expect(IllegalArgumentException.class); this.thrown.expectMessage("TomcatConnectorCustomizers must not be null"); factory.addConnectorCustomizers((TomcatConnectorCustomizer[]) null); @@ -243,20 +240,20 @@ public class TomcatEmbeddedServletContainerFactoryTests @Test public void uriEncoding() throws Exception { - TomcatEmbeddedServletContainerFactory factory = getFactory(); + TomcatServletWebServerFactory factory = getFactory(); factory.setUriEncoding(Charset.forName("US-ASCII")); Tomcat tomcat = getTomcat(factory); - Connector connector = ((TomcatEmbeddedServletContainer) this.container) - .getServiceConnectors().get(tomcat.getService())[0]; + Connector connector = ((TomcatWebServer) this.webServer).getServiceConnectors() + .get(tomcat.getService())[0]; assertThat(connector.getURIEncoding()).isEqualTo("US-ASCII"); } @Test public void defaultUriEncoding() throws Exception { - TomcatEmbeddedServletContainerFactory factory = getFactory(); + TomcatServletWebServerFactory factory = getFactory(); Tomcat tomcat = getTomcat(factory); - Connector connector = ((TomcatEmbeddedServletContainer) this.container) - .getServiceConnectors().get(tomcat.getService())[0]; + Connector connector = ((TomcatWebServer) this.webServer).getServiceConnectors() + .get(tomcat.getService())[0]; assertThat(connector.getURIEncoding()).isEqualTo("UTF-8"); } @@ -266,12 +263,12 @@ public class TomcatEmbeddedServletContainerFactoryTests ssl.setKeyStore("test.jks"); ssl.setKeyStorePassword("secret"); ssl.setCiphers(new String[] { "ALPHA", "BRAVO", "CHARLIE" }); - TomcatEmbeddedServletContainerFactory factory = getFactory(); + TomcatServletWebServerFactory factory = getFactory(); factory.setSsl(ssl); Tomcat tomcat = getTomcat(factory); - Connector connector = ((TomcatEmbeddedServletContainer) this.container) - .getServiceConnectors().get(tomcat.getService())[0]; + Connector connector = ((TomcatWebServer) this.webServer).getServiceConnectors() + .get(tomcat.getService())[0]; SSLHostConfig[] sslHostConfigs = connector.getProtocolHandler() .findSslHostConfigs(); assertThat(sslHostConfigs[0].getCiphers()).isEqualTo("ALPHA:BRAVO:CHARLIE"); @@ -283,13 +280,12 @@ public class TomcatEmbeddedServletContainerFactoryTests ssl.setEnabledProtocols(new String[] { "TLSv1.1", "TLSv1.2" }); ssl.setCiphers(new String[] { "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256", "BRAVO" }); - TomcatEmbeddedServletContainerFactory factory = getFactory(); + TomcatServletWebServerFactory factory = getFactory(); factory.setSsl(ssl); - this.container = factory - .getEmbeddedServletContainer(sessionServletRegistration()); - this.container.start(); - Tomcat tomcat = ((TomcatEmbeddedServletContainer) this.container).getTomcat(); + this.webServer = factory.getWebServer(sessionServletRegistration()); + this.webServer.start(); + Tomcat tomcat = ((TomcatWebServer) this.webServer).getTomcat(); Connector connector = tomcat.getConnector(); SSLHostConfig sslHostConfig = connector.getProtocolHandler() @@ -305,13 +301,12 @@ public class TomcatEmbeddedServletContainerFactoryTests ssl.setEnabledProtocols(new String[] { "TLSv1.2" }); ssl.setCiphers(new String[] { "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256", "BRAVO" }); - TomcatEmbeddedServletContainerFactory factory = getFactory(); + TomcatServletWebServerFactory factory = getFactory(); factory.setSsl(ssl); - this.container = factory - .getEmbeddedServletContainer(sessionServletRegistration()); - Tomcat tomcat = ((TomcatEmbeddedServletContainer) this.container).getTomcat(); - this.container.start(); + this.webServer = factory.getWebServer(sessionServletRegistration()); + Tomcat tomcat = ((TomcatWebServer) this.webServer).getTomcat(); + this.webServer.start(); Connector connector = tomcat.getConnector(); SSLHostConfig sslHostConfig = connector.getProtocolHandler() .findSslHostConfigs()[0]; @@ -326,16 +321,16 @@ public class TomcatEmbeddedServletContainerFactoryTests @Override public void run(int port) { - TomcatEmbeddedServletContainerFactory factory = getFactory(); + TomcatServletWebServerFactory factory = getFactory(); factory.setPort(port); try { - TomcatEmbeddedServletContainerFactoryTests.this.container = factory - .getEmbeddedServletContainer(); - TomcatEmbeddedServletContainerFactoryTests.this.container.start(); + TomcatServletWebServerFactoryTests.this.webServer = factory + .getWebServer(); + TomcatServletWebServerFactoryTests.this.webServer.start(); fail(); } - catch (EmbeddedWebServerException ex) { + catch (WebServerException ex) { // Ignore } } @@ -354,26 +349,24 @@ public class TomcatEmbeddedServletContainerFactoryTests @Test public void stopCalledWithoutStart() throws Exception { - TomcatEmbeddedServletContainerFactory factory = getFactory(); - this.container = factory - .getEmbeddedServletContainer(exampleServletRegistration()); - this.container.stop(); - Tomcat tomcat = ((TomcatEmbeddedServletContainer) this.container).getTomcat(); + TomcatServletWebServerFactory factory = getFactory(); + this.webServer = factory.getWebServer(exampleServletRegistration()); + this.webServer.stop(); + Tomcat tomcat = ((TomcatWebServer) this.webServer).getTomcat(); assertThat(tomcat.getServer().getState()).isSameAs(LifecycleState.DESTROYED); } @Override - protected void addConnector(int port, - AbstractEmbeddedServletContainerFactory factory) { + protected void addConnector(int port, AbstractServletWebServerFactory factory) { Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol"); connector.setPort(port); - ((TomcatEmbeddedServletContainerFactory) factory) + ((TomcatServletWebServerFactory) factory) .addAdditionalTomcatConnectors(connector); } @Test public void useForwardHeaders() throws Exception { - TomcatEmbeddedServletContainerFactory factory = getFactory(); + TomcatServletWebServerFactory factory = getFactory(); factory.addContextValves(new RemoteIpValve()); assertForwardHeaderIsUsed(factory); } @@ -381,19 +374,17 @@ public class TomcatEmbeddedServletContainerFactoryTests @Test public void disableDoesNotSaveSessionFiles() throws Exception { File baseDir = this.temporaryFolder.newFolder(); - TomcatEmbeddedServletContainerFactory factory = getFactory(); + TomcatServletWebServerFactory factory = getFactory(); // If baseDir is not set SESSIONS.ser is written to a different temp directory // each time. By setting it we can really ensure that data isn't saved factory.setBaseDirectory(baseDir); - this.container = factory - .getEmbeddedServletContainer(sessionServletRegistration()); - this.container.start(); + this.webServer = factory.getWebServer(sessionServletRegistration()); + this.webServer.start(); String s1 = getResponse(getLocalUrl("/session")); String s2 = getResponse(getLocalUrl("/session")); - this.container.stop(); - this.container = factory - .getEmbeddedServletContainer(sessionServletRegistration()); - this.container.start(); + this.webServer.stop(); + this.webServer = factory.getWebServer(sessionServletRegistration()); + this.webServer.start(); String s3 = getResponse(getLocalUrl("/session")); String message = "Session error s1=" + s1 + " s2=" + s2 + " s3=" + s3; assertThat(s2.split(":")[0]).as(message).isEqualTo(s1.split(":")[1]); @@ -404,28 +395,22 @@ public class TomcatEmbeddedServletContainerFactoryTests public void jndiLookupsCanBePerformedDuringApplicationContextRefresh() throws NamingException { Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); - TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory( - 0) { + TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(0) { @Override - protected TomcatEmbeddedServletContainer getTomcatEmbeddedServletContainer( - Tomcat tomcat) { + protected TomcatWebServer getTomcatWebServer(Tomcat tomcat) { tomcat.enableNaming(); - return super.getTomcatEmbeddedServletContainer(tomcat); + return super.getTomcatWebServer(tomcat); } }; - - // Container is created in onRefresh - this.container = factory.getEmbeddedServletContainer(); - + // Server is created in onRefresh + this.webServer = factory.getWebServer(); // Lookups should now be possible new InitialContext().lookup("java:comp/env"); - // Called in finishRefresh, giving us an opportunity to remove the context binding // and avoid a leak - this.container.start(); - + this.webServer.start(); // Lookups should no longer be possible this.thrown.expect(NamingException.class); new InitialContext().lookup("java:comp/env"); @@ -433,8 +418,8 @@ public class TomcatEmbeddedServletContainerFactoryTests @Test public void defaultLocaleCharsetMappingsAreOverriden() throws Exception { - TomcatEmbeddedServletContainerFactory factory = getFactory(); - this.container = factory.getEmbeddedServletContainer(); + TomcatServletWebServerFactory factory = getFactory(); + this.webServer = factory.getWebServer(); // override defaults, see org.apache.catalina.util.CharsetMapperDefault.properties assertThat(getCharset(Locale.ENGLISH).toString()).isEqualTo("UTF-8"); assertThat(getCharset(Locale.FRENCH).toString()).isEqualTo("UTF-8"); @@ -444,14 +429,14 @@ public class TomcatEmbeddedServletContainerFactoryTests public void sessionIdGeneratorIsConfiguredWithAttributesFromTheManager() { System.setProperty("jvmRoute", "test"); try { - TomcatEmbeddedServletContainerFactory factory = getFactory(); - this.container = factory.getEmbeddedServletContainer(); - this.container.start(); + TomcatServletWebServerFactory factory = getFactory(); + this.webServer = factory.getWebServer(); + this.webServer.start(); } finally { System.clearProperty("jvmRoute"); } - Tomcat tomcat = ((TomcatEmbeddedServletContainer) this.container).getTomcat(); + Tomcat tomcat = ((TomcatWebServer) this.webServer).getTomcat(); Context context = (Context) tomcat.getHost().findChildren()[0]; SessionIdGenerator sessionIdGenerator = context.getManager() .getSessionIdGenerator(); @@ -461,9 +446,9 @@ public class TomcatEmbeddedServletContainerFactoryTests @Override protected JspServlet getJspServlet() throws ServletException { - Container context = ((TomcatEmbeddedServletContainer) this.container).getTomcat() - .getHost().findChildren()[0]; - StandardWrapper standardWrapper = (StandardWrapper) context.findChild("jsp"); + Tomcat tomcat = ((TomcatWebServer) this.webServer).getTomcat(); + Container container = tomcat.getHost().findChildren()[0]; + StandardWrapper standardWrapper = (StandardWrapper) container.findChild("jsp"); if (standardWrapper == null) { return null; } @@ -474,31 +459,30 @@ public class TomcatEmbeddedServletContainerFactoryTests @SuppressWarnings("unchecked") @Override protected Map getActualMimeMappings() { - Context context = (Context) ((TomcatEmbeddedServletContainer) this.container) - .getTomcat().getHost().findChildren()[0]; + Context context = (Context) ((TomcatWebServer) this.webServer).getTomcat() + .getHost().findChildren()[0]; return (Map) ReflectionTestUtils.getField(context, "mimeMappings"); } @Override protected Charset getCharset(Locale locale) { - Context context = (Context) ((TomcatEmbeddedServletContainer) this.container) - .getTomcat().getHost().findChildren()[0]; + Context context = (Context) ((TomcatWebServer) this.webServer).getTomcat() + .getHost().findChildren()[0]; CharsetMapper mapper = ((TomcatEmbeddedContext) context).getCharsetMapper(); String charsetName = mapper.getCharset(locale); return (charsetName != null) ? Charset.forName(charsetName) : null; } - private void assertTimeout(TomcatEmbeddedServletContainerFactory factory, - int expected) { + private void assertTimeout(TomcatServletWebServerFactory factory, int expected) { Tomcat tomcat = getTomcat(factory); Context context = (Context) tomcat.getHost().findChildren()[0]; assertThat(context.getSessionTimeout()).isEqualTo(expected); } - private Tomcat getTomcat(TomcatEmbeddedServletContainerFactory factory) { - this.container = factory.getEmbeddedServletContainer(); - return ((TomcatEmbeddedServletContainer) this.container).getTomcat(); + private Tomcat getTomcat(TomcatServletWebServerFactory factory) { + this.webServer = factory.getWebServer(); + return ((TomcatWebServer) this.webServer).getTomcat(); } @Override diff --git a/spring-boot/src/test/java/org/springframework/boot/context/embedded/undertow/FileSessionPersistenceTests.java b/spring-boot/src/test/java/org/springframework/boot/web/embedded/undertow/FileSessionPersistenceTests.java similarity index 98% rename from spring-boot/src/test/java/org/springframework/boot/context/embedded/undertow/FileSessionPersistenceTests.java rename to spring-boot/src/test/java/org/springframework/boot/web/embedded/undertow/FileSessionPersistenceTests.java index 482c1706e4..0ceecf3be2 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/embedded/undertow/FileSessionPersistenceTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/web/embedded/undertow/FileSessionPersistenceTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded.undertow; +package org.springframework.boot.web.embedded.undertow; import java.io.File; import java.io.IOException; diff --git a/spring-boot/src/test/java/org/springframework/boot/context/embedded/undertow/JarResourceManagerTests.java b/spring-boot/src/test/java/org/springframework/boot/web/embedded/undertow/JarResourceManagerTests.java similarity index 97% rename from spring-boot/src/test/java/org/springframework/boot/context/embedded/undertow/JarResourceManagerTests.java rename to spring-boot/src/test/java/org/springframework/boot/web/embedded/undertow/JarResourceManagerTests.java index d967478392..4c2052e2c8 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/embedded/undertow/JarResourceManagerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/web/embedded/undertow/JarResourceManagerTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded.undertow; +package org.springframework.boot.web.embedded.undertow; import java.io.File; import java.io.FileOutputStream; diff --git a/spring-boot/src/test/java/org/springframework/boot/context/embedded/undertow/UndertowReactiveWebServerFactoryTests.java b/spring-boot/src/test/java/org/springframework/boot/web/embedded/undertow/UndertowReactiveWebServerFactoryTests.java similarity index 80% rename from spring-boot/src/test/java/org/springframework/boot/context/embedded/undertow/UndertowReactiveWebServerFactoryTests.java rename to spring-boot/src/test/java/org/springframework/boot/web/embedded/undertow/UndertowReactiveWebServerFactoryTests.java index 05dabad77c..c1fd9d1eeb 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/embedded/undertow/UndertowReactiveWebServerFactoryTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/web/embedded/undertow/UndertowReactiveWebServerFactoryTests.java @@ -14,10 +14,10 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded.undertow; +package org.springframework.boot.web.embedded.undertow; -import org.springframework.boot.context.embedded.AbstractReactiveWebServerFactory; -import org.springframework.boot.context.embedded.AbstractReactiveWebServerFactoryTests; +import org.springframework.boot.web.reactive.server.AbstractReactiveWebServerFactory; +import org.springframework.boot.web.reactive.server.AbstractReactiveWebServerFactoryTests; /** * Tests for {@link UndertowReactiveWebServerFactory} and {@link UndertowWebServer}. diff --git a/spring-boot/src/test/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactoryTests.java b/spring-boot/src/test/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServerFactoryTests.java similarity index 80% rename from spring-boot/src/test/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactoryTests.java rename to spring-boot/src/test/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServerFactoryTests.java index bd4891fed8..c9284c103e 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactoryTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServerFactoryTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded.undertow; +package org.springframework.boot.web.embedded.undertow; import java.io.File; import java.io.IOException; @@ -38,13 +38,13 @@ import org.apache.jasper.servlet.JspServlet; import org.junit.Test; import org.mockito.InOrder; -import org.springframework.boot.context.embedded.AbstractEmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.AbstractEmbeddedServletContainerFactoryTests; -import org.springframework.boot.context.embedded.ExampleServlet; -import org.springframework.boot.context.embedded.MimeMappings.Mapping; -import org.springframework.boot.context.embedded.PortInUseException; -import org.springframework.boot.web.servlet.ErrorPage; +import org.springframework.boot.web.server.ErrorPage; +import org.springframework.boot.web.server.MimeMappings.Mapping; +import org.springframework.boot.web.server.PortInUseException; import org.springframework.boot.web.servlet.ServletRegistrationBean; +import org.springframework.boot.web.servlet.server.AbstractServletWebServerFactory; +import org.springframework.boot.web.servlet.server.AbstractServletWebServerFactoryTests; +import org.springframework.boot.web.servlet.server.ExampleServlet; import org.springframework.http.HttpStatus; import org.springframework.test.util.ReflectionTestUtils; @@ -54,34 +54,33 @@ import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.mock; /** - * Tests for {@link UndertowEmbeddedServletContainerFactory} and - * {@link UndertowEmbeddedServletContainer} . + * Tests for {@link UndertowServletWebServerFactory}. * * @author Ivan Sopov * @author Andy Wilkinson */ -public class UndertowEmbeddedServletContainerFactoryTests - extends AbstractEmbeddedServletContainerFactoryTests { +public class UndertowServletWebServerFactoryTests + extends AbstractServletWebServerFactoryTests { @Override - protected UndertowEmbeddedServletContainerFactory getFactory() { - return new UndertowEmbeddedServletContainerFactory(0); + protected UndertowServletWebServerFactory getFactory() { + return new UndertowServletWebServerFactory(0); } @Test public void errorPage404() throws Exception { - AbstractEmbeddedServletContainerFactory factory = getFactory(); + AbstractServletWebServerFactory factory = getFactory(); factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/hello")); - this.container = factory.getEmbeddedServletContainer( + this.webServer = factory.getWebServer( new ServletRegistrationBean<>(new ExampleServlet(), "/hello")); - this.container.start(); + this.webServer.start(); assertThat(getResponse(getLocalUrl("/hello"))).isEqualTo("Hello World"); assertThat(getResponse(getLocalUrl("/not-found"))).isEqualTo("Hello World"); } @Test public void setNullBuilderCustomizersThrows() { - UndertowEmbeddedServletContainerFactory factory = getFactory(); + UndertowServletWebServerFactory factory = getFactory(); this.thrown.expect(IllegalArgumentException.class); this.thrown.expectMessage("Customizers must not be null"); factory.setBuilderCustomizers(null); @@ -89,7 +88,7 @@ public class UndertowEmbeddedServletContainerFactoryTests @Test public void addNullAddBuilderCustomizersThrows() { - UndertowEmbeddedServletContainerFactory factory = getFactory(); + UndertowServletWebServerFactory factory = getFactory(); this.thrown.expect(IllegalArgumentException.class); this.thrown.expectMessage("Customizers must not be null"); factory.addBuilderCustomizers((UndertowBuilderCustomizer[]) null); @@ -97,14 +96,14 @@ public class UndertowEmbeddedServletContainerFactoryTests @Test public void builderCustomizers() throws Exception { - UndertowEmbeddedServletContainerFactory factory = getFactory(); + UndertowServletWebServerFactory factory = getFactory(); UndertowBuilderCustomizer[] customizers = new UndertowBuilderCustomizer[4]; for (int i = 0; i < customizers.length; i++) { customizers[i] = mock(UndertowBuilderCustomizer.class); } factory.setBuilderCustomizers(Arrays.asList(customizers[0], customizers[1])); factory.addBuilderCustomizers(customizers[2], customizers[3]); - this.container = factory.getEmbeddedServletContainer(); + this.webServer = factory.getWebServer(); InOrder ordered = inOrder((Object[]) customizers); for (UndertowBuilderCustomizer customizer : customizers) { ordered.verify(customizer).customize((Builder) any()); @@ -113,7 +112,7 @@ public class UndertowEmbeddedServletContainerFactoryTests @Test public void setNullDeploymentInfoCustomizersThrows() { - UndertowEmbeddedServletContainerFactory factory = getFactory(); + UndertowServletWebServerFactory factory = getFactory(); this.thrown.expect(IllegalArgumentException.class); this.thrown.expectMessage("Customizers must not be null"); factory.setDeploymentInfoCustomizers(null); @@ -121,7 +120,7 @@ public class UndertowEmbeddedServletContainerFactoryTests @Test public void addNullAddDeploymentInfoCustomizersThrows() { - UndertowEmbeddedServletContainerFactory factory = getFactory(); + UndertowServletWebServerFactory factory = getFactory(); this.thrown.expect(IllegalArgumentException.class); this.thrown.expectMessage("Customizers must not be null"); factory.addDeploymentInfoCustomizers((UndertowDeploymentInfoCustomizer[]) null); @@ -129,7 +128,7 @@ public class UndertowEmbeddedServletContainerFactoryTests @Test public void deploymentInfo() throws Exception { - UndertowEmbeddedServletContainerFactory factory = getFactory(); + UndertowServletWebServerFactory factory = getFactory(); UndertowDeploymentInfoCustomizer[] customizers = new UndertowDeploymentInfoCustomizer[4]; for (int i = 0; i < customizers.length; i++) { customizers[i] = mock(UndertowDeploymentInfoCustomizer.class); @@ -137,7 +136,7 @@ public class UndertowEmbeddedServletContainerFactoryTests factory.setDeploymentInfoCustomizers( Arrays.asList(customizers[0], customizers[1])); factory.addDeploymentInfoCustomizers(customizers[2], customizers[3]); - this.container = factory.getEmbeddedServletContainer(); + this.webServer = factory.getWebServer(); InOrder ordered = inOrder((Object[]) customizers); for (UndertowDeploymentInfoCustomizer customizer : customizers) { ordered.verify(customizer).customize((DeploymentInfo) any()); @@ -151,7 +150,7 @@ public class UndertowEmbeddedServletContainerFactoryTests @Test public void defaultContextPath() throws Exception { - UndertowEmbeddedServletContainerFactory factory = getFactory(); + UndertowServletWebServerFactory factory = getFactory(); final AtomicReference contextPath = new AtomicReference<>(); factory.addDeploymentInfoCustomizers(new UndertowDeploymentInfoCustomizer() { @@ -160,13 +159,13 @@ public class UndertowEmbeddedServletContainerFactoryTests contextPath.set(deploymentInfo.getContextPath()); } }); - this.container = factory.getEmbeddedServletContainer(); + this.webServer = factory.getWebServer(); assertThat(contextPath.get()).isEqualTo("/"); } @Test public void useForwardHeaders() throws Exception { - UndertowEmbeddedServletContainerFactory factory = getFactory(); + UndertowServletWebServerFactory factory = getFactory(); factory.setUseForwardHeaders(true); assertForwardHeaderIsUsed(factory); } @@ -191,16 +190,16 @@ public class UndertowEmbeddedServletContainerFactoryTests private void testAccessLog(String prefix, String suffix, String expectedFile) throws IOException, URISyntaxException, InterruptedException { - UndertowEmbeddedServletContainerFactory factory = getFactory(); + UndertowServletWebServerFactory factory = getFactory(); factory.setAccessLogEnabled(true); factory.setAccessLogPrefix(prefix); factory.setAccessLogSuffix(suffix); File accessLogDirectory = this.temporaryFolder.getRoot(); factory.setAccessLogDirectory(accessLogDirectory); assertThat(accessLogDirectory.listFiles()).isEmpty(); - this.container = factory.getEmbeddedServletContainer( + this.webServer = factory.getWebServer( new ServletRegistrationBean<>(new ExampleServlet(), "/hello")); - this.container.start(); + this.webServer.start(); assertThat(getResponse(getLocalUrl("/hello"))).isEqualTo("Hello World"); File accessLog = new File(accessLogDirectory, expectedFile); awaitFile(accessLog); @@ -208,9 +207,8 @@ public class UndertowEmbeddedServletContainerFactoryTests } @Override - protected void addConnector(final int port, - AbstractEmbeddedServletContainerFactory factory) { - ((UndertowEmbeddedServletContainerFactory) factory) + protected void addConnector(final int port, AbstractServletWebServerFactory factory) { + ((UndertowServletWebServerFactory) factory) .addBuilderCustomizers(new UndertowBuilderCustomizer() { @Override @@ -263,15 +261,15 @@ public class UndertowEmbeddedServletContainerFactoryTests } private ServletContainer getServletContainerFromNewFactory() { - UndertowEmbeddedServletContainer undertow1 = (UndertowEmbeddedServletContainer) getFactory() - .getEmbeddedServletContainer(); + UndertowServletWebServer undertow1 = (UndertowServletWebServer) getFactory() + .getWebServer(); return ((DeploymentManager) ReflectionTestUtils.getField(undertow1, "manager")) .getDeployment().getServletContainer(); } @Override protected Map getActualMimeMappings() { - return ((DeploymentManager) ReflectionTestUtils.getField(this.container, + return ((DeploymentManager) ReflectionTestUtils.getField(this.webServer, "manager")).getDeployment().getMimeExtensionMappings(); } @@ -287,7 +285,7 @@ public class UndertowEmbeddedServletContainerFactoryTests @Override protected Charset getCharset(Locale locale) { DeploymentInfo info = ((DeploymentManager) ReflectionTestUtils - .getField(this.container, "manager")).getDeployment().getDeploymentInfo(); + .getField(this.webServer, "manager")).getDeployment().getDeploymentInfo(); String charsetName = info.getLocaleCharsetMapping().get(locale.toString()); return (charsetName != null) ? Charset.forName(charsetName) : null; } diff --git a/spring-boot/src/test/java/org/springframework/boot/context/embedded/AbstractReactiveWebServerFactoryTests.java b/spring-boot/src/test/java/org/springframework/boot/web/reactive/server/AbstractReactiveWebServerFactoryTests.java similarity index 93% rename from spring-boot/src/test/java/org/springframework/boot/context/embedded/AbstractReactiveWebServerFactoryTests.java rename to spring-boot/src/test/java/org/springframework/boot/web/reactive/server/AbstractReactiveWebServerFactoryTests.java index ecd410c1dd..a2f302112b 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/embedded/AbstractReactiveWebServerFactoryTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/web/reactive/server/AbstractReactiveWebServerFactoryTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded; +package org.springframework.boot.web.reactive.server; import org.junit.After; import org.junit.Rule; @@ -25,6 +25,7 @@ import reactor.core.publisher.Mono; import reactor.test.StepVerifier; import org.springframework.boot.testutil.InternalOutputCapture; +import org.springframework.boot.web.server.WebServer; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.server.reactive.HttpHandler; @@ -53,7 +54,7 @@ public abstract class AbstractReactiveWebServerFactoryTests { @Rule public InternalOutputCapture output = new InternalOutputCapture(); - protected EmbeddedWebServer webServer; + protected WebServer webServer; @After public void tearDown() { @@ -71,7 +72,7 @@ public abstract class AbstractReactiveWebServerFactoryTests { @Test public void startStopServer() { - this.webServer = getFactory().getReactiveHttpServer(new EchoHandler()); + this.webServer = getFactory().getWebServer(new EchoHandler()); this.webServer.start(); Mono result = getWebClient().post().uri("/test") .contentType(MediaType.TEXT_PLAIN) @@ -91,7 +92,7 @@ public abstract class AbstractReactiveWebServerFactoryTests { AbstractReactiveWebServerFactory factory = getFactory(); int specificPort = SocketUtils.findAvailableTcpPort(41000); factory.setPort(specificPort); - this.webServer = factory.getReactiveHttpServer(new EchoHandler()); + this.webServer = factory.getWebServer(new EchoHandler()); this.webServer.start(); Mono result = WebClient.create("http://localhost:" + specificPort).post() diff --git a/spring-boot/src/test/java/org/springframework/boot/context/embedded/CompressionTests.java b/spring-boot/src/test/java/org/springframework/boot/web/server/CompressionTests.java similarity index 91% rename from spring-boot/src/test/java/org/springframework/boot/context/embedded/CompressionTests.java rename to spring-boot/src/test/java/org/springframework/boot/web/server/CompressionTests.java index ac5a35fc75..5163532720 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/embedded/CompressionTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/web/server/CompressionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded; +package org.springframework.boot.web.server; import org.apache.coyote.http11.Http11NioProtocol; import org.junit.Test; diff --git a/spring-boot/src/test/java/org/springframework/boot/context/embedded/LocalServerPortTests.java b/spring-boot/src/test/java/org/springframework/boot/web/server/LocalServerPortTests.java similarity index 93% rename from spring-boot/src/test/java/org/springframework/boot/context/embedded/LocalServerPortTests.java rename to spring-boot/src/test/java/org/springframework/boot/web/server/LocalServerPortTests.java index 0d26317de3..378805cbe3 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/embedded/LocalServerPortTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/web/server/LocalServerPortTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded; +package org.springframework.boot.web.server; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/spring-boot/src/test/java/org/springframework/boot/context/embedded/MimeMappingsTests.java b/spring-boot/src/test/java/org/springframework/boot/web/server/MimeMappingsTests.java similarity index 98% rename from spring-boot/src/test/java/org/springframework/boot/context/embedded/MimeMappingsTests.java rename to spring-boot/src/test/java/org/springframework/boot/web/server/MimeMappingsTests.java index 295cdf8bdd..7955dd9f0c 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/embedded/MimeMappingsTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/web/server/MimeMappingsTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded; +package org.springframework.boot.web.server; import java.util.ArrayList; import java.util.HashMap; diff --git a/spring-boot/src/test/java/org/springframework/boot/web/servlet/FilterRegistrationIntegrationTests.java b/spring-boot/src/test/java/org/springframework/boot/web/servlet/FilterRegistrationIntegrationTests.java index 6241afc0a1..da814ac689 100644 --- a/spring-boot/src/test/java/org/springframework/boot/web/servlet/FilterRegistrationIntegrationTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/web/servlet/FilterRegistrationIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -21,9 +21,9 @@ import javax.servlet.Filter; import org.junit.After; import org.junit.Test; -import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; -import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; import org.springframework.boot.testutil.MockFilter; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -36,7 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat; */ public class FilterRegistrationIntegrationTests { - private AnnotationConfigEmbeddedWebApplicationContext context; + private AnnotationConfigServletWebServerApplicationContext context; @After public void cleanUp() { @@ -58,7 +58,7 @@ public class FilterRegistrationIntegrationTests { } private void load(Class configuration) { - this.context = new AnnotationConfigEmbeddedWebApplicationContext( + this.context = new AnnotationConfigServletWebServerApplicationContext( ContainerConfiguration.class, configuration); } @@ -66,8 +66,8 @@ public class FilterRegistrationIntegrationTests { static class ContainerConfiguration { @Bean - public TomcatEmbeddedServletContainerFactory servletContainerFactory() { - return new TomcatEmbeddedServletContainerFactory(0); + public TomcatServletWebServerFactory webServerFactory() { + return new TomcatServletWebServerFactory(0); } } diff --git a/spring-boot/src/test/java/org/springframework/boot/web/servlet/ServletComponentScanIntegrationTests.java b/spring-boot/src/test/java/org/springframework/boot/web/servlet/ServletComponentScanIntegrationTests.java index e30568b89d..01be05f64c 100644 --- a/spring-boot/src/test/java/org/springframework/boot/web/servlet/ServletComponentScanIntegrationTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/web/servlet/ServletComponentScanIntegrationTests.java @@ -23,9 +23,9 @@ import javax.servlet.MultipartConfigElement; import org.junit.After; import org.junit.Test; -import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; -import org.springframework.boot.context.embedded.ServerPortInfoApplicationContextInitializer; -import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; +import org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext; import org.springframework.boot.web.servlet.testcomponents.TestMultipartServlet; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -40,7 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat; */ public class ServletComponentScanIntegrationTests { - private AnnotationConfigEmbeddedWebApplicationContext context; + private AnnotationConfigServletWebServerApplicationContext context; @After public void cleanUp() { @@ -51,7 +51,7 @@ public class ServletComponentScanIntegrationTests { @Test public void componentsAreRegistered() { - this.context = new AnnotationConfigEmbeddedWebApplicationContext(); + this.context = new AnnotationConfigServletWebServerApplicationContext(); this.context.register(TestConfiguration.class); new ServerPortInfoApplicationContextInitializer().initialize(this.context); this.context.refresh(); @@ -63,7 +63,7 @@ public class ServletComponentScanIntegrationTests { @Test public void multipartConfigIsHonoured() { - this.context = new AnnotationConfigEmbeddedWebApplicationContext(); + this.context = new AnnotationConfigServletWebServerApplicationContext(); this.context.register(TestConfiguration.class); new ServerPortInfoApplicationContextInitializer().initialize(this.context); this.context.refresh(); @@ -87,8 +87,8 @@ public class ServletComponentScanIntegrationTests { static class TestConfiguration { @Bean - public TomcatEmbeddedServletContainerFactory servletContainerFactory() { - return new TomcatEmbeddedServletContainerFactory(0); + public TomcatServletWebServerFactory webServerFactory() { + return new TomcatServletWebServerFactory(0); } } diff --git a/spring-boot/src/test/java/org/springframework/boot/context/embedded/AnnotationConfigEmbeddedWebApplicationContextTests.java b/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/AnnotationConfigServletWebServerApplicationContextTests.java similarity index 73% rename from spring-boot/src/test/java/org/springframework/boot/context/embedded/AnnotationConfigEmbeddedWebApplicationContextTests.java rename to spring-boot/src/test/java/org/springframework/boot/web/servlet/context/AnnotationConfigServletWebServerApplicationContextTests.java index a0fd5d3b1a..4003f29f61 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/embedded/AnnotationConfigEmbeddedWebApplicationContextTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/AnnotationConfigServletWebServerApplicationContextTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded; +package org.springframework.boot.web.servlet.context; import java.io.IOException; @@ -28,8 +28,10 @@ import javax.servlet.ServletResponse; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.embedded.config.ExampleEmbeddedWebApplicationConfiguration; import org.springframework.boot.testutil.MockServlet; +import org.springframework.boot.web.servlet.context.config.ExampleEmbeddedWebApplicationConfiguration; +import org.springframework.boot.web.servlet.server.MockServletWebServerFactory; +import org.springframework.boot.web.servlet.server.ServletWebServerFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Scope; @@ -42,24 +44,24 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.verify; /** - * Tests for {@link AnnotationConfigEmbeddedWebApplicationContext}. + * Tests for {@link AnnotationConfigServletWebServerApplicationContext}. * * @author Phillip Webb */ -public class AnnotationConfigEmbeddedWebApplicationContextTests { +public class AnnotationConfigServletWebServerApplicationContextTests { - private AnnotationConfigEmbeddedWebApplicationContext context; + private AnnotationConfigServletWebServerApplicationContext context; @Test public void createFromScan() throws Exception { - this.context = new AnnotationConfigEmbeddedWebApplicationContext( + this.context = new AnnotationConfigServletWebServerApplicationContext( ExampleEmbeddedWebApplicationConfiguration.class.getPackage().getName()); verifyContext(); } @Test public void sessionScopeAvailable() throws Exception { - this.context = new AnnotationConfigEmbeddedWebApplicationContext( + this.context = new AnnotationConfigServletWebServerApplicationContext( ExampleEmbeddedWebApplicationConfiguration.class, SessionScopedComponent.class); verifyContext(); @@ -67,7 +69,7 @@ public class AnnotationConfigEmbeddedWebApplicationContextTests { @Test public void sessionScopeAvailableToServlet() throws Exception { - this.context = new AnnotationConfigEmbeddedWebApplicationContext( + this.context = new AnnotationConfigServletWebServerApplicationContext( ExampleEmbeddedWebApplicationConfiguration.class, ExampleServletWithAutowired.class, SessionScopedComponent.class); Servlet servlet = this.context.getBean(ExampleServletWithAutowired.class); @@ -76,14 +78,14 @@ public class AnnotationConfigEmbeddedWebApplicationContextTests { @Test public void createFromConfigClass() throws Exception { - this.context = new AnnotationConfigEmbeddedWebApplicationContext( + this.context = new AnnotationConfigServletWebServerApplicationContext( ExampleEmbeddedWebApplicationConfiguration.class); verifyContext(); } @Test public void registerAndRefresh() throws Exception { - this.context = new AnnotationConfigEmbeddedWebApplicationContext(); + this.context = new AnnotationConfigServletWebServerApplicationContext(); this.context.register(ExampleEmbeddedWebApplicationConfiguration.class); this.context.refresh(); verifyContext(); @@ -91,7 +93,7 @@ public class AnnotationConfigEmbeddedWebApplicationContextTests { @Test public void scanAndRefresh() throws Exception { - this.context = new AnnotationConfigEmbeddedWebApplicationContext(); + this.context = new AnnotationConfigServletWebServerApplicationContext(); this.context.scan( ExampleEmbeddedWebApplicationConfiguration.class.getPackage().getName()); this.context.refresh(); @@ -100,7 +102,7 @@ public class AnnotationConfigEmbeddedWebApplicationContextTests { @Test public void createAndInitializeCyclic() throws Exception { - this.context = new AnnotationConfigEmbeddedWebApplicationContext( + this.context = new AnnotationConfigServletWebServerApplicationContext( ServletContextAwareEmbeddedConfiguration.class); verifyContext(); // You can't initialize the application context and inject the servlet context @@ -111,10 +113,10 @@ public class AnnotationConfigEmbeddedWebApplicationContextTests { @Test public void createAndInitializeWithParent() throws Exception { - AnnotationConfigEmbeddedWebApplicationContext parent = new AnnotationConfigEmbeddedWebApplicationContext( - EmbeddedContainerConfiguration.class); - this.context = new AnnotationConfigEmbeddedWebApplicationContext(); - this.context.register(EmbeddedContainerConfiguration.class, + AnnotationConfigServletWebServerApplicationContext parent = new AnnotationConfigServletWebServerApplicationContext( + WebServerConfiguration.class); + this.context = new AnnotationConfigServletWebServerApplicationContext(); + this.context.register(WebServerConfiguration.class, ServletContextAwareConfiguration.class); this.context.setParent(parent); this.context.refresh(); @@ -124,10 +126,10 @@ public class AnnotationConfigEmbeddedWebApplicationContextTests { } private void verifyContext() { - MockEmbeddedServletContainerFactory containerFactory = this.context - .getBean(MockEmbeddedServletContainerFactory.class); + MockServletWebServerFactory factory = this.context + .getBean(MockServletWebServerFactory.class); Servlet servlet = this.context.getBean(Servlet.class); - verify(containerFactory.getServletContext()).addServlet("servlet", servlet); + verify(factory.getServletContext()).addServlet("servlet", servlet); } @Component @@ -159,8 +161,8 @@ public class AnnotationConfigEmbeddedWebApplicationContextTests { private ServletContext servletContext; @Bean - public EmbeddedServletContainerFactory containerFactory() { - return new MockEmbeddedServletContainerFactory(); + public ServletWebServerFactory webServerFactory() { + return new MockServletWebServerFactory(); } @Bean @@ -180,11 +182,11 @@ public class AnnotationConfigEmbeddedWebApplicationContextTests { } @Configuration - public static class EmbeddedContainerConfiguration { + public static class WebServerConfiguration { @Bean - public EmbeddedServletContainerFactory containerFactory() { - return new MockEmbeddedServletContainerFactory(); + public ServletWebServerFactory webServerFactory() { + return new MockServletWebServerFactory(); } } diff --git a/spring-boot/src/test/java/org/springframework/boot/context/embedded/EmbeddedWebApplicationContextTests.java b/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/ServletWebServerApplicationContextTests.java similarity index 73% rename from spring-boot/src/test/java/org/springframework/boot/context/embedded/EmbeddedWebApplicationContextTests.java rename to spring-boot/src/test/java/org/springframework/boot/web/servlet/context/ServletWebServerApplicationContextTests.java index e3cb540451..e4320681e8 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/embedded/EmbeddedWebApplicationContextTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/ServletWebServerApplicationContextTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded; +package org.springframework.boot.web.servlet.context; import java.io.IOException; import java.lang.reflect.Field; @@ -48,10 +48,12 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.config.ConstructorArgumentValues; import org.springframework.beans.factory.config.Scope; import org.springframework.beans.factory.support.RootBeanDefinition; +import org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer; import org.springframework.boot.web.servlet.DelegatingFilterProxyRegistrationBean; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.boot.web.servlet.ServletContextInitializer; import org.springframework.boot.web.servlet.ServletRegistrationBean; +import org.springframework.boot.web.servlet.server.MockServletWebServerFactory; import org.springframework.context.ApplicationContextException; import org.springframework.context.ApplicationListener; import org.springframework.context.support.AbstractApplicationContext; @@ -79,17 +81,17 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.withSettings; /** - * Tests for {@link EmbeddedWebApplicationContext}. + * Tests for {@link ServletWebServerApplicationContext}. * * @author Phillip Webb * @author Stephane Nicoll */ -public class EmbeddedWebApplicationContextTests { +public class ServletWebServerApplicationContextTests { @Rule public ExpectedException thrown = ExpectedException.none(); - private EmbeddedWebApplicationContext context; + private ServletWebServerApplicationContext context; @Captor private ArgumentCaptor filterCaptor; @@ -97,7 +99,7 @@ public class EmbeddedWebApplicationContextTests { @Before public void setup() { MockitoAnnotations.initMocks(this); - this.context = new EmbeddedWebApplicationContext(); + this.context = new ServletWebServerApplicationContext(); } @After @@ -107,22 +109,19 @@ public class EmbeddedWebApplicationContextTests { @Test public void startRegistrations() throws Exception { - addEmbeddedServletContainerFactoryBean(); + addWebServerFactoryBean(); this.context.refresh(); - - MockEmbeddedServletContainerFactory escf = getEmbeddedServletContainerFactory(); - + MockServletWebServerFactory factory = getWebServerFactory(); // Ensure that the context has been setup - assertThat(this.context.getServletContext()).isEqualTo(escf.getServletContext()); - verify(escf.getServletContext()).setAttribute( + assertThat(this.context.getServletContext()) + .isEqualTo(factory.getServletContext()); + verify(factory.getServletContext()).setAttribute( WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.context); - // Ensure WebApplicationContextUtils.registerWebApplicationScopes was called assertThat(this.context.getBeanFactory() .getRegisteredScope(WebApplicationContext.SCOPE_SESSION)) .isInstanceOf(SessionScope.class); - // Ensure WebApplicationContextUtils.registerEnvironmentBeans was called assertThat(this.context .containsBean(WebApplicationContext.SERVLET_CONTEXT_BEAN_NAME)).isTrue(); @@ -133,7 +132,7 @@ public class EmbeddedWebApplicationContextTests { // See gh-314 for background. We no longer register the shutdown hook // since it is really the callers responsibility. The shutdown hook could // also be problematic in a classic WAR deployment. - addEmbeddedServletContainerFactoryBean(); + addWebServerFactoryBean(); this.context.refresh(); Field shutdownHookField = AbstractApplicationContext.class .getDeclaredField("shutdownHook"); @@ -143,13 +142,13 @@ public class EmbeddedWebApplicationContextTests { } @Test - public void containerEventPublished() throws Exception { - addEmbeddedServletContainerFactoryBean(); + public void ServletWebServerInitializedEventPublished() throws Exception { + addWebServerFactoryBean(); this.context.registerBeanDefinition("listener", new RootBeanDefinition(MockListener.class)); this.context.refresh(); - EmbeddedServletContainerInitializedEvent event = this.context - .getBean(MockListener.class).getEvent(); + ServletWebServerInitializedEvent event = this.context.getBean(MockListener.class) + .getEvent(); assertThat(event).isNotNull(); assertThat(event.getSource().getPort() >= 0).isTrue(); assertThat(event.getApplicationContext()).isEqualTo(this.context); @@ -157,7 +156,7 @@ public class EmbeddedWebApplicationContextTests { @Test public void localPortIsAvailable() throws Exception { - addEmbeddedServletContainerFactoryBean(); + addWebServerFactoryBean(); new ServerPortInfoApplicationContextInitializer().initialize(this.context); this.context.refresh(); ConfigurableEnvironment environment = this.context.getEnvironment(); @@ -167,16 +166,16 @@ public class EmbeddedWebApplicationContextTests { @Test public void stopOnClose() throws Exception { - addEmbeddedServletContainerFactoryBean(); + addWebServerFactoryBean(); this.context.refresh(); - MockEmbeddedServletContainerFactory escf = getEmbeddedServletContainerFactory(); + MockServletWebServerFactory factory = getWebServerFactory(); this.context.close(); - verify(escf.getContainer()).stop(); + verify(factory.getWebServer()).stop(); } @Test public void cannotSecondRefresh() throws Exception { - addEmbeddedServletContainerFactoryBean(); + addWebServerFactoryBean(); this.context.refresh(); this.thrown.expect(IllegalStateException.class); this.context.refresh(); @@ -184,48 +183,49 @@ public class EmbeddedWebApplicationContextTests { @Test public void servletContextAwareBeansAreInjected() throws Exception { - addEmbeddedServletContainerFactoryBean(); + addWebServerFactoryBean(); ServletContextAware bean = mock(ServletContextAware.class); this.context.registerBeanDefinition("bean", beanDefinition(bean)); this.context.refresh(); - verify(bean).setServletContext( - getEmbeddedServletContainerFactory().getServletContext()); + verify(bean).setServletContext(getWebServerFactory().getServletContext()); } @Test - public void missingEmbeddedServletContainerFactory() throws Exception { + public void missingServletWebServerFactory() throws Exception { this.thrown.expect(ApplicationContextException.class); - this.thrown.expectMessage("Unable to start EmbeddedWebApplicationContext due to " - + "missing EmbeddedServletContainerFactory bean"); + this.thrown.expectMessage( + "Unable to start ServletWebServerApplicationContext due to missing " + + "ServletWebServerFactory bean"); this.context.refresh(); } @Test - public void tooManyEmbeddedServletContainerFactories() throws Exception { - addEmbeddedServletContainerFactoryBean(); - this.context.registerBeanDefinition("embeddedServletContainerFactory2", - new RootBeanDefinition(MockEmbeddedServletContainerFactory.class)); + public void tooManyWebServerFactories() throws Exception { + addWebServerFactoryBean(); + this.context.registerBeanDefinition("webServerFactory2", + new RootBeanDefinition(MockServletWebServerFactory.class)); this.thrown.expect(ApplicationContextException.class); - this.thrown.expectMessage("Unable to start EmbeddedWebApplicationContext due to " - + "multiple EmbeddedServletContainerFactory beans"); + this.thrown.expectMessage( + "Unable to start ServletWebServerApplicationContext due to " + + "multiple ServletWebServerFactory beans"); this.context.refresh(); } @Test public void singleServletBean() throws Exception { - addEmbeddedServletContainerFactoryBean(); + addWebServerFactoryBean(); Servlet servlet = mock(Servlet.class); this.context.registerBeanDefinition("servletBean", beanDefinition(servlet)); this.context.refresh(); - MockEmbeddedServletContainerFactory escf = getEmbeddedServletContainerFactory(); - verify(escf.getServletContext()).addServlet("servletBean", servlet); - verify(escf.getRegisteredServlet(0).getRegistration()).addMapping("/"); + MockServletWebServerFactory factory = getWebServerFactory(); + verify(factory.getServletContext()).addServlet("servletBean", servlet); + verify(factory.getRegisteredServlet(0).getRegistration()).addMapping("/"); } @Test public void orderedBeanInsertedCorrectly() throws Exception { - addEmbeddedServletContainerFactoryBean(); + addWebServerFactoryBean(); OrderedFilter filter = new OrderedFilter(); this.context.registerBeanDefinition("filterBean", beanDefinition(filter)); FilterRegistrationBean registration = new FilterRegistrationBean<>(); @@ -234,15 +234,15 @@ public class EmbeddedWebApplicationContextTests { this.context.registerBeanDefinition("filterRegistrationBean", beanDefinition(registration)); this.context.refresh(); - MockEmbeddedServletContainerFactory escf = getEmbeddedServletContainerFactory(); - verify(escf.getServletContext()).addFilter("filterBean", filter); - verify(escf.getServletContext()).addFilter("object", registration.getFilter()); - assertThat(escf.getRegisteredFilter(0).getFilter()).isEqualTo(filter); + MockServletWebServerFactory factory = getWebServerFactory(); + verify(factory.getServletContext()).addFilter("filterBean", filter); + verify(factory.getServletContext()).addFilter("object", registration.getFilter()); + assertThat(factory.getRegisteredFilter(0).getFilter()).isEqualTo(filter); } @Test public void multipleServletBeans() throws Exception { - addEmbeddedServletContainerFactoryBean(); + addWebServerFactoryBean(); Servlet servlet1 = mock(Servlet.class, withSettings().extraInterfaces(Ordered.class)); given(((Ordered) servlet1).getOrder()).willReturn(1); @@ -252,20 +252,20 @@ public class EmbeddedWebApplicationContextTests { this.context.registerBeanDefinition("servletBean2", beanDefinition(servlet2)); this.context.registerBeanDefinition("servletBean1", beanDefinition(servlet1)); this.context.refresh(); - MockEmbeddedServletContainerFactory escf = getEmbeddedServletContainerFactory(); - ServletContext servletContext = escf.getServletContext(); + MockServletWebServerFactory factory = getWebServerFactory(); + ServletContext servletContext = factory.getServletContext(); InOrder ordered = inOrder(servletContext); ordered.verify(servletContext).addServlet("servletBean1", servlet1); ordered.verify(servletContext).addServlet("servletBean2", servlet2); - verify(escf.getRegisteredServlet(0).getRegistration()) + verify(factory.getRegisteredServlet(0).getRegistration()) .addMapping("/servletBean1/"); - verify(escf.getRegisteredServlet(1).getRegistration()) + verify(factory.getRegisteredServlet(1).getRegistration()) .addMapping("/servletBean2/"); } @Test public void multipleServletBeansWithMainDispatcher() throws Exception { - addEmbeddedServletContainerFactoryBean(); + addWebServerFactoryBean(); Servlet servlet1 = mock(Servlet.class, withSettings().extraInterfaces(Ordered.class)); given(((Ordered) servlet1).getOrder()).willReturn(1); @@ -276,19 +276,19 @@ public class EmbeddedWebApplicationContextTests { this.context.registerBeanDefinition("dispatcherServlet", beanDefinition(servlet1)); this.context.refresh(); - MockEmbeddedServletContainerFactory escf = getEmbeddedServletContainerFactory(); - ServletContext servletContext = escf.getServletContext(); + MockServletWebServerFactory factory = getWebServerFactory(); + ServletContext servletContext = factory.getServletContext(); InOrder ordered = inOrder(servletContext); ordered.verify(servletContext).addServlet("dispatcherServlet", servlet1); ordered.verify(servletContext).addServlet("servletBean2", servlet2); - verify(escf.getRegisteredServlet(0).getRegistration()).addMapping("/"); - verify(escf.getRegisteredServlet(1).getRegistration()) + verify(factory.getRegisteredServlet(0).getRegistration()).addMapping("/"); + verify(factory.getRegisteredServlet(1).getRegistration()) .addMapping("/servletBean2/"); } @Test public void servletAndFilterBeans() throws Exception { - addEmbeddedServletContainerFactoryBean(); + addWebServerFactoryBean(); Servlet servlet = mock(Servlet.class); Filter filter1 = mock(Filter.class, withSettings().extraInterfaces(Ordered.class)); @@ -300,22 +300,22 @@ public class EmbeddedWebApplicationContextTests { this.context.registerBeanDefinition("filterBean2", beanDefinition(filter2)); this.context.registerBeanDefinition("filterBean1", beanDefinition(filter1)); this.context.refresh(); - MockEmbeddedServletContainerFactory escf = getEmbeddedServletContainerFactory(); - ServletContext servletContext = escf.getServletContext(); + MockServletWebServerFactory factory = getWebServerFactory(); + ServletContext servletContext = factory.getServletContext(); InOrder ordered = inOrder(servletContext); - verify(escf.getServletContext()).addServlet("servletBean", servlet); - verify(escf.getRegisteredServlet(0).getRegistration()).addMapping("/"); - ordered.verify(escf.getServletContext()).addFilter("filterBean1", filter1); - ordered.verify(escf.getServletContext()).addFilter("filterBean2", filter2); - verify(escf.getRegisteredFilter(0).getRegistration()).addMappingForUrlPatterns( + verify(factory.getServletContext()).addServlet("servletBean", servlet); + verify(factory.getRegisteredServlet(0).getRegistration()).addMapping("/"); + ordered.verify(factory.getServletContext()).addFilter("filterBean1", filter1); + ordered.verify(factory.getServletContext()).addFilter("filterBean2", filter2); + verify(factory.getRegisteredFilter(0).getRegistration()).addMappingForUrlPatterns( EnumSet.of(DispatcherType.REQUEST), false, "/*"); - verify(escf.getRegisteredFilter(1).getRegistration()).addMappingForUrlPatterns( + verify(factory.getRegisteredFilter(1).getRegistration()).addMappingForUrlPatterns( EnumSet.of(DispatcherType.REQUEST), false, "/*"); } @Test public void servletContextInitializerBeans() throws Exception { - addEmbeddedServletContainerFactoryBean(); + addWebServerFactoryBean(); ServletContextInitializer initializer1 = mock(ServletContextInitializer.class, withSettings().extraInterfaces(Ordered.class)); given(((Ordered) initializer1).getOrder()).willReturn(1); @@ -327,8 +327,7 @@ public class EmbeddedWebApplicationContextTests { this.context.registerBeanDefinition("initializerBean1", beanDefinition(initializer1)); this.context.refresh(); - ServletContext servletContext = getEmbeddedServletContainerFactory() - .getServletContext(); + ServletContext servletContext = getWebServerFactory().getServletContext(); InOrder ordered = inOrder(initializer1, initializer2); ordered.verify(initializer1).onStartup(servletContext); ordered.verify(initializer2).onStartup(servletContext); @@ -336,19 +335,18 @@ public class EmbeddedWebApplicationContextTests { @Test public void servletContextListenerBeans() throws Exception { - addEmbeddedServletContainerFactoryBean(); + addWebServerFactoryBean(); ServletContextListener initializer = mock(ServletContextListener.class); this.context.registerBeanDefinition("initializerBean", beanDefinition(initializer)); this.context.refresh(); - ServletContext servletContext = getEmbeddedServletContainerFactory() - .getServletContext(); + ServletContext servletContext = getWebServerFactory().getServletContext(); verify(servletContext).addListener(initializer); } @Test public void unorderedServletContextInitializerBeans() throws Exception { - addEmbeddedServletContainerFactoryBean(); + addWebServerFactoryBean(); ServletContextInitializer initializer1 = mock(ServletContextInitializer.class); ServletContextInitializer initializer2 = mock(ServletContextInitializer.class); this.context.registerBeanDefinition("initializerBean2", @@ -356,8 +354,7 @@ public class EmbeddedWebApplicationContextTests { this.context.registerBeanDefinition("initializerBean1", beanDefinition(initializer1)); this.context.refresh(); - ServletContext servletContext = getEmbeddedServletContainerFactory() - .getServletContext(); + ServletContext servletContext = getWebServerFactory().getServletContext(); verify(initializer1).onStartup(servletContext); verify(initializer2).onStartup(servletContext); } @@ -365,7 +362,7 @@ public class EmbeddedWebApplicationContextTests { @Test public void servletContextInitializerBeansDoesNotSkipServletsAndFilters() throws Exception { - addEmbeddedServletContainerFactoryBean(); + addWebServerFactoryBean(); ServletContextInitializer initializer = mock(ServletContextInitializer.class); Servlet servlet = mock(Servlet.class); Filter filter = mock(Filter.class); @@ -374,8 +371,7 @@ public class EmbeddedWebApplicationContextTests { this.context.registerBeanDefinition("servletBean", beanDefinition(servlet)); this.context.registerBeanDefinition("filterBean", beanDefinition(filter)); this.context.refresh(); - ServletContext servletContext = getEmbeddedServletContainerFactory() - .getServletContext(); + ServletContext servletContext = getWebServerFactory().getServletContext(); verify(initializer).onStartup(servletContext); verify(servletContext).addServlet(anyString(), (Servlet) any()); verify(servletContext).addFilter(anyString(), (Filter) any()); @@ -384,7 +380,7 @@ public class EmbeddedWebApplicationContextTests { @Test public void servletContextInitializerBeansSkipsRegisteredServletsAndFilters() throws Exception { - addEmbeddedServletContainerFactoryBean(); + addWebServerFactoryBean(); Servlet servlet = mock(Servlet.class); Filter filter = mock(Filter.class); ServletRegistrationBean initializer = new ServletRegistrationBean<>( @@ -394,30 +390,28 @@ public class EmbeddedWebApplicationContextTests { this.context.registerBeanDefinition("servletBean", beanDefinition(servlet)); this.context.registerBeanDefinition("filterBean", beanDefinition(filter)); this.context.refresh(); - ServletContext servletContext = getEmbeddedServletContainerFactory() - .getServletContext(); + ServletContext servletContext = getWebServerFactory().getServletContext(); verify(servletContext, atMost(1)).addServlet(anyString(), (Servlet) any()); verify(servletContext, atMost(1)).addFilter(anyString(), (Filter) any()); } @Test public void filterRegistrationBeansSkipsRegisteredFilters() throws Exception { - addEmbeddedServletContainerFactoryBean(); + addWebServerFactoryBean(); Filter filter = mock(Filter.class); FilterRegistrationBean initializer = new FilterRegistrationBean<>(filter); this.context.registerBeanDefinition("initializerBean", beanDefinition(initializer)); this.context.registerBeanDefinition("filterBean", beanDefinition(filter)); this.context.refresh(); - ServletContext servletContext = getEmbeddedServletContainerFactory() - .getServletContext(); + ServletContext servletContext = getWebServerFactory().getServletContext(); verify(servletContext, atMost(1)).addFilter(anyString(), (Filter) any()); } @Test public void delegatingFilterProxyRegistrationBeansSkipsTargetBeanNames() throws Exception { - addEmbeddedServletContainerFactoryBean(); + addWebServerFactoryBean(); DelegatingFilterProxyRegistrationBean initializer = new DelegatingFilterProxyRegistrationBean( "filterBean"); this.context.registerBeanDefinition("initializerBean", @@ -427,8 +421,7 @@ public class EmbeddedWebApplicationContextTests { filterBeanDefinition.setLazyInit(true); this.context.registerBeanDefinition("filterBean", filterBeanDefinition); this.context.refresh(); - ServletContext servletContext = getEmbeddedServletContainerFactory() - .getServletContext(); + ServletContext servletContext = getWebServerFactory().getServletContext(); verify(servletContext, atMost(1)).addFilter(anyString(), this.filterCaptor.capture()); // Up to this point the filterBean should not have been created, calling @@ -441,24 +434,21 @@ public class EmbeddedWebApplicationContextTests { } @Test - public void postProcessEmbeddedServletContainerFactory() throws Exception { - RootBeanDefinition bd = new RootBeanDefinition( - MockEmbeddedServletContainerFactory.class); + public void postProcessWebServerFactory() throws Exception { + RootBeanDefinition beanDefinition = new RootBeanDefinition( + MockServletWebServerFactory.class); MutablePropertyValues pv = new MutablePropertyValues(); pv.add("port", "${port}"); - bd.setPropertyValues(pv); - this.context.registerBeanDefinition("embeddedServletContainerFactory", bd); - + beanDefinition.setPropertyValues(pv); + this.context.registerBeanDefinition("webServerFactory", beanDefinition); PropertySourcesPlaceholderConfigurer propertySupport = new PropertySourcesPlaceholderConfigurer(); Properties properties = new Properties(); properties.put("port", 8080); propertySupport.setProperties(properties); this.context.registerBeanDefinition("propertySupport", beanDefinition(propertySupport)); - this.context.refresh(); - assertThat(getEmbeddedServletContainerFactory().getContainer().getPort()) - .isEqualTo(8080); + assertThat(getWebServerFactory().getWebServer().getPort()).isEqualTo(8080); } @Test @@ -467,7 +457,7 @@ public class EmbeddedWebApplicationContextTests { ConfigurableListableBeanFactory factory = this.context.getBeanFactory(); factory.registerScope(WebApplicationContext.SCOPE_REQUEST, scope); factory.registerScope(WebApplicationContext.SCOPE_SESSION, scope); - addEmbeddedServletContainerFactoryBean(); + addWebServerFactoryBean(); this.context.refresh(); assertThat(factory.getRegisteredScope(WebApplicationContext.SCOPE_REQUEST)) .isSameAs(scope); @@ -475,13 +465,13 @@ public class EmbeddedWebApplicationContextTests { .isSameAs(scope); } - private void addEmbeddedServletContainerFactoryBean() { - this.context.registerBeanDefinition("embeddedServletContainerFactory", - new RootBeanDefinition(MockEmbeddedServletContainerFactory.class)); + private void addWebServerFactoryBean() { + this.context.registerBeanDefinition("webServerFactory", + new RootBeanDefinition(MockServletWebServerFactory.class)); } - public MockEmbeddedServletContainerFactory getEmbeddedServletContainerFactory() { - return this.context.getBean(MockEmbeddedServletContainerFactory.class); + public MockServletWebServerFactory getWebServerFactory() { + return this.context.getBean(MockServletWebServerFactory.class); } private BeanDefinition beanDefinition(Object bean) { @@ -502,16 +492,16 @@ public class EmbeddedWebApplicationContextTests { } public static class MockListener - implements ApplicationListener { + implements ApplicationListener { - private EmbeddedServletContainerInitializedEvent event; + private ServletWebServerInitializedEvent event; @Override - public void onApplicationEvent(EmbeddedServletContainerInitializedEvent event) { + public void onApplicationEvent(ServletWebServerInitializedEvent event) { this.event = event; } - public EmbeddedServletContainerInitializedEvent getEvent() { + public ServletWebServerInitializedEvent getEvent() { return this.event; } diff --git a/spring-boot/src/test/java/org/springframework/boot/context/embedded/EmbeddedServletContainerMvcIntegrationTests.java b/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/ServletWebServerMvcIntegrationTests.java similarity index 72% rename from spring-boot/src/test/java/org/springframework/boot/context/embedded/EmbeddedServletContainerMvcIntegrationTests.java rename to spring-boot/src/test/java/org/springframework/boot/web/servlet/context/ServletWebServerMvcIntegrationTests.java index 4c53f0c2ed..abd44b8471 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/embedded/EmbeddedServletContainerMvcIntegrationTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/ServletWebServerMvcIntegrationTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded; +package org.springframework.boot.web.servlet.context; import java.net.URI; import java.nio.charset.Charset; @@ -22,10 +22,12 @@ import java.nio.charset.Charset; import org.junit.After; import org.junit.Test; -import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory; +import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory; +import org.springframework.boot.web.server.WebServer; import org.springframework.boot.web.servlet.ServletRegistrationBean; +import org.springframework.boot.web.servlet.server.ServletWebServerFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @@ -45,15 +47,15 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc; import static org.assertj.core.api.Assertions.assertThat; /** - * Integration tests for {@link EmbeddedWebApplicationContext} and - * {@link EmbeddedWebServer}s running Spring MVC. + * Integration tests for {@link ServletWebServerApplicationContext} and {@link WebServer}s + * running Spring MVC. * * @author Phillip Webb * @author Ivan Sopov */ -public class EmbeddedServletContainerMvcIntegrationTests { +public class ServletWebServerMvcIntegrationTests { - private AnnotationConfigEmbeddedWebApplicationContext context; + private AnnotationConfigServletWebServerApplicationContext context; @After public void closeContext() { @@ -67,38 +69,37 @@ public class EmbeddedServletContainerMvcIntegrationTests { @Test public void tomcat() throws Exception { - this.context = new AnnotationConfigEmbeddedWebApplicationContext( + this.context = new AnnotationConfigServletWebServerApplicationContext( TomcatConfig.class); doTest(this.context, "/hello"); } @Test public void jetty() throws Exception { - this.context = new AnnotationConfigEmbeddedWebApplicationContext( + this.context = new AnnotationConfigServletWebServerApplicationContext( JettyConfig.class); doTest(this.context, "/hello"); } @Test public void undertow() throws Exception { - this.context = new AnnotationConfigEmbeddedWebApplicationContext( + this.context = new AnnotationConfigServletWebServerApplicationContext( UndertowConfig.class); doTest(this.context, "/hello"); } @Test public void advancedConfig() throws Exception { - this.context = new AnnotationConfigEmbeddedWebApplicationContext( + this.context = new AnnotationConfigServletWebServerApplicationContext( AdvancedConfig.class); doTest(this.context, "/example/spring/hello"); } - private void doTest(AnnotationConfigEmbeddedWebApplicationContext context, + private void doTest(AnnotationConfigServletWebServerApplicationContext context, String resourcePath) throws Exception { SimpleClientHttpRequestFactory clientHttpRequestFactory = new SimpleClientHttpRequestFactory(); - ClientHttpRequest request = clientHttpRequestFactory.createRequest( - new URI("http://localhost:" + context.getEmbeddedWebServer().getPort() - + resourcePath), + ClientHttpRequest request = clientHttpRequestFactory.createRequest(new URI( + "http://localhost:" + context.getWebServer().getPort() + resourcePath), HttpMethod.GET); ClientHttpResponse response = request.execute(); try { @@ -114,8 +115,8 @@ public class EmbeddedServletContainerMvcIntegrationTests { // Simple main method for testing in a browser @SuppressWarnings("resource") public static void main(String[] args) { - new AnnotationConfigEmbeddedWebApplicationContext( - JettyEmbeddedServletContainerFactory.class, Config.class); + new AnnotationConfigServletWebServerApplicationContext( + JettyServletWebServerFactory.class, Config.class); } @Configuration @@ -123,8 +124,8 @@ public class EmbeddedServletContainerMvcIntegrationTests { public static class TomcatConfig { @Bean - public EmbeddedServletContainerFactory containerFactory() { - return new TomcatEmbeddedServletContainerFactory(0); + public ServletWebServerFactory webServerFactory() { + return new TomcatServletWebServerFactory(0); } } @@ -134,8 +135,8 @@ public class EmbeddedServletContainerMvcIntegrationTests { public static class JettyConfig { @Bean - public EmbeddedServletContainerFactory containerFactory() { - return new JettyEmbeddedServletContainerFactory(0); + public ServletWebServerFactory webServerFactory() { + return new JettyServletWebServerFactory(0); } } @@ -145,8 +146,8 @@ public class EmbeddedServletContainerMvcIntegrationTests { public static class UndertowConfig { @Bean - public EmbeddedServletContainerFactory containerFactory() { - return new UndertowEmbeddedServletContainerFactory(0); + public ServletWebServerFactory webServerFactory() { + return new UndertowServletWebServerFactory(0); } } @@ -172,7 +173,7 @@ public class EmbeddedServletContainerMvcIntegrationTests { @Configuration @EnableWebMvc - @PropertySource("classpath:/org/springframework/boot/context/embedded/conf.properties") + @PropertySource("classpath:/org/springframework/boot/web/servlet/context/conf.properties") public static class AdvancedConfig { private final Environment env; @@ -182,9 +183,8 @@ public class EmbeddedServletContainerMvcIntegrationTests { } @Bean - public EmbeddedServletContainerFactory containerFactory() { - JettyEmbeddedServletContainerFactory factory = new JettyEmbeddedServletContainerFactory( - 0); + public ServletWebServerFactory webServerFactory() { + JettyServletWebServerFactory factory = new JettyServletWebServerFactory(0); factory.setContextPath(this.env.getProperty("context")); return factory; } diff --git a/spring-boot/src/test/java/org/springframework/boot/context/embedded/XmlEmbeddedWebApplicationContextTests.java b/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/XmlServletWebServerApplicationContextTests.java similarity index 66% rename from spring-boot/src/test/java/org/springframework/boot/context/embedded/XmlEmbeddedWebApplicationContextTests.java rename to spring-boot/src/test/java/org/springframework/boot/web/servlet/context/XmlServletWebServerApplicationContextTests.java index 94ae430a18..5ab35dea67 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/embedded/XmlEmbeddedWebApplicationContextTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/XmlServletWebServerApplicationContextTests.java @@ -14,52 +14,53 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded; +package org.springframework.boot.web.servlet.context; import javax.servlet.Servlet; import org.junit.Test; +import org.springframework.boot.web.servlet.server.MockServletWebServerFactory; import org.springframework.core.io.ClassPathResource; import static org.mockito.Mockito.verify; /** - * Tests for {@link XmlEmbeddedWebApplicationContext}. + * Tests for {@link XmlServletWebServerApplicationContext}. * * @author Phillip Webb */ -public class XmlEmbeddedWebApplicationContextTests { +public class XmlServletWebServerApplicationContextTests { - private static final String PATH = XmlEmbeddedWebApplicationContextTests.class + private static final String PATH = XmlServletWebServerApplicationContextTests.class .getPackage().getName().replace('.', '/') + "/"; private static final String FILE = "exampleEmbeddedWebApplicationConfiguration.xml"; - private XmlEmbeddedWebApplicationContext context; + private XmlServletWebServerApplicationContext context; @Test public void createFromResource() throws Exception { - this.context = new XmlEmbeddedWebApplicationContext( + this.context = new XmlServletWebServerApplicationContext( new ClassPathResource(FILE, getClass())); verifyContext(); } @Test public void createFromResourceLocation() throws Exception { - this.context = new XmlEmbeddedWebApplicationContext(PATH + FILE); + this.context = new XmlServletWebServerApplicationContext(PATH + FILE); verifyContext(); } @Test public void createFromRelativeResourceLocation() throws Exception { - this.context = new XmlEmbeddedWebApplicationContext(getClass(), FILE); + this.context = new XmlServletWebServerApplicationContext(getClass(), FILE); verifyContext(); } @Test public void loadAndRefreshFromResource() throws Exception { - this.context = new XmlEmbeddedWebApplicationContext(); + this.context = new XmlServletWebServerApplicationContext(); this.context.load(new ClassPathResource(FILE, getClass())); this.context.refresh(); verifyContext(); @@ -67,7 +68,7 @@ public class XmlEmbeddedWebApplicationContextTests { @Test public void loadAndRefreshFromResourceLocation() throws Exception { - this.context = new XmlEmbeddedWebApplicationContext(); + this.context = new XmlServletWebServerApplicationContext(); this.context.load(PATH + FILE); this.context.refresh(); verifyContext(); @@ -75,17 +76,17 @@ public class XmlEmbeddedWebApplicationContextTests { @Test public void loadAndRefreshFromRelativeResourceLocation() throws Exception { - this.context = new XmlEmbeddedWebApplicationContext(); + this.context = new XmlServletWebServerApplicationContext(); this.context.load(getClass(), FILE); this.context.refresh(); verifyContext(); } private void verifyContext() { - MockEmbeddedServletContainerFactory containerFactory = this.context - .getBean(MockEmbeddedServletContainerFactory.class); + MockServletWebServerFactory factory = this.context + .getBean(MockServletWebServerFactory.class); Servlet servlet = this.context.getBean(Servlet.class); - verify(containerFactory.getServletContext()).addServlet("servlet", servlet); + verify(factory.getServletContext()).addServlet("servlet", servlet); } } diff --git a/spring-boot/src/test/java/org/springframework/boot/context/embedded/config/ExampleEmbeddedWebApplicationConfiguration.java b/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/config/ExampleEmbeddedWebApplicationConfiguration.java similarity index 64% rename from spring-boot/src/test/java/org/springframework/boot/context/embedded/config/ExampleEmbeddedWebApplicationConfiguration.java rename to spring-boot/src/test/java/org/springframework/boot/web/servlet/context/config/ExampleEmbeddedWebApplicationConfiguration.java index 7ebd6597ca..1900648401 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/embedded/config/ExampleEmbeddedWebApplicationConfiguration.java +++ b/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/config/ExampleEmbeddedWebApplicationConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -14,20 +14,19 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded.config; +package org.springframework.boot.web.servlet.context.config; import javax.servlet.Servlet; -import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContextTests; -import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.MockEmbeddedServletContainerFactory; import org.springframework.boot.testutil.MockServlet; +import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContextTests; +import org.springframework.boot.web.servlet.server.MockServletWebServerFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; /** * Example {@code @Configuration} for use with - * {@link AnnotationConfigEmbeddedWebApplicationContextTests}. + * {@link AnnotationConfigServletWebServerApplicationContextTests}. * * @author Phillip Webb */ @@ -35,8 +34,8 @@ import org.springframework.context.annotation.Configuration; public class ExampleEmbeddedWebApplicationConfiguration { @Bean - public EmbeddedServletContainerFactory containerFactory() { - return new MockEmbeddedServletContainerFactory(); + public MockServletWebServerFactory webServerFactory() { + return new MockServletWebServerFactory(); } @Bean diff --git a/spring-boot/src/test/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactoryTests.java b/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactoryTests.java similarity index 80% rename from spring-boot/src/test/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactoryTests.java rename to spring-boot/src/test/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactoryTests.java index 0405e8031b..4a50a1906d 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactoryTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactoryTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded; +package org.springframework.boot.web.servlet.server; import java.io.File; import java.io.FileInputStream; @@ -81,9 +81,14 @@ import org.mockito.InOrder; import org.springframework.boot.ApplicationHome; import org.springframework.boot.ApplicationTemp; -import org.springframework.boot.context.embedded.Ssl.ClientAuth; import org.springframework.boot.testutil.InternalOutputCapture; -import org.springframework.boot.web.servlet.ErrorPage; +import org.springframework.boot.web.server.Compression; +import org.springframework.boot.web.server.ErrorPage; +import org.springframework.boot.web.server.MimeMappings; +import org.springframework.boot.web.server.Ssl; +import org.springframework.boot.web.server.Ssl.ClientAuth; +import org.springframework.boot.web.server.SslStoreProvider; +import org.springframework.boot.web.server.WebServer; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.boot.web.servlet.ServletContextInitializer; import org.springframework.boot.web.servlet.ServletRegistrationBean; @@ -111,13 +116,13 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; /** - * Base for testing classes that extends {@link AbstractEmbeddedServletContainerFactory}. + * Base for testing classes that extends {@link AbstractServletWebServerFactory}. * * @author Phillip Webb * @author Greg Turnquist * @author Andy Wilkinson */ -public abstract class AbstractEmbeddedServletContainerFactoryTests { +public abstract class AbstractServletWebServerFactoryTests { @Rule public ExpectedException thrown = ExpectedException.none(); @@ -128,7 +133,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Rule public InternalOutputCapture output = new InternalOutputCapture(); - protected EmbeddedWebServer container; + protected WebServer webServer; private final HttpClientContext httpClientContext = HttpClientContext.create(); @@ -142,9 +147,9 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @After public void tearDown() { - if (this.container != null) { + if (this.webServer != null) { try { - this.container.stop(); + this.webServer.stop(); } catch (Exception ex) { // Ignore @@ -154,54 +159,54 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Test public void startServlet() throws Exception { - AbstractEmbeddedServletContainerFactory factory = getFactory(); - this.container = factory - .getEmbeddedServletContainer(exampleServletRegistration()); - this.container.start(); + AbstractServletWebServerFactory factory = getFactory(); + this.webServer = factory + .getWebServer(exampleServletRegistration()); + this.webServer.start(); assertThat(getResponse(getLocalUrl("/hello"))).isEqualTo("Hello World"); } @Test public void startCalledTwice() throws Exception { - AbstractEmbeddedServletContainerFactory factory = getFactory(); - this.container = factory - .getEmbeddedServletContainer(exampleServletRegistration()); - this.container.start(); - int port = this.container.getPort(); - this.container.start(); - assertThat(this.container.getPort()).isEqualTo(port); + AbstractServletWebServerFactory factory = getFactory(); + this.webServer = factory + .getWebServer(exampleServletRegistration()); + this.webServer.start(); + int port = this.webServer.getPort(); + this.webServer.start(); + assertThat(this.webServer.getPort()).isEqualTo(port); assertThat(getResponse(getLocalUrl("/hello"))).isEqualTo("Hello World"); assertThat(this.output.toString()).containsOnlyOnce("started on port"); } @Test public void stopCalledTwice() throws Exception { - AbstractEmbeddedServletContainerFactory factory = getFactory(); - this.container = factory - .getEmbeddedServletContainer(exampleServletRegistration()); - this.container.start(); - this.container.stop(); - this.container.stop(); + AbstractServletWebServerFactory factory = getFactory(); + this.webServer = factory + .getWebServer(exampleServletRegistration()); + this.webServer.start(); + this.webServer.stop(); + this.webServer.stop(); } @Test public void emptyServerWhenPortIsMinusOne() throws Exception { - AbstractEmbeddedServletContainerFactory factory = getFactory(); + AbstractServletWebServerFactory factory = getFactory(); factory.setPort(-1); - this.container = factory - .getEmbeddedServletContainer(exampleServletRegistration()); - this.container.start(); - assertThat(this.container.getPort()).isLessThan(0); // Jetty is -2 + this.webServer = factory + .getWebServer(exampleServletRegistration()); + this.webServer.start(); + assertThat(this.webServer.getPort()).isLessThan(0); // Jetty is -2 } @Test public void stopServlet() throws Exception { - AbstractEmbeddedServletContainerFactory factory = getFactory(); - this.container = factory - .getEmbeddedServletContainer(exampleServletRegistration()); - this.container.start(); - int port = this.container.getPort(); - this.container.stop(); + AbstractServletWebServerFactory factory = getFactory(); + this.webServer = factory + .getWebServer(exampleServletRegistration()); + this.webServer.start(); + int port = this.webServer.getPort(); + this.webServer.stop(); this.thrown.expect(IOException.class); String response = getResponse(getLocalUrl(port, "/hello")); throw new RuntimeException( @@ -210,20 +215,20 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Test public void restartWithKeepAlive() throws Exception { - AbstractEmbeddedServletContainerFactory factory = getFactory(); - this.container = factory - .getEmbeddedServletContainer(exampleServletRegistration()); - this.container.start(); + AbstractServletWebServerFactory factory = getFactory(); + this.webServer = factory + .getWebServer(exampleServletRegistration()); + this.webServer.start(); HttpComponentsAsyncClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsAsyncClientHttpRequestFactory(); ListenableFuture response1 = clientHttpRequestFactory .createAsyncRequest(new URI(getLocalUrl("/hello")), HttpMethod.GET) .executeAsync(); assertThat(response1.get(10, TimeUnit.SECONDS).getRawStatusCode()).isEqualTo(200); - this.container.stop(); - this.container = factory - .getEmbeddedServletContainer(exampleServletRegistration()); - this.container.start(); + this.webServer.stop(); + this.webServer = factory + .getWebServer(exampleServletRegistration()); + this.webServer.start(); ListenableFuture response2 = clientHttpRequestFactory .createAsyncRequest(new URI(getLocalUrl("/hello")), HttpMethod.GET) @@ -234,19 +239,19 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Test public void startServletAndFilter() throws Exception { - AbstractEmbeddedServletContainerFactory factory = getFactory(); - this.container = factory.getEmbeddedServletContainer(exampleServletRegistration(), + AbstractServletWebServerFactory factory = getFactory(); + this.webServer = factory.getWebServer(exampleServletRegistration(), new FilterRegistrationBean<>(new ExampleFilter())); - this.container.start(); + this.webServer.start(); assertThat(getResponse(getLocalUrl("/hello"))).isEqualTo("[Hello World]"); } @Test public void startBlocksUntilReadyToServe() throws Exception { - AbstractEmbeddedServletContainerFactory factory = getFactory(); + AbstractServletWebServerFactory factory = getFactory(); final Date[] date = new Date[1]; - this.container = factory - .getEmbeddedServletContainer(new ServletContextInitializer() { + this.webServer = factory + .getWebServer(new ServletContextInitializer() { @Override public void onStartup(ServletContext servletContext) throws ServletException { @@ -259,16 +264,16 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { } } }); - this.container.start(); + this.webServer.start(); assertThat(date[0]).isNotNull(); } @Test public void loadOnStartAfterContextIsInitialized() throws Exception { - AbstractEmbeddedServletContainerFactory factory = getFactory(); + AbstractServletWebServerFactory factory = getFactory(); final InitCountingServlet servlet = new InitCountingServlet(); - this.container = factory - .getEmbeddedServletContainer(new ServletContextInitializer() { + this.webServer = factory + .getWebServer(new ServletContextInitializer() { @Override public void onStartup(ServletContext servletContext) throws ServletException { @@ -276,30 +281,30 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { } }); assertThat(servlet.getInitCount()).isEqualTo(0); - this.container.start(); + this.webServer.start(); assertThat(servlet.getInitCount()).isEqualTo(1); } @Test public void specificPort() throws Exception { - AbstractEmbeddedServletContainerFactory factory = getFactory(); + AbstractServletWebServerFactory factory = getFactory(); int specificPort = SocketUtils.findAvailableTcpPort(41000); factory.setPort(specificPort); - this.container = factory - .getEmbeddedServletContainer(exampleServletRegistration()); - this.container.start(); + this.webServer = factory + .getWebServer(exampleServletRegistration()); + this.webServer.start(); assertThat(getResponse("http://localhost:" + specificPort + "/hello")) .isEqualTo("Hello World"); - assertThat(this.container.getPort()).isEqualTo(specificPort); + assertThat(this.webServer.getPort()).isEqualTo(specificPort); } @Test public void specificContextRoot() throws Exception { - AbstractEmbeddedServletContainerFactory factory = getFactory(); + AbstractServletWebServerFactory factory = getFactory(); factory.setContextPath("/say"); - this.container = factory - .getEmbeddedServletContainer(exampleServletRegistration()); - this.container.start(); + this.webServer = factory + .getWebServer(exampleServletRegistration()); + this.webServer.start(); assertThat(getResponse(getLocalUrl("/say/hello"))).isEqualTo("Hello World"); } @@ -327,16 +332,16 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Test public void multipleConfigurations() throws Exception { - AbstractEmbeddedServletContainerFactory factory = getFactory(); + AbstractServletWebServerFactory factory = getFactory(); ServletContextInitializer[] initializers = new ServletContextInitializer[6]; for (int i = 0; i < initializers.length; i++) { initializers[i] = mock(ServletContextInitializer.class); } factory.setInitializers(Arrays.asList(initializers[2], initializers[3])); factory.addInitializers(initializers[4], initializers[5]); - this.container = factory.getEmbeddedServletContainer(initializers[0], + this.webServer = factory.getWebServer(initializers[0], initializers[1]); - this.container.start(); + this.webServer.start(); InOrder ordered = inOrder((Object[]) initializers); for (ServletContextInitializer initializer : initializers) { ordered.verify(initializer).onStartup((ServletContext) any()); @@ -345,10 +350,10 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Test public void documentRoot() throws Exception { - AbstractEmbeddedServletContainerFactory factory = getFactory(); + AbstractServletWebServerFactory factory = getFactory(); addTestTxtFile(factory); - this.container = factory.getEmbeddedServletContainer(); - this.container.start(); + this.webServer = factory.getWebServer(); + this.webServer.start(); assertThat(getResponse(getLocalUrl("/test.txt"))).isEqualTo("test"); } @@ -356,13 +361,13 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { public void mimeType() throws Exception { FileCopyUtils.copy("test", new FileWriter(this.temporaryFolder.newFile("test.xxcss"))); - AbstractEmbeddedServletContainerFactory factory = getFactory(); + AbstractServletWebServerFactory factory = getFactory(); factory.setDocumentRoot(this.temporaryFolder.getRoot()); MimeMappings mimeMappings = new MimeMappings(); mimeMappings.add("xxcss", "text/css"); factory.setMimeMappings(mimeMappings); - this.container = factory.getEmbeddedServletContainer(); - this.container.start(); + this.webServer = factory.getWebServer(); + this.webServer.start(); ClientHttpResponse response = getClientResponse(getLocalUrl("/test.xxcss")); assertThat(response.getHeaders().getContentType().toString()) .isEqualTo("text/css"); @@ -371,22 +376,22 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Test public void errorPage() throws Exception { - AbstractEmbeddedServletContainerFactory factory = getFactory(); + AbstractServletWebServerFactory factory = getFactory(); factory.addErrorPages(new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/hello")); - this.container = factory.getEmbeddedServletContainer(exampleServletRegistration(), + this.webServer = factory.getWebServer(exampleServletRegistration(), errorServletRegistration()); - this.container.start(); + this.webServer.start(); assertThat(getResponse(getLocalUrl("/hello"))).isEqualTo("Hello World"); assertThat(getResponse(getLocalUrl("/bang"))).isEqualTo("Hello World"); } @Test public void errorPageFromPutRequest() throws Exception { - AbstractEmbeddedServletContainerFactory factory = getFactory(); + AbstractServletWebServerFactory factory = getFactory(); factory.addErrorPages(new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/hello")); - this.container = factory.getEmbeddedServletContainer(exampleServletRegistration(), + this.webServer = factory.getWebServer(exampleServletRegistration(), errorServletRegistration()); - this.container.start(); + this.webServer.start(); assertThat(getResponse(getLocalUrl("/hello"), HttpMethod.PUT)) .isEqualTo("Hello World"); assertThat(getResponse(getLocalUrl("/bang"), HttpMethod.PUT)) @@ -405,13 +410,13 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Test public void sslDisabled() throws Exception { - AbstractEmbeddedServletContainerFactory factory = getFactory(); + AbstractServletWebServerFactory factory = getFactory(); Ssl ssl = getSsl(null, "password", "classpath:test.jks"); ssl.setEnabled(false); factory.setSsl(ssl); - this.container = factory.getEmbeddedServletContainer( + this.webServer = factory.getWebServer( new ServletRegistrationBean<>(new ExampleServlet(true, false), "/hello")); - this.container.start(); + this.webServer.start(); SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory( new SSLContextBuilder() .loadTrustMaterial(null, new TrustSelfSignedStrategy()).build()); @@ -425,11 +430,11 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Test public void sslGetScheme() throws Exception { // gh-2232 - AbstractEmbeddedServletContainerFactory factory = getFactory(); + AbstractServletWebServerFactory factory = getFactory(); factory.setSsl(getSsl(null, "password", "src/test/resources/test.jks")); - this.container = factory.getEmbeddedServletContainer( + this.webServer = factory.getWebServer( new ServletRegistrationBean<>(new ExampleServlet(true, false), "/hello")); - this.container.start(); + this.webServer.start(); SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory( new SSLContextBuilder() .loadTrustMaterial(null, new TrustSelfSignedStrategy()).build()); @@ -443,11 +448,11 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Test public void serverHeaderIsDisabledByDefaultWhenUsingSsl() throws Exception { - AbstractEmbeddedServletContainerFactory factory = getFactory(); + AbstractServletWebServerFactory factory = getFactory(); factory.setSsl(getSsl(null, "password", "src/test/resources/test.jks")); - this.container = factory.getEmbeddedServletContainer( + this.webServer = factory.getWebServer( new ServletRegistrationBean<>(new ExampleServlet(true, false), "/hello")); - this.container.start(); + this.webServer.start(); SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory( new SSLContextBuilder() .loadTrustMaterial(null, new TrustSelfSignedStrategy()).build()); @@ -460,12 +465,12 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Test public void serverHeaderCanBeCustomizedWhenUsingSsl() throws Exception { - AbstractEmbeddedServletContainerFactory factory = getFactory(); + AbstractServletWebServerFactory factory = getFactory(); factory.setServerHeader("MyServer"); factory.setSsl(getSsl(null, "password", "src/test/resources/test.jks")); - this.container = factory.getEmbeddedServletContainer( + this.webServer = factory.getWebServer( new ServletRegistrationBean<>(new ExampleServlet(true, false), "/hello")); - this.container.start(); + this.webServer.start(); SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory( new SSLContextBuilder() .loadTrustMaterial(null, new TrustSelfSignedStrategy()).build()); @@ -477,11 +482,11 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { } protected final void testBasicSslWithKeyStore(String keyStore) throws Exception { - AbstractEmbeddedServletContainerFactory factory = getFactory(); + AbstractServletWebServerFactory factory = getFactory(); addTestTxtFile(factory); factory.setSsl(getSsl(null, "password", keyStore)); - this.container = factory.getEmbeddedServletContainer(); - this.container.start(); + this.webServer = factory.getWebServer(); + this.webServer.start(); SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory( new SSLContextBuilder() .loadTrustMaterial(null, new TrustSelfSignedStrategy()).build()); @@ -495,12 +500,12 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Test public void pkcs12KeyStoreAndTrustStore() throws Exception { - AbstractEmbeddedServletContainerFactory factory = getFactory(); + AbstractServletWebServerFactory factory = getFactory(); addTestTxtFile(factory); factory.setSsl(getSsl(ClientAuth.NEED, null, "classpath:test.p12", "classpath:test.p12", null, null)); - this.container = factory.getEmbeddedServletContainer(); - this.container.start(); + this.webServer = factory.getWebServer(); + this.webServer.start(); KeyStore keyStore = KeyStore.getInstance("pkcs12"); keyStore.load(new FileInputStream(new File("src/test/resources/test.p12")), "secret".toCharArray()); @@ -519,12 +524,12 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Test public void sslNeedsClientAuthenticationSucceedsWithClientCertificate() throws Exception { - AbstractEmbeddedServletContainerFactory factory = getFactory(); + AbstractServletWebServerFactory factory = getFactory(); addTestTxtFile(factory); factory.setSsl(getSsl(ClientAuth.NEED, "password", "classpath:test.jks", "classpath:test.jks", null, null)); - this.container = factory.getEmbeddedServletContainer(); - this.container.start(); + this.webServer = factory.getWebServer(); + this.webServer.start(); KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); keyStore.load(new FileInputStream(new File("src/test/resources/test.jks")), "secret".toCharArray()); @@ -543,11 +548,11 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Test(expected = IOException.class) public void sslNeedsClientAuthenticationFailsWithoutClientCertificate() throws Exception { - AbstractEmbeddedServletContainerFactory factory = getFactory(); + AbstractServletWebServerFactory factory = getFactory(); addTestTxtFile(factory); factory.setSsl(getSsl(ClientAuth.NEED, "password", "classpath:test.jks")); - this.container = factory.getEmbeddedServletContainer(); - this.container.start(); + this.webServer = factory.getWebServer(); + this.webServer.start(); SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory( new SSLContextBuilder() .loadTrustMaterial(null, new TrustSelfSignedStrategy()).build()); @@ -561,11 +566,11 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Test public void sslWantsClientAuthenticationSucceedsWithClientCertificate() throws Exception { - AbstractEmbeddedServletContainerFactory factory = getFactory(); + AbstractServletWebServerFactory factory = getFactory(); addTestTxtFile(factory); factory.setSsl(getSsl(ClientAuth.WANT, "password", "classpath:test.jks")); - this.container = factory.getEmbeddedServletContainer(); - this.container.start(); + this.webServer = factory.getWebServer(); + this.webServer.start(); KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); keyStore.load(new FileInputStream(new File("src/test/resources/test.jks")), "secret".toCharArray()); @@ -584,11 +589,11 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Test public void sslWantsClientAuthenticationSucceedsWithoutClientCertificate() throws Exception { - AbstractEmbeddedServletContainerFactory factory = getFactory(); + AbstractServletWebServerFactory factory = getFactory(); addTestTxtFile(factory); factory.setSsl(getSsl(ClientAuth.WANT, "password", "classpath:test.jks")); - this.container = factory.getEmbeddedServletContainer(); - this.container.start(); + this.webServer = factory.getWebServer(); + this.webServer.start(); SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory( new SSLContextBuilder() .loadTrustMaterial(null, new TrustSelfSignedStrategy()).build()); @@ -602,7 +607,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Test public void sslWithCustomSslStoreProvider() throws Exception { - AbstractEmbeddedServletContainerFactory factory = getFactory(); + AbstractServletWebServerFactory factory = getFactory(); addTestTxtFile(factory); Ssl ssl = new Ssl(); ssl.setClientAuth(ClientAuth.NEED); @@ -612,8 +617,8 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { given(sslStoreProvider.getKeyStore()).willReturn(loadStore()); given(sslStoreProvider.getTrustStore()).willReturn(loadStore()); factory.setSslStoreProvider(sslStoreProvider); - this.container = factory.getEmbeddedServletContainer(); - this.container.start(); + this.webServer = factory.getWebServer(); + this.webServer.start(); KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); keyStore.load(new FileInputStream(new File("src/test/resources/test.jks")), "secret".toCharArray()); @@ -633,18 +638,18 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Test public void disableJspServletRegistration() throws Exception { - AbstractEmbeddedServletContainerFactory factory = getFactory(); + AbstractServletWebServerFactory factory = getFactory(); factory.getJsp().setRegistered(false); - this.container = factory.getEmbeddedServletContainer(); + this.webServer = factory.getWebServer(); assertThat(getJspServlet()).isNull(); } @Test public void cannotReadClassPathFiles() throws Exception { - AbstractEmbeddedServletContainerFactory factory = getFactory(); - this.container = factory - .getEmbeddedServletContainer(exampleServletRegistration()); - this.container.start(); + AbstractServletWebServerFactory factory = getFactory(); + this.webServer = factory + .getWebServer(exampleServletRegistration()); + this.webServer.start(); ClientHttpResponse response = getClientResponse( getLocalUrl("/org/springframework/boot/SpringApplication.class")); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); @@ -682,12 +687,12 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { protected void testRestrictedSSLProtocolsAndCipherSuites(String[] protocols, String[] ciphers) throws Exception { - AbstractEmbeddedServletContainerFactory factory = getFactory(); + AbstractServletWebServerFactory factory = getFactory(); factory.setSsl(getSsl(null, "password", "src/test/resources/test.jks", null, protocols, ciphers)); - this.container = factory.getEmbeddedServletContainer( + this.webServer = factory.getWebServer( new ServletRegistrationBean<>(new ExampleServlet(true, false), "/hello")); - this.container.start(); + this.webServer.start(); SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory( new SSLContextBuilder() @@ -713,17 +718,17 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Test public void persistSession() throws Exception { - AbstractEmbeddedServletContainerFactory factory = getFactory(); + AbstractServletWebServerFactory factory = getFactory(); factory.setPersistSession(true); - this.container = factory - .getEmbeddedServletContainer(sessionServletRegistration()); - this.container.start(); + this.webServer = factory + .getWebServer(sessionServletRegistration()); + this.webServer.start(); String s1 = getResponse(getLocalUrl("/session")); String s2 = getResponse(getLocalUrl("/session")); - this.container.stop(); - this.container = factory - .getEmbeddedServletContainer(sessionServletRegistration()); - this.container.start(); + this.webServer.stop(); + this.webServer = factory + .getWebServer(sessionServletRegistration()); + this.webServer.start(); String s3 = getResponse(getLocalUrl("/session")); String message = "Session error s1=" + s1 + " s2=" + s2 + " s3=" + s3; assertThat(s2.split(":")[0]).as(message).isEqualTo(s1.split(":")[1]); @@ -732,15 +737,15 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Test public void persistSessionInSpecificSessionStoreDir() throws Exception { - AbstractEmbeddedServletContainerFactory factory = getFactory(); + AbstractServletWebServerFactory factory = getFactory(); File sessionStoreDir = this.temporaryFolder.newFolder(); factory.setPersistSession(true); factory.setSessionStoreDir(sessionStoreDir); - this.container = factory - .getEmbeddedServletContainer(sessionServletRegistration()); - this.container.start(); + this.webServer = factory + .getWebServer(sessionServletRegistration()); + this.webServer.start(); getResponse(getLocalUrl("/session")); - this.container.stop(); + this.webServer.stop(); File[] dirContents = sessionStoreDir.listFiles(new FilenameFilter() { @Override @@ -754,7 +759,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Test public void getValidSessionStoreWhenSessionStoreNotSet() throws Exception { - AbstractEmbeddedServletContainerFactory factory = getFactory(); + AbstractServletWebServerFactory factory = getFactory(); File dir = factory.getValidSessionStoreDir(false); assertThat(dir.getName()).isEqualTo("servlet-sessions"); assertThat(dir.getParentFile()).isEqualTo(new ApplicationTemp().getDir()); @@ -762,7 +767,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Test public void getValidSessionStoreWhenSessionStoreIsRelative() throws Exception { - AbstractEmbeddedServletContainerFactory factory = getFactory(); + AbstractServletWebServerFactory factory = getFactory(); factory.setSessionStoreDir(new File("sessions")); File dir = factory.getValidSessionStoreDir(false); assertThat(dir.getName()).isEqualTo("sessions"); @@ -771,7 +776,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Test public void getValidSessionStoreWhenSessionStoreReferencesFile() throws Exception { - AbstractEmbeddedServletContainerFactory factory = getFactory(); + AbstractServletWebServerFactory factory = getFactory(); factory.setSessionStoreDir(this.temporaryFolder.newFile()); this.thrown.expect(IllegalStateException.class); this.thrown.expectMessage("points to a file"); @@ -802,13 +807,13 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Test public void compressionWithoutContentSizeHeader() throws Exception { - AbstractEmbeddedServletContainerFactory factory = getFactory(); + AbstractServletWebServerFactory factory = getFactory(); Compression compression = new Compression(); compression.setEnabled(true); factory.setCompression(compression); - this.container = factory.getEmbeddedServletContainer( + this.webServer = factory.getWebServer( new ServletRegistrationBean<>(new ExampleServlet(false, true), "/hello")); - this.container.start(); + this.webServer.start(); TestGzipInputStreamFactory inputStreamFactory = new TestGzipInputStreamFactory(); Map contentDecoderMap = Collections .singletonMap("gzip", (InputStreamFactory) inputStreamFactory); @@ -820,8 +825,8 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Test public void mimeMappingsAreCorrectlyConfigured() throws Exception { - AbstractEmbeddedServletContainerFactory factory = getFactory(); - this.container = factory.getEmbeddedServletContainer(); + AbstractServletWebServerFactory factory = getFactory(); + this.webServer = factory.getWebServer(); Map configuredMimeMappings = getActualMimeMappings(); Set> entrySet = configuredMimeMappings.entrySet(); Collection expectedMimeMappings = getExpectedMimeMappings(); @@ -838,10 +843,10 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Test public void rootServletContextResource() throws Exception { - AbstractEmbeddedServletContainerFactory factory = getFactory(); + AbstractServletWebServerFactory factory = getFactory(); final AtomicReference rootResource = new AtomicReference<>(); - this.container = factory - .getEmbeddedServletContainer(new ServletContextInitializer() { + this.webServer = factory + .getWebServer(new ServletContextInitializer() { @Override public void onStartup(ServletContext servletContext) throws ServletException { @@ -853,27 +858,27 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { } } }); - this.container.start(); + this.webServer.start(); assertThat(rootResource.get()).isNotNull(); } @Test public void customServerHeader() throws Exception { - AbstractEmbeddedServletContainerFactory factory = getFactory(); + AbstractServletWebServerFactory factory = getFactory(); factory.setServerHeader("MyServer"); - this.container = factory - .getEmbeddedServletContainer(exampleServletRegistration()); - this.container.start(); + this.webServer = factory + .getWebServer(exampleServletRegistration()); + this.webServer.start(); ClientHttpResponse response = getClientResponse(getLocalUrl("/hello")); assertThat(response.getHeaders().getFirst("server")).isEqualTo("MyServer"); } @Test public void serverHeaderIsDisabledByDefault() throws Exception { - AbstractEmbeddedServletContainerFactory factory = getFactory(); - this.container = factory - .getEmbeddedServletContainer(exampleServletRegistration()); - this.container.start(); + AbstractServletWebServerFactory factory = getFactory(); + this.webServer = factory + .getWebServer(exampleServletRegistration()); + this.webServer.start(); ClientHttpResponse response = getClientResponse(getLocalUrl("/hello")); assertThat(response.getHeaders().getFirst("server")).isNull(); } @@ -886,11 +891,11 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Override public void run(int port) { try { - AbstractEmbeddedServletContainerFactory factory = getFactory(); + AbstractServletWebServerFactory factory = getFactory(); factory.setPort(port); - AbstractEmbeddedServletContainerFactoryTests.this.container = factory - .getEmbeddedServletContainer(); - AbstractEmbeddedServletContainerFactoryTests.this.container.start(); + AbstractServletWebServerFactoryTests.this.webServer = factory + .getWebServer(); + AbstractServletWebServerFactoryTests.this.webServer.start(); fail(); } catch (RuntimeException ex) { @@ -909,12 +914,12 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Override public void run(int port) { try { - AbstractEmbeddedServletContainerFactory factory = getFactory(); + AbstractServletWebServerFactory factory = getFactory(); factory.setPort(SocketUtils.findAvailableTcpPort(40000)); addConnector(port, factory); - AbstractEmbeddedServletContainerFactoryTests.this.container = factory - .getEmbeddedServletContainer(); - AbstractEmbeddedServletContainerFactoryTests.this.container.start(); + AbstractServletWebServerFactoryTests.this.webServer = factory + .getWebServer(); + AbstractServletWebServerFactoryTests.this.webServer.start(); fail(); } catch (RuntimeException ex) { @@ -927,11 +932,11 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Test public void localeCharsetMappingsAreConfigured() throws Exception { - AbstractEmbeddedServletContainerFactory factory = getFactory(); + AbstractServletWebServerFactory factory = getFactory(); Map mappings = new HashMap<>(); mappings.put(Locale.GERMAN, Charset.forName("UTF-8")); factory.setLocaleCharsetMappings(mappings); - this.container = factory.getEmbeddedServletContainer(); + this.webServer = factory.getWebServer(); assertThat(getCharset(Locale.GERMAN).toString()).isEqualTo("UTF-8"); assertThat(getCharset(Locale.ITALIAN)).isNull(); } @@ -940,9 +945,9 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { public void jspServletInitParameters() throws Exception { Map initParameters = new HashMap<>(); initParameters.put("a", "alpha"); - AbstractEmbeddedServletContainerFactory factory = getFactory(); + AbstractServletWebServerFactory factory = getFactory(); factory.getJsp().setInitParameters(initParameters); - this.container = factory.getEmbeddedServletContainer(); + this.webServer = factory.getWebServer(); Assume.assumeThat(getJspServlet(), notNullValue()); JspServlet jspServlet = getJspServlet(); assertThat(jspServlet.getInitParameter("a")).isEqualTo("alpha"); @@ -950,8 +955,8 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Test public void jspServletIsNotInDevelopmentModeByDefault() throws Exception { - AbstractEmbeddedServletContainerFactory factory = getFactory(); - this.container = factory.getEmbeddedServletContainer(); + AbstractServletWebServerFactory factory = getFactory(); + this.webServer = factory.getWebServer(); Assume.assumeThat(getJspServlet(), notNullValue()); JspServlet jspServlet = getJspServlet(); EmbeddedServletOptions options = (EmbeddedServletOptions) ReflectionTestUtils @@ -961,7 +966,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Test public void explodedWarFileDocumentRootWhenRunningFromExplodedWar() throws Exception { - AbstractEmbeddedServletContainerFactory factory = getFactory(); + AbstractServletWebServerFactory factory = getFactory(); File webInfClasses = this.temporaryFolder.newFolder("test.war", "WEB-INF", "lib", "spring-boot.jar"); File documentRoot = factory.getExplodedWarFileDocumentRoot(webInfClasses); @@ -971,14 +976,14 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Test public void explodedWarFileDocumentRootWhenRunningFromPackagedWar() throws Exception { - AbstractEmbeddedServletContainerFactory factory = getFactory(); + AbstractServletWebServerFactory factory = getFactory(); File codeSourceFile = this.temporaryFolder.newFile("test.war"); File documentRoot = factory.getExplodedWarFileDocumentRoot(codeSourceFile); assertThat(documentRoot).isNull(); } protected abstract void addConnector(int port, - AbstractEmbeddedServletContainerFactory factory); + AbstractServletWebServerFactory factory); protected abstract void handleExceptionCausedByBlockedPort(RuntimeException ex, int blockedPort); @@ -1003,7 +1008,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { char[] chars = new char[contentSize]; Arrays.fill(chars, 'F'); String testContent = new String(chars); - AbstractEmbeddedServletContainerFactory factory = getFactory(); + AbstractServletWebServerFactory factory = getFactory(); FileCopyUtils.copy(testContent, new FileWriter(this.temporaryFolder.newFile("test.txt"))); factory.setDocumentRoot(this.temporaryFolder.getRoot()); @@ -1016,8 +1021,8 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { compression.setExcludedUserAgents(excludedUserAgents); } factory.setCompression(compression); - this.container = factory.getEmbeddedServletContainer(); - this.container.start(); + this.webServer = factory.getWebServer(); + this.webServer.start(); return testContent; } @@ -1029,7 +1034,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { protected abstract Charset getCharset(Locale locale); - private void addTestTxtFile(AbstractEmbeddedServletContainerFactory factory) + private void addTestTxtFile(AbstractServletWebServerFactory factory) throws IOException { FileCopyUtils.copy("test", new FileWriter(this.temporaryFolder.newFile("test.txt"))); @@ -1041,7 +1046,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { } protected String getLocalUrl(String scheme, String resourcePath) { - return scheme + "://localhost:" + this.container.getPort() + resourcePath; + return scheme + "://localhost:" + this.webServer.getPort() + resourcePath; } protected String getLocalUrl(int port, String resourcePath) { @@ -1096,7 +1101,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Override protected HttpContext createHttpContext(HttpMethod httpMethod, URI uri) { - return AbstractEmbeddedServletContainerFactoryTests.this.httpClientContext; + return AbstractServletWebServerFactoryTests.this.httpClientContext; } }, headers); @@ -1115,16 +1120,16 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { return response; } - protected void assertForwardHeaderIsUsed(EmbeddedServletContainerFactory factory) + protected void assertForwardHeaderIsUsed(ServletWebServerFactory factory) throws IOException, URISyntaxException { - this.container = factory.getEmbeddedServletContainer( + this.webServer = factory.getWebServer( new ServletRegistrationBean<>(new ExampleServlet(true, false), "/hello")); - this.container.start(); + this.webServer.start(); assertThat(getResponse(getLocalUrl("/hello"), "X-Forwarded-For:140.211.11.130")) .contains("remoteaddr=140.211.11.130"); } - protected abstract AbstractEmbeddedServletContainerFactory getFactory(); + protected abstract AbstractServletWebServerFactory getFactory(); protected abstract org.apache.jasper.servlet.JspServlet getJspServlet() throws Exception; diff --git a/spring-boot/src/test/java/org/springframework/boot/context/embedded/ExampleFilter.java b/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/ExampleFilter.java similarity index 92% rename from spring-boot/src/test/java/org/springframework/boot/context/embedded/ExampleFilter.java rename to spring-boot/src/test/java/org/springframework/boot/web/servlet/server/ExampleFilter.java index 19c36178ff..30d658c260 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/embedded/ExampleFilter.java +++ b/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/ExampleFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded; +package org.springframework.boot.web.servlet.server; import java.io.IOException; diff --git a/spring-boot/src/test/java/org/springframework/boot/context/embedded/ExampleServlet.java b/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/ExampleServlet.java similarity index 94% rename from spring-boot/src/test/java/org/springframework/boot/context/embedded/ExampleServlet.java rename to spring-boot/src/test/java/org/springframework/boot/web/servlet/server/ExampleServlet.java index de8c065886..bb5d85fb4f 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/embedded/ExampleServlet.java +++ b/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/ExampleServlet.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2017 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded; +package org.springframework.boot.web.servlet.server; import java.io.IOException; diff --git a/spring-boot/src/test/java/org/springframework/boot/context/embedded/MockEmbeddedServletContainerFactory.java b/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/MockServletWebServerFactory.java similarity index 82% rename from spring-boot/src/test/java/org/springframework/boot/context/embedded/MockEmbeddedServletContainerFactory.java rename to spring-boot/src/test/java/org/springframework/boot/web/servlet/server/MockServletWebServerFactory.java index 064893f4c7..ef71941151 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/embedded/MockEmbeddedServletContainerFactory.java +++ b/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/MockServletWebServerFactory.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.context.embedded; +package org.springframework.boot.web.servlet.server; import java.util.ArrayList; import java.util.Collections; @@ -35,6 +35,8 @@ import javax.servlet.ServletRegistration; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; +import org.springframework.boot.web.server.WebServer; +import org.springframework.boot.web.server.WebServerException; import org.springframework.boot.web.servlet.ServletContextInitializer; import static org.mockito.ArgumentMatchers.any; @@ -44,43 +46,41 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; /** - * Mock {@link EmbeddedServletContainerFactory}. + * Mock {@link ServletWebServerFactory}. * * @author Phillip Webb * @author Andy Wilkinson */ -public class MockEmbeddedServletContainerFactory - extends AbstractEmbeddedServletContainerFactory { +public class MockServletWebServerFactory extends AbstractServletWebServerFactory { - private MockEmbeddedServletContainer container; + private MockServletWebServer webServer; @Override - public EmbeddedWebServer getEmbeddedServletContainer( - ServletContextInitializer... initializers) { - this.container = spy(new MockEmbeddedServletContainer( - mergeInitializers(initializers), getPort())); - return this.container; + public WebServer getWebServer(ServletContextInitializer... initializers) { + this.webServer = spy( + new MockServletWebServer(mergeInitializers(initializers), getPort())); + return this.webServer; } - public MockEmbeddedServletContainer getContainer() { - return this.container; + public MockServletWebServer getWebServer() { + return this.webServer; } public ServletContext getServletContext() { - return getContainer() == null ? null : getContainer().servletContext; + return getWebServer() == null ? null : getWebServer().servletContext; } public RegisteredServlet getRegisteredServlet(int index) { - return getContainer() == null ? null - : getContainer().getRegisteredServlets().get(index); + return getWebServer() == null ? null + : getWebServer().getRegisteredServlets().get(index); } public RegisteredFilter getRegisteredFilter(int index) { - return getContainer() == null ? null - : getContainer().getRegisteredFilters().get(index); + return getWebServer() == null ? null + : getWebServer().getRegisteredFilters().get(index); } - public static class MockEmbeddedServletContainer implements EmbeddedWebServer { + public static class MockServletWebServer implements WebServer { private ServletContext servletContext; @@ -92,8 +92,7 @@ public class MockEmbeddedServletContainerFactory private final int port; - public MockEmbeddedServletContainer(ServletContextInitializer[] initializers, - int port) { + public MockServletWebServer(ServletContextInitializer[] initializers, int port) { this.initializers = initializers; this.port = port; initialize(); @@ -109,7 +108,7 @@ public class MockEmbeddedServletContainerFactory InvocationOnMock invocation) throws Throwable { RegisteredServlet registeredServlet = new RegisteredServlet( (Servlet) invocation.getArguments()[1]); - MockEmbeddedServletContainer.this.registeredServlets + MockServletWebServer.this.registeredServlets .add(registeredServlet); return registeredServlet.getRegistration(); } @@ -121,7 +120,7 @@ public class MockEmbeddedServletContainerFactory InvocationOnMock invocation) throws Throwable { RegisteredFilter registeredFilter = new RegisteredFilter( (Filter) invocation.getArguments()[1]); - MockEmbeddedServletContainer.this.registeredFilters + MockServletWebServer.this.registeredFilters .add(registeredFilter); return registeredFilter.getRegistration(); } @@ -148,8 +147,8 @@ public class MockEmbeddedServletContainerFactory return initParameters.get(invocation.getArgument(0)); } }); - given(this.servletContext.getAttributeNames()).willReturn( - MockEmbeddedServletContainer.emptyEnumeration()); + given(this.servletContext.getAttributeNames()) + .willReturn(MockServletWebServer.emptyEnumeration()); given(this.servletContext.getNamedDispatcher("default")) .willReturn(mock(RequestDispatcher.class)); for (ServletContextInitializer initializer : this.initializers) { @@ -167,7 +166,7 @@ public class MockEmbeddedServletContainerFactory } @Override - public void start() throws EmbeddedWebServerException { + public void start() throws WebServerException { } @Override diff --git a/spring-boot/src/test/java/org/springframework/boot/web/support/ErrorPageFilterIntegrationTests.java b/spring-boot/src/test/java/org/springframework/boot/web/support/ErrorPageFilterIntegrationTests.java index 31c795b5db..2ccfcf2d01 100644 --- a/spring-boot/src/test/java/org/springframework/boot/web/support/ErrorPageFilterIntegrationTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/web/support/ErrorPageFilterIntegrationTests.java @@ -29,9 +29,9 @@ import org.junit.runner.RunWith; import org.xnio.channels.UnsupportedOptionException; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; -import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext; +import org.springframework.boot.web.servlet.server.ServletWebServerFactory; import org.springframework.boot.web.support.ErrorPageFilterIntegrationTests.EmbeddedWebContextLoader; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; @@ -72,7 +72,7 @@ public class ErrorPageFilterIntegrationTests { private HelloWorldController controller; @Autowired - private AnnotationConfigEmbeddedWebApplicationContext context; + private AnnotationConfigServletWebServerApplicationContext context; @After public void init() { @@ -91,9 +91,9 @@ public class ErrorPageFilterIntegrationTests { assertThat(this.controller.getStatus()).isEqualTo(200); } - private void doTest(AnnotationConfigEmbeddedWebApplicationContext context, + private void doTest(AnnotationConfigServletWebServerApplicationContext context, String resourcePath, HttpStatus status) throws Exception { - int port = context.getEmbeddedWebServer().getPort(); + int port = context.getWebServer().getPort(); RestTemplate template = new RestTemplate(); ResponseEntity entity = template.getForEntity( new URI("http://localhost:" + port + resourcePath), String.class); @@ -106,8 +106,8 @@ public class ErrorPageFilterIntegrationTests { public static class TomcatConfig { @Bean - public EmbeddedServletContainerFactory containerFactory() { - return new TomcatEmbeddedServletContainerFactory(0); + public ServletWebServerFactory webServerFactory() { + return new TomcatServletWebServerFactory(0); } @Bean @@ -184,7 +184,7 @@ public class ErrorPageFilterIntegrationTests { @Override public ApplicationContext loadContext(MergedContextConfiguration config) throws Exception { - AnnotationConfigEmbeddedWebApplicationContext context = new AnnotationConfigEmbeddedWebApplicationContext( + AnnotationConfigServletWebServerApplicationContext context = new AnnotationConfigServletWebServerApplicationContext( config.getClasses()); context.registerShutdownHook(); return context; diff --git a/spring-boot/src/test/java/org/springframework/boot/web/support/ErrorPageFilterTests.java b/spring-boot/src/test/java/org/springframework/boot/web/support/ErrorPageFilterTests.java index 4a6ac79f3e..ab1fa270b7 100644 --- a/spring-boot/src/test/java/org/springframework/boot/web/support/ErrorPageFilterTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/web/support/ErrorPageFilterTests.java @@ -32,7 +32,7 @@ import org.junit.Rule; import org.junit.Test; import org.springframework.boot.testutil.InternalOutputCapture; -import org.springframework.boot.web.servlet.ErrorPage; +import org.springframework.boot.web.server.ErrorPage; import org.springframework.http.HttpStatus; import org.springframework.mock.web.MockFilterChain; import org.springframework.mock.web.MockFilterConfig; diff --git a/spring-boot/src/test/java/org/springframework/boot/web/support/SpringBootServletInitializerTests.java b/spring-boot/src/test/java/org/springframework/boot/web/support/SpringBootServletInitializerTests.java index f1673af55b..97bf425f5d 100644 --- a/spring-boot/src/test/java/org/springframework/boot/web/support/SpringBootServletInitializerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/web/support/SpringBootServletInitializerTests.java @@ -26,10 +26,10 @@ import org.junit.rules.ExpectedException; import org.springframework.beans.DirectFieldAccessor; import org.springframework.boot.SpringApplication; import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.EmbeddedWebServer; -import org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory; +import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory; +import org.springframework.boot.web.server.WebServer; import org.springframework.boot.web.servlet.ServletContextInitializer; +import org.springframework.boot.web.servlet.server.ServletWebServerFactory; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -96,8 +96,8 @@ public class SpringBootServletInitializerTests { @Test public void errorPageFilterRegistrationCanBeDisabled() throws Exception { - EmbeddedWebServer container = new UndertowEmbeddedServletContainerFactory(0) - .getEmbeddedServletContainer(new ServletContextInitializer() { + WebServer webServer = new UndertowServletWebServerFactory(0) + .getWebServer(new ServletContextInitializer() { @Override public void onStartup(ServletContext servletContext) @@ -114,10 +114,10 @@ public class SpringBootServletInitializerTests { } }); try { - container.start(); + webServer.start(); } finally { - container.stop(); + webServer.stop(); } } @@ -198,8 +198,8 @@ public class SpringBootServletInitializerTests { public static class ExecutableWar extends SpringBootServletInitializer { @Bean - public EmbeddedServletContainerFactory containerFactory() { - return new UndertowEmbeddedServletContainerFactory(0); + public ServletWebServerFactory webServerFactory() { + return new UndertowServletWebServerFactory(0); } } diff --git a/spring-boot/src/test/resources/org/springframework/boot/context/embedded/conf.properties b/spring-boot/src/test/resources/org/springframework/boot/web/servlet/context/conf.properties similarity index 100% rename from spring-boot/src/test/resources/org/springframework/boot/context/embedded/conf.properties rename to spring-boot/src/test/resources/org/springframework/boot/web/servlet/context/conf.properties diff --git a/spring-boot/src/test/resources/org/springframework/boot/context/embedded/exampleEmbeddedWebApplicationConfiguration.xml b/spring-boot/src/test/resources/org/springframework/boot/web/servlet/context/exampleEmbeddedWebApplicationConfiguration.xml similarity index 81% rename from spring-boot/src/test/resources/org/springframework/boot/context/embedded/exampleEmbeddedWebApplicationConfiguration.xml rename to spring-boot/src/test/resources/org/springframework/boot/web/servlet/context/exampleEmbeddedWebApplicationConfiguration.xml index a03e06c9cf..5bee47b4eb 100644 --- a/spring-boot/src/test/resources/org/springframework/boot/context/embedded/exampleEmbeddedWebApplicationConfiguration.xml +++ b/spring-boot/src/test/resources/org/springframework/boot/web/servlet/context/exampleEmbeddedWebApplicationConfiguration.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> + class="org.springframework.boot.web.servlet.server.MockServletWebServerFactory" />