Drop server-specific TomcatRequestUpgradeStrategy for WebFlux

StandardWebSocketUpgradeStrategy is the common replacement on Tomcat.

See gh-33744
This commit is contained in:
Juergen Hoeller
2024-12-04 16:50:16 +01:00
parent 162e533393
commit da75840712
3 changed files with 36 additions and 86 deletions

View File

@@ -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<Map<String, Object>> 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) {

View File

@@ -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<String, String> pathParams) throws Exception {
((WsServerContainer) getContainer(request)).upgradeHttpToWebSocket(
request, response, endpointConfig, pathParams);
}
}

View File

@@ -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();
}
}
}