mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-07 13:41:21 +00:00
GUAC-1161: Generalize HTTPException to APIException.
This commit is contained in:
@@ -28,29 +28,29 @@ import javax.ws.rs.core.Response;
|
||||
import org.glyptodon.guacamole.form.Parameter;
|
||||
|
||||
/**
|
||||
* An exception that will result in the given HTTP Status and error being
|
||||
* An exception that will result in the given error error information being
|
||||
* returned from the API layer. All error messages have the same format which
|
||||
* is defined by APIError.
|
||||
*
|
||||
* @author James Muehlner
|
||||
* @author Michael Jumper
|
||||
*/
|
||||
public class HTTPException extends WebApplicationException {
|
||||
public class APIException extends WebApplicationException {
|
||||
|
||||
/**
|
||||
* Construct a new HTTPException with the given error. All information
|
||||
* Construct a new APIException with the given error. All information
|
||||
* associated with this new exception will be extracted from the given
|
||||
* APIError.
|
||||
*
|
||||
* @param error
|
||||
* The error that occurred.
|
||||
*/
|
||||
public HTTPException(APIError error) {
|
||||
public APIException(APIError error) {
|
||||
super(Response.status(error.getType().getStatus()).entity(error).build());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new HTTPException with the given type and message. The
|
||||
* Creates a new APIException with the given type and message. The
|
||||
* corresponding APIError will be created from the provided information.
|
||||
*
|
||||
* @param type
|
||||
@@ -59,14 +59,14 @@ public class HTTPException extends WebApplicationException {
|
||||
* @param message
|
||||
* A human-readable message describing the error.
|
||||
*/
|
||||
public HTTPException(APIError.Type type, String message) {
|
||||
public APIException(APIError.Type type, String message) {
|
||||
this(new APIError(type, message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new HTTPException with the given type, message, and
|
||||
* parameter information. The corresponding APIError will be created from
|
||||
* the provided information.
|
||||
* Creates a new APIException with the given type, message, and parameter
|
||||
* information. The corresponding APIError will be created from the
|
||||
* provided information.
|
||||
*
|
||||
* @param type
|
||||
* The type of error that occurred.
|
||||
@@ -78,7 +78,7 @@ public class HTTPException extends WebApplicationException {
|
||||
* All parameters expected in the original request, or now required as
|
||||
* a result of the original request.
|
||||
*/
|
||||
public HTTPException(APIError.Type type, String message, Collection<Parameter> expected) {
|
||||
public APIException(APIError.Type type, String message, Collection<Parameter> expected) {
|
||||
this(new APIError(type, message, expected));
|
||||
}
|
||||
|
@@ -62,7 +62,7 @@ public class AuthProviderRESTExceptionWrapper implements MethodInterceptor {
|
||||
if (message == null)
|
||||
message = "Permission denied.";
|
||||
|
||||
throw new HTTPException(
|
||||
throw new APIException(
|
||||
APIError.Type.INSUFFICIENT_CREDENTIALS,
|
||||
message,
|
||||
e.getCredentialsInfo().getParameters()
|
||||
@@ -77,7 +77,7 @@ public class AuthProviderRESTExceptionWrapper implements MethodInterceptor {
|
||||
if (message == null)
|
||||
message = "Permission denied.";
|
||||
|
||||
throw new HTTPException(
|
||||
throw new APIException(
|
||||
APIError.Type.INVALID_CREDENTIALS,
|
||||
message,
|
||||
e.getCredentialsInfo().getParameters()
|
||||
@@ -92,7 +92,7 @@ public class AuthProviderRESTExceptionWrapper implements MethodInterceptor {
|
||||
if (message == null)
|
||||
message = "Permission denied.";
|
||||
|
||||
throw new HTTPException(
|
||||
throw new APIException(
|
||||
APIError.Type.PERMISSION_DENIED,
|
||||
message
|
||||
);
|
||||
@@ -107,7 +107,7 @@ public class AuthProviderRESTExceptionWrapper implements MethodInterceptor {
|
||||
if (message == null)
|
||||
message = "Not found.";
|
||||
|
||||
throw new HTTPException(
|
||||
throw new APIException(
|
||||
APIError.Type.NOT_FOUND,
|
||||
message
|
||||
);
|
||||
@@ -122,7 +122,7 @@ public class AuthProviderRESTExceptionWrapper implements MethodInterceptor {
|
||||
if (message == null)
|
||||
message = "Invalid request.";
|
||||
|
||||
throw new HTTPException(
|
||||
throw new APIException(
|
||||
APIError.Type.BAD_REQUEST,
|
||||
message
|
||||
);
|
||||
@@ -138,7 +138,7 @@ public class AuthProviderRESTExceptionWrapper implements MethodInterceptor {
|
||||
message = "Unexpected server error.";
|
||||
|
||||
logger.debug("Unexpected exception in REST endpoint.", e);
|
||||
throw new HTTPException(
|
||||
throw new APIException(
|
||||
APIError.Type.INTERNAL_ERROR,
|
||||
message
|
||||
);
|
||||
|
@@ -46,7 +46,7 @@ import org.glyptodon.guacamole.net.basic.GuacamoleSession;
|
||||
import org.glyptodon.guacamole.net.basic.rest.APIError;
|
||||
import org.glyptodon.guacamole.net.basic.rest.APIRequest;
|
||||
import org.glyptodon.guacamole.net.basic.rest.AuthProviderRESTExposure;
|
||||
import org.glyptodon.guacamole.net.basic.rest.HTTPException;
|
||||
import org.glyptodon.guacamole.net.basic.rest.APIException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -290,7 +290,7 @@ public class TokenRESTService {
|
||||
|
||||
GuacamoleSession session = tokenSessionMap.remove(authToken);
|
||||
if (session == null)
|
||||
throw new HTTPException(APIError.Type.NOT_FOUND, "No such token.");
|
||||
throw new APIException(APIError.Type.NOT_FOUND, "No such token.");
|
||||
|
||||
session.invalidate();
|
||||
|
||||
|
@@ -56,7 +56,7 @@ import org.glyptodon.guacamole.net.basic.rest.APIPatch;
|
||||
import static org.glyptodon.guacamole.net.basic.rest.APIPatch.Operation.add;
|
||||
import static org.glyptodon.guacamole.net.basic.rest.APIPatch.Operation.remove;
|
||||
import org.glyptodon.guacamole.net.basic.rest.AuthProviderRESTExposure;
|
||||
import org.glyptodon.guacamole.net.basic.rest.HTTPException;
|
||||
import org.glyptodon.guacamole.net.basic.rest.APIException;
|
||||
import org.glyptodon.guacamole.net.basic.rest.ObjectRetrievalService;
|
||||
import org.glyptodon.guacamole.net.basic.rest.PATCH;
|
||||
import org.glyptodon.guacamole.net.basic.rest.auth.AuthenticationService;
|
||||
@@ -275,12 +275,12 @@ public class UserRESTService {
|
||||
|
||||
// Validate data and path are sane
|
||||
if (!user.getUsername().equals(username))
|
||||
throw new HTTPException(APIError.Type.BAD_REQUEST,
|
||||
throw new APIException(APIError.Type.BAD_REQUEST,
|
||||
"Username in path does not match username provided JSON data.");
|
||||
|
||||
// A user may not use this endpoint to modify himself
|
||||
if (userContext.self().getIdentifier().equals(user.getUsername())) {
|
||||
throw new HTTPException(APIError.Type.PERMISSION_DENIED,
|
||||
throw new APIException(APIError.Type.PERMISSION_DENIED,
|
||||
"Permission denied.");
|
||||
}
|
||||
|
||||
@@ -335,7 +335,7 @@ public class UserRESTService {
|
||||
|
||||
// Verify that the old password was correct
|
||||
if (authProvider.getUserContext(credentials) == null) {
|
||||
throw new HTTPException(APIError.Type.PERMISSION_DENIED,
|
||||
throw new APIException(APIError.Type.PERMISSION_DENIED,
|
||||
"Permission denied.");
|
||||
}
|
||||
|
||||
@@ -466,7 +466,7 @@ public class UserRESTService {
|
||||
|
||||
// Unsupported patch operation
|
||||
default:
|
||||
throw new HTTPException(APIError.Type.BAD_REQUEST,
|
||||
throw new APIException(APIError.Type.BAD_REQUEST,
|
||||
"Unsupported patch operation: \"" + operation + "\"");
|
||||
|
||||
}
|
||||
@@ -585,7 +585,7 @@ public class UserRESTService {
|
||||
|
||||
// Otherwise, the path is not supported
|
||||
else
|
||||
throw new HTTPException(APIError.Type.BAD_REQUEST, "Unsupported patch path: \"" + path + "\"");
|
||||
throw new APIException(APIError.Type.BAD_REQUEST, "Unsupported patch path: \"" + path + "\"");
|
||||
|
||||
} // end for each patch operation
|
||||
|
||||
|
Reference in New Issue
Block a user