git-svn-id: http://jclouds.googlecode.com/svn/trunk@1416 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-06-11 15:43:10 +00:00
parent d806a056ff
commit 818489e9a3
4 changed files with 40 additions and 42 deletions

View File

@ -28,7 +28,6 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.jclouds.aws.AWSResponseException;
import org.jclouds.http.HttpResponseException;
import org.jclouds.http.commands.callables.ReturnTrueIf2xx;
import com.google.common.annotations.VisibleForTesting;

View File

@ -29,7 +29,6 @@ import java.util.concurrent.TimeoutException;
import org.jclouds.aws.AWSResponseException;
import org.jclouds.aws.s3.domain.AccessControlList;
import org.jclouds.http.HttpResponseException;
import org.jclouds.http.commands.callables.xml.ParseSax;
import com.google.common.annotations.VisibleForTesting;

View File

@ -72,6 +72,12 @@ public class ListBucket extends S3FutureCommand<S3Bucket> {
}
}
/**
* {@code bucketParser} is only enacted when the http status code is 2xx. Amazon treats
* NoSuchBucket as an exception, while we regard this as a valid response. Accordingly, we check
* for this {@code NoSuchBucket} message and return {@code S3Bucket#NOT_FOUND} if present.
*
*/
@VisibleForTesting
S3Bucket attemptNotFound(ExecutionException e) throws ExecutionException {
if (e.getCause() != null && e.getCause() instanceof AWSResponseException) {

View File

@ -32,56 +32,50 @@ import org.jclouds.command.FutureCommand;
import org.jclouds.logging.Logger;
/**
* // TODO: Adrian: Document this!
* HttpFutureCommand associates a request with a {@link ResponseCallable response parser} which
* extracts the result object specified as generic type <code>T</code> from the HttpResponse.
*
* @author Adrian Cole
*/
public class HttpFutureCommand<T> extends
FutureCommand<HttpRequest, HttpResponse, T> {
public class HttpFutureCommand<T> extends FutureCommand<HttpRequest, HttpResponse, T> {
public HttpFutureCommand(String method, String uri,
ResponseCallable<T> responseCallable) {
super(new HttpRequest(checkNotNull(method, "method"), checkNotNull(uri,
"uri")), responseCallable);
}
public HttpFutureCommand(String method, String uri, ResponseCallable<T> responseCallable) {
super(new HttpRequest(checkNotNull(method, "method"), checkNotNull(uri, "uri")),
responseCallable);
}
protected void addHostHeader(String host) {
getRequest().getHeaders().put("Host", host);
}
protected void addHostHeader(String host) {
getRequest().getHeaders().put("Host", host);
}
@Override
public String toString() {
return this.getClass().getName() + "{" + "request=" + this.getRequest()
+ "," + "responseFuture=" + this.getResponseFuture() + '}';
}
@Override
public String toString() {
return this.getClass().getName() + "{" + "request=" + this.getRequest() + ","
+ "responseFuture=" + this.getResponseFuture() + '}';
}
/**
* // TODO: Adrian: Document this!
*
* @author Adrian Cole
*/
public abstract static class ResponseCallable<T> implements
FutureCommand.ResponseCallable<HttpResponse, T> {
@Resource
protected Logger logger = Logger.NULL;
public abstract static class ResponseCallable<T> implements
FutureCommand.ResponseCallable<HttpResponse, T> {
@Resource
protected Logger logger = Logger.NULL;
public void checkCode() {
int code = getResponse().getStatusCode();
if (code >= 300){
IOUtils.closeQuietly(getResponse().getContent());
throw new IllegalStateException("incorrect code for this operation: "+getResponse());
}
}
public void checkCode() {
int code = getResponse().getStatusCode();
if (code >= 300) {
IOUtils.closeQuietly(getResponse().getContent());
throw new IllegalStateException("incorrect code for this operation: " + getResponse());
}
}
private HttpResponse response;
private HttpResponse response;
public HttpResponse getResponse() {
return response;
}
public HttpResponse getResponse() {
return response;
}
public void setResponse(HttpResponse response) {
this.response = response;
}
}
public void setResponse(HttpResponse response) {
this.response = response;
}
}
}