GUACAMOLE-504: Implement overloaded closeConnection() method.

Project: http://git-wip-us.apache.org/repos/asf/guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/guacamole-client/commit/4e0e852a
Tree: http://git-wip-us.apache.org/repos/asf/guacamole-client/tree/4e0e852a
Diff: http://git-wip-us.apache.org/repos/asf/guacamole-client/diff/4e0e852a

Branch: refs/heads/master
Commit: 4e0e852ad3eba6fc7ae5ffef8d2cfb329521f0f7
Parents: bb1670a
Author: Nick Couchman <vn...@apache.org>
Authored: Sat Feb 10 19:50:08 2018 -0500
Committer: Nick Couchman <vn...@apache.org>
Committed: Sun Feb 11 14:54:55 2018 -0500

----------------------------------------------------------------------
 .../GuacamoleWebSocketTunnelEndpoint.java       | 51 ++++++++++++++------
 .../jetty8/GuacamoleWebSocketTunnelServlet.java | 48 ++++++++++++------
 .../GuacamoleWebSocketTunnelListener.java       | 44 ++++++++++++-----
 .../tomcat/GuacamoleWebSocketTunnelServlet.java | 44 ++++++++++++-----
 4 files changed, 131 insertions(+), 56 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/4e0e852a/guacamole-common/src/main/java/org/apache/guacamole/websocket/GuacamoleWebSocketTunnelEndpoint.java
----------------------------------------------------------------------
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 @@ public abstract class GuacamoleWebSocketTunnelEndpoint 
extends Endpoint {
     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 guacamoleStatusCode
+     *     The numeric Guacamole status to send.
      *
-     * @param session The outbound WebSocket connection to close.
-     * @param guac_status The status to send.
-     * @param webSocketCode The numeric WebSocket status to send.
+     * @param webSocketCode
+     *     The numeric WebSocket status to send.
      */
     private void closeConnection(Session session, int guacamoleStatusCode,
             int webSocketCode) {
@@ -88,6 +93,21 @@ public abstract class GuacamoleWebSocketTunnelEndpoint 
extends Endpoint {
     }
 
     /**
+     * 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 @@ public abstract class GuacamoleWebSocketTunnelEndpoint 
extends Endpoint {
             // 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 @@ public abstract class GuacamoleWebSocketTunnelEndpoint 
extends Endpoint {
         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 @@ public abstract class GuacamoleWebSocketTunnelEndpoint 
extends Endpoint {
                         }
 
                         // No more data
-                        closeConnection(session, 
GuacamoleStatus.SUCCESS.getGuacamoleStatusCode(),
-                                GuacamoleStatus.SUCCESS.getWebSocketCode());
+                        closeConnection(session, GuacamoleStatus.SUCCESS);
 
                     }
 
@@ -185,24 +204,24 @@ public abstract class GuacamoleWebSocketTunnelEndpoint 
extends Endpoint {
                     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);
                 }
 
             }

http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/4e0e852a/guacamole/src/main/java/org/apache/guacamole/tunnel/websocket/jetty8/GuacamoleWebSocketTunnelServlet.java
----------------------------------------------------------------------
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 @@ public abstract class GuacamoleWebSocketTunnelServlet 
extends WebSocketServlet {
     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 @@ public abstract class GuacamoleWebSocketTunnelServlet 
extends WebSocketServlet {
 
     }
 
+    /**
+     * 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 @@ public abstract class GuacamoleWebSocketTunnelServlet 
extends WebSocketServlet {
 
                 // 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 @@ public abstract class GuacamoleWebSocketTunnelServlet 
extends WebSocketServlet {
                                 }
 
                                 // No more data
-                                closeConnection(connection,
-                                        
GuacamoleStatus.SUCCESS.getGuacamoleStatusCode(),
-                                        
GuacamoleStatus.SUCCESS.getWebSocketCode());
+                                closeConnection(connection, 
GuacamoleStatus.SUCCESS);
                                 
                             }
 
@@ -179,9 +199,7 @@ public abstract class GuacamoleWebSocketTunnelServlet 
extends WebSocketServlet {
                             }
                             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 @@ public abstract class GuacamoleWebSocketTunnelServlet 
extends WebSocketServlet {
                         }
                         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);
                         }
 
                     }

http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/4e0e852a/guacamole/src/main/java/org/apache/guacamole/tunnel/websocket/jetty9/GuacamoleWebSocketTunnelListener.java
----------------------------------------------------------------------
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 @@ public abstract class GuacamoleWebSocketTunnelListener 
implements WebSocketListe
     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 @@ public abstract class GuacamoleWebSocketTunnelListener 
implements WebSocketListe
     }
 
     /**
+     * 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 @@ public abstract class GuacamoleWebSocketTunnelListener 
implements WebSocketListe
             // 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 @@ public abstract class GuacamoleWebSocketTunnelListener 
implements WebSocketListe
                         }
 
                         // No more data
-                        closeConnection(session, 
GuacamoleStatus.SUCCESS.getGuacamoleStatusCode(),
-                                GuacamoleStatus.SUCCESS.getWebSocketCode());
+                        closeConnection(session, GuacamoleStatus.SUCCESS);
 
                     }
 
@@ -167,8 +189,7 @@ public abstract class GuacamoleWebSocketTunnelListener 
implements WebSocketListe
                     }
                     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 @@ public abstract class GuacamoleWebSocketTunnelListener 
implements WebSocketListe
                 }
                 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);
                 }
 
             }

http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/4e0e852a/guacamole/src/main/java/org/apache/guacamole/tunnel/websocket/tomcat/GuacamoleWebSocketTunnelServlet.java
----------------------------------------------------------------------
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 @@ public abstract class GuacamoleWebSocketTunnelServlet 
extends WebSocketServlet {
     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 @@ public abstract class GuacamoleWebSocketTunnelServlet 
extends WebSocketServlet {
 
     }
 
+    /**
+     * 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 @@ public abstract class GuacamoleWebSocketTunnelServlet 
extends WebSocketServlet {
 
                 // 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 @@ public abstract class GuacamoleWebSocketTunnelServlet 
extends WebSocketServlet {
                                 }
 
                                 // No more data
-                                closeConnection(outbound, 
GuacamoleStatus.SUCCESS.getGuacamoleStatusCode(),
-                                        
GuacamoleStatus.SUCCESS.getWebSocketCode());
+                                closeConnection(outbound, 
GuacamoleStatus.SUCCESS);
 
                             }
 
@@ -206,8 +228,7 @@ public abstract class GuacamoleWebSocketTunnelServlet 
extends WebSocketServlet {
                             }
                             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 @@ public abstract class GuacamoleWebSocketTunnelServlet 
extends WebSocketServlet {
                         }
                         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);
                         }
 
                     }

Reply via email to