mirror of https://github.com/apache/jclouds.git
issue #1107: remove special casing of bucketExists relating to HEAD vs GET
This commit is contained in:
parent
ff1fb6c1f6
commit
34156ca090
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -181,7 +181,7 @@ public abstract class S3AsyncClientTest<T extends S3AsyncClient> 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);
|
||||
|
||||
|
|
|
@ -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.<String, String> 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());
|
||||
|
|
|
@ -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.<Class<? extends Module>>of(WalrusRestClientModule.class, S3BlobStoreContextModule.class));
|
||||
.defaultModules(ImmutableSet.<Class<? extends Module>>of(S3RestClientModule.class, S3BlobStoreContextModule.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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<Boolean> bucketExists(
|
||||
@Bucket @BinderParam(BindAsHostPrefixIfConfigured.class) @ParamValidators(BucketNameValidator.class) String bucketName);
|
||||
|
||||
}
|
|
@ -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<S3Client, WalrusAsyncClient> {
|
||||
public WalrusRestClientModule() {
|
||||
super(TypeToken.of(S3Client.class), TypeToken.of(WalrusAsyncClient.class));
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
S3AsyncClient provideS3AsyncClient(WalrusAsyncClient in) {
|
||||
return in;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue