GUACAMOLE-504: Rework HTTP Tunnel to use exception getHttpStatusCode()

This commit is contained in:
Nick Couchman
2018-02-08 09:55:03 -05:00
parent 0c5b3012ac
commit 5aaea07b5e

View File

@@ -149,26 +149,23 @@ public abstract class GuacamoleHTTPTunnelServlet extends HttpServlet {
* @param response * @param response
* The HTTP response to use to send the error. * The HTTP response to use to send the error.
* *
* @param guacStatus * @param guacamoleException
* The status to send * The exception that caused this error.
*
* @param message
* A human-readable message that can be presented to the user.
* *
* @throws ServletException * @throws ServletException
* If an error prevents sending of the error code. * If an error prevents sending of the error code.
*/ */
protected void sendError(HttpServletResponse response, protected void sendError(HttpServletResponse response,
GuacamoleStatus guacStatus, String message) GuacamoleException guacamoleException)
throws ServletException { throws ServletException {
try { try {
// If response not committed, send error code and message // If response not committed, send error code and message
if (!response.isCommitted()) { if (!response.isCommitted()) {
response.addHeader("Guacamole-Status-Code", Integer.toString(guacStatus.getGuacamoleStatusCode())); response.addHeader("Guacamole-Status-Code", Integer.toString(guacamoleException.getStatus().getGuacamoleStatusCode()));
response.addHeader("Guacamole-Error-Message", message); response.addHeader("Guacamole-Error-Message", guacamoleException.getMessage());
response.sendError(guacStatus.getHttpStatusCode()); response.sendError(guacamoleException.getHttpStatusCode());
} }
} }
@@ -258,12 +255,12 @@ public abstract class GuacamoleHTTPTunnelServlet extends HttpServlet {
// HTTP response, logging each error appropriately. // HTTP response, logging each error appropriately.
catch (GuacamoleClientException e) { catch (GuacamoleClientException e) {
logger.warn("HTTP tunnel request rejected: {}", e.getMessage()); logger.warn("HTTP tunnel request rejected: {}", e.getMessage());
sendError(response, e.getStatus(), e.getMessage()); sendError(response, e);
} }
catch (GuacamoleException e) { catch (GuacamoleException e) {
logger.error("HTTP tunnel request failed: {}", e.getMessage()); logger.error("HTTP tunnel request failed: {}", e.getMessage());
logger.debug("Internal error in HTTP tunnel.", e); logger.debug("Internal error in HTTP tunnel.", e);
sendError(response, e.getStatus(), "Internal server error."); sendError(response, e);
} }
} }