From ea80ca2ffc6b3b6c8c67372d926b0add4da19bab Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 2 Apr 2019 15:10:55 +0100 Subject: [PATCH] Do not assume HTTP protocol when customizing processor cache Closes gh-16413 --- .../embedded/TomcatWebServerFactoryCustomizer.java | 9 ++++++--- .../TomcatWebServerFactoryCustomizerTests.java | 11 +++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/TomcatWebServerFactoryCustomizer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/TomcatWebServerFactoryCustomizer.java index 76cba0c8623..632a2850168 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/TomcatWebServerFactoryCustomizer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/TomcatWebServerFactoryCustomizer.java @@ -133,9 +133,12 @@ public class TomcatWebServerFactoryCustomizer implements private void customizeProcessorCache(ConfigurableTomcatWebServerFactory factory, int processorCache) { - factory.addConnectorCustomizers(( - connector) -> ((AbstractHttp11Protocol) connector.getProtocolHandler()) - .setProcessorCache(processorCache)); + factory.addConnectorCustomizers((connector) -> { + ProtocolHandler handler = connector.getProtocolHandler(); + if (handler instanceof AbstractProtocol) { + ((AbstractProtocol) handler).setProcessorCache(processorCache); + } + }); } private void customizeMaxConnections(ConfigurableTomcatWebServerFactory factory, diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/TomcatWebServerFactoryCustomizerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/TomcatWebServerFactoryCustomizerTests.java index 12ee998d541..f99fe9f80aa 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/TomcatWebServerFactoryCustomizerTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/TomcatWebServerFactoryCustomizerTests.java @@ -36,6 +36,7 @@ import org.springframework.boot.context.properties.bind.Binder; import org.springframework.boot.context.properties.source.ConfigurationPropertySources; import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; import org.springframework.boot.web.embedded.tomcat.TomcatWebServer; +import org.springframework.boot.web.server.WebServer; import org.springframework.mock.env.MockEnvironment; import org.springframework.test.context.support.TestPropertySourceUtils; import org.springframework.util.unit.DataSize; @@ -421,6 +422,16 @@ public class TomcatWebServerFactoryCustomizerTests { .getIpv6Canonical()).isTrue(); } + @Test + public void ajpConnectorCanBeCustomized() { + TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(0); + factory.setProtocol("AJP/1.3"); + this.customizer.customize(factory); + WebServer server = factory.getWebServer(); + server.start(); + server.stop(); + } + private void bind(String... inlinedProperties) { TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment, inlinedProperties);