mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
Ticket #362. Improved error handling.
This commit is contained in:
@@ -5,15 +5,12 @@ import javax.ws.rs.POST;
|
|||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
import javax.ws.rs.QueryParam;
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.WebApplicationException;
|
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
|
||||||
import javax.ws.rs.core.Response.Status;
|
import javax.ws.rs.core.Response.Status;
|
||||||
import org.glyptodon.guacamole.GuacamoleException;
|
import org.glyptodon.guacamole.GuacamoleException;
|
||||||
import org.glyptodon.guacamole.net.auth.AuthenticationProvider;
|
import org.glyptodon.guacamole.net.auth.AuthenticationProvider;
|
||||||
import org.glyptodon.guacamole.net.auth.Credentials;
|
import org.glyptodon.guacamole.net.auth.Credentials;
|
||||||
import org.glyptodon.guacamole.net.auth.UserContext;
|
import org.glyptodon.guacamole.net.auth.UserContext;
|
||||||
import org.glyptodon.guacamole.net.basic.rest.APIError;
|
|
||||||
import org.glyptodon.guacamole.net.basic.rest.HTTPException;
|
import org.glyptodon.guacamole.net.basic.rest.HTTPException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@@ -32,6 +32,7 @@ import javax.ws.rs.Produces;
|
|||||||
import javax.ws.rs.QueryParam;
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response.Status;
|
import javax.ws.rs.core.Response.Status;
|
||||||
|
import org.glyptodon.guacamole.GuacamoleClientException;
|
||||||
import org.glyptodon.guacamole.GuacamoleException;
|
import org.glyptodon.guacamole.GuacamoleException;
|
||||||
import org.glyptodon.guacamole.GuacamoleSecurityException;
|
import org.glyptodon.guacamole.GuacamoleSecurityException;
|
||||||
import org.glyptodon.guacamole.net.auth.Connection;
|
import org.glyptodon.guacamole.net.auth.Connection;
|
||||||
@@ -96,8 +97,7 @@ public class ConnectionRESTService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(parentConnectionGroup == null)
|
if(parentConnectionGroup == null)
|
||||||
throw new HTTPException(Status.BAD_REQUEST,
|
throw new GuacamoleClientException("No ConnectionGroup found with the provided parentID.");
|
||||||
"No ConnectionGroup found with the provided parentID.");
|
|
||||||
|
|
||||||
Directory<String, Connection> connectionDirectory =
|
Directory<String, Connection> connectionDirectory =
|
||||||
parentConnectionGroup.getConnectionDirectory();
|
parentConnectionGroup.getConnectionDirectory();
|
||||||
@@ -112,11 +112,12 @@ public class ConnectionRESTService {
|
|||||||
|
|
||||||
return connectionService.convertConnectionList(connections);
|
return connectionService.convertConnectionList(connections);
|
||||||
} catch(GuacamoleSecurityException e) {
|
} catch(GuacamoleSecurityException e) {
|
||||||
throw new HTTPException(Status.UNAUTHORIZED, "Permission Denied.");
|
throw new HTTPException(Status.UNAUTHORIZED, e.getMessage() != null ? e.getMessage() : "Permission denied.");
|
||||||
|
} catch(GuacamoleClientException e) {
|
||||||
|
throw new HTTPException(Status.BAD_REQUEST, e.getMessage() != null ? e.getMessage() : "Invalid Request.");
|
||||||
} catch(GuacamoleException e) {
|
} catch(GuacamoleException e) {
|
||||||
logger.error("Unexpected GuacamoleException caught while listing connections.", e);
|
logger.error("Unexpected GuacamoleException caught while listing connections.", e);
|
||||||
throw new HTTPException(Status.INTERNAL_SERVER_ERROR,
|
throw new HTTPException(Status.INTERNAL_SERVER_ERROR, e.getMessage() != null ? e.getMessage() : "Unexpected server error.");
|
||||||
"Unexpected server error. " + e.getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,16 +145,16 @@ public class ConnectionRESTService {
|
|||||||
Connection connection = connectionDirectory.get(connectionID);
|
Connection connection = connectionDirectory.get(connectionID);
|
||||||
|
|
||||||
if(connection == null)
|
if(connection == null)
|
||||||
throw new HTTPException(Status.BAD_REQUEST,
|
throw new GuacamoleClientException("No Connection found with the provided ID.");
|
||||||
"No Connection found with the provided ID.");
|
|
||||||
|
|
||||||
return new APIConnection(connection);
|
return new APIConnection(connection);
|
||||||
} catch(GuacamoleSecurityException e) {
|
} catch(GuacamoleSecurityException e) {
|
||||||
throw new HTTPException(Status.UNAUTHORIZED, "Permission Denied.");
|
throw new HTTPException(Status.UNAUTHORIZED, e.getMessage() != null ? e.getMessage() : "Permission denied.");
|
||||||
|
} catch(GuacamoleClientException e) {
|
||||||
|
throw new HTTPException(Status.BAD_REQUEST, e.getMessage() != null ? e.getMessage() : "Invalid Request.");
|
||||||
} catch(GuacamoleException e) {
|
} catch(GuacamoleException e) {
|
||||||
logger.error("Unexpected GuacamoleException caught while getting a connection.", e);
|
logger.error("Unexpected GuacamoleException caught while getting connection.", e);
|
||||||
throw new HTTPException(Status.INTERNAL_SERVER_ERROR,
|
throw new HTTPException(Status.INTERNAL_SERVER_ERROR, e.getMessage() != null ? e.getMessage() : "Unexpected server error.");
|
||||||
"Unexpected server error. " + e.getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,17 +178,17 @@ public class ConnectionRESTService {
|
|||||||
|
|
||||||
// Make sure the connection is there before trying to delete
|
// Make sure the connection is there before trying to delete
|
||||||
if(connectionDirectory.get(connectionID) == null)
|
if(connectionDirectory.get(connectionID) == null)
|
||||||
throw new HTTPException(Status.BAD_REQUEST,
|
throw new GuacamoleClientException("No Connection found with the provided ID.");
|
||||||
"No Connection found with the provided ID.");
|
|
||||||
|
|
||||||
// Delete the connection
|
// Delete the connection
|
||||||
connectionDirectory.remove(connectionID);
|
connectionDirectory.remove(connectionID);
|
||||||
} catch(GuacamoleSecurityException e) {
|
} catch(GuacamoleSecurityException e) {
|
||||||
throw new HTTPException(Status.UNAUTHORIZED, "Permission Denied.");
|
throw new HTTPException(Status.UNAUTHORIZED, e.getMessage() != null ? e.getMessage() : "Permission denied.");
|
||||||
|
} catch(GuacamoleClientException e) {
|
||||||
|
throw new HTTPException(Status.BAD_REQUEST, e.getMessage() != null ? e.getMessage() : "Invalid Request.");
|
||||||
} catch(GuacamoleException e) {
|
} catch(GuacamoleException e) {
|
||||||
logger.error("Unexpected GuacamoleException caught while deleting a connection.", e);
|
logger.error("Unexpected GuacamoleException caught while deleting connection.", e);
|
||||||
throw new HTTPException(Status.INTERNAL_SERVER_ERROR,
|
throw new HTTPException(Status.INTERNAL_SERVER_ERROR, e.getMessage() != null ? e.getMessage() : "Unexpected server error.");
|
||||||
"Unexpected server error. " + e.getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,11 +210,10 @@ public class ConnectionRESTService {
|
|||||||
@QueryParam("parentID") String parentID, APIConnection connection) {
|
@QueryParam("parentID") String parentID, APIConnection connection) {
|
||||||
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
||||||
|
|
||||||
if(connection == null)
|
|
||||||
throw new HTTPException(Status.BAD_REQUEST,
|
|
||||||
"A connection is required for this request.");
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if(connection == null)
|
||||||
|
throw new GuacamoleClientException("A connection is required for this request.");
|
||||||
|
|
||||||
// If the parent connection group is passed in, try to find it.
|
// If the parent connection group is passed in, try to find it.
|
||||||
ConnectionGroup parentConnectionGroup;
|
ConnectionGroup parentConnectionGroup;
|
||||||
if(parentID == null)
|
if(parentID == null)
|
||||||
@@ -225,8 +225,7 @@ public class ConnectionRESTService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(parentConnectionGroup == null)
|
if(parentConnectionGroup == null)
|
||||||
throw new HTTPException(Status.BAD_REQUEST,
|
throw new GuacamoleClientException("No ConnectionGroup found with the provided parentID.");
|
||||||
"No ConnectionGroup found with the provided parentID.");
|
|
||||||
|
|
||||||
Directory<String, Connection> connectionDirectory =
|
Directory<String, Connection> connectionDirectory =
|
||||||
parentConnectionGroup.getConnectionDirectory();
|
parentConnectionGroup.getConnectionDirectory();
|
||||||
@@ -237,11 +236,12 @@ public class ConnectionRESTService {
|
|||||||
// Return the new connection identifier
|
// Return the new connection identifier
|
||||||
return connection.getIdentifier();
|
return connection.getIdentifier();
|
||||||
} catch(GuacamoleSecurityException e) {
|
} catch(GuacamoleSecurityException e) {
|
||||||
throw new HTTPException(Status.UNAUTHORIZED, "Permission Denied.");
|
throw new HTTPException(Status.UNAUTHORIZED, e.getMessage() != null ? e.getMessage() : "Permission denied.");
|
||||||
|
} catch(GuacamoleClientException e) {
|
||||||
|
throw new HTTPException(Status.BAD_REQUEST, e.getMessage() != null ? e.getMessage() : "Invalid Request.");
|
||||||
} catch(GuacamoleException e) {
|
} catch(GuacamoleException e) {
|
||||||
logger.error("Unexpected GuacamoleException caught while listing connections.", e);
|
logger.error("Unexpected GuacamoleException caught while creating connection.", e);
|
||||||
throw new HTTPException(Status.INTERNAL_SERVER_ERROR,
|
throw new HTTPException(Status.INTERNAL_SERVER_ERROR, e.getMessage() != null ? e.getMessage() : "Unexpected server error.");
|
||||||
"Unexpected server error. " + e.getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,11 +259,10 @@ public class ConnectionRESTService {
|
|||||||
@PathParam("connectionID") String connectionID, APIConnection connection) {
|
@PathParam("connectionID") String connectionID, APIConnection connection) {
|
||||||
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
UserContext userContext = authenticationService.getUserContextFromAuthToken(authToken);
|
||||||
|
|
||||||
if(connection == null)
|
|
||||||
throw new HTTPException(Status.BAD_REQUEST,
|
|
||||||
"A connection is required for this request.");
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if(connection == null)
|
||||||
|
throw new GuacamoleClientException("A connection is required for this request.");
|
||||||
|
|
||||||
// Get the connection directory
|
// Get the connection directory
|
||||||
ConnectionGroup rootGroup = userContext.getRootConnectionGroup();
|
ConnectionGroup rootGroup = userContext.getRootConnectionGroup();
|
||||||
Directory<String, Connection> connectionDirectory =
|
Directory<String, Connection> connectionDirectory =
|
||||||
@@ -271,17 +270,17 @@ public class ConnectionRESTService {
|
|||||||
|
|
||||||
// Make sure the connection is there before trying to update
|
// Make sure the connection is there before trying to update
|
||||||
if(connectionDirectory.get(connectionID) == null)
|
if(connectionDirectory.get(connectionID) == null)
|
||||||
throw new HTTPException(Status.BAD_REQUEST,
|
throw new GuacamoleClientException("No Connection with the provided ID.");
|
||||||
"No Connection with the provided ID.");
|
|
||||||
|
|
||||||
// Update the connection
|
// Update the connection
|
||||||
connectionDirectory.update(connection);
|
connectionDirectory.update(connection);
|
||||||
} catch(GuacamoleSecurityException e) {
|
} catch(GuacamoleSecurityException e) {
|
||||||
throw new HTTPException(Status.UNAUTHORIZED, "Permission Denied.");
|
throw new HTTPException(Status.UNAUTHORIZED, e.getMessage() != null ? e.getMessage() : "Permission denied.");
|
||||||
|
} catch(GuacamoleClientException e) {
|
||||||
|
throw new HTTPException(Status.BAD_REQUEST, e.getMessage() != null ? e.getMessage() : "Invalid Request.");
|
||||||
} catch(GuacamoleException e) {
|
} catch(GuacamoleException e) {
|
||||||
logger.error("Unexpected GuacamoleException caught while listing connections.", e);
|
logger.error("Unexpected GuacamoleException caught updating connection.", e);
|
||||||
throw new HTTPException(Status.INTERNAL_SERVER_ERROR,
|
throw new HTTPException(Status.INTERNAL_SERVER_ERROR, e.getMessage() != null ? e.getMessage() : "Unexpected server error.");
|
||||||
"Unexpected server error. " + e.getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,22 +310,20 @@ public class ConnectionRESTService {
|
|||||||
ConnectionGroup parentConnectionGroup = connectionGroupDirectory.get(parentID);
|
ConnectionGroup parentConnectionGroup = connectionGroupDirectory.get(parentID);
|
||||||
|
|
||||||
if(parentConnectionGroup == null)
|
if(parentConnectionGroup == null)
|
||||||
throw new HTTPException(Status.BAD_REQUEST,
|
throw new GuacamoleClientException("No ConnectionGroup found with the provided parentID.");
|
||||||
"No ConnectionGroup found with the provided parentID.");
|
|
||||||
|
|
||||||
// Make sure the connection is there before trying to delete
|
// Make sure the connection is there before trying to delete
|
||||||
if(connectionDirectory.get(connectionID) == null)
|
if(connectionDirectory.get(connectionID) == null)
|
||||||
throw new HTTPException(Status.BAD_REQUEST,
|
throw new GuacamoleClientException("No Connection found with the provided ID.");
|
||||||
"No Connection found with the provided ID.");
|
|
||||||
|
|
||||||
// Move the connection
|
// Move the connection
|
||||||
connectionDirectory.move(connectionID, connectionDirectory);
|
|
||||||
} catch(GuacamoleSecurityException e) {
|
} catch(GuacamoleSecurityException e) {
|
||||||
throw new HTTPException(Status.UNAUTHORIZED, "Permission Denied.");
|
throw new HTTPException(Status.UNAUTHORIZED, e.getMessage() != null ? e.getMessage() : "Permission denied.");
|
||||||
|
} catch(GuacamoleClientException e) {
|
||||||
|
throw new HTTPException(Status.BAD_REQUEST, e.getMessage() != null ? e.getMessage() : "Invalid Request.");
|
||||||
} catch(GuacamoleException e) {
|
} catch(GuacamoleException e) {
|
||||||
logger.error("Unexpected GuacamoleException caught while deleting a connection.", e);
|
logger.error("Unexpected GuacamoleException caught moving connection.", e);
|
||||||
throw new HTTPException(Status.INTERNAL_SERVER_ERROR,
|
throw new HTTPException(Status.INTERNAL_SERVER_ERROR, e.getMessage() != null ? e.getMessage() : "Unexpected server error.");
|
||||||
"Unexpected server error. " + e.getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user