From 7113c10b0889d17770d8b20cc88cb81e73f30d63 Mon Sep 17 00:00:00 2001 From: Onur Kagan Ozcan Date: Sun, 7 Jan 2024 16:38:41 +0300 Subject: [PATCH 1/2] Fix Jetty ConnectionLimit configuration See gh-39052 --- .../jetty/JettyServletWebServerFactory.java | 3 ++- .../jetty/JettyServletWebServerFactoryTests.java | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactory.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactory.java index 89d0159d52ae..6644d775fc4e 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactory.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactory.java @@ -116,6 +116,7 @@ * @author Venil Noronha * @author Henri Kerola * @author Moritz Halbritter + * @author Onur Kagan Ozcan * @since 2.0.0 * @see #setPort(int) * @see #setConfigurations(Collection) @@ -183,7 +184,7 @@ public WebServer getWebServer(ServletContextInitializer... initializers) { server.setHandler(addHandlerWrappers(context)); this.logger.info("Server initialized with port: " + port); if (this.maxConnections > -1) { - server.addBean(new ConnectionLimit(this.maxConnections, server)); + server.addBean(new ConnectionLimit(this.maxConnections, server.getConnectors())); } if (Ssl.isEnabled(getSsl())) { customizeSsl(server, address); diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactoryTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactoryTests.java index dbb73701e06c..62f04c0d7bbd 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactoryTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactoryTests.java @@ -72,6 +72,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.assertj.core.api.InstanceOfAssertFactories.LIST; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.inOrder; @@ -85,6 +86,7 @@ * @author Andy Wilkinson * @author Henri Kerola * @author Moritz Halbritter + * @author Onur Kagan Ozcan */ class JettyServletWebServerFactoryTests extends AbstractServletWebServerFactoryTests { @@ -541,6 +543,17 @@ void shouldApplyMaxConnections() { assertThat(connectionLimit.getMaxConnections()).isOne(); } + @Test + void shouldApplyingMaxConnectionUseConnector() throws Exception { + JettyServletWebServerFactory factory = getFactory(); + factory.setMaxConnections(1); + this.webServer = factory.getWebServer(); + Server server = ((JettyWebServer) this.webServer).getServer(); + assertThat(server.getConnectors()).isEmpty(); + ConnectionLimit connectionLimit = server.getBean(ConnectionLimit.class); + assertThat(connectionLimit).extracting("_connectors", LIST).hasSize(1); + } + @Override protected String startedLogMessage() { return ((JettyWebServer) this.webServer).getStartedLogMessage(); From 66dc72da4638cc7feb05da35b1b12edccfbf58ef Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Wed, 10 Jan 2024 10:17:38 +0100 Subject: [PATCH 2/2] Polish "Fix Jetty ConnectionLimit configuration" See gh-39052 --- .../embedded/jetty/JettyServletWebServerFactoryTests.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactoryTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactoryTests.java index 62f04c0d7bbd..07f030593476 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactoryTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactoryTests.java @@ -39,6 +39,7 @@ import org.apache.hc.core5.http.Header; import org.apache.hc.core5.http.HttpResponse; import org.apache.jasper.servlet.JspServlet; +import org.assertj.core.api.InstanceOfAssertFactories; import org.awaitility.Awaitility; import org.eclipse.jetty.ee10.servlet.ErrorPageErrorHandler; import org.eclipse.jetty.ee10.servlet.ServletHolder; @@ -46,6 +47,7 @@ import org.eclipse.jetty.ee10.webapp.ClassMatcher; import org.eclipse.jetty.ee10.webapp.Configuration; import org.eclipse.jetty.ee10.webapp.WebAppContext; +import org.eclipse.jetty.server.AbstractConnector; import org.eclipse.jetty.server.ConnectionLimit; import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.Handler; @@ -72,7 +74,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.InstanceOfAssertFactories.LIST; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.inOrder; @@ -551,7 +552,9 @@ void shouldApplyingMaxConnectionUseConnector() throws Exception { Server server = ((JettyWebServer) this.webServer).getServer(); assertThat(server.getConnectors()).isEmpty(); ConnectionLimit connectionLimit = server.getBean(ConnectionLimit.class); - assertThat(connectionLimit).extracting("_connectors", LIST).hasSize(1); + assertThat(connectionLimit).extracting("_connectors") + .asInstanceOf(InstanceOfAssertFactories.list(AbstractConnector.class)) + .hasSize(1); } @Override