use of org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException in project scheduling by ow2-proactive.
the class SchedulerRestClient method delete.
public boolean delete(String sessionId, String dataspacePath, String path, List<String> includes, List<String> excludes) throws Exception {
StringBuffer uriTmpl = (new StringBuffer()).append(restEndpointURL).append(addSlashIfMissing(restEndpointURL)).append("data/").append(dataspacePath).append('/');
ResteasyClient client = new ResteasyClientBuilder().httpEngine(httpEngine).providerFactory(providerFactory).build();
ResteasyWebTarget target = client.target(uriTmpl.toString()).path(path);
if (includes != null && !includes.isEmpty()) {
target = target.queryParam("includes", includes.toArray(new Object[includes.size()]));
}
if (excludes != null && !excludes.isEmpty()) {
target = target.queryParam("excludes", excludes.toArray(new Object[excludes.size()]));
}
Response response = null;
try {
response = target.request().header("sessionid", sessionId).delete();
if (response.getStatus() != HttpURLConnection.HTTP_NO_CONTENT) {
if (response.getStatus() == HttpURLConnection.HTTP_UNAUTHORIZED) {
throw new NotConnectedRestException("User not authenticated or session timeout.");
} else {
throwException(String.format("Cannot delete file(s). Status code: %s", response.getStatus()), response);
}
}
return true;
} finally {
if (response != null) {
response.close();
}
}
}
use of org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException in project scheduling by ow2-proactive.
the class SchedulerRestClient method upload.
public boolean upload(String sessionId, File file, List<String> includes, List<String> excludes, String dataspacePath, final String path) throws Exception {
StringBuffer uriTmpl = (new StringBuffer()).append(restEndpointURL).append(addSlashIfMissing(restEndpointURL)).append("data/").append(dataspacePath).append('/').append(escapeUrlPathSegment(path));
ResteasyClient client = new ResteasyClientBuilder().httpEngine(httpEngine).providerFactory(providerFactory).build();
ResteasyWebTarget target = client.target(uriTmpl.toString());
Response response = null;
try {
response = target.request().header("sessionid", sessionId).put(Entity.entity(new CompressedStreamingOutput(file, includes, excludes), new Variant(MediaType.APPLICATION_OCTET_STREAM_TYPE, (Locale) null, encoding(file))));
if (response.getStatus() != HttpURLConnection.HTTP_CREATED) {
if (response.getStatus() == HttpURLConnection.HTTP_UNAUTHORIZED) {
throw new NotConnectedRestException("User not authenticated or session timeout.");
} else {
throwException(String.format("File upload failed. Status code: %d", response.getStatus()), response);
}
}
return true;
} finally {
if (response != null) {
response.close();
}
}
}
use of org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException in project scheduling by ow2-proactive.
the class AbstractCommand method handleError.
@SuppressWarnings("unchecked")
protected void handleError(String errorMessage, Exception error, ApplicationContext currentContext) {
Stack resultStack = resultStack(currentContext);
resultStack.push(error);
if (error instanceof NotConnectedRestException) {
throw new CLIException(REASON_UNAUTHORIZED_ACCESS, errorMessage, error);
}
writeLine(currentContext, errorMessage);
Throwable cause = error.getCause();
String message = error.getMessage();
if (cause != null) {
message = cause.getMessage();
}
writeLine(currentContext, "Error message: %s", message);
if (isDebugModeEnabled(currentContext)) {
writeLine(currentContext, "Stack trace: %s", getStackTraceAsString((cause == null) ? error : cause));
} else {
writeDebugModeUsage(currentContext);
}
}
Aggregations