From da7584071262e9b7a0beef7b17f88d3cf00b1abf Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 4 Dec 2024 16:50:16 +0100 Subject: [PATCH] Drop server-specific TomcatRequestUpgradeStrategy for WebFlux StandardWebSocketUpgradeStrategy is the common replacement on Tomcat. See gh-33744 --- .../support/HandshakeWebSocketService.java | 12 +---- .../upgrade/TomcatRequestUpgradeStrategy.java | 46 ------------------- ...ractReactiveWebSocketIntegrationTests.java | 30 ++++++------ 3 files changed, 19 insertions(+), 69 deletions(-) delete mode 100644 spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/TomcatRequestUpgradeStrategy.java diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/support/HandshakeWebSocketService.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/support/HandshakeWebSocketService.java index 603d8e618340..d6c4940d9f54 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/support/HandshakeWebSocketService.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/support/HandshakeWebSocketService.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -48,7 +48,6 @@ import org.springframework.web.reactive.socket.server.upgrade.ReactorNetty2RequestUpgradeStrategy; import org.springframework.web.reactive.socket.server.upgrade.ReactorNettyRequestUpgradeStrategy; import org.springframework.web.reactive.socket.server.upgrade.StandardWebSocketUpgradeStrategy; -import org.springframework.web.reactive.socket.server.upgrade.TomcatRequestUpgradeStrategy; import org.springframework.web.reactive.socket.server.upgrade.UndertowRequestUpgradeStrategy; import org.springframework.web.server.MethodNotAllowedException; import org.springframework.web.server.ServerWebExchange; @@ -73,8 +72,6 @@ public class HandshakeWebSocketService implements WebSocketService, Lifecycle { private static final Mono> EMPTY_ATTRIBUTES = Mono.just(Collections.emptyMap()); - private static final boolean tomcatWsPresent; - private static final boolean jettyWsPresent; private static final boolean jettyCoreWsPresent; @@ -87,8 +84,6 @@ public class HandshakeWebSocketService implements WebSocketService, Lifecycle { static { ClassLoader classLoader = HandshakeWebSocketService.class.getClassLoader(); - tomcatWsPresent = ClassUtils.isPresent( - "org.apache.tomcat.websocket.server.WsHttpUpgradeHandler", classLoader); jettyWsPresent = ClassUtils.isPresent( "org.eclipse.jetty.ee10.websocket.server.JettyWebSocketServerContainer", classLoader); jettyCoreWsPresent = ClassUtils.isPresent( @@ -277,10 +272,7 @@ private HandshakeInfo createHandshakeInfo(ServerWebExchange exchange, ServerHttp static RequestUpgradeStrategy initUpgradeStrategy() { - if (tomcatWsPresent) { - return new TomcatRequestUpgradeStrategy(); - } - else if (jettyWsPresent) { + if (jettyWsPresent) { return new JettyRequestUpgradeStrategy(); } else if (jettyCoreWsPresent) { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/TomcatRequestUpgradeStrategy.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/TomcatRequestUpgradeStrategy.java deleted file mode 100644 index 8837a4543f69..000000000000 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/TomcatRequestUpgradeStrategy.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2002-2022 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.web.reactive.socket.server.upgrade; - -import java.util.Map; - -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import jakarta.websocket.server.ServerEndpointConfig; -import org.apache.tomcat.websocket.server.WsServerContainer; - -/** - * A WebSocket {@code RequestUpgradeStrategy} for Apache Tomcat. Compatible with Tomcat 10 - * and higher, in particular with Tomcat 10.0 (not based on Jakarta WebSocket 2.1 yet). - * - * @author Violeta Georgieva - * @author Rossen Stoyanchev - * @author Juergen Hoeller - * @since 5.0 - * @see org.apache.tomcat.websocket.server.WsServerContainer#upgradeHttpToWebSocket - */ -public class TomcatRequestUpgradeStrategy extends StandardWebSocketUpgradeStrategy { - - @Override - protected void upgradeHttpToWebSocket(HttpServletRequest request, HttpServletResponse response, - ServerEndpointConfig endpointConfig, Map pathParams) throws Exception { - - ((WsServerContainer) getContainer(request)).upgradeHttpToWebSocket( - request, response, endpointConfig, pathParams); - } - -} diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/socket/AbstractReactiveWebSocketIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/socket/AbstractReactiveWebSocketIntegrationTests.java index c4c988ecf426..b3388954bd67 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/socket/AbstractReactiveWebSocketIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/socket/AbstractReactiveWebSocketIntegrationTests.java @@ -60,7 +60,7 @@ import org.springframework.web.reactive.socket.server.upgrade.JettyRequestUpgradeStrategy; import org.springframework.web.reactive.socket.server.upgrade.ReactorNetty2RequestUpgradeStrategy; import org.springframework.web.reactive.socket.server.upgrade.ReactorNettyRequestUpgradeStrategy; -import org.springframework.web.reactive.socket.server.upgrade.TomcatRequestUpgradeStrategy; +import org.springframework.web.reactive.socket.server.upgrade.StandardWebSocketUpgradeStrategy; import org.springframework.web.reactive.socket.server.upgrade.UndertowRequestUpgradeStrategy; import org.springframework.web.server.WebFilter; import org.springframework.web.server.adapter.WebHttpHandlerBuilder; @@ -205,58 +205,62 @@ public WebSocketService webSocketService() { @Configuration - static class ReactorNettyConfig extends AbstractHandlerAdapterConfig { + static class TomcatConfig extends AbstractHandlerAdapterConfig { @Override protected RequestUpgradeStrategy getUpgradeStrategy() { - return new ReactorNettyRequestUpgradeStrategy(); + return new StandardWebSocketUpgradeStrategy(); } } + @Configuration - static class ReactorNetty2Config extends AbstractHandlerAdapterConfig { + static class JettyConfig extends AbstractHandlerAdapterConfig { @Override protected RequestUpgradeStrategy getUpgradeStrategy() { - return new ReactorNetty2RequestUpgradeStrategy(); + return new JettyRequestUpgradeStrategy(); } } + @Configuration - static class TomcatConfig extends AbstractHandlerAdapterConfig { + static class JettyCoreConfig extends AbstractHandlerAdapterConfig { @Override protected RequestUpgradeStrategy getUpgradeStrategy() { - return new TomcatRequestUpgradeStrategy(); + return new JettyCoreRequestUpgradeStrategy(); } } @Configuration - static class UndertowConfig extends AbstractHandlerAdapterConfig { + static class ReactorNettyConfig extends AbstractHandlerAdapterConfig { @Override protected RequestUpgradeStrategy getUpgradeStrategy() { - return new UndertowRequestUpgradeStrategy(); + return new ReactorNettyRequestUpgradeStrategy(); } } @Configuration - static class JettyConfig extends AbstractHandlerAdapterConfig { + static class ReactorNetty2Config extends AbstractHandlerAdapterConfig { @Override protected RequestUpgradeStrategy getUpgradeStrategy() { - return new JettyRequestUpgradeStrategy(); + return new ReactorNetty2RequestUpgradeStrategy(); } } + @Configuration - static class JettyCoreConfig extends AbstractHandlerAdapterConfig { + static class UndertowConfig extends AbstractHandlerAdapterConfig { @Override protected RequestUpgradeStrategy getUpgradeStrategy() { - return new JettyCoreRequestUpgradeStrategy(); + return new UndertowRequestUpgradeStrategy(); } } + }