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 java.util.concurrent.TimeoutException;
import org.jclouds.aws.AWSResponseException; import org.jclouds.aws.AWSResponseException;
import org.jclouds.http.HttpResponseException;
import org.jclouds.http.commands.callables.ReturnTrueIf2xx; import org.jclouds.http.commands.callables.ReturnTrueIf2xx;
import com.google.common.annotations.VisibleForTesting; 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.AWSResponseException;
import org.jclouds.aws.s3.domain.AccessControlList; import org.jclouds.aws.s3.domain.AccessControlList;
import org.jclouds.http.HttpResponseException;
import org.jclouds.http.commands.callables.xml.ParseSax; import org.jclouds.http.commands.callables.xml.ParseSax;
import com.google.common.annotations.VisibleForTesting; 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 @VisibleForTesting
S3Bucket attemptNotFound(ExecutionException e) throws ExecutionException { S3Bucket attemptNotFound(ExecutionException e) throws ExecutionException {
if (e.getCause() != null && e.getCause() instanceof AWSResponseException) { if (e.getCause() != null && e.getCause() instanceof AWSResponseException) {

View File

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