Commit 3f9ca688 authored by Phillip Webb's avatar Phillip Webb

Tweak ConfigurableEmbeddedServletContainerFactory

Update ConfigurableEmbeddedServletContainerFactory to no longer directly
extend EmbeddedServletContainerFactory.
parent 9c4dc0c6
...@@ -60,6 +60,8 @@ public class ServerPropertiesAutoConfiguration implements ApplicationContextAwar ...@@ -60,6 +60,8 @@ public class ServerPropertiesAutoConfiguration implements ApplicationContextAwar
@Override @Override
public void customize(ConfigurableEmbeddedServletContainerFactory factory) { public void customize(ConfigurableEmbeddedServletContainerFactory factory) {
// ServerProperties handles customization, this just checks we only have
// a single bean
String[] serverPropertiesBeans = this.applicationContext String[] serverPropertiesBeans = this.applicationContext
.getBeanNamesForType(ServerProperties.class); .getBeanNamesForType(ServerProperties.class);
Assert.state( Assert.state(
......
...@@ -48,7 +48,7 @@ import static org.junit.Assert.assertNotNull; ...@@ -48,7 +48,7 @@ import static org.junit.Assert.assertNotNull;
*/ */
public class ServerPropertiesAutoConfigurationTests { public class ServerPropertiesAutoConfigurationTests {
private static ConfigurableEmbeddedServletContainerFactory containerFactory; private static AbstractEmbeddedServletContainerFactory containerFactory;
@Rule @Rule
public ExpectedException thrown = ExpectedException.none(); public ExpectedException thrown = ExpectedException.none();
...@@ -57,8 +57,7 @@ public class ServerPropertiesAutoConfigurationTests { ...@@ -57,8 +57,7 @@ public class ServerPropertiesAutoConfigurationTests {
@Before @Before
public void init() { public void init() {
containerFactory = Mockito containerFactory = Mockito.mock(AbstractEmbeddedServletContainerFactory.class);
.mock(ConfigurableEmbeddedServletContainerFactory.class);
} }
@After @After
...@@ -104,13 +103,12 @@ public class ServerPropertiesAutoConfigurationTests { ...@@ -104,13 +103,12 @@ public class ServerPropertiesAutoConfigurationTests {
PropertyPlaceholderAutoConfiguration.class); PropertyPlaceholderAutoConfiguration.class);
this.context.refresh(); this.context.refresh();
containerFactory = this.context containerFactory = this.context
.getBean(ConfigurableEmbeddedServletContainerFactory.class); .getBean(AbstractEmbeddedServletContainerFactory.class);
ServerProperties server = this.context.getBean(ServerProperties.class); ServerProperties server = this.context.getBean(ServerProperties.class);
assertNotNull(server); assertNotNull(server);
// The server.port environment property was not explicitly set so the container // The server.port environment property was not explicitly set so the container
// factory should take precedence... // factory should take precedence...
assertEquals(3000, assertEquals(3000, containerFactory.getPort());
((AbstractEmbeddedServletContainerFactory) containerFactory).getPort());
} }
@Test @Test
......
...@@ -41,7 +41,7 @@ import org.springframework.util.Assert; ...@@ -41,7 +41,7 @@ import org.springframework.util.Assert;
* @author Dave Syer * @author Dave Syer
*/ */
public abstract class AbstractEmbeddedServletContainerFactory implements public abstract class AbstractEmbeddedServletContainerFactory implements
ConfigurableEmbeddedServletContainerFactory { EmbeddedServletContainerFactory, ConfigurableEmbeddedServletContainerFactory {
private static final String[] COMMON_DOC_ROOTS = { "src/main/webapp", "public", private static final String[] COMMON_DOC_ROOTS = { "src/main/webapp", "public",
"static" }; "static" };
......
...@@ -28,9 +28,9 @@ import java.util.concurrent.TimeUnit; ...@@ -28,9 +28,9 @@ import java.util.concurrent.TimeUnit;
* *
* @author Dave Syer * @author Dave Syer
* @see EmbeddedServletContainerFactory * @see EmbeddedServletContainerFactory
* @see EmbeddedServletContainerCustomizer
*/ */
public interface ConfigurableEmbeddedServletContainerFactory extends public interface ConfigurableEmbeddedServletContainerFactory {
EmbeddedServletContainerFactory {
/** /**
* Sets the context path for the embedded servlet container. The context should start * Sets the context path for the embedded servlet container. The context should start
...@@ -122,8 +122,8 @@ public interface ConfigurableEmbeddedServletContainerFactory extends ...@@ -122,8 +122,8 @@ public interface ConfigurableEmbeddedServletContainerFactory extends
/** /**
* Sets {@link ServletContextInitializer} that should be applied in addition to * Sets {@link ServletContextInitializer} that should be applied in addition to
* {@link #getEmbeddedServletContainer(ServletContextInitializer...)} parameters. This * {@link EmbeddedServletContainerFactory#getEmbeddedServletContainer(ServletContextInitializer...)}
* method will replace any previously set or added initializers. * parameters. This method will replace any previously set or added initializers.
* @param initializers the initializers to set * @param initializers the initializers to set
* @see #addInitializers * @see #addInitializers
*/ */
...@@ -131,7 +131,9 @@ public interface ConfigurableEmbeddedServletContainerFactory extends ...@@ -131,7 +131,9 @@ public interface ConfigurableEmbeddedServletContainerFactory extends
/** /**
* Add {@link ServletContextInitializer}s to those that should be applied in addition * Add {@link ServletContextInitializer}s to those that should be applied in addition
* to {@link #getEmbeddedServletContainer(ServletContextInitializer...)} parameters. * to
* {@link EmbeddedServletContainerFactory#getEmbeddedServletContainer(ServletContextInitializer...)}
* parameters.
* @param initializers the initializers to add * @param initializers the initializers to add
* @see #setInitializers * @see #setInitializers
*/ */
......
...@@ -84,7 +84,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { ...@@ -84,7 +84,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests {
@Test @Test
public void startServlet() throws Exception { public void startServlet() throws Exception {
ConfigurableEmbeddedServletContainerFactory factory = getFactory(); AbstractEmbeddedServletContainerFactory factory = getFactory();
this.container = factory this.container = factory
.getEmbeddedServletContainer(exampleServletRegistration()); .getEmbeddedServletContainer(exampleServletRegistration());
this.container.start(); this.container.start();
...@@ -93,7 +93,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { ...@@ -93,7 +93,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests {
@Test @Test
public void emptyServerWhenPortIsZero() throws Exception { public void emptyServerWhenPortIsZero() throws Exception {
ConfigurableEmbeddedServletContainerFactory factory = getFactory(); AbstractEmbeddedServletContainerFactory factory = getFactory();
factory.setPort(0); factory.setPort(0);
this.container = factory this.container = factory
.getEmbeddedServletContainer(exampleServletRegistration()); .getEmbeddedServletContainer(exampleServletRegistration());
...@@ -104,7 +104,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { ...@@ -104,7 +104,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests {
@Test @Test
public void stopServlet() throws Exception { public void stopServlet() throws Exception {
ConfigurableEmbeddedServletContainerFactory factory = getFactory(); AbstractEmbeddedServletContainerFactory factory = getFactory();
this.container = factory this.container = factory
.getEmbeddedServletContainer(exampleServletRegistration()); .getEmbeddedServletContainer(exampleServletRegistration());
this.container.start(); this.container.start();
...@@ -115,7 +115,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { ...@@ -115,7 +115,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests {
@Test @Test
public void restartWithKeepAlive() throws Exception { public void restartWithKeepAlive() throws Exception {
ConfigurableEmbeddedServletContainerFactory factory = getFactory(); AbstractEmbeddedServletContainerFactory factory = getFactory();
this.container = factory this.container = factory
.getEmbeddedServletContainer(exampleServletRegistration()); .getEmbeddedServletContainer(exampleServletRegistration());
this.container.start(); this.container.start();
...@@ -138,7 +138,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { ...@@ -138,7 +138,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests {
@Test @Test
public void startServletAndFilter() throws Exception { public void startServletAndFilter() throws Exception {
ConfigurableEmbeddedServletContainerFactory factory = getFactory(); AbstractEmbeddedServletContainerFactory factory = getFactory();
this.container = factory.getEmbeddedServletContainer( this.container = factory.getEmbeddedServletContainer(
exampleServletRegistration(), new FilterRegistrationBean( exampleServletRegistration(), new FilterRegistrationBean(
new ExampleFilter())); new ExampleFilter()));
...@@ -148,7 +148,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { ...@@ -148,7 +148,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests {
@Test @Test
public void startBlocksUntilReadyToServe() throws Exception { public void startBlocksUntilReadyToServe() throws Exception {
ConfigurableEmbeddedServletContainerFactory factory = getFactory(); AbstractEmbeddedServletContainerFactory factory = getFactory();
final Date[] date = new Date[1]; final Date[] date = new Date[1];
this.container = factory this.container = factory
.getEmbeddedServletContainer(new ServletContextInitializer() { .getEmbeddedServletContainer(new ServletContextInitializer() {
...@@ -170,7 +170,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { ...@@ -170,7 +170,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests {
@Test @Test
public void loadOnStartAfterContextIsInitialized() throws Exception { public void loadOnStartAfterContextIsInitialized() throws Exception {
ConfigurableEmbeddedServletContainerFactory factory = getFactory(); AbstractEmbeddedServletContainerFactory factory = getFactory();
final InitCountingServlet servlet = new InitCountingServlet(); final InitCountingServlet servlet = new InitCountingServlet();
this.container = factory this.container = factory
.getEmbeddedServletContainer(new ServletContextInitializer() { .getEmbeddedServletContainer(new ServletContextInitializer() {
...@@ -187,7 +187,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { ...@@ -187,7 +187,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests {
@Test @Test
public void specificPort() throws Exception { public void specificPort() throws Exception {
ConfigurableEmbeddedServletContainerFactory factory = getFactory(); AbstractEmbeddedServletContainerFactory factory = getFactory();
factory.setPort(8081); factory.setPort(8081);
this.container = factory this.container = factory
.getEmbeddedServletContainer(exampleServletRegistration()); .getEmbeddedServletContainer(exampleServletRegistration());
...@@ -198,7 +198,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { ...@@ -198,7 +198,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests {
@Test @Test
public void specificContextRoot() throws Exception { public void specificContextRoot() throws Exception {
ConfigurableEmbeddedServletContainerFactory factory = getFactory(); AbstractEmbeddedServletContainerFactory factory = getFactory();
factory.setContextPath("/say"); factory.setContextPath("/say");
this.container = factory this.container = factory
.getEmbeddedServletContainer(exampleServletRegistration()); .getEmbeddedServletContainer(exampleServletRegistration());
...@@ -230,7 +230,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { ...@@ -230,7 +230,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests {
@Test @Test
public void doubleStop() throws Exception { public void doubleStop() throws Exception {
ConfigurableEmbeddedServletContainerFactory factory = getFactory(); AbstractEmbeddedServletContainerFactory factory = getFactory();
this.container = factory this.container = factory
.getEmbeddedServletContainer(exampleServletRegistration()); .getEmbeddedServletContainer(exampleServletRegistration());
this.container.start(); this.container.start();
...@@ -240,7 +240,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { ...@@ -240,7 +240,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests {
@Test @Test
public void multipleConfigurations() throws Exception { public void multipleConfigurations() throws Exception {
ConfigurableEmbeddedServletContainerFactory factory = getFactory(); AbstractEmbeddedServletContainerFactory factory = getFactory();
ServletContextInitializer[] initializers = new ServletContextInitializer[6]; ServletContextInitializer[] initializers = new ServletContextInitializer[6];
for (int i = 0; i < initializers.length; i++) { for (int i = 0; i < initializers.length; i++) {
initializers[i] = mock(ServletContextInitializer.class); initializers[i] = mock(ServletContextInitializer.class);
...@@ -285,7 +285,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { ...@@ -285,7 +285,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests {
@Test @Test
public void errorPage() throws Exception { public void errorPage() throws Exception {
ConfigurableEmbeddedServletContainerFactory factory = getFactory(); AbstractEmbeddedServletContainerFactory factory = getFactory();
factory.addErrorPages(new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/hello")); factory.addErrorPages(new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/hello"));
this.container = factory.getEmbeddedServletContainer( this.container = factory.getEmbeddedServletContainer(
exampleServletRegistration(), errorServletRegistration()); exampleServletRegistration(), errorServletRegistration());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment