Skip to content

Commit

Permalink
Make WebSocket upgrade strategies compatible with Tomcat 10.1
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkinsona authored and jhoeller committed Nov 5, 2022
1 parent ac5eb9b commit 95395b5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
@@ -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");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -121,8 +121,6 @@ public Integer getMaxBinaryMessageBufferSize() {
return this.maxBinaryMessageBufferSize;
}


@SuppressWarnings("deprecation") // for old doUpgrade variant in Tomcat 9.0.55
@Override
public Mono<Void> upgrade(ServerWebExchange exchange, WebSocketHandler handler,
@Nullable String subProtocol, Supplier<HandshakeInfo> handshakeInfoFactory){
Expand Down Expand Up @@ -150,7 +148,7 @@ public Mono<Void> upgrade(ServerWebExchange exchange, WebSocketHandler handler,

WsServerContainer container = getContainer(servletRequest);
try {
container.doUpgrade(servletRequest, servletResponse, config, Collections.emptyMap());
container.upgradeHttpToWebSocket(servletRequest, servletResponse, config, Collections.emptyMap());
}
catch (Exception ex) {
return Mono.error(ex);
Expand Down
@@ -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");
* you may not use this file except in compliance with the License.
Expand All @@ -16,12 +16,10 @@

package org.springframework.web.socket.server.standard;

import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.websocket.Endpoint;
Expand All @@ -35,7 +33,7 @@

/**
* 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}
* you can use {@link ServletServerContainerFactoryBean} in XML configuration or,
Expand All @@ -52,7 +50,6 @@ public String[] getSupportedVersions() {
return new String[] {"13"};
}

@SuppressWarnings("deprecation") // for old doUpgrade variant in Tomcat 9.0.55
@Override
public void upgradeInternal(ServerHttpRequest request, ServerHttpResponse response,
@Nullable String selectedProtocol, List<Extension> selectedExtensions, Endpoint endpoint)
Expand All @@ -70,16 +67,12 @@ public void upgradeInternal(ServerHttpRequest request, ServerHttpResponse respon
endpointConfig.setExtensions(selectedExtensions);

try {
getContainer(servletRequest).doUpgrade(servletRequest, servletResponse, endpointConfig, pathParams);
getContainer(servletRequest).upgradeHttpToWebSocket(servletRequest, servletResponse, endpointConfig, pathParams);
}
catch (ServletException ex) {
catch (Exception ex) {
throw new HandshakeFailureException(
"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
Expand Down

0 comments on commit 95395b5

Please sign in to comment.