Skip to content

Commit ea80ca2

Browse files
committed
Do not assume HTTP protocol when customizing processor cache
Closes gh-16413
1 parent c5024f2 commit ea80ca2

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/TomcatWebServerFactoryCustomizer.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,12 @@ private void customizeAcceptCount(ConfigurableTomcatWebServerFactory factory,
133133

134134
private void customizeProcessorCache(ConfigurableTomcatWebServerFactory factory,
135135
int processorCache) {
136-
factory.addConnectorCustomizers((
137-
connector) -> ((AbstractHttp11Protocol<?>) connector.getProtocolHandler())
138-
.setProcessorCache(processorCache));
136+
factory.addConnectorCustomizers((connector) -> {
137+
ProtocolHandler handler = connector.getProtocolHandler();
138+
if (handler instanceof AbstractProtocol) {
139+
((AbstractProtocol<?>) handler).setProcessorCache(processorCache);
140+
}
141+
});
139142
}
140143

141144
private void customizeMaxConnections(ConfigurableTomcatWebServerFactory factory,

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/TomcatWebServerFactoryCustomizerTests.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.springframework.boot.context.properties.source.ConfigurationPropertySources;
3737
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
3838
import org.springframework.boot.web.embedded.tomcat.TomcatWebServer;
39+
import org.springframework.boot.web.server.WebServer;
3940
import org.springframework.mock.env.MockEnvironment;
4041
import org.springframework.test.context.support.TestPropertySourceUtils;
4142
import org.springframework.util.unit.DataSize;
@@ -421,6 +422,16 @@ public void accessLogwithIpv6CanonicalSet() {
421422
.getIpv6Canonical()).isTrue();
422423
}
423424

425+
@Test
426+
public void ajpConnectorCanBeCustomized() {
427+
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(0);
428+
factory.setProtocol("AJP/1.3");
429+
this.customizer.customize(factory);
430+
WebServer server = factory.getWebServer();
431+
server.start();
432+
server.stop();
433+
}
434+
424435
private void bind(String... inlinedProperties) {
425436
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment,
426437
inlinedProperties);

0 commit comments

Comments
 (0)