Skip to content

Commit 8f56926

Browse files
committed
Fix issue in GlassfishRequestUpgradeStrategy
The observed behavior was that the client does not get a response from the WebSocket HTTP handshake. On the server the handshake actually succeeds, the response is set correctly to status 101, and the WebSocketHandler gets notified of the successfully established connection. This change flushes the ServletResponse just before returning from the GlassfishRequestUpgradeStrategy. This is actually what Glassfish's own TyrusServletFilter does as well at the end along with a comment that it is a possible bug.
1 parent 3ac14e7 commit 8f56926

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,21 +163,27 @@ private boolean performUpgrade(HttpServletRequest request, HttpServletResponse r
163163

164164
Connection connection = createConnection(upgradeHandler, response);
165165

166-
RequestContext wsRequest = RequestContext.Builder.create().
166+
RequestContext requestContext = RequestContext.Builder.create().
167167
requestURI(URI.create(wsApp.getPath())).requestPath(wsApp.getPath()).
168168
userPrincipal(request.getUserPrincipal()).
169169
connection(connection).secure(request.isSecure()).build();
170170

171171
for (String header : headers.keySet()) {
172-
wsRequest.getHeaders().put(header, headers.get(header));
172+
requestContext.getHeaders().put(header, headers.get(header));
173173
}
174174

175-
return WebSocketEngine.getEngine().upgrade(connection, wsRequest, new WebSocketEngine.WebSocketHolderListener() {
176-
@Override
177-
public void onWebSocketHolder(WebSocketEngine.WebSocketHolder webSocketHolder) {
178-
upgradeHandler.setWebSocketHolder(webSocketHolder);
179-
}
180-
});
175+
boolean upgraded = WebSocketEngine.getEngine().upgrade(connection, requestContext,
176+
new WebSocketEngine.WebSocketHolderListener() {
177+
@Override
178+
public void onWebSocketHolder(WebSocketEngine.WebSocketHolder webSocketHolder) {
179+
upgradeHandler.setWebSocketHolder(webSocketHolder);
180+
}
181+
});
182+
183+
// Glassfish bug ?? (see same line in TyrusServletFilter.doFilter)
184+
response.flushBuffer();
185+
186+
return upgraded;
181187
}
182188

183189
private WebSocketApplication createTyrusEndpoint(HttpServletRequest request,

0 commit comments

Comments
 (0)