Apply context and connector customizer beans to Tomcat factories
See gh-15492
This commit is contained in:
parent
de599819ae
commit
90c489048f
|
@ -16,13 +16,18 @@
|
||||||
|
|
||||||
package org.springframework.boot.autoconfigure.web.reactive;
|
package org.springframework.boot.autoconfigure.web.reactive;
|
||||||
|
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import io.undertow.Undertow;
|
import io.undertow.Undertow;
|
||||||
import reactor.netty.http.server.HttpServer;
|
import reactor.netty.http.server.HttpServer;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.ObjectProvider;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
import org.springframework.boot.web.embedded.jetty.JettyReactiveWebServerFactory;
|
import org.springframework.boot.web.embedded.jetty.JettyReactiveWebServerFactory;
|
||||||
import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory;
|
import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory;
|
||||||
|
import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer;
|
||||||
|
import org.springframework.boot.web.embedded.tomcat.TomcatContextCustomizer;
|
||||||
import org.springframework.boot.web.embedded.tomcat.TomcatReactiveWebServerFactory;
|
import org.springframework.boot.web.embedded.tomcat.TomcatReactiveWebServerFactory;
|
||||||
import org.springframework.boot.web.embedded.undertow.UndertowReactiveWebServerFactory;
|
import org.springframework.boot.web.embedded.undertow.UndertowReactiveWebServerFactory;
|
||||||
import org.springframework.boot.web.reactive.server.ReactiveWebServerFactory;
|
import org.springframework.boot.web.reactive.server.ReactiveWebServerFactory;
|
||||||
|
@ -38,6 +43,7 @@ import org.springframework.http.client.reactive.ReactorResourceFactory;
|
||||||
* their order of execution.
|
* their order of execution.
|
||||||
*
|
*
|
||||||
* @author Brian Clozel
|
* @author Brian Clozel
|
||||||
|
* @author Raheela Aslam
|
||||||
*/
|
*/
|
||||||
abstract class ReactiveWebServerFactoryConfiguration {
|
abstract class ReactiveWebServerFactoryConfiguration {
|
||||||
|
|
||||||
|
@ -68,8 +74,15 @@ abstract class ReactiveWebServerFactoryConfiguration {
|
||||||
static class EmbeddedTomcat {
|
static class EmbeddedTomcat {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public TomcatReactiveWebServerFactory tomcatReactiveWebServerFactory() {
|
public TomcatReactiveWebServerFactory tomcatReactiveWebServerFactory(
|
||||||
return new TomcatReactiveWebServerFactory();
|
ObjectProvider<TomcatConnectorCustomizer> connectorCustomizers,
|
||||||
|
ObjectProvider<TomcatContextCustomizer> contextCustomizers) {
|
||||||
|
TomcatReactiveWebServerFactory factory = new TomcatReactiveWebServerFactory();
|
||||||
|
factory.getTomcatConnectorCustomizers().addAll(
|
||||||
|
connectorCustomizers.orderedStream().collect(Collectors.toList()));
|
||||||
|
factory.getTomcatContextCustomizers().addAll(
|
||||||
|
contextCustomizers.orderedStream().collect(Collectors.toList()));
|
||||||
|
return factory;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
|
|
||||||
package org.springframework.boot.autoconfigure.web.servlet;
|
package org.springframework.boot.autoconfigure.web.servlet;
|
||||||
|
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import javax.servlet.Servlet;
|
import javax.servlet.Servlet;
|
||||||
|
|
||||||
import io.undertow.Undertow;
|
import io.undertow.Undertow;
|
||||||
|
@ -26,10 +28,13 @@ import org.eclipse.jetty.util.Loader;
|
||||||
import org.eclipse.jetty.webapp.WebAppContext;
|
import org.eclipse.jetty.webapp.WebAppContext;
|
||||||
import org.xnio.SslClientAuthMode;
|
import org.xnio.SslClientAuthMode;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.ObjectProvider;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
import org.springframework.boot.autoconfigure.condition.SearchStrategy;
|
import org.springframework.boot.autoconfigure.condition.SearchStrategy;
|
||||||
import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory;
|
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.tomcat.TomcatServletWebServerFactory;
|
||||||
import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory;
|
import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory;
|
||||||
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
|
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
|
||||||
|
@ -47,6 +52,7 @@ import org.springframework.context.annotation.Configuration;
|
||||||
* @author Ivan Sopov
|
* @author Ivan Sopov
|
||||||
* @author Brian Clozel
|
* @author Brian Clozel
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
|
* @author Raheela Asalm
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
class ServletWebServerFactoryConfiguration {
|
class ServletWebServerFactoryConfiguration {
|
||||||
|
@ -57,8 +63,15 @@ class ServletWebServerFactoryConfiguration {
|
||||||
public static class EmbeddedTomcat {
|
public static class EmbeddedTomcat {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public TomcatServletWebServerFactory tomcatServletWebServerFactory() {
|
public TomcatServletWebServerFactory tomcatServletWebServerFactory(
|
||||||
return new TomcatServletWebServerFactory();
|
ObjectProvider<TomcatConnectorCustomizer> connectorCustomizers,
|
||||||
|
ObjectProvider<TomcatContextCustomizer> contextCustomizers) {
|
||||||
|
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
|
||||||
|
factory.getTomcatConnectorCustomizers().addAll(
|
||||||
|
connectorCustomizers.orderedStream().collect(Collectors.toList()));
|
||||||
|
factory.getTomcatContextCustomizers().addAll(
|
||||||
|
contextCustomizers.orderedStream().collect(Collectors.toList()));
|
||||||
|
return factory;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,10 @@ import org.mockito.Mockito;
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||||
import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner;
|
import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner;
|
||||||
|
import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer;
|
||||||
|
import org.springframework.boot.web.embedded.tomcat.TomcatContextCustomizer;
|
||||||
import org.springframework.boot.web.embedded.tomcat.TomcatReactiveWebServerFactory;
|
import org.springframework.boot.web.embedded.tomcat.TomcatReactiveWebServerFactory;
|
||||||
|
import org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebApplicationContext;
|
||||||
import org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext;
|
import org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext;
|
||||||
import org.springframework.boot.web.reactive.server.ConfigurableReactiveWebServerFactory;
|
import org.springframework.boot.web.reactive.server.ConfigurableReactiveWebServerFactory;
|
||||||
import org.springframework.boot.web.reactive.server.ReactiveWebServerFactory;
|
import org.springframework.boot.web.reactive.server.ReactiveWebServerFactory;
|
||||||
|
@ -37,6 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
* Tests for {@link ReactiveWebServerFactoryAutoConfiguration}.
|
* Tests for {@link ReactiveWebServerFactoryAutoConfiguration}.
|
||||||
*
|
*
|
||||||
* @author Brian Clozel
|
* @author Brian Clozel
|
||||||
|
* @author Raheela Aslam
|
||||||
*/
|
*/
|
||||||
public class ReactiveWebServerFactoryAutoConfigurationTests {
|
public class ReactiveWebServerFactoryAutoConfigurationTests {
|
||||||
|
|
||||||
|
@ -97,6 +101,36 @@ public class ReactiveWebServerFactoryAutoConfigurationTests {
|
||||||
.isInstanceOf(TomcatReactiveWebServerFactory.class));
|
.isInstanceOf(TomcatReactiveWebServerFactory.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void tomcatConnectorCustomizerBeanIsAddedToFactory() {
|
||||||
|
ReactiveWebApplicationContextRunner runner = new ReactiveWebApplicationContextRunner(
|
||||||
|
AnnotationConfigReactiveWebApplicationContext::new)
|
||||||
|
.withConfiguration(AutoConfigurations
|
||||||
|
.of(ReactiveWebServerFactoryAutoConfiguration.class))
|
||||||
|
.withUserConfiguration(
|
||||||
|
TomcatConnectorCustomizerConfiguration.class);
|
||||||
|
runner.run((context) -> {
|
||||||
|
TomcatReactiveWebServerFactory factory = context
|
||||||
|
.getBean(TomcatReactiveWebServerFactory.class);
|
||||||
|
assertThat(factory.getTomcatConnectorCustomizers()).hasSize(1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void tomcatContextCustomizerBeanIsAddedToFactory() {
|
||||||
|
ReactiveWebApplicationContextRunner runner = new ReactiveWebApplicationContextRunner(
|
||||||
|
AnnotationConfigReactiveWebApplicationContext::new)
|
||||||
|
.withConfiguration(AutoConfigurations
|
||||||
|
.of(ReactiveWebServerFactoryAutoConfiguration.class))
|
||||||
|
.withUserConfiguration(
|
||||||
|
TomcatContextCustomizerConfiguration.class);
|
||||||
|
runner.run((context) -> {
|
||||||
|
TomcatReactiveWebServerFactory factory = context
|
||||||
|
.getBean(TomcatReactiveWebServerFactory.class);
|
||||||
|
assertThat(factory.getTomcatContextCustomizers()).hasSize(1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
protected static class HttpHandlerConfiguration {
|
protected static class HttpHandlerConfiguration {
|
||||||
|
|
||||||
|
@ -137,4 +171,26 @@ public class ReactiveWebServerFactoryAutoConfigurationTests {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
static class TomcatConnectorCustomizerConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public TomcatConnectorCustomizer connectorCustomizer() {
|
||||||
|
return (connector) -> {
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
static class TomcatContextCustomizerConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public TomcatContextCustomizer connectorCustomizer() {
|
||||||
|
return (context) -> {
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,9 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
||||||
import org.springframework.boot.test.context.assertj.AssertableWebApplicationContext;
|
import org.springframework.boot.test.context.assertj.AssertableWebApplicationContext;
|
||||||
import org.springframework.boot.test.context.runner.ContextConsumer;
|
import org.springframework.boot.test.context.runner.ContextConsumer;
|
||||||
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
|
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
|
||||||
|
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.server.WebServerFactoryCustomizer;
|
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
|
||||||
import org.springframework.boot.web.servlet.ServletRegistrationBean;
|
import org.springframework.boot.web.servlet.ServletRegistrationBean;
|
||||||
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext;
|
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext;
|
||||||
|
@ -51,6 +54,7 @@ import static org.mockito.Mockito.verify;
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
|
* @author Raheela Aslam
|
||||||
*/
|
*/
|
||||||
public class ServletWebServerFactoryAutoConfigurationTests {
|
public class ServletWebServerFactoryAutoConfigurationTests {
|
||||||
|
|
||||||
|
@ -138,6 +142,34 @@ public class ServletWebServerFactoryAutoConfigurationTests {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void tomcatConnectorCustomizerBeanIsAddedToFactory() {
|
||||||
|
WebApplicationContextRunner runner = new WebApplicationContextRunner(
|
||||||
|
AnnotationConfigServletWebServerApplicationContext::new)
|
||||||
|
.withConfiguration(AutoConfigurations
|
||||||
|
.of(ServletWebServerFactoryAutoConfiguration.class))
|
||||||
|
.withUserConfiguration(
|
||||||
|
TomcatConnectorCustomizerConfiguration.class);
|
||||||
|
runner.run((context) -> {
|
||||||
|
TomcatServletWebServerFactory factory = context
|
||||||
|
.getBean(TomcatServletWebServerFactory.class);
|
||||||
|
assertThat(factory.getTomcatConnectorCustomizers()).hasSize(1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void tomcatContextCustomizerBeanIsAddedToFactory() {
|
||||||
|
WebApplicationContextRunner runner = new WebApplicationContextRunner(
|
||||||
|
AnnotationConfigServletWebServerApplicationContext::new)
|
||||||
|
.withConfiguration(AutoConfigurations
|
||||||
|
.of(ServletWebServerFactoryAutoConfiguration.class));
|
||||||
|
runner.run((context) -> {
|
||||||
|
TomcatServletWebServerFactory factory = context
|
||||||
|
.getBean(TomcatServletWebServerFactory.class);
|
||||||
|
assertThat(factory.getTomcatContextCustomizers()).hasSize(1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private ContextConsumer<AssertableWebApplicationContext> verifyContext() {
|
private ContextConsumer<AssertableWebApplicationContext> verifyContext() {
|
||||||
return this::verifyContext;
|
return this::verifyContext;
|
||||||
}
|
}
|
||||||
|
@ -253,4 +285,26 @@ public class ServletWebServerFactoryAutoConfigurationTests {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
static class TomcatConnectorCustomizerConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public TomcatConnectorCustomizer connectorCustomizer() {
|
||||||
|
return (connector) -> {
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
static class TomcatContextCustomizerConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public TomcatContextCustomizer connectorCustomizer() {
|
||||||
|
return (context) -> {
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue