Skip to content

Commit c809143

Browse files
committed
Upgrade to Undertow 1.0.15 and fix failing test
Issue: SPR-11777
1 parent d746e3f commit c809143

File tree

2 files changed

+26
-27
lines changed

2 files changed

+26
-27
lines changed

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -670,12 +670,12 @@ project("spring-websocket") {
670670
exclude group: "javax.servlet", module: "javax.servlet"
671671
}
672672
optional("org.eclipse.jetty.websocket:websocket-client:${jettyVersion}")
673-
optional("io.undertow:undertow-core:1.0.1.Final")
674-
optional("io.undertow:undertow-servlet:1.0.1.Final") {
673+
optional("io.undertow:undertow-core:1.0.15.Final")
674+
optional("io.undertow:undertow-servlet:1.0.15.Final") {
675675
exclude group: "org.jboss.spec.javax.servlet", module: "jboss-servlet-api_3.1_spec"
676676
exclude group: "org.jboss.spec.javax.annotation", module: "jboss-annotations-api_1.2_spec"
677677
}
678-
optional("io.undertow:undertow-websockets-jsr:1.0.1.Final") {
678+
optional("io.undertow:undertow-websockets-jsr:1.0.15.Final") {
679679
exclude group: "org.jboss.spec.javax.websocket", module: "jboss-websocket-api_1.0_spec"
680680
}
681681
optional("com.fasterxml.jackson.core:jackson-databind:${jackson2Version}")

spring-websocket/src/main/java/org/springframework/web/socket/server/standard/UndertowRequestUpgradeStrategy.java

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import io.undertow.servlet.api.InstanceHandle;
3333
import io.undertow.servlet.websockets.ServletWebSocketHttpExchange;
3434
import io.undertow.websockets.core.WebSocketChannel;
35+
import io.undertow.websockets.core.WebSocketVersion;
3536
import io.undertow.websockets.core.protocol.Handshake;
3637
import io.undertow.websockets.core.protocol.version07.Hybi07Handshake;
3738
import io.undertow.websockets.core.protocol.version08.Hybi08Handshake;
@@ -41,6 +42,9 @@
4142
import io.undertow.websockets.jsr.EndpointSessionHandler;
4243
import io.undertow.websockets.jsr.ServerWebSocketContainer;
4344
import io.undertow.websockets.jsr.handshake.HandshakeUtil;
45+
import io.undertow.websockets.jsr.handshake.JsrHybi07Handshake;
46+
import io.undertow.websockets.jsr.handshake.JsrHybi08Handshake;
47+
import io.undertow.websockets.jsr.handshake.JsrHybi13Handshake;
4448
import org.xnio.StreamConnection;
4549

4650
import org.springframework.http.server.ServerHttpRequest;
@@ -57,23 +61,12 @@
5761
*/
5862
public class UndertowRequestUpgradeStrategy extends AbstractStandardUpgradeStrategy {
5963

60-
private final Handshake[] handshakes;
64+
private final String[] supportedVersions = new String[] {
65+
WebSocketVersion.V13.toHttpHeaderValue(),
66+
WebSocketVersion.V08.toHttpHeaderValue(),
67+
WebSocketVersion.V07.toHttpHeaderValue()
68+
};
6169

62-
private final String[] supportedVersions;
63-
64-
65-
public UndertowRequestUpgradeStrategy() {
66-
this.handshakes = new Handshake[] {new Hybi13Handshake(), new Hybi08Handshake(), new Hybi07Handshake()};
67-
this.supportedVersions = initSupportedVersions(this.handshakes);
68-
}
69-
70-
private String[] initSupportedVersions(Handshake[] handshakes) {
71-
String[] versions = new String[handshakes.length];
72-
for (int i = 0; i < versions.length; i++) {
73-
versions[i] = handshakes[i].getVersion().toHttpHeaderValue();
74-
}
75-
return versions;
76-
}
7770

7871
@Override
7972
public String[] getSupportedVersions() {
@@ -93,28 +86,34 @@ protected void upgradeInternal(ServerHttpRequest request, ServerHttpResponse res
9386
ServerWebSocketContainer wsContainer = (ServerWebSocketContainer) getContainer(servletRequest);
9487
final EndpointSessionHandler endpointSessionHandler = new EndpointSessionHandler(wsContainer);
9588

96-
final Handshake handshake = getHandshakeToUse(exchange);
97-
9889
final ConfiguredServerEndpoint configuredServerEndpoint = createConfiguredServerEndpoint(
9990
selectedProtocol, selectedExtensions, endpoint, servletRequest);
10091

92+
final Handshake handshake = getHandshakeToUse(exchange, configuredServerEndpoint);
93+
10194
exchange.upgradeChannel(new HttpUpgradeListener() {
10295
@Override
10396
public void handleUpgrade(StreamConnection connection, HttpServerExchange serverExchange) {
10497
WebSocketChannel channel = handshake.createChannel(exchange, connection, exchange.getBufferPool());
105-
HandshakeUtil.setConfig(channel, configuredServerEndpoint);
10698
endpointSessionHandler.onConnect(exchange, channel);
10799
}
108100
});
109101

110102
handshake.handshake(exchange);
111103
}
112104

113-
private Handshake getHandshakeToUse(ServletWebSocketHttpExchange exchange) {
114-
for (Handshake handshake : this.handshakes) {
115-
if (handshake.matches(exchange)) {
116-
return handshake;
117-
}
105+
private Handshake getHandshakeToUse(ServletWebSocketHttpExchange exchange, ConfiguredServerEndpoint endpoint) {
106+
Handshake handshake = new JsrHybi13Handshake(endpoint);
107+
if (handshake.matches(exchange)) {
108+
return handshake;
109+
}
110+
handshake = new JsrHybi08Handshake(endpoint);
111+
if (handshake.matches(exchange)) {
112+
return handshake;
113+
}
114+
handshake = new JsrHybi07Handshake(endpoint);
115+
if (handshake.matches(exchange)) {
116+
return handshake;
118117
}
119118
// Should never occur
120119
throw new HandshakeFailureException("No matching Undertow Handshake found: " + exchange.getRequestHeaders());

0 commit comments

Comments
 (0)