mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
GUACAMOLE-504: Implement overloaded closeConnection() method.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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) {
|
||||
@@ -77,6 +83,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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user