mirror of
https://github.com/apache/jclouds.git
synced 2025-02-16 15:08:28 +00:00
slicehost fixes
This commit is contained in:
parent
89e7fd6092
commit
b1b29ec222
@ -38,6 +38,7 @@ import org.jclouds.rest.annotations.SkipEncoding;
|
|||||||
import org.jclouds.rest.annotations.XMLResponseParser;
|
import org.jclouds.rest.annotations.XMLResponseParser;
|
||||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||||
|
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
|
||||||
import org.jclouds.slicehost.binders.BindCreateSliceToXmlPayload;
|
import org.jclouds.slicehost.binders.BindCreateSliceToXmlPayload;
|
||||||
import org.jclouds.slicehost.domain.Backup;
|
import org.jclouds.slicehost.domain.Backup;
|
||||||
import org.jclouds.slicehost.domain.Flavor;
|
import org.jclouds.slicehost.domain.Flavor;
|
||||||
@ -92,6 +93,7 @@ public interface SlicehostAsyncClient {
|
|||||||
* @see SlicehostClient#destroySlice
|
* @see SlicehostClient#destroySlice
|
||||||
*/
|
*/
|
||||||
@DELETE
|
@DELETE
|
||||||
|
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
|
||||||
@Path("/slices/{id}/destroy.xml")
|
@Path("/slices/{id}/destroy.xml")
|
||||||
ListenableFuture<Void> destroySlice(@PathParam("id") int id);
|
ListenableFuture<Void> destroySlice(@PathParam("id") int id);
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ package org.jclouds.slicehost.handlers;
|
|||||||
|
|
||||||
import static org.jclouds.http.HttpUtils.releasePayload;
|
import static org.jclouds.http.HttpUtils.releasePayload;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@ -41,6 +42,7 @@ import org.jclouds.logging.Logger;
|
|||||||
import org.jclouds.rest.AuthorizationException;
|
import org.jclouds.rest.AuthorizationException;
|
||||||
import org.jclouds.rest.ResourceNotFoundException;
|
import org.jclouds.rest.ResourceNotFoundException;
|
||||||
import org.jclouds.slicehost.xml.ErrorHandler;
|
import org.jclouds.slicehost.xml.ErrorHandler;
|
||||||
|
import org.jclouds.util.Strings2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This will parse and set an appropriate exception on the command object.
|
* This will parse and set an appropriate exception on the command object.
|
||||||
@ -67,28 +69,28 @@ public class ParseSlicehostErrorFromHttpResponse implements HttpErrorHandler {
|
|||||||
String content = response.getStatusCode() != 401 ? parseErrorFromContentOrNull(command, response) : null;
|
String content = response.getStatusCode() != 401 ? parseErrorFromContentOrNull(command, response) : null;
|
||||||
exception = content != null ? new HttpResponseException(command, response, content) : exception;
|
exception = content != null ? new HttpResponseException(command, response, content) : exception;
|
||||||
switch (response.getStatusCode()) {
|
switch (response.getStatusCode()) {
|
||||||
case 401:
|
case 401:
|
||||||
exception = new AuthorizationException(exception.getMessage(), exception);
|
exception = new AuthorizationException(exception.getMessage(), exception);
|
||||||
break;
|
break;
|
||||||
case 403:
|
case 403:
|
||||||
case 404:
|
case 404:
|
||||||
if (!command.getCurrentRequest().getMethod().equals("DELETE")) {
|
if (!command.getCurrentRequest().getMethod().equals("DELETE")) {
|
||||||
String path = command.getCurrentRequest().getEndpoint().getPath();
|
String path = command.getCurrentRequest().getEndpoint().getPath();
|
||||||
Matcher matcher = RESOURCE_PATTERN.matcher(path);
|
Matcher matcher = RESOURCE_PATTERN.matcher(path);
|
||||||
String message;
|
String message;
|
||||||
if (matcher.find()) {
|
if (matcher.find()) {
|
||||||
message = String.format("%s %s not found", matcher.group(1), matcher.group(2));
|
message = String.format("%s %s not found", matcher.group(1), matcher.group(2));
|
||||||
} else {
|
} else {
|
||||||
message = path;
|
message = path;
|
||||||
|
}
|
||||||
|
exception = new ResourceNotFoundException(message);
|
||||||
}
|
}
|
||||||
exception = new ResourceNotFoundException(message);
|
break;
|
||||||
}
|
case 422:
|
||||||
break;
|
exception = new IllegalStateException(content);
|
||||||
case 422:
|
break;
|
||||||
exception = new IllegalStateException(content);
|
default:
|
||||||
break;
|
exception = new HttpResponseException(command, response, content);
|
||||||
default:
|
|
||||||
exception = new HttpResponseException(command, response, content);
|
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
releasePayload(response);
|
releasePayload(response);
|
||||||
@ -124,8 +126,18 @@ public class ParseSlicehostErrorFromHttpResponse implements HttpErrorHandler {
|
|||||||
|
|
||||||
String parseErrorFromContentOrNull(HttpCommand command, HttpResponse response) {
|
String parseErrorFromContentOrNull(HttpCommand command, HttpResponse response) {
|
||||||
// slicehost returns " " which is unparsable
|
// slicehost returns " " which is unparsable
|
||||||
if (response.getPayload() != null && response.getPayload().getContentMetadata().getContentLength() != 1) {
|
if (response.getPayload() != null) {
|
||||||
return errorParser.parse(response.getPayload());
|
String contentType = response.getPayload().getContentMetadata().getContentType();
|
||||||
|
if (response.getPayload().getContentMetadata().getContentLength() != 1) {
|
||||||
|
response.getPayload().release();
|
||||||
|
} else if (contentType != null && contentType.indexOf("xml") != -1) {
|
||||||
|
return errorParser.parse(response.getPayload());
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
return Strings2.toStringAndClose(response.getPayload().getInput());
|
||||||
|
} catch (IOException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@ import org.jclouds.rest.RestContextFactory;
|
|||||||
import org.jclouds.rest.RestContextSpec;
|
import org.jclouds.rest.RestContextSpec;
|
||||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||||
|
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
|
||||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||||
import org.jclouds.slicehost.filters.SlicehostBasic;
|
import org.jclouds.slicehost.filters.SlicehostBasic;
|
||||||
import org.jclouds.slicehost.xml.FlavorHandler;
|
import org.jclouds.slicehost.xml.FlavorHandler;
|
||||||
@ -83,7 +84,7 @@ public class SlicehostAsyncClientTest extends RestClientTest<SlicehostAsyncClien
|
|||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
|
||||||
|
|
||||||
checkFilters(request);
|
checkFilters(request);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user