Ensure that customizers registered multiple times are only called once
Closes gh-17264
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.web.reactive;
|
||||
|
||||
import io.undertow.Undertow.Builder;
|
||||
import org.apache.catalina.Context;
|
||||
import org.apache.catalina.connector.Connector;
|
||||
import org.apache.catalina.startup.Tomcat;
|
||||
@@ -222,6 +223,21 @@ class ReactiveWebServerFactoryAutoConfigurationTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void jettyServerCustomizerRegisteredAsBeanAndViaFactoryIsOnlyCalledOnce() {
|
||||
new ReactiveWebApplicationContextRunner(AnnotationConfigReactiveWebServerApplicationContext::new)
|
||||
.withConfiguration(AutoConfigurations.of(ReactiveWebServerFactoryAutoConfiguration.class))
|
||||
.withClassLoader(new FilteredClassLoader(Tomcat.class, HttpServer.class))
|
||||
.withUserConfiguration(DoubleRegistrationJettyServerCustomizerConfiguration.class,
|
||||
HttpHandlerConfiguration.class)
|
||||
.withPropertyValues("server.port=0").run((context) -> {
|
||||
JettyReactiveWebServerFactory factory = context.getBean(JettyReactiveWebServerFactory.class);
|
||||
JettyServerCustomizer customizer = context.getBean("serverCustomizer", JettyServerCustomizer.class);
|
||||
assertThat(factory.getServerCustomizers()).contains(customizer);
|
||||
verify(customizer, times(1)).customize(any(Server.class));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void undertowDeploymentInfoCustomizerBeanIsAddedToFactory() {
|
||||
new ReactiveWebApplicationContextRunner(AnnotationConfigReactiveWebApplicationContext::new)
|
||||
@@ -247,6 +263,22 @@ class ReactiveWebServerFactoryAutoConfigurationTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void undertowBuilderCustomizerRegisteredAsBeanAndViaFactoryIsOnlyCalledOnce() {
|
||||
new ReactiveWebApplicationContextRunner(AnnotationConfigReactiveWebServerApplicationContext::new)
|
||||
.withConfiguration(AutoConfigurations.of(ReactiveWebServerFactoryAutoConfiguration.class))
|
||||
.withClassLoader(new FilteredClassLoader(Tomcat.class, HttpServer.class, Server.class))
|
||||
.withUserConfiguration(DoubleRegistrationUndertowBuilderCustomizerConfiguration.class,
|
||||
HttpHandlerConfiguration.class)
|
||||
.withPropertyValues("server.port: 0").run((context) -> {
|
||||
UndertowReactiveWebServerFactory factory = context.getBean(UndertowReactiveWebServerFactory.class);
|
||||
UndertowBuilderCustomizer customizer = context.getBean("builderCustomizer",
|
||||
UndertowBuilderCustomizer.class);
|
||||
assertThat(factory.getBuilderCustomizers()).contains(customizer);
|
||||
verify(customizer, times(1)).customize(any(Builder.class));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void forwardedHeaderTransformerShouldBeConfigured() {
|
||||
this.contextRunner.withUserConfiguration(HttpHandlerConfiguration.class)
|
||||
@@ -401,6 +433,23 @@ class ReactiveWebServerFactoryAutoConfigurationTests {
|
||||
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class DoubleRegistrationJettyServerCustomizerConfiguration {
|
||||
|
||||
private final JettyServerCustomizer customizer = mock(JettyServerCustomizer.class);
|
||||
|
||||
@Bean
|
||||
JettyServerCustomizer serverCustomizer() {
|
||||
return this.customizer;
|
||||
}
|
||||
|
||||
@Bean
|
||||
WebServerFactoryCustomizer<JettyReactiveWebServerFactory> jettyCustomizer() {
|
||||
return (jetty) -> jetty.addServerCustomizers(this.customizer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class UndertowBuilderCustomizerConfiguration {
|
||||
|
||||
@@ -412,6 +461,23 @@ class ReactiveWebServerFactoryAutoConfigurationTests {
|
||||
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class DoubleRegistrationUndertowBuilderCustomizerConfiguration {
|
||||
|
||||
private final UndertowBuilderCustomizer customizer = mock(UndertowBuilderCustomizer.class);
|
||||
|
||||
@Bean
|
||||
UndertowBuilderCustomizer builderCustomizer() {
|
||||
return this.customizer;
|
||||
}
|
||||
|
||||
@Bean
|
||||
WebServerFactoryCustomizer<UndertowReactiveWebServerFactory> undertowCustomizer() {
|
||||
return (undertow) -> undertow.addBuilderCustomizers(this.customizer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class UndertowDeploymentInfoCustomizerConfiguration {
|
||||
|
||||
|
||||
@@ -22,6 +22,8 @@ import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import io.undertow.Undertow.Builder;
|
||||
import io.undertow.servlet.api.DeploymentInfo;
|
||||
import org.apache.catalina.Context;
|
||||
import org.apache.catalina.connector.Connector;
|
||||
import org.apache.catalina.startup.Tomcat;
|
||||
@@ -163,6 +165,22 @@ class ServletWebServerFactoryAutoConfigurationTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void jettyServerCustomizerRegisteredAsBeanAndViaFactoryIsOnlyCalledOnce() {
|
||||
WebApplicationContextRunner runner = new WebApplicationContextRunner(
|
||||
AnnotationConfigServletWebServerApplicationContext::new)
|
||||
.withClassLoader(new FilteredClassLoader(Tomcat.class, HttpServer.class))
|
||||
.withConfiguration(AutoConfigurations.of(ServletWebServerFactoryAutoConfiguration.class))
|
||||
.withUserConfiguration(DoubleRegistrationJettyServerCustomizerConfiguration.class)
|
||||
.withPropertyValues("server.port: 0");
|
||||
runner.run((context) -> {
|
||||
JettyServletWebServerFactory factory = context.getBean(JettyServletWebServerFactory.class);
|
||||
JettyServerCustomizer customizer = context.getBean("serverCustomizer", JettyServerCustomizer.class);
|
||||
assertThat(factory.getServerCustomizers()).contains(customizer);
|
||||
verify(customizer, times(1)).customize(any(Server.class));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void undertowDeploymentInfoCustomizerBeanIsAddedToFactory() {
|
||||
WebApplicationContextRunner runner = new WebApplicationContextRunner(
|
||||
@@ -177,6 +195,40 @@ class ServletWebServerFactoryAutoConfigurationTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void undertowDeploymentInfoCustomizerRegisteredAsBeanAndViaFactoryIsOnlyCalledOnce() {
|
||||
WebApplicationContextRunner runner = new WebApplicationContextRunner(
|
||||
AnnotationConfigServletWebServerApplicationContext::new)
|
||||
.withClassLoader(new FilteredClassLoader(Tomcat.class, HttpServer.class, Server.class))
|
||||
.withConfiguration(AutoConfigurations.of(ServletWebServerFactoryAutoConfiguration.class))
|
||||
.withUserConfiguration(DoubleRegistrationUndertowDeploymentInfoCustomizerConfiguration.class)
|
||||
.withPropertyValues("server.port: 0");
|
||||
runner.run((context) -> {
|
||||
UndertowServletWebServerFactory factory = context.getBean(UndertowServletWebServerFactory.class);
|
||||
UndertowDeploymentInfoCustomizer customizer = context.getBean("deploymentInfoCustomizer",
|
||||
UndertowDeploymentInfoCustomizer.class);
|
||||
assertThat(factory.getDeploymentInfoCustomizers()).contains(customizer);
|
||||
verify(customizer, times(1)).customize(any(DeploymentInfo.class));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void undertowBuilderCustomizerRegisteredAsBeanAndViaFactoryIsOnlyCalledOnce() {
|
||||
WebApplicationContextRunner runner = new WebApplicationContextRunner(
|
||||
AnnotationConfigServletWebServerApplicationContext::new)
|
||||
.withClassLoader(new FilteredClassLoader(Tomcat.class, HttpServer.class, Server.class))
|
||||
.withConfiguration(AutoConfigurations.of(ServletWebServerFactoryAutoConfiguration.class))
|
||||
.withUserConfiguration(DoubleRegistrationUndertowBuilderCustomizerConfiguration.class)
|
||||
.withPropertyValues("server.port: 0");
|
||||
runner.run((context) -> {
|
||||
UndertowServletWebServerFactory factory = context.getBean(UndertowServletWebServerFactory.class);
|
||||
UndertowBuilderCustomizer customizer = context.getBean("builderCustomizer",
|
||||
UndertowBuilderCustomizer.class);
|
||||
assertThat(factory.getBuilderCustomizers()).contains(customizer);
|
||||
verify(customizer, times(1)).customize(any(Builder.class));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void undertowBuilderCustomizerBeanIsAddedToFactory() {
|
||||
WebApplicationContextRunner runner = new WebApplicationContextRunner(
|
||||
@@ -510,6 +562,23 @@ class ServletWebServerFactoryAutoConfigurationTests {
|
||||
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class DoubleRegistrationJettyServerCustomizerConfiguration {
|
||||
|
||||
private final JettyServerCustomizer customizer = mock(JettyServerCustomizer.class);
|
||||
|
||||
@Bean
|
||||
JettyServerCustomizer serverCustomizer() {
|
||||
return this.customizer;
|
||||
}
|
||||
|
||||
@Bean
|
||||
WebServerFactoryCustomizer<JettyServletWebServerFactory> jettyCustomizer() {
|
||||
return (jetty) -> jetty.addServerCustomizers(this.customizer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class UndertowBuilderCustomizerConfiguration {
|
||||
|
||||
@@ -521,6 +590,23 @@ class ServletWebServerFactoryAutoConfigurationTests {
|
||||
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class DoubleRegistrationUndertowBuilderCustomizerConfiguration {
|
||||
|
||||
private final UndertowBuilderCustomizer customizer = mock(UndertowBuilderCustomizer.class);
|
||||
|
||||
@Bean
|
||||
UndertowBuilderCustomizer builderCustomizer() {
|
||||
return this.customizer;
|
||||
}
|
||||
|
||||
@Bean
|
||||
WebServerFactoryCustomizer<UndertowServletWebServerFactory> undertowCustomizer() {
|
||||
return (undertow) -> undertow.addBuilderCustomizers(this.customizer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class UndertowDeploymentInfoCustomizerConfiguration {
|
||||
|
||||
@@ -532,6 +618,23 @@ class ServletWebServerFactoryAutoConfigurationTests {
|
||||
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class DoubleRegistrationUndertowDeploymentInfoCustomizerConfiguration {
|
||||
|
||||
private final UndertowDeploymentInfoCustomizer customizer = mock(UndertowDeploymentInfoCustomizer.class);
|
||||
|
||||
@Bean
|
||||
UndertowDeploymentInfoCustomizer deploymentInfoCustomizer() {
|
||||
return this.customizer;
|
||||
}
|
||||
|
||||
@Bean
|
||||
WebServerFactoryCustomizer<UndertowServletWebServerFactory> undertowCustomizer() {
|
||||
return (undertow) -> undertow.addDeploymentInfoCustomizers(this.customizer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class ForwardedHeaderFilterConfiguration {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user