From 1289c168699d9b6d7e96860c382110076962265e Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 21 Mar 2014 11:06:31 -0700 Subject: [PATCH] GUAC-558: Send status along WebSocket when end-of-stream is received. --- .../jetty/GuacamoleWebSocketTunnelServlet.java | 13 ++++++------- .../tomcat/GuacamoleWebSocketTunnelServlet.java | 14 ++++++-------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/websocket/jetty/GuacamoleWebSocketTunnelServlet.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/websocket/jetty/GuacamoleWebSocketTunnelServlet.java index 612e21f4a..c72edcd2c 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/websocket/jetty/GuacamoleWebSocketTunnelServlet.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/websocket/jetty/GuacamoleWebSocketTunnelServlet.java @@ -54,14 +54,13 @@ public abstract class GuacamoleWebSocketTunnelServlet extends WebSocketServlet { private static final int BUFFER_SIZE = 8192; /** - * Sends an error on the given WebSocket connection and closes the - * connection. The error sent is determined from using the information - * within the given GuacamoleStatus. + * Sends the given status on the given WebSocket connection and closes the + * connection. * * @param connection The WebSocket connection to close. * @param guac_status The status to send. */ - public static void sendError(Connection connection, + public static void closeConnection(Connection connection, GuacamoleStatus guac_status) { connection.close(guac_status.getWebSocketCode(), @@ -132,7 +131,7 @@ public abstract class GuacamoleWebSocketTunnelServlet extends WebSocketServlet { } // No more data - connection.close(1001, null); // Shutdown + closeConnection(connection, GuacamoleStatus.SUCCESS); } @@ -141,11 +140,11 @@ public abstract class GuacamoleWebSocketTunnelServlet extends WebSocketServlet { // each error appropriately. catch (GuacamoleClientException e) { logger.warn("Client request rejected: {}", e.getMessage()); - sendError(connection, e.getStatus()); + closeConnection(connection, e.getStatus()); } catch (GuacamoleException e) { logger.error("Internal server error.", e); - sendError(connection, e.getStatus()); + closeConnection(connection, e.getStatus()); } } diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/websocket/tomcat/GuacamoleWebSocketTunnelServlet.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/websocket/tomcat/GuacamoleWebSocketTunnelServlet.java index 237fd9a47..1cf8d90c6 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/websocket/tomcat/GuacamoleWebSocketTunnelServlet.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/websocket/tomcat/GuacamoleWebSocketTunnelServlet.java @@ -28,7 +28,6 @@ import java.io.Reader; import java.nio.ByteBuffer; import java.nio.CharBuffer; import javax.servlet.http.HttpServletRequest; -import org.apache.catalina.websocket.Constants; import org.glyptodon.guacamole.GuacamoleException; import org.glyptodon.guacamole.io.GuacamoleReader; import org.glyptodon.guacamole.io.GuacamoleWriter; @@ -59,16 +58,15 @@ public abstract class GuacamoleWebSocketTunnelServlet extends WebSocketServlet { private final Logger logger = LoggerFactory.getLogger(GuacamoleWebSocketTunnelServlet.class); /** - * Sends an error on the given WebSocket connection and closes the - * connection. The error sent is determined from using the information - * within the given GuacamoleStatus. + * Sends the given status on the given WebSocket connection and closes the + * connection. * * @param outbound The outbound WebSocket connection to close. * @param guac_status The status to send. * @throws IOException If an error prevents proper closure of the WebSocket * connection. */ - public static void sendError(WsOutbound outbound, + public static void closeConnection(WsOutbound outbound, GuacamoleStatus guac_status) throws IOException { byte[] message = Integer.toString(guac_status.getGuacamoleStatusCode()).getBytes("UTF-8"); @@ -146,7 +144,7 @@ public abstract class GuacamoleWebSocketTunnelServlet extends WebSocketServlet { } // No more data - outbound.close(Constants.STATUS_SHUTDOWN, null); + closeConnection(outbound, GuacamoleStatus.SUCCESS); } @@ -155,11 +153,11 @@ public abstract class GuacamoleWebSocketTunnelServlet extends WebSocketServlet { // each error appropriately. catch (GuacamoleClientException e) { logger.warn("Client request rejected: {}", e.getMessage()); - sendError(outbound, e.getStatus()); + closeConnection(outbound, e.getStatus()); } catch (GuacamoleException e) { logger.error("Internal server error.", e); - sendError(outbound, e.getStatus()); + closeConnection(outbound, e.getStatus()); } }