diff --git a/apis/s3/src/main/java/org/jclouds/s3/S3AsyncClient.java b/apis/s3/src/main/java/org/jclouds/s3/S3AsyncClient.java index 951f0196d2..e79e83f856 100644 --- a/apis/s3/src/main/java/org/jclouds/s3/S3AsyncClient.java +++ b/apis/s3/src/main/java/org/jclouds/s3/S3AsyncClient.java @@ -201,7 +201,7 @@ public interface S3AsyncClient { * @see S3Client#bucketExists */ @Named("s3:ListBucket") - @HEAD + @GET @Path("/") @QueryParams(keys = "max-keys", values = "0") @Fallback(FalseOnContainerNotFound.class) diff --git a/apis/s3/src/main/java/org/jclouds/s3/handlers/S3RedirectionRetryHandler.java b/apis/s3/src/main/java/org/jclouds/s3/handlers/S3RedirectionRetryHandler.java index 1d74731085..343dd9a8be 100644 --- a/apis/s3/src/main/java/org/jclouds/s3/handlers/S3RedirectionRetryHandler.java +++ b/apis/s3/src/main/java/org/jclouds/s3/handlers/S3RedirectionRetryHandler.java @@ -25,7 +25,6 @@ import java.net.URI; import javax.inject.Inject; import javax.inject.Singleton; -import javax.ws.rs.HttpMethod; import javax.ws.rs.core.HttpHeaders; import org.jclouds.aws.domain.AWSError; @@ -54,28 +53,22 @@ public class S3RedirectionRetryHandler extends RedirectionRetryHandler { public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) { if (response.getFirstHeaderOrNull(HttpHeaders.LOCATION) == null && (response.getStatusCode() == 301 || response.getStatusCode() == 307)) { - if (command.getCurrentRequest().getMethod().equals(HttpMethod.HEAD)) { - command.incrementRedirectCount(); - command.setCurrentRequest(command.getCurrentRequest().toBuilder().method("GET").build()); + command.incrementRedirectCount(); + closeClientButKeepContentStream(response); + AWSError error = utils.parseAWSErrorFromContent(command.getCurrentRequest(), response); + String host = error.getDetails().get("Endpoint"); + if (host != null) { + if (host.equals(command.getCurrentRequest().getEndpoint().getHost())) { + // must be an amazon error related to + // http://developer.amazonwebservices.com/connect/thread.jspa?messageID=72287𑩟 + return backoffHandler.shouldRetryRequest(command, response); + } else { + URI newHost = uriBuilder(command.getCurrentRequest().getEndpoint()).host(host).build(); + command.setCurrentRequest(command.getCurrentRequest().toBuilder().endpoint(newHost).build()); + } return true; } else { - command.incrementRedirectCount(); - closeClientButKeepContentStream(response); - AWSError error = utils.parseAWSErrorFromContent(command.getCurrentRequest(), response); - String host = error.getDetails().get("Endpoint"); - if (host != null) { - if (host.equals(command.getCurrentRequest().getEndpoint().getHost())) { - // must be an amazon error related to - // http://developer.amazonwebservices.com/connect/thread.jspa?messageID=72287𑩟 - return backoffHandler.shouldRetryRequest(command, response); - } else { - URI newHost = uriBuilder(command.getCurrentRequest().getEndpoint()).host(host).build(); - command.setCurrentRequest(command.getCurrentRequest().toBuilder().endpoint(newHost).build()); - } - return true; - } else { - return false; - } + return false; } } else { return super.shouldRetryRequest(command, response); diff --git a/apis/s3/src/test/java/org/jclouds/s3/PathBasedS3ClientExpectTest.java b/apis/s3/src/test/java/org/jclouds/s3/PathBasedS3ClientExpectTest.java index 7de2db9fc5..e637d29ccf 100644 --- a/apis/s3/src/test/java/org/jclouds/s3/PathBasedS3ClientExpectTest.java +++ b/apis/s3/src/test/java/org/jclouds/s3/PathBasedS3ClientExpectTest.java @@ -48,10 +48,10 @@ public class PathBasedS3ClientExpectTest extends BaseS3ClientExpectTest { @Test public void testBucketExistsReturnsTrueOn200AndFalseOn404() { - HttpRequest bucketFooExists = HttpRequest.builder().method("HEAD") + HttpRequest bucketFooExists = HttpRequest.builder().method("GET") .endpoint("https://s3.amazonaws.com/foo?max-keys=0") .addHeader("Date", CONSTANT_DATE) - .addHeader("Authorization", "AWS identity:lLD0mzo2bZPIWhxlFDZoT09MKUQ=") + .addHeader("Authorization", "AWS identity:p32RsBr2inawMBeCkkiA228BT2w=") .build(); S3Client clientWhenBucketExists = requestSendsResponse(bucketFooExists, HttpResponse.builder().statusCode(200).build()); diff --git a/apis/s3/src/test/java/org/jclouds/s3/S3AsyncClientTest.java b/apis/s3/src/test/java/org/jclouds/s3/S3AsyncClientTest.java index 29c4cbe4fe..9372088ef2 100644 --- a/apis/s3/src/test/java/org/jclouds/s3/S3AsyncClientTest.java +++ b/apis/s3/src/test/java/org/jclouds/s3/S3AsyncClientTest.java @@ -181,7 +181,7 @@ public abstract class S3AsyncClientTest extends BaseS3A Method method = S3AsyncClient.class.getMethod("bucketExists", String.class); HttpRequest request = processor.createRequest(method, "bucket"); - assertRequestLineEquals(request, "HEAD https://bucket." + url + "/?max-keys=0 HTTP/1.1"); + assertRequestLineEquals(request, "GET https://bucket." + url + "/?max-keys=0 HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Host: bucket." + url + "\n"); assertPayloadEquals(request, null, null, false); diff --git a/apis/s3/src/test/java/org/jclouds/s3/S3ClientExpectTest.java b/apis/s3/src/test/java/org/jclouds/s3/S3ClientExpectTest.java index 7109ecb1df..c4053d060a 100644 --- a/apis/s3/src/test/java/org/jclouds/s3/S3ClientExpectTest.java +++ b/apis/s3/src/test/java/org/jclouds/s3/S3ClientExpectTest.java @@ -37,12 +37,12 @@ public class S3ClientExpectTest extends BaseS3ClientExpectTest { @Test public void testBucketExistsReturnsTrueOn200AndFalseOn404() { - HttpRequest bucketFooExists = HttpRequest.builder().method("HEAD").endpoint( + HttpRequest bucketFooExists = HttpRequest.builder().method("GET").endpoint( URI.create("https://foo.s3.amazonaws.com/?max-keys=0")).headers( ImmutableMultimap. builder() .put("Host", "foo.s3.amazonaws.com") .put("Date", CONSTANT_DATE) - .put("Authorization", "AWS identity:86P4BBb7xT+gBqq7jxM8Tc28ktY=") + .put("Authorization", "AWS identity:ZWVz2v/jGB+ZMmijoyfH9mFMPo0=") .build()).build(); S3Client clientWhenBucketExists = requestSendsResponse(bucketFooExists, HttpResponse.builder().statusCode(200).build()); diff --git a/apis/walrus/src/main/java/org/jclouds/walrus/WalrusApiMetadata.java b/apis/walrus/src/main/java/org/jclouds/walrus/WalrusApiMetadata.java index 84b25cfdbe..fc994c3b9e 100644 --- a/apis/walrus/src/main/java/org/jclouds/walrus/WalrusApiMetadata.java +++ b/apis/walrus/src/main/java/org/jclouds/walrus/WalrusApiMetadata.java @@ -28,7 +28,7 @@ import org.jclouds.s3.S3ApiMetadata; import org.jclouds.s3.S3AsyncClient; import org.jclouds.s3.S3Client; import org.jclouds.s3.blobstore.config.S3BlobStoreContextModule; -import org.jclouds.walrus.config.WalrusRestClientModule; +import org.jclouds.s3.config.S3RestClientModule; import com.google.common.collect.ImmutableSet; import com.google.inject.Module; @@ -71,7 +71,7 @@ public class WalrusApiMetadata extends S3ApiMetadata { .name("Walrus (S3 clone) API") .version("Walrus-1.6") .defaultProperties(WalrusApiMetadata.defaultProperties()) - .defaultModules(ImmutableSet.>of(WalrusRestClientModule.class, S3BlobStoreContextModule.class)); + .defaultModules(ImmutableSet.>of(S3RestClientModule.class, S3BlobStoreContextModule.class)); } @Override diff --git a/apis/walrus/src/main/java/org/jclouds/walrus/WalrusAsyncClient.java b/apis/walrus/src/main/java/org/jclouds/walrus/WalrusAsyncClient.java deleted file mode 100644 index 54dc55303a..0000000000 --- a/apis/walrus/src/main/java/org/jclouds/walrus/WalrusAsyncClient.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.walrus; - -import static org.jclouds.blobstore.attr.BlobScopes.CONTAINER; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; - -import org.jclouds.blobstore.BlobStoreFallbacks.FalseOnContainerNotFound; -import org.jclouds.blobstore.attr.BlobScope; -import org.jclouds.rest.annotations.BinderParam; -import org.jclouds.rest.annotations.Endpoint; -import org.jclouds.rest.annotations.Fallback; -import org.jclouds.rest.annotations.ParamValidators; -import org.jclouds.rest.annotations.QueryParams; -import org.jclouds.rest.annotations.RequestFilters; -import org.jclouds.s3.Bucket; -import org.jclouds.s3.S3AsyncClient; -import org.jclouds.s3.S3Client; -import org.jclouds.s3.binders.BindAsHostPrefixIfConfigured; -import org.jclouds.s3.filters.RequestAuthorizeSignature; -import org.jclouds.s3.predicates.validators.BucketNameValidator; - -import com.google.common.util.concurrent.ListenableFuture; - -/** - * - * @author Adrian Cole - */ -@RequestFilters(RequestAuthorizeSignature.class) -@BlobScope(CONTAINER) -public interface WalrusAsyncClient extends S3AsyncClient { - - /** - * @see S3Client#bucketExists - */ - @Override - @GET - @Path("/") - @Endpoint(Bucket.class) - @QueryParams(keys = "max-keys", values = "0") - @Fallback(FalseOnContainerNotFound.class) - ListenableFuture bucketExists( - @Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators(BucketNameValidator.class) String bucketName); - -} diff --git a/apis/walrus/src/main/java/org/jclouds/walrus/config/WalrusRestClientModule.java b/apis/walrus/src/main/java/org/jclouds/walrus/config/WalrusRestClientModule.java deleted file mode 100644 index b5c75f3f37..0000000000 --- a/apis/walrus/src/main/java/org/jclouds/walrus/config/WalrusRestClientModule.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.walrus.config; - -import javax.inject.Singleton; - -import org.jclouds.rest.ConfiguresRestClient; -import org.jclouds.s3.S3AsyncClient; -import org.jclouds.s3.S3Client; -import org.jclouds.s3.config.S3RestClientModule; -import org.jclouds.walrus.WalrusAsyncClient; - -import com.google.common.reflect.TypeToken; -import com.google.inject.Provides; - -/** - * - * @author Adrian Cole - */ -@ConfiguresRestClient -public class WalrusRestClientModule extends S3RestClientModule { - public WalrusRestClientModule() { - super(TypeToken.of(S3Client.class), TypeToken.of(WalrusAsyncClient.class)); - } - - @Provides - @Singleton - S3AsyncClient provideS3AsyncClient(WalrusAsyncClient in) { - return in; - } - -}