mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 05:07:41 +00:00
GUACAMOLE-504: Implement overloaded closeConnection() method.
This commit is contained in:
@@ -66,12 +66,17 @@ public abstract class GuacamoleWebSocketTunnelEndpoint extends Endpoint {
|
|||||||
private GuacamoleTunnel tunnel;
|
private GuacamoleTunnel tunnel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends the given status on the given WebSocket connection and closes the
|
* Sends the numeric Guacaomle Status Code and Web Socket
|
||||||
* connection.
|
* code and closes the connection.
|
||||||
*
|
*
|
||||||
* @param session The outbound WebSocket connection to close.
|
* @param session
|
||||||
* @param guac_status The status to send.
|
* The outbound WebSocket connection to close.
|
||||||
* @param webSocketCode The numeric WebSocket status to send.
|
*
|
||||||
|
* @param guacamoleStatusCode
|
||||||
|
* The numeric Guacamole status to send.
|
||||||
|
*
|
||||||
|
* @param webSocketCode
|
||||||
|
* The numeric WebSocket status to send.
|
||||||
*/
|
*/
|
||||||
private void closeConnection(Session session, int guacamoleStatusCode,
|
private void closeConnection(Session session, int guacamoleStatusCode,
|
||||||
int webSocketCode) {
|
int webSocketCode) {
|
||||||
@@ -87,6 +92,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
|
* Returns a new tunnel for the given session. How this tunnel is created
|
||||||
* or retrieved is implementation-dependent.
|
* or retrieved is implementation-dependent.
|
||||||
@@ -111,8 +131,7 @@ public abstract class GuacamoleWebSocketTunnelEndpoint extends Endpoint {
|
|||||||
// Get tunnel
|
// Get tunnel
|
||||||
tunnel = createTunnel(session, config);
|
tunnel = createTunnel(session, config);
|
||||||
if (tunnel == null) {
|
if (tunnel == null) {
|
||||||
closeConnection(session, GuacamoleStatus.RESOURCE_NOT_FOUND.getGuacamoleStatusCode(),
|
closeConnection(session, GuacamoleStatus.RESOURCE_NOT_FOUND);
|
||||||
GuacamoleStatus.RESOURCE_NOT_FOUND.getWebSocketCode());
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,7 +139,8 @@ public abstract class GuacamoleWebSocketTunnelEndpoint extends Endpoint {
|
|||||||
catch (GuacamoleException e) {
|
catch (GuacamoleException e) {
|
||||||
logger.error("Creation of WebSocket tunnel to guacd failed: {}", e.getMessage());
|
logger.error("Creation of WebSocket tunnel to guacd failed: {}", e.getMessage());
|
||||||
logger.debug("Error connecting WebSocket tunnel.", e);
|
logger.debug("Error connecting WebSocket tunnel.", e);
|
||||||
closeConnection(session, e.getStatus().getGuacamoleStatusCode(), e.getWebSocketCode());
|
closeConnection(session, e.getStatus().getGuacamoleStatusCode(),
|
||||||
|
e.getWebSocketCode());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,8 +194,7 @@ public abstract class GuacamoleWebSocketTunnelEndpoint extends Endpoint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// No more data
|
// No more data
|
||||||
closeConnection(session, GuacamoleStatus.SUCCESS.getGuacamoleStatusCode(),
|
closeConnection(session, GuacamoleStatus.SUCCESS);
|
||||||
GuacamoleStatus.SUCCESS.getWebSocketCode());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,24 +204,24 @@ public abstract class GuacamoleWebSocketTunnelEndpoint extends Endpoint {
|
|||||||
catch (GuacamoleClientException e) {
|
catch (GuacamoleClientException e) {
|
||||||
logger.info("WebSocket connection terminated: {}", e.getMessage());
|
logger.info("WebSocket connection terminated: {}", e.getMessage());
|
||||||
logger.debug("WebSocket connection terminated due to client error.", e);
|
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) {
|
catch (GuacamoleConnectionClosedException e) {
|
||||||
logger.debug("Connection to guacd closed.", e);
|
logger.debug("Connection to guacd closed.", e);
|
||||||
closeConnection(session, GuacamoleStatus.SUCCESS.getGuacamoleStatusCode(),
|
closeConnection(session, GuacamoleStatus.SUCCESS);
|
||||||
GuacamoleStatus.SUCCESS.getWebSocketCode());
|
|
||||||
}
|
}
|
||||||
catch (GuacamoleException e) {
|
catch (GuacamoleException e) {
|
||||||
logger.error("Connection to guacd terminated abnormally: {}", e.getMessage());
|
logger.error("Connection to guacd terminated abnormally: {}", e.getMessage());
|
||||||
logger.debug("Internal error during connection to guacd.", e);
|
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) {
|
catch (IOException e) {
|
||||||
logger.debug("I/O error prevents further reads.", e);
|
logger.debug("I/O error prevents further reads.", e);
|
||||||
closeConnection(session, GuacamoleStatus.SERVER_ERROR.getGuacamoleStatusCode(),
|
closeConnection(session, GuacamoleStatus.SERVER_ERROR);
|
||||||
GuacamoleStatus.SERVER_ERROR.getWebSocketCode());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -53,12 +53,18 @@ public abstract class GuacamoleWebSocketTunnelServlet extends WebSocketServlet {
|
|||||||
private static final int BUFFER_SIZE = 8192;
|
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.
|
* connection.
|
||||||
*
|
*
|
||||||
* @param connection The WebSocket connection to close.
|
* @param connection
|
||||||
* @param guac_status The status to send.
|
* The WebSocket connection to close.
|
||||||
* @param webSocketCode The numeric WebSocket status code to send.
|
*
|
||||||
|
* @param guacamoleStatusCode
|
||||||
|
* The numeric Guacamole Status code to send.
|
||||||
|
*
|
||||||
|
* @param webSocketCode
|
||||||
|
* The numeric WebSocket status code to send.
|
||||||
*/
|
*/
|
||||||
private static void closeConnection(Connection connection,
|
private static void closeConnection(Connection connection,
|
||||||
int guacamoleStatusCode, int webSocketCode) {
|
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
|
@Override
|
||||||
public WebSocket doWebSocketConnect(HttpServletRequest request, String protocol) {
|
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
|
// Do not start connection if tunnel does not exist
|
||||||
if (tunnel == null) {
|
if (tunnel == null) {
|
||||||
closeConnection(connection,
|
closeConnection(connection, GuacamoleStatus.RESOURCE_NOT_FOUND);
|
||||||
GuacamoleStatus.RESOURCE_NOT_FOUND.getGuacamoleStatusCode(),
|
|
||||||
GuacamoleStatus.RESOURCE_NOT_FOUND.getWebSocketCode());
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,9 +184,7 @@ public abstract class GuacamoleWebSocketTunnelServlet extends WebSocketServlet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// No more data
|
// No more data
|
||||||
closeConnection(connection,
|
closeConnection(connection, GuacamoleStatus.SUCCESS);
|
||||||
GuacamoleStatus.SUCCESS.getGuacamoleStatusCode(),
|
|
||||||
GuacamoleStatus.SUCCESS.getWebSocketCode());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,9 +199,7 @@ public abstract class GuacamoleWebSocketTunnelServlet extends WebSocketServlet {
|
|||||||
}
|
}
|
||||||
catch (GuacamoleConnectionClosedException e) {
|
catch (GuacamoleConnectionClosedException e) {
|
||||||
logger.debug("Connection to guacd closed.", e);
|
logger.debug("Connection to guacd closed.", e);
|
||||||
closeConnection(connection,
|
closeConnection(connection, GuacamoleStatus.SUCCESS);
|
||||||
GuacamoleStatus.SUCCESS.getGuacamoleStatusCode(),
|
|
||||||
GuacamoleStatus.SUCCESS.getWebSocketCode());
|
|
||||||
}
|
}
|
||||||
catch (GuacamoleException e) {
|
catch (GuacamoleException e) {
|
||||||
logger.error("Connection to guacd terminated abnormally: {}", e.getMessage());
|
logger.error("Connection to guacd terminated abnormally: {}", e.getMessage());
|
||||||
@@ -193,9 +211,7 @@ public abstract class GuacamoleWebSocketTunnelServlet extends WebSocketServlet {
|
|||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
logger.debug("WebSocket tunnel read failed due to I/O error.", e);
|
logger.debug("WebSocket tunnel read failed due to I/O error.", e);
|
||||||
closeConnection(connection,
|
closeConnection(connection, GuacamoleStatus.SERVER_ERROR);
|
||||||
GuacamoleStatus.SERVER_ERROR.getGuacamoleStatusCode(),
|
|
||||||
GuacamoleStatus.SERVER_ERROR.getWebSocketCode());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -57,12 +57,18 @@ public abstract class GuacamoleWebSocketTunnelListener implements WebSocketListe
|
|||||||
private GuacamoleTunnel tunnel;
|
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.
|
* connection.
|
||||||
*
|
*
|
||||||
* @param session The outbound WebSocket connection to close.
|
* @param session
|
||||||
* @param guac_status The status to send.
|
* The outbound WebSocket connection to close.
|
||||||
* @param webSocketCode The numeric WebSocket status code to send.
|
*
|
||||||
|
* @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,
|
private void closeConnection(Session session, int guacamoleStatusCode,
|
||||||
int webSocketCode) {
|
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
|
* Returns a new tunnel for the given session. How this tunnel is created
|
||||||
* or retrieved is implementation-dependent.
|
* or retrieved is implementation-dependent.
|
||||||
@@ -98,8 +122,7 @@ public abstract class GuacamoleWebSocketTunnelListener implements WebSocketListe
|
|||||||
// Get tunnel
|
// Get tunnel
|
||||||
tunnel = createTunnel(session);
|
tunnel = createTunnel(session);
|
||||||
if (tunnel == null) {
|
if (tunnel == null) {
|
||||||
closeConnection(session, GuacamoleStatus.RESOURCE_NOT_FOUND.getGuacamoleStatusCode(),
|
closeConnection(session, GuacamoleStatus.RESOURCE_NOT_FOUND);
|
||||||
GuacamoleStatus.RESOURCE_NOT_FOUND.getWebSocketCode());
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,8 +174,7 @@ public abstract class GuacamoleWebSocketTunnelListener implements WebSocketListe
|
|||||||
}
|
}
|
||||||
|
|
||||||
// No more data
|
// No more data
|
||||||
closeConnection(session, GuacamoleStatus.SUCCESS.getGuacamoleStatusCode(),
|
closeConnection(session, GuacamoleStatus.SUCCESS);
|
||||||
GuacamoleStatus.SUCCESS.getWebSocketCode());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,8 +189,7 @@ public abstract class GuacamoleWebSocketTunnelListener implements WebSocketListe
|
|||||||
}
|
}
|
||||||
catch (GuacamoleConnectionClosedException e) {
|
catch (GuacamoleConnectionClosedException e) {
|
||||||
logger.debug("Connection to guacd closed.", e);
|
logger.debug("Connection to guacd closed.", e);
|
||||||
closeConnection(session, GuacamoleStatus.SUCCESS.getGuacamoleStatusCode(),
|
closeConnection(session, GuacamoleStatus.SUCCESS);
|
||||||
GuacamoleStatus.SUCCESS.getWebSocketCode());
|
|
||||||
}
|
}
|
||||||
catch (GuacamoleException e) {
|
catch (GuacamoleException e) {
|
||||||
logger.error("Connection to guacd terminated abnormally: {}", e.getMessage());
|
logger.error("Connection to guacd terminated abnormally: {}", e.getMessage());
|
||||||
@@ -180,8 +201,7 @@ public abstract class GuacamoleWebSocketTunnelListener implements WebSocketListe
|
|||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
logger.debug("I/O error prevents further reads.", e);
|
logger.debug("I/O error prevents further reads.", e);
|
||||||
closeConnection(session, GuacamoleStatus.SERVER_ERROR.getGuacamoleStatusCode(),
|
closeConnection(session, GuacamoleStatus.SERVER_ERROR);
|
||||||
GuacamoleStatus.SERVER_ERROR.getWebSocketCode());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -58,12 +58,18 @@ public abstract class GuacamoleWebSocketTunnelServlet extends WebSocketServlet {
|
|||||||
private final Logger logger = LoggerFactory.getLogger(GuacamoleWebSocketTunnelServlet.class);
|
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.
|
* connection.
|
||||||
*
|
*
|
||||||
* @param outbound The outbound WebSocket connection to close.
|
* @param outbound
|
||||||
* @param guac_status The status to send.
|
* The outbound WebSocket connection to close.
|
||||||
* @param webSocketCode The numeric WebSocket status code to send.
|
*
|
||||||
|
* @param guacamoleStatusCode
|
||||||
|
* The status to send.
|
||||||
|
*
|
||||||
|
* @param webSocketCode
|
||||||
|
* The numeric WebSocket status code to send.
|
||||||
*/
|
*/
|
||||||
private void closeConnection(WsOutbound outbound, int guacamoleStatusCode,
|
private void closeConnection(WsOutbound outbound, int guacamoleStatusCode,
|
||||||
int webSocketCode) {
|
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
|
@Override
|
||||||
protected String selectSubProtocol(List<String> subProtocols) {
|
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
|
// Do not start connection if tunnel does not exist
|
||||||
if (tunnel == null) {
|
if (tunnel == null) {
|
||||||
closeConnection(outbound, GuacamoleStatus.RESOURCE_NOT_FOUND.getGuacamoleStatusCode(),
|
closeConnection(outbound, GuacamoleStatus.RESOURCE_NOT_FOUND);
|
||||||
GuacamoleStatus.RESOURCE_NOT_FOUND.getWebSocketCode());
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,8 +213,7 @@ public abstract class GuacamoleWebSocketTunnelServlet extends WebSocketServlet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// No more data
|
// No more data
|
||||||
closeConnection(outbound, GuacamoleStatus.SUCCESS.getGuacamoleStatusCode(),
|
closeConnection(outbound, GuacamoleStatus.SUCCESS);
|
||||||
GuacamoleStatus.SUCCESS.getWebSocketCode());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,8 +228,7 @@ public abstract class GuacamoleWebSocketTunnelServlet extends WebSocketServlet {
|
|||||||
}
|
}
|
||||||
catch (GuacamoleConnectionClosedException e) {
|
catch (GuacamoleConnectionClosedException e) {
|
||||||
logger.debug("Connection to guacd closed.", e);
|
logger.debug("Connection to guacd closed.", e);
|
||||||
closeConnection(outbound, GuacamoleStatus.SUCCESS.getGuacamoleStatusCode(),
|
closeConnection(outbound, GuacamoleStatus.SUCCESS);
|
||||||
GuacamoleStatus.SUCCESS.getWebSocketCode());
|
|
||||||
}
|
}
|
||||||
catch (GuacamoleException e) {
|
catch (GuacamoleException e) {
|
||||||
logger.error("Connection to guacd terminated abnormally: {}", e.getMessage());
|
logger.error("Connection to guacd terminated abnormally: {}", e.getMessage());
|
||||||
@@ -219,8 +240,7 @@ public abstract class GuacamoleWebSocketTunnelServlet extends WebSocketServlet {
|
|||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
logger.debug("I/O error prevents further reads.", e);
|
logger.debug("I/O error prevents further reads.", e);
|
||||||
closeConnection(outbound, GuacamoleStatus.SERVER_ERROR.getGuacamoleStatusCode(),
|
closeConnection(outbound, GuacamoleStatus.SERVER_ERROR);
|
||||||
GuacamoleStatus.SERVER_ERROR.getWebSocketCode());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user