diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ServletManagementChildContextConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ServletManagementChildContextConfiguration.java index fbd89ae27cd..a222bb2be65 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ServletManagementChildContextConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ServletManagementChildContextConfiguration.java @@ -45,6 +45,7 @@ import org.springframework.boot.autoconfigure.web.embedded.TomcatWebServerFactor import org.springframework.boot.autoconfigure.web.embedded.UndertowWebServerFactoryCustomizer; import org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryCustomizer; import org.springframework.boot.autoconfigure.web.servlet.TomcatServletWebServerFactoryCustomizer; +import org.springframework.boot.autoconfigure.web.servlet.UndertowServletWebServerFactoryCustomizer; import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory; import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory; @@ -115,7 +116,7 @@ class ServletManagementChildContextConfiguration { ServletManagementWebServerFactoryCustomizer(ListableBeanFactory beanFactory) { super(beanFactory, ServletWebServerFactoryCustomizer.class, TomcatServletWebServerFactoryCustomizer.class, TomcatWebServerFactoryCustomizer.class, JettyWebServerFactoryCustomizer.class, - UndertowWebServerFactoryCustomizer.class); + UndertowServletWebServerFactoryCustomizer.class, UndertowWebServerFactoryCustomizer.class); } @Override diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/UndertowWebServerFactoryCustomizer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/UndertowWebServerFactoryCustomizer.java index 0288b4b05bb..06a57cd342c 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/UndertowWebServerFactoryCustomizer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/UndertowWebServerFactoryCustomizer.java @@ -92,7 +92,6 @@ public class UndertowWebServerFactoryCustomizer map.from(properties::getIoThreads).to(factory::setIoThreads); map.from(properties::getWorkerThreads).to(factory::setWorkerThreads); map.from(properties::getDirectBuffers).to(factory::setUseDirectBuffers); - map.from(properties::isEagerFilterInit).to((x) -> setEagerFilterInit(factory, x)); map.from(properties::getMaxHttpPostSize).as(DataSize::toBytes).when(this::isPositive) .to(options.server(UndertowOptions.MAX_ENTITY_SIZE)); map.from(properties::getMaxParameters).to(options.server(UndertowOptions.MAX_PARAMETERS)); @@ -106,10 +105,6 @@ public class UndertowWebServerFactoryCustomizer map.from(properties.getOptions()::getSocket).to(options.forEach(options::socket)); } - private void setEagerFilterInit(ConfigurableUndertowWebServerFactory factory, Boolean eagerFilterInit) { - factory.addDeploymentInfoCustomizers((deploymentInfo) -> deploymentInfo.setEagerFilterInit(eagerFilterInit)); - } - private boolean isPositive(Number value) { return value.longValue() > 0; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/ReactiveWebServerFactoryConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/ReactiveWebServerFactoryConfiguration.java index 8d10a1fdc21..0a14bc90e39 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/ReactiveWebServerFactoryConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/ReactiveWebServerFactoryConfiguration.java @@ -34,7 +34,6 @@ import org.springframework.boot.web.embedded.tomcat.TomcatContextCustomizer; import org.springframework.boot.web.embedded.tomcat.TomcatProtocolHandlerCustomizer; import org.springframework.boot.web.embedded.tomcat.TomcatReactiveWebServerFactory; import org.springframework.boot.web.embedded.undertow.UndertowBuilderCustomizer; -import org.springframework.boot.web.embedded.undertow.UndertowDeploymentInfoCustomizer; import org.springframework.boot.web.embedded.undertow.UndertowReactiveWebServerFactory; import org.springframework.boot.web.reactive.server.ReactiveWebServerFactory; import org.springframework.context.annotation.Bean; @@ -128,11 +127,8 @@ abstract class ReactiveWebServerFactoryConfiguration { @Bean UndertowReactiveWebServerFactory undertowReactiveWebServerFactory( - ObjectProvider deploymentInfoCustomizers, ObjectProvider builderCustomizers) { UndertowReactiveWebServerFactory factory = new UndertowReactiveWebServerFactory(); - factory.getDeploymentInfoCustomizers() - .addAll(deploymentInfoCustomizers.orderedStream().collect(Collectors.toList())); factory.getBuilderCustomizers().addAll(builderCustomizers.orderedStream().collect(Collectors.toList())); return factory; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/UndertowServletWebServerFactoryCustomizer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/UndertowServletWebServerFactoryCustomizer.java new file mode 100644 index 00000000000..86362316f5e --- /dev/null +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/UndertowServletWebServerFactoryCustomizer.java @@ -0,0 +1,45 @@ +/* + * Copyright 2012-2019 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 + * + * https://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.autoconfigure.web.servlet; + +import org.springframework.boot.autoconfigure.web.ServerProperties; +import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory; +import org.springframework.boot.web.server.WebServerFactoryCustomizer; + +/** + * {@link WebServerFactoryCustomizer} to apply {@link ServerProperties} to Undertow + * Servlet web servers. + * + * @author Andy Wilkinson + * @since 2.1.7 + */ +public class UndertowServletWebServerFactoryCustomizer + implements WebServerFactoryCustomizer { + + private final ServerProperties serverProperties; + + public UndertowServletWebServerFactoryCustomizer(ServerProperties serverProperties) { + this.serverProperties = serverProperties; + } + + @Override + public void customize(UndertowServletWebServerFactory factory) { + factory.addDeploymentInfoCustomizers((deploymentInfo) -> deploymentInfo + .setEagerFilterInit(this.serverProperties.getUndertow().isEagerFilterInit())); + } + +} diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/ReactiveWebServerFactoryAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/ReactiveWebServerFactoryAutoConfigurationTests.java index a602ce7d345..6805e7fe911 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/ReactiveWebServerFactoryAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/ReactiveWebServerFactoryAutoConfigurationTests.java @@ -244,19 +244,6 @@ class ReactiveWebServerFactoryAutoConfigurationTests { }); } - @Test - void undertowDeploymentInfoCustomizerBeanIsAddedToFactory() { - new ReactiveWebApplicationContextRunner(AnnotationConfigReactiveWebApplicationContext::new) - .withConfiguration(AutoConfigurations.of(ReactiveWebServerFactoryAutoConfiguration.class)) - .withClassLoader(new FilteredClassLoader(Tomcat.class, HttpServer.class, Server.class)) - .withUserConfiguration(UndertowDeploymentInfoCustomizerConfiguration.class, - HttpHandlerConfiguration.class) - .run((context) -> { - UndertowReactiveWebServerFactory factory = context.getBean(UndertowReactiveWebServerFactory.class); - assertThat(factory.getDeploymentInfoCustomizers()).hasSize(1); - }); - } - @Test void undertowBuilderCustomizerBeanIsAddedToFactory() { new ReactiveWebApplicationContextRunner(AnnotationConfigReactiveWebApplicationContext::new) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/ConfigurableUndertowWebServerFactory.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/ConfigurableUndertowWebServerFactory.java index 324bc41f02b..0dd8e30ad54 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/ConfigurableUndertowWebServerFactory.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/ConfigurableUndertowWebServerFactory.java @@ -19,7 +19,6 @@ package org.springframework.boot.web.embedded.undertow; import java.io.File; import io.undertow.Undertow.Builder; -import io.undertow.servlet.api.DeploymentInfo; import org.springframework.boot.web.server.ConfigurableWebServerFactory; @@ -40,13 +39,6 @@ public interface ConfigurableUndertowWebServerFactory extends ConfigurableWebSer */ void addBuilderCustomizers(UndertowBuilderCustomizer... customizers); - /** - * Add {@link UndertowDeploymentInfoCustomizer}s that should be used to customize the - * Undertow {@link DeploymentInfo}. - * @param customizers the customizers to add - */ - void addDeploymentInfoCustomizers(UndertowDeploymentInfoCustomizer... customizers); - /** * Set the buffer size. * @param bufferSize buffer size diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowReactiveWebServerFactory.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowReactiveWebServerFactory.java index 49db2c7a6c5..8221de69ca8 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowReactiveWebServerFactory.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowReactiveWebServerFactory.java @@ -33,7 +33,6 @@ import io.undertow.UndertowOptions; import io.undertow.server.HttpHandler; import io.undertow.server.handlers.accesslog.AccessLogHandler; import io.undertow.server.handlers.accesslog.DefaultAccessLogReceiver; -import io.undertow.servlet.api.DeploymentInfo; import org.xnio.OptionMap; import org.xnio.Options; import org.xnio.Xnio; @@ -56,6 +55,7 @@ public class UndertowReactiveWebServerFactory extends AbstractReactiveWebServerF private Set builderCustomizers = new LinkedHashSet<>(); + @Deprecated private List deploymentInfoCustomizers = new ArrayList<>(); private Integer bufferSize; @@ -200,32 +200,6 @@ public class UndertowReactiveWebServerFactory extends AbstractReactiveWebServerF return getAddress().getHostAddress(); } - /** - * Set {@link UndertowDeploymentInfoCustomizer}s that should be applied to the - * Undertow {@link DeploymentInfo}. Calling this method will replace any existing - * customizers. - * @param customizers the customizers to set - */ - public void setDeploymentInfoCustomizers(Collection customizers) { - Assert.notNull(customizers, "Customizers must not be null"); - this.deploymentInfoCustomizers = new ArrayList<>(customizers); - } - - /** - * Returns a mutable collection of the {@link UndertowDeploymentInfoCustomizer}s that - * will be applied to the Undertow {@link DeploymentInfo}. - * @return the customizers that will be applied - */ - public Collection getDeploymentInfoCustomizers() { - return this.deploymentInfoCustomizers; - } - - @Override - public void addDeploymentInfoCustomizers(UndertowDeploymentInfoCustomizer... customizers) { - Assert.notNull(customizers, "UndertowDeploymentInfoCustomizers must not be null"); - this.deploymentInfoCustomizers.addAll(Arrays.asList(customizers)); - } - @Override public void setAccessLogDirectory(File accessLogDirectory) { this.accessLogDirectory = accessLogDirectory; diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServerFactory.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServerFactory.java index aa534c8c933..a87fe5bb064 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServerFactory.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/undertow/UndertowServletWebServerFactory.java @@ -196,7 +196,11 @@ public class UndertowServletWebServerFactory extends AbstractServletWebServerFac return this.deploymentInfoCustomizers; } - @Override + /** + * Add {@link UndertowDeploymentInfoCustomizer}s that should be used to customize the + * Undertow {@link DeploymentInfo}. + * @param customizers the customizers to add + */ public void addDeploymentInfoCustomizers(UndertowDeploymentInfoCustomizer... customizers) { Assert.notNull(customizers, "UndertowDeploymentInfoCustomizers must not be null"); this.deploymentInfoCustomizers.addAll(Arrays.asList(customizers));