From 8f569264daf9abe977e4325393b767bfab731f5e Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Tue, 3 Dec 2013 14:38:55 -0500 Subject: [PATCH] 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. --- .../GlassFishRequestUpgradeStrategy.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/server/standard/GlassFishRequestUpgradeStrategy.java b/spring-websocket/src/main/java/org/springframework/web/socket/server/standard/GlassFishRequestUpgradeStrategy.java index 57ddd4366d..52da6cd1d4 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/server/standard/GlassFishRequestUpgradeStrategy.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/server/standard/GlassFishRequestUpgradeStrategy.java @@ -163,21 +163,27 @@ public class GlassFishRequestUpgradeStrategy extends AbstractStandardUpgradeStra Connection connection = createConnection(upgradeHandler, response); - RequestContext wsRequest = RequestContext.Builder.create(). + RequestContext requestContext = RequestContext.Builder.create(). requestURI(URI.create(wsApp.getPath())).requestPath(wsApp.getPath()). userPrincipal(request.getUserPrincipal()). connection(connection).secure(request.isSecure()).build(); for (String header : headers.keySet()) { - wsRequest.getHeaders().put(header, headers.get(header)); + requestContext.getHeaders().put(header, headers.get(header)); } - return WebSocketEngine.getEngine().upgrade(connection, wsRequest, new WebSocketEngine.WebSocketHolderListener() { - @Override - public void onWebSocketHolder(WebSocketEngine.WebSocketHolder webSocketHolder) { - upgradeHandler.setWebSocketHolder(webSocketHolder); - } - }); + boolean upgraded = WebSocketEngine.getEngine().upgrade(connection, requestContext, + new WebSocketEngine.WebSocketHolderListener() { + @Override + public void onWebSocketHolder(WebSocketEngine.WebSocketHolder webSocketHolder) { + upgradeHandler.setWebSocketHolder(webSocketHolder); + } + }); + + // Glassfish bug ?? (see same line in TyrusServletFilter.doFilter) + response.flushBuffer(); + + return upgraded; } private WebSocketApplication createTyrusEndpoint(HttpServletRequest request,