mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 21:27:40 +00:00
GUACAMOLE-504: Allow exceptions to pass WebSocket status to closeConnection.
This commit is contained in:
@@ -71,11 +71,15 @@ public abstract class GuacamoleWebSocketTunnelEndpoint extends Endpoint {
|
|||||||
*
|
*
|
||||||
* @param session The outbound WebSocket connection to close.
|
* @param session The outbound WebSocket connection to close.
|
||||||
* @param guac_status The status to send.
|
* @param guac_status The status to send.
|
||||||
|
* @param webSocketCode The numeric WebSocket status to send.
|
||||||
*/
|
*/
|
||||||
private void closeConnection(Session session, GuacamoleStatus guac_status) {
|
private void closeConnection(Session session, GuacamoleStatus guac_status,
|
||||||
|
Integer webSocketCode) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
CloseCode code = CloseReason.CloseCodes.getCloseCode(guac_status.getWebSocketCode());
|
if (webSocketCode == null)
|
||||||
|
webSocketCode = guac_status.getWebSocketCode();
|
||||||
|
CloseCode code = CloseReason.CloseCodes.getCloseCode(webSocketCode);
|
||||||
String message = Integer.toString(guac_status.getGuacamoleStatusCode());
|
String message = Integer.toString(guac_status.getGuacamoleStatusCode());
|
||||||
session.close(new CloseReason(code, message));
|
session.close(new CloseReason(code, message));
|
||||||
}
|
}
|
||||||
@@ -109,7 +113,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);
|
closeConnection(session, GuacamoleStatus.RESOURCE_NOT_FOUND, null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,7 +121,7 @@ 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());
|
closeConnection(session, e.getStatus(), e.getWebSocketCode());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,7 +175,7 @@ public abstract class GuacamoleWebSocketTunnelEndpoint extends Endpoint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// No more data
|
// No more data
|
||||||
closeConnection(session, GuacamoleStatus.SUCCESS);
|
closeConnection(session, GuacamoleStatus.SUCCESS, null);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,22 +185,22 @@ 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());
|
closeConnection(session, e.getStatus(), 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);
|
closeConnection(session, GuacamoleStatus.SUCCESS, null);
|
||||||
}
|
}
|
||||||
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());
|
closeConnection(session, e.getStatus(), 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);
|
closeConnection(session, GuacamoleStatus.SERVER_ERROR, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -58,11 +58,15 @@ public abstract class GuacamoleWebSocketTunnelServlet extends WebSocketServlet {
|
|||||||
*
|
*
|
||||||
* @param connection The WebSocket connection to close.
|
* @param connection The WebSocket connection to close.
|
||||||
* @param guac_status The status to send.
|
* @param guac_status The status to send.
|
||||||
|
* @param webSocketCode The numeric WebSocket status code to send.
|
||||||
*/
|
*/
|
||||||
public static void closeConnection(Connection connection,
|
private static void closeConnection(Connection connection,
|
||||||
GuacamoleStatus guac_status) {
|
GuacamoleStatus guac_status, Integer webSocketCode) {
|
||||||
|
|
||||||
connection.close(guac_status.getWebSocketCode(),
|
if (webSocketCode == null)
|
||||||
|
webSocketCode = guac_status.getWebSocketCode();
|
||||||
|
|
||||||
|
connection.close(webSocketCode,
|
||||||
Integer.toString(guac_status.getGuacamoleStatusCode()));
|
Integer.toString(guac_status.getGuacamoleStatusCode()));
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -114,13 +118,13 @@ public abstract class GuacamoleWebSocketTunnelServlet extends WebSocketServlet {
|
|||||||
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(connection, e.getStatus());
|
closeConnection(connection, e.getStatus(), e.getWebSocketCode());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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, GuacamoleStatus.RESOURCE_NOT_FOUND);
|
closeConnection(connection, GuacamoleStatus.RESOURCE_NOT_FOUND, null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,7 +162,7 @@ public abstract class GuacamoleWebSocketTunnelServlet extends WebSocketServlet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// No more data
|
// No more data
|
||||||
closeConnection(connection, GuacamoleStatus.SUCCESS);
|
closeConnection(connection, GuacamoleStatus.SUCCESS, null);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,22 +172,22 @@ public abstract class GuacamoleWebSocketTunnelServlet extends WebSocketServlet {
|
|||||||
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(connection, e.getStatus());
|
closeConnection(connection, e.getStatus(), e.getWebSocketCode());
|
||||||
}
|
}
|
||||||
catch (GuacamoleConnectionClosedException e) {
|
catch (GuacamoleConnectionClosedException e) {
|
||||||
logger.debug("Connection to guacd closed.", e);
|
logger.debug("Connection to guacd closed.", e);
|
||||||
closeConnection(connection, GuacamoleStatus.SUCCESS);
|
closeConnection(connection, GuacamoleStatus.SUCCESS, null);
|
||||||
}
|
}
|
||||||
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(connection, e.getStatus());
|
closeConnection(connection, e.getStatus(), e.getWebSocketCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
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, GuacamoleStatus.SERVER_ERROR);
|
closeConnection(connection, GuacamoleStatus.SERVER_ERROR, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -62,13 +62,16 @@ public abstract class GuacamoleWebSocketTunnelListener implements WebSocketListe
|
|||||||
*
|
*
|
||||||
* @param session The outbound WebSocket connection to close.
|
* @param session The outbound WebSocket connection to close.
|
||||||
* @param guac_status The status to send.
|
* @param guac_status The status to send.
|
||||||
|
* @param webSocketCode The numeric WebSocket status code to send.
|
||||||
*/
|
*/
|
||||||
private void closeConnection(Session session, GuacamoleStatus guac_status) {
|
private void closeConnection(Session session, GuacamoleStatus guac_status,
|
||||||
|
Integer webSocketCode) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
int code = guac_status.getWebSocketCode();
|
if (webSocketCode == null)
|
||||||
|
webSocketCode = guac_status.getWebSocketCode();
|
||||||
String message = Integer.toString(guac_status.getGuacamoleStatusCode());
|
String message = Integer.toString(guac_status.getGuacamoleStatusCode());
|
||||||
session.close(new CloseStatus(code, message));
|
session.close(new CloseStatus(webSocketCode, message));
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
logger.debug("Unable to close WebSocket connection.", e);
|
logger.debug("Unable to close WebSocket connection.", e);
|
||||||
@@ -97,7 +100,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);
|
closeConnection(session, GuacamoleStatus.RESOURCE_NOT_FOUND, null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,7 +108,7 @@ public abstract class GuacamoleWebSocketTunnelListener implements WebSocketListe
|
|||||||
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());
|
closeConnection(session, e.getStatus(), e.getWebSocketCode());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,7 +152,7 @@ public abstract class GuacamoleWebSocketTunnelListener implements WebSocketListe
|
|||||||
}
|
}
|
||||||
|
|
||||||
// No more data
|
// No more data
|
||||||
closeConnection(session, GuacamoleStatus.SUCCESS);
|
closeConnection(session, GuacamoleStatus.SUCCESS, null);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,22 +162,22 @@ public abstract class GuacamoleWebSocketTunnelListener implements WebSocketListe
|
|||||||
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());
|
closeConnection(session, e.getStatus(), 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);
|
closeConnection(session, GuacamoleStatus.SUCCESS, null);
|
||||||
}
|
}
|
||||||
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());
|
closeConnection(session, e.getStatus(), 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);
|
closeConnection(session, GuacamoleStatus.SERVER_ERROR, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -63,12 +63,16 @@ public abstract class GuacamoleWebSocketTunnelServlet extends WebSocketServlet {
|
|||||||
*
|
*
|
||||||
* @param outbound The outbound WebSocket connection to close.
|
* @param outbound The outbound WebSocket connection to close.
|
||||||
* @param guac_status The status to send.
|
* @param guac_status The status to send.
|
||||||
|
* @param webSocketCode The numeric WebSocket status code to send.
|
||||||
*/
|
*/
|
||||||
public void closeConnection(WsOutbound outbound, GuacamoleStatus guac_status) {
|
private void closeConnection(WsOutbound outbound, GuacamoleStatus guac_status,
|
||||||
|
Integer webSocketCode) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if(webSocketCode == null)
|
||||||
|
webSocketCode = guac_status.getWebSocketCode();
|
||||||
byte[] message = Integer.toString(guac_status.getGuacamoleStatusCode()).getBytes("UTF-8");
|
byte[] message = Integer.toString(guac_status.getGuacamoleStatusCode()).getBytes("UTF-8");
|
||||||
outbound.close(guac_status.getWebSocketCode(), ByteBuffer.wrap(message));
|
outbound.close(webSocketCode, ByteBuffer.wrap(message));
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
logger.debug("Unable to close WebSocket tunnel.", e);
|
logger.debug("Unable to close WebSocket tunnel.", e);
|
||||||
@@ -142,13 +146,13 @@ public abstract class GuacamoleWebSocketTunnelServlet extends WebSocketServlet {
|
|||||||
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(outbound, e.getStatus());
|
closeConnection(outbound, e.getStatus(), e.getWebSocketCode());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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);
|
closeConnection(outbound, GuacamoleStatus.RESOURCE_NOT_FOUND, null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,7 +190,7 @@ public abstract class GuacamoleWebSocketTunnelServlet extends WebSocketServlet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// No more data
|
// No more data
|
||||||
closeConnection(outbound, GuacamoleStatus.SUCCESS);
|
closeConnection(outbound, GuacamoleStatus.SUCCESS, null);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,22 +200,22 @@ public abstract class GuacamoleWebSocketTunnelServlet extends WebSocketServlet {
|
|||||||
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(outbound, e.getStatus());
|
closeConnection(outbound, e.getStatus(), e.getWebSocketCode());
|
||||||
}
|
}
|
||||||
catch (GuacamoleConnectionClosedException e) {
|
catch (GuacamoleConnectionClosedException e) {
|
||||||
logger.debug("Connection to guacd closed.", e);
|
logger.debug("Connection to guacd closed.", e);
|
||||||
closeConnection(outbound, GuacamoleStatus.SUCCESS);
|
closeConnection(outbound, GuacamoleStatus.SUCCESS, null);
|
||||||
}
|
}
|
||||||
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(outbound, e.getStatus());
|
closeConnection(outbound, e.getStatus(), 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(outbound, GuacamoleStatus.SERVER_ERROR);
|
closeConnection(outbound, GuacamoleStatus.SERVER_ERROR, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user