protected void sendError(HttpServletResponse response, int guacamoleStatusCode,
            int guacamoleHttpCode, String message)
            throws ServletException {

        try {

            // If response not committed, send error code and message
            if (!response.isCommitted()) {
                response.addHeader("Guacamole-Status-Code", Integer.toString(guacamoleStatusCode));
                response.addHeader("Guacamole-Error-Message", message);
                response.sendError(guacamoleHttpCode);
            }

        }
        catch (IOException ioe) {

            // If unable to send error at all due to I/O problems,
            // rethrow as servlet exception
            throw new ServletException(ioe);

        }

    }
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 guacamoleStatusCode
    The GuacamoleStatus code to send.

@param guacamoleHttpCode
    The numeric HTTP code to send.

@param message
    The human-readable error message to send.

@throws ServletException
    If an error prevents sending of the error code.
guacamole-common/src/main/java/org/apache/guacamole/servlet/GuacamoleHTTPTunnelServlet.java