mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 05:07:41 +00:00
GUAC-547: Send status code as header. Use status code wherever GuacamoleExceptions are handled.
This commit is contained in:
@@ -42,6 +42,7 @@ import org.glyptodon.guacamole.GuacamoleServerException;
|
|||||||
import org.glyptodon.guacamole.io.GuacamoleReader;
|
import org.glyptodon.guacamole.io.GuacamoleReader;
|
||||||
import org.glyptodon.guacamole.io.GuacamoleWriter;
|
import org.glyptodon.guacamole.io.GuacamoleWriter;
|
||||||
import org.glyptodon.guacamole.net.GuacamoleTunnel;
|
import org.glyptodon.guacamole.net.GuacamoleTunnel;
|
||||||
|
import org.glyptodon.guacamole.protocol.GuacamoleStatus;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@@ -94,21 +95,28 @@ public abstract class GuacamoleHTTPTunnelServlet extends HttpServlet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends an error on the given HTTP response with the given integer error
|
* Sends an error on the given HTTP response using the information within
|
||||||
* code.
|
* the given GuacamoleStatus.
|
||||||
*
|
*
|
||||||
* @param response The HTTP response to use to send the error.
|
* @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
|
* @throws ServletException If an error prevents sending of the error
|
||||||
* code.
|
* code.
|
||||||
*/
|
*/
|
||||||
private void sendError(HttpServletResponse response, int code) throws ServletException {
|
public static void sendError(HttpServletResponse response,
|
||||||
|
GuacamoleStatus guac_status, String message)
|
||||||
|
throws ServletException {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// If response not committed, send error code
|
// If response not committed, send error code and message
|
||||||
if (!response.isCommitted())
|
if (!response.isCommitted()) {
|
||||||
response.sendError(code);
|
response.addHeader("Guacamole-Status-Code", Integer.toString(guac_status.getGuacamoleStatusCode()));
|
||||||
|
response.addHeader("Guacamole-Error-Message", message);
|
||||||
|
response.sendError(guac_status.getHttpStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (IOException ioe) {
|
catch (IOException ioe) {
|
||||||
@@ -197,21 +205,13 @@ public abstract class GuacamoleHTTPTunnelServlet extends HttpServlet {
|
|||||||
|
|
||||||
// Catch any thrown guacamole exception and attempt to pass within the
|
// Catch any thrown guacamole exception and attempt to pass within the
|
||||||
// HTTP response, logging each error appropriately.
|
// HTTP response, logging each error appropriately.
|
||||||
catch (GuacamoleSecurityException e) {
|
|
||||||
logger.warn("Authorization failed.", e);
|
|
||||||
sendError(response, HttpServletResponse.SC_FORBIDDEN);
|
|
||||||
}
|
|
||||||
catch (GuacamoleResourceNotFoundException e) {
|
|
||||||
logger.debug("Resource not found.", e);
|
|
||||||
sendError(response, HttpServletResponse.SC_NOT_FOUND);
|
|
||||||
}
|
|
||||||
catch (GuacamoleClientException e) {
|
catch (GuacamoleClientException e) {
|
||||||
logger.warn("Error in client request.", e);
|
logger.warn("Client request rejected: {}", e.getMessage());
|
||||||
sendError(response, HttpServletResponse.SC_BAD_REQUEST);
|
sendError(response, e.getStatus(), e.getMessage());
|
||||||
}
|
}
|
||||||
catch (GuacamoleException e) {
|
catch (GuacamoleException e) {
|
||||||
logger.error("Server error in tunnel", e);
|
logger.error("Internal server error.", e);
|
||||||
sendError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
sendError(response, e.getStatus(), "Internal server error.");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -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.AuthenticationFailureListener;
|
||||||
import org.glyptodon.guacamole.net.event.listener.AuthenticationSuccessListener;
|
import org.glyptodon.guacamole.net.event.listener.AuthenticationSuccessListener;
|
||||||
import org.glyptodon.guacamole.properties.GuacamoleProperties;
|
import org.glyptodon.guacamole.properties.GuacamoleProperties;
|
||||||
|
import org.glyptodon.guacamole.protocol.GuacamoleStatus;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
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
|
* Sends an error on the given HTTP response using the information within
|
||||||
* code.
|
* the given GuacamoleStatus.
|
||||||
*
|
*
|
||||||
* @param response The HTTP response to use to send the error.
|
* @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
|
* @param message A human-readable message that can be presented to the
|
||||||
* user.
|
* user.
|
||||||
* @throws ServletException If an error prevents sending of the error
|
* @throws ServletException If an error prevents sending of the error
|
||||||
* code.
|
* code.
|
||||||
*/
|
*/
|
||||||
private void sendError(HttpServletResponse response, int code,
|
public static void sendError(HttpServletResponse response,
|
||||||
String message) throws ServletException {
|
GuacamoleStatus guac_status, String message)
|
||||||
|
throws ServletException {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// If response not committed, send error code
|
// If response not committed, send error code and message
|
||||||
if (!response.isCommitted()) {
|
if (!response.isCommitted()) {
|
||||||
|
response.addHeader("Guacamole-Status-Code", Integer.toString(guac_status.getGuacamoleStatusCode()));
|
||||||
response.addHeader("Guacamole-Error-Message", message);
|
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
|
// Catch any thrown guacamole exception and attempt to pass within the
|
||||||
// HTTP response, logging each error appropriately.
|
// 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) {
|
catch (GuacamoleClientException e) {
|
||||||
logger.warn("Error in client request: {}", e.getMessage());
|
logger.warn("Client request rejected: {}", e.getMessage());
|
||||||
sendError(response, HttpServletResponse.SC_BAD_REQUEST,
|
sendError(response, e.getStatus(), e.getMessage());
|
||||||
e.getMessage());
|
|
||||||
}
|
}
|
||||||
catch (GuacamoleException e) {
|
catch (GuacamoleException e) {
|
||||||
logger.error("Internal server error.", e);
|
logger.error("Internal server error.", e);
|
||||||
sendError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
|
sendError(response, e.getStatus(), "Internal server error.");
|
||||||
"Internal server error.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user