mirror of
				https://github.com/gyurix1968/guacamole-client.git
				synced 2025-10-31 00:53:21 +00:00 
			
		
		
		
	GUAC-547: Send status code as header. Use status code wherever GuacamoleExceptions are handled.
This commit is contained in:
		| @@ -44,6 +44,7 @@ import org.glyptodon.guacamole.net.event.AuthenticationSuccessEvent; | ||||
| import org.glyptodon.guacamole.net.event.listener.AuthenticationFailureListener; | ||||
| import org.glyptodon.guacamole.net.event.listener.AuthenticationSuccessListener; | ||||
| import org.glyptodon.guacamole.properties.GuacamoleProperties; | ||||
| import org.glyptodon.guacamole.protocol.GuacamoleStatus; | ||||
| import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | ||||
|  | ||||
| @@ -171,25 +172,27 @@ public abstract class AuthenticatingHttpServlet extends HttpServlet { | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Sends an error on the given HTTP response with the given integer error | ||||
|      * code. | ||||
|      * Sends an error on the given HTTP response using the information within | ||||
|      * the given GuacamoleStatus. | ||||
|      * | ||||
|      * @param response The HTTP response to use to send the error. | ||||
|      * @param code The HTTP status code of the error. | ||||
|      * @param guac_status The status to send | ||||
|      * @param message A human-readable message that can be presented to the | ||||
|      *                user. | ||||
|      * @throws ServletException If an error prevents sending of the error | ||||
|      *                          code. | ||||
|      */ | ||||
|     private void sendError(HttpServletResponse response, int code, | ||||
|             String message) throws ServletException { | ||||
|     public static void sendError(HttpServletResponse response, | ||||
|             GuacamoleStatus guac_status, String message) | ||||
|             throws ServletException { | ||||
|  | ||||
|         try { | ||||
|  | ||||
|             // If response not committed, send error code | ||||
|             // If response not committed, send error code and message | ||||
|             if (!response.isCommitted()) { | ||||
|                 response.addHeader("Guacamole-Status-Code", Integer.toString(guac_status.getGuacamoleStatusCode())); | ||||
|                 response.addHeader("Guacamole-Error-Message", message); | ||||
|                 response.sendError(code); | ||||
|                 response.sendError(guac_status.getHttpStatusCode()); | ||||
|             } | ||||
|  | ||||
|         } | ||||
| @@ -337,25 +340,13 @@ public abstract class AuthenticatingHttpServlet extends HttpServlet { | ||||
|  | ||||
|         // Catch any thrown guacamole exception and attempt to pass within the | ||||
|         // HTTP response, logging each error appropriately. | ||||
|         catch (GuacamoleSecurityException e) { | ||||
|             logger.warn("Permission denied: {}", e.getMessage()); | ||||
|             sendError(response, HttpServletResponse.SC_FORBIDDEN, | ||||
|                     "Permission denied."); | ||||
|         } | ||||
|         catch (GuacamoleResourceNotFoundException e) { | ||||
|             logger.debug("Resource not found: {}", e.getMessage()); | ||||
|             sendError(response, HttpServletResponse.SC_NOT_FOUND, | ||||
|                     e.getMessage()); | ||||
|         } | ||||
|         catch (GuacamoleClientException e) { | ||||
|             logger.warn("Error in client request: {}", e.getMessage()); | ||||
|             sendError(response, HttpServletResponse.SC_BAD_REQUEST, | ||||
|                     e.getMessage()); | ||||
|             logger.warn("Client request rejected: {}", e.getMessage()); | ||||
|             sendError(response, e.getStatus(), e.getMessage()); | ||||
|         } | ||||
|         catch (GuacamoleException e) { | ||||
|             logger.error("Internal server error.", e); | ||||
|             sendError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, | ||||
|                       "Internal server error."); | ||||
|             sendError(response, e.getStatus(), "Internal server error."); | ||||
|         } | ||||
|  | ||||
|     } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user