Make WebSocket upgrade strategies compatible with Tomcat 10.1

This commit is contained in:
Andy Wilkinson 2022-11-05 13:37:25 +00:00 committed by Juergen Hoeller
parent ac5eb9bfd3
commit 95395b53d5
2 changed files with 6 additions and 15 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2021 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -121,8 +121,6 @@ public class TomcatRequestUpgradeStrategy implements RequestUpgradeStrategy {
return this.maxBinaryMessageBufferSize; return this.maxBinaryMessageBufferSize;
} }
@SuppressWarnings("deprecation") // for old doUpgrade variant in Tomcat 9.0.55
@Override @Override
public Mono<Void> upgrade(ServerWebExchange exchange, WebSocketHandler handler, public Mono<Void> upgrade(ServerWebExchange exchange, WebSocketHandler handler,
@Nullable String subProtocol, Supplier<HandshakeInfo> handshakeInfoFactory){ @Nullable String subProtocol, Supplier<HandshakeInfo> handshakeInfoFactory){
@ -150,7 +148,7 @@ public class TomcatRequestUpgradeStrategy implements RequestUpgradeStrategy {
WsServerContainer container = getContainer(servletRequest); WsServerContainer container = getContainer(servletRequest);
try { try {
container.doUpgrade(servletRequest, servletResponse, config, Collections.emptyMap()); container.upgradeHttpToWebSocket(servletRequest, servletResponse, config, Collections.emptyMap());
} }
catch (Exception ex) { catch (Exception ex) {
return Mono.error(ex); return Mono.error(ex);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2021 the original author or authors. * Copyright 2002-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,12 +16,10 @@
package org.springframework.web.socket.server.standard; package org.springframework.web.socket.server.standard;
import java.io.IOException;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import jakarta.websocket.Endpoint; import jakarta.websocket.Endpoint;
@ -35,7 +33,7 @@ import org.springframework.web.socket.server.HandshakeFailureException;
/** /**
* A WebSocket {@code RequestUpgradeStrategy} for Apache Tomcat. Compatible with * A WebSocket {@code RequestUpgradeStrategy} for Apache Tomcat. Compatible with
* all versions of Tomcat that support JSR-356, i.e. Tomcat 7.0.47+ and higher. * Tomcat 10 and higher.
* *
* <p>To modify properties of the underlying {@link jakarta.websocket.server.ServerContainer} * <p>To modify properties of the underlying {@link jakarta.websocket.server.ServerContainer}
* you can use {@link ServletServerContainerFactoryBean} in XML configuration or, * you can use {@link ServletServerContainerFactoryBean} in XML configuration or,
@ -52,7 +50,6 @@ public class TomcatRequestUpgradeStrategy extends AbstractStandardUpgradeStrateg
return new String[] {"13"}; return new String[] {"13"};
} }
@SuppressWarnings("deprecation") // for old doUpgrade variant in Tomcat 9.0.55
@Override @Override
public void upgradeInternal(ServerHttpRequest request, ServerHttpResponse response, public void upgradeInternal(ServerHttpRequest request, ServerHttpResponse response,
@Nullable String selectedProtocol, List<Extension> selectedExtensions, Endpoint endpoint) @Nullable String selectedProtocol, List<Extension> selectedExtensions, Endpoint endpoint)
@ -70,16 +67,12 @@ public class TomcatRequestUpgradeStrategy extends AbstractStandardUpgradeStrateg
endpointConfig.setExtensions(selectedExtensions); endpointConfig.setExtensions(selectedExtensions);
try { try {
getContainer(servletRequest).doUpgrade(servletRequest, servletResponse, endpointConfig, pathParams); getContainer(servletRequest).upgradeHttpToWebSocket(servletRequest, servletResponse, endpointConfig, pathParams);
} }
catch (ServletException ex) { catch (Exception ex) {
throw new HandshakeFailureException( throw new HandshakeFailureException(
"Servlet request failed to upgrade to WebSocket: " + requestUrl, ex); "Servlet request failed to upgrade to WebSocket: " + requestUrl, ex);
} }
catch (IOException ex) {
throw new HandshakeFailureException(
"Response update failed during upgrade to WebSocket: " + requestUrl, ex);
}
} }
@Override @Override