mirror of
				https://github.com/gyurix1968/guacamole-client.git
				synced 2025-10-31 00:53:21 +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 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 { | ||||
|             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()); | ||||
|             session.close(new CloseReason(code, message)); | ||||
|         } | ||||
| @@ -109,7 +113,7 @@ public abstract class GuacamoleWebSocketTunnelEndpoint extends Endpoint { | ||||
|             // Get tunnel | ||||
|             tunnel = createTunnel(session, config); | ||||
|             if (tunnel == null) { | ||||
|                 closeConnection(session, GuacamoleStatus.RESOURCE_NOT_FOUND); | ||||
|                 closeConnection(session, GuacamoleStatus.RESOURCE_NOT_FOUND, null); | ||||
|                 return; | ||||
|             } | ||||
|  | ||||
| @@ -117,7 +121,7 @@ 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()); | ||||
|             closeConnection(session, e.getStatus(), e.getWebSocketCode()); | ||||
|             return; | ||||
|         } | ||||
|  | ||||
| @@ -171,7 +175,7 @@ public abstract class GuacamoleWebSocketTunnelEndpoint extends Endpoint { | ||||
|                         } | ||||
|  | ||||
|                         // 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) { | ||||
|                         logger.info("WebSocket connection terminated: {}", e.getMessage()); | ||||
|                         logger.debug("WebSocket connection terminated due to client error.", e); | ||||
|                         closeConnection(session, e.getStatus()); | ||||
|                         closeConnection(session, e.getStatus(), e.getWebSocketCode()); | ||||
|                     } | ||||
|                     catch (GuacamoleConnectionClosedException e) { | ||||
|                         logger.debug("Connection to guacd closed.", e); | ||||
|                         closeConnection(session, GuacamoleStatus.SUCCESS); | ||||
|                         closeConnection(session, GuacamoleStatus.SUCCESS, null); | ||||
|                     } | ||||
|                     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()); | ||||
|                         closeConnection(session, e.getStatus(), e.getWebSocketCode()); | ||||
|                     } | ||||
|  | ||||
|                 } | ||||
|                 catch (IOException e) { | ||||
|                     logger.debug("I/O error prevents further reads.", e); | ||||
|                     closeConnection(session, GuacamoleStatus.SERVER_ERROR); | ||||
|                     closeConnection(session, GuacamoleStatus.SERVER_ERROR, null); | ||||
|                 } | ||||
|  | ||||
|             } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user