Skip to content

Commit 30df137

Browse files
committed
HandshakeWebSocketService detects upgrade strategies
Issue: SPR-14527
1 parent 47e1416 commit 30df137

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

spring-web-reactive/src/main/java/org/springframework/web/reactive/socket/server/support/HandshakeWebSocketService.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,24 @@ public class HandshakeWebSocketService implements WebSocketService, Lifecycle {
5050
private static final String SEC_WEBSOCKET_KEY = "Sec-WebSocket-Key";
5151

5252

53+
private static final boolean tomcatPresent = ClassUtils.isPresent(
54+
"org.apache.tomcat.websocket.server.WsHttpUpgradeHandler",
55+
HandshakeWebSocketService.class.getClassLoader());
56+
57+
private static final boolean jettyPresent = ClassUtils.isPresent(
58+
"org.eclipse.jetty.websocket.server.WebSocketServerFactory",
59+
HandshakeWebSocketService.class.getClassLoader());
60+
61+
private static final boolean reactorNettyPresent = ClassUtils.isPresent(
62+
"reactor.ipc.netty.http.server.HttpServerResponse",
63+
HandshakeWebSocketService.class.getClassLoader());
64+
5365
private static final boolean rxNettyPresent = ClassUtils.isPresent(
54-
"io.reactivex.netty.protocol.http.ws.WebSocketConnection",
66+
"io.reactivex.netty.protocol.http.server.HttpServerResponse",
67+
HandshakeWebSocketService.class.getClassLoader());
68+
69+
private static final boolean undertowPresent = ClassUtils.isPresent(
70+
"io.undertow.websockets.WebSocketProtocolHandshakeHandler",
5571
HandshakeWebSocketService.class.getClassLoader());
5672

5773

@@ -82,9 +98,21 @@ public HandshakeWebSocketService(RequestUpgradeStrategy upgradeStrategy) {
8298

8399
private static RequestUpgradeStrategy initUpgradeStrategy() {
84100
String className;
85-
if (rxNettyPresent) {
101+
if (tomcatPresent) {
102+
className = "TomcatRequestUpgradeStrategy";
103+
}
104+
else if (jettyPresent) {
105+
className = "JettyRequestUpgradeStrategy";
106+
}
107+
else if (reactorNettyPresent) {
108+
className = "ReactorNettyRequestUpgradeStrategy";
109+
}
110+
else if (rxNettyPresent) {
86111
className = "RxNettyRequestUpgradeStrategy";
87112
}
113+
else if (undertowPresent) {
114+
className = "UndertowRequestUpgradeStrategy";
115+
}
88116
else {
89117
throw new IllegalStateException("No suitable default RequestUpgradeStrategy found");
90118
}

0 commit comments

Comments
 (0)