diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizer.java index 6f96a46cdc..af50cb5048 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizer.java @@ -17,6 +17,7 @@ package org.springframework.boot.autoconfigure.web.embedded; import java.time.Duration; +import java.util.Arrays; import org.eclipse.jetty.server.AbstractConnector; import org.eclipse.jetty.server.ConnectionFactory; @@ -76,8 +77,8 @@ public class JettyWebServerFactoryCustomizer implements .to(factory::setSelectors); propertyMapper.from(properties::getMaxHttpHeaderSize).whenNonNull() .asInt(DataSize::toBytes).when(this::isPositive) - .to((maxHttpHeaderSize) -> customizeMaxHttpHeaderSize(factory, - maxHttpHeaderSize)); + .to((maxHttpHeaderSize) -> factory.addServerCustomizers( + new MaxHttpHeaderSizeCustomizer(maxHttpHeaderSize))); propertyMapper.from(jettyProperties::getMaxHttpPostSize).asInt(DataSize::toBytes) .when(this::isPositive) .to((maxHttpPostSize) -> customizeMaxHttpPostSize(factory, @@ -115,32 +116,6 @@ public class JettyWebServerFactoryCustomizer implements }); } - private void customizeMaxHttpHeaderSize(ConfigurableJettyWebServerFactory factory, - int maxHttpHeaderSize) { - factory.addServerCustomizers(new JettyServerCustomizer() { - - @Override - public void customize(Server server) { - for (org.eclipse.jetty.server.Connector connector : server - .getConnectors()) { - for (ConnectionFactory connectionFactory : connector - .getConnectionFactories()) { - if (connectionFactory instanceof HttpConfiguration.ConnectionFactory) { - customize( - (HttpConfiguration.ConnectionFactory) connectionFactory); - } - } - } - } - - private void customize(HttpConfiguration.ConnectionFactory factory) { - HttpConfiguration configuration = factory.getHttpConfiguration(); - configuration.setRequestHeaderSize(maxHttpHeaderSize); - } - - }); - } - private void customizeMaxHttpPostSize(ConfigurableJettyWebServerFactory factory, int maxHttpPostSize) { factory.addServerCustomizers(new JettyServerCustomizer() { @@ -199,4 +174,30 @@ public class JettyWebServerFactoryCustomizer implements }); } + private static class MaxHttpHeaderSizeCustomizer implements JettyServerCustomizer { + + private final int maxHttpHeaderSize; + + MaxHttpHeaderSizeCustomizer(int maxHttpHeaderSize) { + this.maxHttpHeaderSize = maxHttpHeaderSize; + } + + @Override + public void customize(Server server) { + Arrays.stream(server.getConnectors()).forEach(this::customize); + } + + private void customize(org.eclipse.jetty.server.Connector connector) { + connector.getConnectionFactories().forEach(this::customize); + } + + private void customize(ConnectionFactory factory) { + if (factory instanceof HttpConfiguration.ConnectionFactory) { + ((HttpConfiguration.ConnectionFactory) factory).getHttpConfiguration() + .setRequestHeaderSize(this.maxHttpHeaderSize); + } + } + + } + } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/jdbc/JdbcRepositoriesAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/jdbc/JdbcRepositoriesAutoConfigurationTests.java index 2c897eb362..364dab9d25 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/jdbc/JdbcRepositoriesAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/jdbc/JdbcRepositoriesAutoConfigurationTests.java @@ -51,10 +51,8 @@ public class JdbcRepositoriesAutoConfigurationTests { @Test public void backsOffWithNoDataSource() { this.contextRunner.withUserConfiguration(TestConfiguration.class) - .run((context) -> { - assertThat(context) - .doesNotHaveBean(JdbcRepositoryConfigExtension.class); - }); + .run((context) -> assertThat(context) + .doesNotHaveBean(JdbcRepositoryConfigExtension.class)); } @Test diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jsonb/JsonbAutoConfigurationWithNoProviderTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jsonb/JsonbAutoConfigurationWithNoProviderTests.java index b1c5a759da..11ec0dd88a 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jsonb/JsonbAutoConfigurationWithNoProviderTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jsonb/JsonbAutoConfigurationWithNoProviderTests.java @@ -42,9 +42,8 @@ public class JsonbAutoConfigurationWithNoProviderTests { @Test public void jsonbBacksOffWhenThereIsNoProvider() { - this.contextRunner.run((context) -> { - assertThat(context).doesNotHaveBean(Jsonb.class); - }); + this.contextRunner + .run((context) -> assertThat(context).doesNotHaveBean(Jsonb.class)); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfigurationTests.java index 54c0e6f82b..844ec4c8c7 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfigurationTests.java @@ -592,9 +592,7 @@ public class HibernateJpaAutoConfigurationTests @Bean public EntityManagerFactoryBuilderCustomizer asyncBootstrappingCustomizer( ThreadPoolTaskExecutor executor) { - return (builder) -> { - builder.setBootstrapExecutor(executor); - }; + return (builder) -> builder.setBootstrapExecutor(executor); } } 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 6f8083fa8c..5f4b7615f1 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 @@ -73,12 +73,10 @@ public class TomcatWebServerFactoryCustomizerTests { @Test public void defaultsAreConsistent() { - customizeAndRunServer((server) -> { - assertThat(((AbstractHttp11Protocol) server.getTomcat().getConnector() - .getProtocolHandler()).getMaxSwallowSize()) - .isEqualTo(this.serverProperties.getTomcat() - .getMaxSwallowSize().toBytes()); - }); + customizeAndRunServer((server) -> assertThat(((AbstractHttp11Protocol) server + .getTomcat().getConnector().getProtocolHandler()).getMaxSwallowSize()) + .isEqualTo(this.serverProperties.getTomcat().getMaxSwallowSize() + .toBytes())); } @Test