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 603d8e6183..d6c4940d9f 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.JettyRequestUpgrad 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 @@ public class HandshakeWebSocketService implements WebSocketService, Lifecycle { 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 8837a4543f..0000000000 --- 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 c4c988ecf4..b3388954bd 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.JettyCoreRequestUp 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; @@ -204,40 +204,12 @@ abstract class AbstractReactiveWebSocketIntegrationTests { } - @Configuration - static class ReactorNettyConfig extends AbstractHandlerAdapterConfig { - - @Override - protected RequestUpgradeStrategy getUpgradeStrategy() { - return new ReactorNettyRequestUpgradeStrategy(); - } - } - - @Configuration - static class ReactorNetty2Config extends AbstractHandlerAdapterConfig { - - @Override - protected RequestUpgradeStrategy getUpgradeStrategy() { - return new ReactorNetty2RequestUpgradeStrategy(); - } - } - @Configuration static class TomcatConfig extends AbstractHandlerAdapterConfig { @Override protected RequestUpgradeStrategy getUpgradeStrategy() { - return new TomcatRequestUpgradeStrategy(); - } - } - - - @Configuration - static class UndertowConfig extends AbstractHandlerAdapterConfig { - - @Override - protected RequestUpgradeStrategy getUpgradeStrategy() { - return new UndertowRequestUpgradeStrategy(); + return new StandardWebSocketUpgradeStrategy(); } } @@ -251,6 +223,7 @@ abstract class AbstractReactiveWebSocketIntegrationTests { } } + @Configuration static class JettyCoreConfig extends AbstractHandlerAdapterConfig { @@ -259,4 +232,35 @@ abstract class AbstractReactiveWebSocketIntegrationTests { return new JettyCoreRequestUpgradeStrategy(); } } + + + @Configuration + static class ReactorNettyConfig extends AbstractHandlerAdapterConfig { + + @Override + protected RequestUpgradeStrategy getUpgradeStrategy() { + return new ReactorNettyRequestUpgradeStrategy(); + } + } + + + @Configuration + static class ReactorNetty2Config extends AbstractHandlerAdapterConfig { + + @Override + protected RequestUpgradeStrategy getUpgradeStrategy() { + return new ReactorNetty2RequestUpgradeStrategy(); + } + } + + + @Configuration + static class UndertowConfig extends AbstractHandlerAdapterConfig { + + @Override + protected RequestUpgradeStrategy getUpgradeStrategy() { + return new UndertowRequestUpgradeStrategy(); + } + } + }