mirror of
				https://github.com/gyurix1968/guacamole-client.git
				synced 2025-10-31 00:53:21 +00:00 
			
		
		
		
	GUACAMOLE-504: Reimplement closeConnection() with int parameters.
This commit is contained in:
		| @@ -61,13 +61,10 @@ public abstract class GuacamoleWebSocketTunnelServlet extends WebSocketServlet { | ||||
|      * @param webSocketCode The numeric WebSocket status code to send. | ||||
|      */ | ||||
|     private static void closeConnection(Connection connection, | ||||
|             GuacamoleStatus guac_status, Integer webSocketCode) { | ||||
|  | ||||
|         if (webSocketCode == null) | ||||
|             webSocketCode = guac_status.getWebSocketCode(); | ||||
|             int guacamoleStatusCode, int webSocketCode) { | ||||
|  | ||||
|         connection.close(webSocketCode, | ||||
|                 Integer.toString(guac_status.getGuacamoleStatusCode())); | ||||
|                 Integer.toString(guacamoleStatusCode)); | ||||
|  | ||||
|     } | ||||
|  | ||||
| @@ -118,13 +115,16 @@ public abstract class GuacamoleWebSocketTunnelServlet extends WebSocketServlet { | ||||
|                 catch (GuacamoleException e) { | ||||
|                     logger.error("Creation of WebSocket tunnel to guacd failed: {}", e.getMessage()); | ||||
|                     logger.debug("Error connecting WebSocket tunnel.", e); | ||||
|                     closeConnection(connection, e.getStatus(), e.getWebSocketCode()); | ||||
|                     closeConnection(connection, e.getStatus().getGuacamoleStatusCode(), | ||||
|                             e.getWebSocketCode()); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 // Do not start connection if tunnel does not exist | ||||
|                 if (tunnel == null) { | ||||
|                     closeConnection(connection, GuacamoleStatus.RESOURCE_NOT_FOUND, null); | ||||
|                     closeConnection(connection, | ||||
|                             GuacamoleStatus.RESOURCE_NOT_FOUND.getGuacamoleStatusCode(), | ||||
|                             GuacamoleStatus.RESOURCE_NOT_FOUND.getWebSocketCode()); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
| @@ -162,7 +162,9 @@ public abstract class GuacamoleWebSocketTunnelServlet extends WebSocketServlet { | ||||
|                                 } | ||||
|  | ||||
|                                 // No more data | ||||
|                                 closeConnection(connection, GuacamoleStatus.SUCCESS, null); | ||||
|                                 closeConnection(connection, | ||||
|                                         GuacamoleStatus.SUCCESS.getGuacamoleStatusCode(), | ||||
|                                         GuacamoleStatus.SUCCESS.getWebSocketCode()); | ||||
|                                  | ||||
|                             } | ||||
|  | ||||
| @@ -172,22 +174,28 @@ public abstract class GuacamoleWebSocketTunnelServlet extends WebSocketServlet { | ||||
|                             catch (GuacamoleClientException e) { | ||||
|                                 logger.info("WebSocket connection terminated: {}", e.getMessage()); | ||||
|                                 logger.debug("WebSocket connection terminated due to client error.", e); | ||||
|                                 closeConnection(connection, e.getStatus(), e.getWebSocketCode()); | ||||
|                                 closeConnection(connection, e.getStatus().getGuacamoleStatusCode(), | ||||
|                                         e.getWebSocketCode()); | ||||
|                             } | ||||
|                             catch (GuacamoleConnectionClosedException e) { | ||||
|                                 logger.debug("Connection to guacd closed.", e); | ||||
|                                 closeConnection(connection, GuacamoleStatus.SUCCESS, null); | ||||
|                                 closeConnection(connection, | ||||
|                                         GuacamoleStatus.SUCCESS.getGuacamoleStatusCode(), | ||||
|                                         GuacamoleStatus.SUCCESS.getWebSocketCode()); | ||||
|                             } | ||||
|                             catch (GuacamoleException e) { | ||||
|                                 logger.error("Connection to guacd terminated abnormally: {}", e.getMessage()); | ||||
|                                 logger.debug("Internal error during connection to guacd.", e); | ||||
|                                 closeConnection(connection, e.getStatus(), e.getWebSocketCode()); | ||||
|                                 closeConnection(connection, e.getStatus().getGuacamoleStatusCode(), | ||||
|                                         e.getWebSocketCode()); | ||||
|                             } | ||||
|  | ||||
|                         } | ||||
|                         catch (IOException e) { | ||||
|                             logger.debug("WebSocket tunnel read failed due to I/O error.", e); | ||||
|                             closeConnection(connection, GuacamoleStatus.SERVER_ERROR, null); | ||||
|                             closeConnection(connection, | ||||
|                                     GuacamoleStatus.SERVER_ERROR.getGuacamoleStatusCode(), | ||||
|                                     GuacamoleStatus.SERVER_ERROR.getWebSocketCode()); | ||||
|                         } | ||||
|  | ||||
|                     } | ||||
|   | ||||
| @@ -64,13 +64,11 @@ public abstract class GuacamoleWebSocketTunnelListener implements WebSocketListe | ||||
|      * @param guac_status The status to send. | ||||
|      * @param webSocketCode The numeric WebSocket status code to send. | ||||
|      */ | ||||
|     private void closeConnection(Session session, GuacamoleStatus guac_status, | ||||
|             Integer webSocketCode) { | ||||
|     private void closeConnection(Session session, int guacamoleStatusCode, | ||||
|             int webSocketCode) { | ||||
|  | ||||
|         try { | ||||
|             if (webSocketCode == null) | ||||
|                 webSocketCode = guac_status.getWebSocketCode(); | ||||
|             String message = Integer.toString(guac_status.getGuacamoleStatusCode()); | ||||
|             String message = Integer.toString(guacamoleStatusCode); | ||||
|             session.close(new CloseStatus(webSocketCode, message)); | ||||
|         } | ||||
|         catch (IOException e) { | ||||
| @@ -100,7 +98,8 @@ public abstract class GuacamoleWebSocketTunnelListener implements WebSocketListe | ||||
|             // Get tunnel | ||||
|             tunnel = createTunnel(session); | ||||
|             if (tunnel == null) { | ||||
|                 closeConnection(session, GuacamoleStatus.RESOURCE_NOT_FOUND, null); | ||||
|                 closeConnection(session, GuacamoleStatus.RESOURCE_NOT_FOUND.getGuacamoleStatusCode(), | ||||
|                         GuacamoleStatus.RESOURCE_NOT_FOUND.getWebSocketCode()); | ||||
|                 return; | ||||
|             } | ||||
|  | ||||
| @@ -108,7 +107,7 @@ public abstract class GuacamoleWebSocketTunnelListener implements WebSocketListe | ||||
|         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(), e.getWebSocketCode()); | ||||
|             closeConnection(session, e.getStatus().getGuacamoleStatusCode(), e.getWebSocketCode()); | ||||
|             return; | ||||
|         } | ||||
|  | ||||
| @@ -152,7 +151,8 @@ public abstract class GuacamoleWebSocketTunnelListener implements WebSocketListe | ||||
|                         } | ||||
|  | ||||
|                         // No more data | ||||
|                         closeConnection(session, GuacamoleStatus.SUCCESS, null); | ||||
|                         closeConnection(session, GuacamoleStatus.SUCCESS.getGuacamoleStatusCode(), | ||||
|                                 GuacamoleStatus.SUCCESS.getWebSocketCode()); | ||||
|  | ||||
|                     } | ||||
|  | ||||
| @@ -162,22 +162,26 @@ public abstract class GuacamoleWebSocketTunnelListener implements WebSocketListe | ||||
|                     catch (GuacamoleClientException e) { | ||||
|                         logger.info("WebSocket connection terminated: {}", e.getMessage()); | ||||
|                         logger.debug("WebSocket connection terminated due to client error.", e); | ||||
|                         closeConnection(session, e.getStatus(), e.getWebSocketCode()); | ||||
|                         closeConnection(session, e.getStatus().getGuacamoleStatusCode(), | ||||
|                                 e.getWebSocketCode()); | ||||
|                     } | ||||
|                     catch (GuacamoleConnectionClosedException e) { | ||||
|                         logger.debug("Connection to guacd closed.", e); | ||||
|                         closeConnection(session, GuacamoleStatus.SUCCESS, null); | ||||
|                         closeConnection(session, GuacamoleStatus.SUCCESS.getGuacamoleStatusCode(), | ||||
|                                 GuacamoleStatus.SUCCESS.getWebSocketCode()); | ||||
|                     } | ||||
|                     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(), 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, null); | ||||
|                     closeConnection(session, GuacamoleStatus.SERVER_ERROR.getGuacamoleStatusCode(), | ||||
|                             GuacamoleStatus.SERVER_ERROR.getWebSocketCode()); | ||||
|                 } | ||||
|  | ||||
|             } | ||||
|   | ||||
| @@ -65,13 +65,11 @@ public abstract class GuacamoleWebSocketTunnelServlet extends WebSocketServlet { | ||||
|      * @param guac_status The status to send. | ||||
|      * @param webSocketCode The numeric WebSocket status code to send. | ||||
|      */ | ||||
|     private void closeConnection(WsOutbound outbound, GuacamoleStatus guac_status, | ||||
|             Integer webSocketCode) { | ||||
|     private void closeConnection(WsOutbound outbound, int guacamoleStatusCode, | ||||
|             int webSocketCode) { | ||||
|  | ||||
|         try { | ||||
|             if (webSocketCode == null) | ||||
|                 webSocketCode = guac_status.getWebSocketCode(); | ||||
|             byte[] message = Integer.toString(guac_status.getGuacamoleStatusCode()).getBytes("UTF-8"); | ||||
|             byte[] message = Integer.toString(guacamoleStatusCode).getBytes("UTF-8"); | ||||
|             outbound.close(webSocketCode, ByteBuffer.wrap(message)); | ||||
|         } | ||||
|         catch (IOException e) { | ||||
| @@ -146,13 +144,15 @@ public abstract class GuacamoleWebSocketTunnelServlet extends WebSocketServlet { | ||||
|                 catch (GuacamoleException e) { | ||||
|                     logger.error("Creation of WebSocket tunnel to guacd failed: {}", e.getMessage()); | ||||
|                     logger.debug("Error connecting WebSocket tunnel.", e); | ||||
|                     closeConnection(outbound, e.getStatus(), e.getWebSocketCode()); | ||||
|                     closeConnection(outbound, e.getStatus().getGuacamoleStatusCode(), | ||||
|                             e.getWebSocketCode()); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
|                 // Do not start connection if tunnel does not exist | ||||
|                 if (tunnel == null) { | ||||
|                     closeConnection(outbound, GuacamoleStatus.RESOURCE_NOT_FOUND, null); | ||||
|                     closeConnection(outbound, GuacamoleStatus.RESOURCE_NOT_FOUND.getGuacamoleStatusCode(), | ||||
|                             GuacamoleStatus.RESOURCE_NOT_FOUND.getWebSocketCode()); | ||||
|                     return; | ||||
|                 } | ||||
|  | ||||
| @@ -190,7 +190,8 @@ public abstract class GuacamoleWebSocketTunnelServlet extends WebSocketServlet { | ||||
|                                 } | ||||
|  | ||||
|                                 // No more data | ||||
|                                 closeConnection(outbound, GuacamoleStatus.SUCCESS, null); | ||||
|                                 closeConnection(outbound, GuacamoleStatus.SUCCESS.getGuacamoleStatusCode(), | ||||
|                                         GuacamoleStatus.SUCCESS.getWebSocketCode()); | ||||
|  | ||||
|                             } | ||||
|  | ||||
| @@ -200,22 +201,26 @@ public abstract class GuacamoleWebSocketTunnelServlet extends WebSocketServlet { | ||||
|                             catch (GuacamoleClientException e) { | ||||
|                                 logger.info("WebSocket connection terminated: {}", e.getMessage()); | ||||
|                                 logger.debug("WebSocket connection terminated due to client error.", e); | ||||
|                                 closeConnection(outbound, e.getStatus(), e.getWebSocketCode()); | ||||
|                                 closeConnection(outbound, e.getStatus().getGuacamoleStatusCode(), | ||||
|                                         e.getWebSocketCode()); | ||||
|                             } | ||||
|                             catch (GuacamoleConnectionClosedException e) { | ||||
|                                 logger.debug("Connection to guacd closed.", e); | ||||
|                                 closeConnection(outbound, GuacamoleStatus.SUCCESS, null); | ||||
|                                 closeConnection(outbound, GuacamoleStatus.SUCCESS.getGuacamoleStatusCode(), | ||||
|                                         GuacamoleStatus.SUCCESS.getWebSocketCode()); | ||||
|                             } | ||||
|                             catch (GuacamoleException e) { | ||||
|                                 logger.error("Connection to guacd terminated abnormally: {}", e.getMessage()); | ||||
|                                 logger.debug("Internal error during connection to guacd.", e); | ||||
|                                 closeConnection(outbound, e.getStatus(), e.getWebSocketCode()); | ||||
|                                 closeConnection(outbound, e.getStatus().getGuacamoleStatusCode(), | ||||
|                                         e.getWebSocketCode()); | ||||
|                             } | ||||
|  | ||||
|                         } | ||||
|                         catch (IOException e) { | ||||
|                             logger.debug("I/O error prevents further reads.", e); | ||||
|                             closeConnection(outbound, GuacamoleStatus.SERVER_ERROR, null); | ||||
|                             closeConnection(outbound, GuacamoleStatus.SERVER_ERROR.getGuacamoleStatusCode(), | ||||
|                                     GuacamoleStatus.SERVER_ERROR.getWebSocketCode()); | ||||
|                         } | ||||
|  | ||||
|                     } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user