GUACAMOLE-504: Implement overloaded closeConnection() method.
diff --git a/guacamole-common/src/main/java/org/apache/guacamole/websocket/GuacamoleWebSocketTunnelEndpoint.java b/guacamole-common/src/main/java/org/apache/guacamole/websocket/GuacamoleWebSocketTunnelEndpoint.java
index 492ca4c..c16f506 100644
--- a/guacamole-common/src/main/java/org/apache/guacamole/websocket/GuacamoleWebSocketTunnelEndpoint.java
+++ b/guacamole-common/src/main/java/org/apache/guacamole/websocket/GuacamoleWebSocketTunnelEndpoint.java
@@ -66,12 +66,17 @@
private GuacamoleTunnel tunnel;
/**
- * Sends the given status on the given WebSocket connection and closes the
- * connection.
+ * Sends the numeric Guacaomle Status Code and Web Socket
+ * code and closes the connection.
*
- * @param session The outbound WebSocket connection to close.
- * @param guac_status The status to send.
- * @param webSocketCode The numeric WebSocket status to send.
+ * @param session
+ * The outbound WebSocket connection to close.
+ *
+ * @param guacamoleStatusCode
+ * The numeric Guacamole status to send.
+ *
+ * @param webSocketCode
+ * The numeric WebSocket status to send.
*/
private void closeConnection(Session session, int guacamoleStatusCode,
int webSocketCode) {
@@ -88,6 +93,21 @@
}
/**
+ * Sends the given Guacaomle Status and closes the given
+ * connection.
+ *
+ * @param session
+ * The outbound WebSocket connection to close.
+ *
+ * @param guac_status
+ * The status to use for the connection.
+ */
+ private void closeConnection(Session session, GuacamoleStatus guac_status) {
+ closeConnection(session, guac_status.getGuacamoleStatusCode(),
+ guac_status.getWebSocketCode());
+ }
+
+ /**
* Returns a new tunnel for the given session. How this tunnel is created
* or retrieved is implementation-dependent.
*
@@ -111,8 +131,7 @@
// Get tunnel
tunnel = createTunnel(session, config);
if (tunnel == null) {
- closeConnection(session, GuacamoleStatus.RESOURCE_NOT_FOUND.getGuacamoleStatusCode(),
- GuacamoleStatus.RESOURCE_NOT_FOUND.getWebSocketCode());
+ closeConnection(session, GuacamoleStatus.RESOURCE_NOT_FOUND);
return;
}
@@ -120,7 +139,8 @@
catch (GuacamoleException e) {
logger.error("Creation of WebSocket tunnel to guacd failed: {}", e.getMessage());
logger.debug("Error connecting WebSocket tunnel.", e);
- closeConnection(session, e.getStatus().getGuacamoleStatusCode(), e.getWebSocketCode());
+ closeConnection(session, e.getStatus().getGuacamoleStatusCode(),
+ e.getWebSocketCode());
return;
}
@@ -174,8 +194,7 @@
}
// No more data
- closeConnection(session, GuacamoleStatus.SUCCESS.getGuacamoleStatusCode(),
- GuacamoleStatus.SUCCESS.getWebSocketCode());
+ closeConnection(session, GuacamoleStatus.SUCCESS);
}
@@ -185,24 +204,24 @@
catch (GuacamoleClientException e) {
logger.info("WebSocket connection terminated: {}", e.getMessage());
logger.debug("WebSocket connection terminated due to client error.", e);
- closeConnection(session, e.getStatus().getGuacamoleStatusCode(), e.getWebSocketCode());
+ closeConnection(session, e.getStatus().getGuacamoleStatusCode(),
+ e.getWebSocketCode());
}
catch (GuacamoleConnectionClosedException e) {
logger.debug("Connection to guacd closed.", e);
- closeConnection(session, GuacamoleStatus.SUCCESS.getGuacamoleStatusCode(),
- GuacamoleStatus.SUCCESS.getWebSocketCode());
+ closeConnection(session, GuacamoleStatus.SUCCESS);
}
catch (GuacamoleException e) {
logger.error("Connection to guacd terminated abnormally: {}", e.getMessage());
logger.debug("Internal error during connection to guacd.", e);
- closeConnection(session, e.getStatus().getGuacamoleStatusCode(), e.getWebSocketCode());
+ closeConnection(session, e.getStatus().getGuacamoleStatusCode(),
+ e.getWebSocketCode());
}
}
catch (IOException e) {
logger.debug("I/O error prevents further reads.", e);
- closeConnection(session, GuacamoleStatus.SERVER_ERROR.getGuacamoleStatusCode(),
- GuacamoleStatus.SERVER_ERROR.getWebSocketCode());
+ closeConnection(session, GuacamoleStatus.SERVER_ERROR);
}
}
diff --git a/guacamole/src/main/java/org/apache/guacamole/tunnel/websocket/jetty8/GuacamoleWebSocketTunnelServlet.java b/guacamole/src/main/java/org/apache/guacamole/tunnel/websocket/jetty8/GuacamoleWebSocketTunnelServlet.java
index 6a7b76f..f1d3b63 100644
--- a/guacamole/src/main/java/org/apache/guacamole/tunnel/websocket/jetty8/GuacamoleWebSocketTunnelServlet.java
+++ b/guacamole/src/main/java/org/apache/guacamole/tunnel/websocket/jetty8/GuacamoleWebSocketTunnelServlet.java
@@ -53,12 +53,18 @@
private static final int BUFFER_SIZE = 8192;
/**
- * Sends the given status on the given WebSocket connection and closes the
+ * Sends the given numeric Guacamole and WebSocket status
+ * on the given WebSocket connection and closes the
* connection.
*
- * @param connection The WebSocket connection to close.
- * @param guac_status The status to send.
- * @param webSocketCode The numeric WebSocket status code to send.
+ * @param connection
+ * The WebSocket connection to close.
+ *
+ * @param guacamoleStatusCode
+ * The numeric Guacamole Status code to send.
+ *
+ * @param webSocketCode
+ * The numeric WebSocket status code to send.
*/
private static void closeConnection(Connection connection,
int guacamoleStatusCode, int webSocketCode) {
@@ -68,6 +74,24 @@
}
+ /**
+ * 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.
+ */
+ private static void closeConnection(Connection connection,
+ GuacamoleStatus guac_status) {
+
+ closeConnection(connection, guac_status.getGuacamoleStatusCode(),
+ guac_status.getWebSocketCode());
+
+ }
+
@Override
public WebSocket doWebSocketConnect(HttpServletRequest request, String protocol) {
@@ -122,9 +146,7 @@
// Do not start connection if tunnel does not exist
if (tunnel == null) {
- closeConnection(connection,
- GuacamoleStatus.RESOURCE_NOT_FOUND.getGuacamoleStatusCode(),
- GuacamoleStatus.RESOURCE_NOT_FOUND.getWebSocketCode());
+ closeConnection(connection, GuacamoleStatus.RESOURCE_NOT_FOUND);
return;
}
@@ -162,9 +184,7 @@
}
// No more data
- closeConnection(connection,
- GuacamoleStatus.SUCCESS.getGuacamoleStatusCode(),
- GuacamoleStatus.SUCCESS.getWebSocketCode());
+ closeConnection(connection, GuacamoleStatus.SUCCESS);
}
@@ -179,9 +199,7 @@
}
catch (GuacamoleConnectionClosedException e) {
logger.debug("Connection to guacd closed.", e);
- closeConnection(connection,
- GuacamoleStatus.SUCCESS.getGuacamoleStatusCode(),
- GuacamoleStatus.SUCCESS.getWebSocketCode());
+ closeConnection(connection, GuacamoleStatus.SUCCESS);
}
catch (GuacamoleException e) {
logger.error("Connection to guacd terminated abnormally: {}", e.getMessage());
@@ -193,9 +211,7 @@
}
catch (IOException e) {
logger.debug("WebSocket tunnel read failed due to I/O error.", e);
- closeConnection(connection,
- GuacamoleStatus.SERVER_ERROR.getGuacamoleStatusCode(),
- GuacamoleStatus.SERVER_ERROR.getWebSocketCode());
+ closeConnection(connection, GuacamoleStatus.SERVER_ERROR);
}
}
diff --git a/guacamole/src/main/java/org/apache/guacamole/tunnel/websocket/jetty9/GuacamoleWebSocketTunnelListener.java b/guacamole/src/main/java/org/apache/guacamole/tunnel/websocket/jetty9/GuacamoleWebSocketTunnelListener.java
index 93dc43f..9afaae7 100644
--- a/guacamole/src/main/java/org/apache/guacamole/tunnel/websocket/jetty9/GuacamoleWebSocketTunnelListener.java
+++ b/guacamole/src/main/java/org/apache/guacamole/tunnel/websocket/jetty9/GuacamoleWebSocketTunnelListener.java
@@ -57,12 +57,18 @@
private GuacamoleTunnel tunnel;
/**
- * Sends the given status on the given WebSocket connection and closes the
+ * Sends the given numeric Guacamole and WebSocket status
+ * codes on the given WebSocket connection and closes the
* connection.
*
- * @param session The outbound WebSocket connection to close.
- * @param guac_status The status to send.
- * @param webSocketCode The numeric WebSocket status code to send.
+ * @param session
+ * The outbound WebSocket connection to close.
+ *
+ * @param guacamoleStatusCode
+ * The numeric Guacamole status code to send.
+ *
+ * @param webSocketCode
+ * The numeric WebSocket status code to send.
*/
private void closeConnection(Session session, int guacamoleStatusCode,
int webSocketCode) {
@@ -78,6 +84,24 @@
}
/**
+ * Sends the given status on the given WebSocket connection
+ * and closes the connection.
+ *
+ * @param session
+ * The outbound WebSocket connection to close.
+ *
+ * @param guac_status
+ * The status to send.
+ */
+ private void closeConnection(Session session,
+ GuacamoleStatus guac_status) {
+
+ closeConnection(session, guac_status.getGuacamoleStatusCode(),
+ guac_status.getWebSocketCode());
+
+ }
+
+ /**
* Returns a new tunnel for the given session. How this tunnel is created
* or retrieved is implementation-dependent.
*
@@ -98,8 +122,7 @@
// Get tunnel
tunnel = createTunnel(session);
if (tunnel == null) {
- closeConnection(session, GuacamoleStatus.RESOURCE_NOT_FOUND.getGuacamoleStatusCode(),
- GuacamoleStatus.RESOURCE_NOT_FOUND.getWebSocketCode());
+ closeConnection(session, GuacamoleStatus.RESOURCE_NOT_FOUND);
return;
}
@@ -151,8 +174,7 @@
}
// No more data
- closeConnection(session, GuacamoleStatus.SUCCESS.getGuacamoleStatusCode(),
- GuacamoleStatus.SUCCESS.getWebSocketCode());
+ closeConnection(session, GuacamoleStatus.SUCCESS);
}
@@ -167,8 +189,7 @@
}
catch (GuacamoleConnectionClosedException e) {
logger.debug("Connection to guacd closed.", e);
- closeConnection(session, GuacamoleStatus.SUCCESS.getGuacamoleStatusCode(),
- GuacamoleStatus.SUCCESS.getWebSocketCode());
+ closeConnection(session, GuacamoleStatus.SUCCESS);
}
catch (GuacamoleException e) {
logger.error("Connection to guacd terminated abnormally: {}", e.getMessage());
@@ -180,8 +201,7 @@
}
catch (IOException e) {
logger.debug("I/O error prevents further reads.", e);
- closeConnection(session, GuacamoleStatus.SERVER_ERROR.getGuacamoleStatusCode(),
- GuacamoleStatus.SERVER_ERROR.getWebSocketCode());
+ closeConnection(session, GuacamoleStatus.SERVER_ERROR);
}
}
diff --git a/guacamole/src/main/java/org/apache/guacamole/tunnel/websocket/tomcat/GuacamoleWebSocketTunnelServlet.java b/guacamole/src/main/java/org/apache/guacamole/tunnel/websocket/tomcat/GuacamoleWebSocketTunnelServlet.java
index 4384825..5c4dfac 100644
--- a/guacamole/src/main/java/org/apache/guacamole/tunnel/websocket/tomcat/GuacamoleWebSocketTunnelServlet.java
+++ b/guacamole/src/main/java/org/apache/guacamole/tunnel/websocket/tomcat/GuacamoleWebSocketTunnelServlet.java
@@ -58,12 +58,18 @@
private final Logger logger = LoggerFactory.getLogger(GuacamoleWebSocketTunnelServlet.class);
/**
- * Sends the given status on the given WebSocket connection and closes the
+ * Sends the given Guacamole and WebSocket numeric 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.
- * @param webSocketCode The numeric WebSocket status code to send.
+ * @param outbound
+ * The outbound WebSocket connection to close.
+ *
+ * @param guacamoleStatusCode
+ * The status to send.
+ *
+ * @param webSocketCode
+ * The numeric WebSocket status code to send.
*/
private void closeConnection(WsOutbound outbound, int guacamoleStatusCode,
int webSocketCode) {
@@ -78,6 +84,24 @@
}
+ /**
+ * 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.
+ */
+ private void closeConnection(WsOutbound outbound,
+ GuacamoleStatus guac_status) {
+
+ closeConnection(outbound, guac_status.getGuacamoleStatusCode(),
+ guac_status.getWebSocketCode());
+
+ }
+
@Override
protected String selectSubProtocol(List<String> subProtocols) {
@@ -151,8 +175,7 @@
// Do not start connection if tunnel does not exist
if (tunnel == null) {
- closeConnection(outbound, GuacamoleStatus.RESOURCE_NOT_FOUND.getGuacamoleStatusCode(),
- GuacamoleStatus.RESOURCE_NOT_FOUND.getWebSocketCode());
+ closeConnection(outbound, GuacamoleStatus.RESOURCE_NOT_FOUND);
return;
}
@@ -190,8 +213,7 @@
}
// No more data
- closeConnection(outbound, GuacamoleStatus.SUCCESS.getGuacamoleStatusCode(),
- GuacamoleStatus.SUCCESS.getWebSocketCode());
+ closeConnection(outbound, GuacamoleStatus.SUCCESS);
}
@@ -206,8 +228,7 @@
}
catch (GuacamoleConnectionClosedException e) {
logger.debug("Connection to guacd closed.", e);
- closeConnection(outbound, GuacamoleStatus.SUCCESS.getGuacamoleStatusCode(),
- GuacamoleStatus.SUCCESS.getWebSocketCode());
+ closeConnection(outbound, GuacamoleStatus.SUCCESS);
}
catch (GuacamoleException e) {
logger.error("Connection to guacd terminated abnormally: {}", e.getMessage());
@@ -219,8 +240,7 @@
}
catch (IOException e) {
logger.debug("I/O error prevents further reads.", e);
- closeConnection(outbound, GuacamoleStatus.SERVER_ERROR.getGuacamoleStatusCode(),
- GuacamoleStatus.SERVER_ERROR.getWebSocketCode());
+ closeConnection(outbound, GuacamoleStatus.SERVER_ERROR);
}
}