diff --git a/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosBlobRequestSigner.java b/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosBlobRequestSigner.java index 26d3540b0f..9a21e4e501 100644 --- a/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosBlobRequestSigner.java +++ b/apis/atmos/src/main/java/org/jclouds/atmos/blobstore/AtmosBlobRequestSigner.java @@ -32,6 +32,7 @@ import org.jclouds.atmos.blobstore.functions.BlobToObject; import org.jclouds.atmos.domain.AtmosObject; import org.jclouds.blobstore.BlobRequestSigner; import org.jclouds.blobstore.domain.Blob; +import org.jclouds.blobstore.functions.BlobToHttpGetOptions; import org.jclouds.http.HttpRequest; import org.jclouds.http.options.GetOptions; import org.jclouds.rest.internal.RestAnnotationProcessor; @@ -44,19 +45,21 @@ import org.jclouds.rest.internal.RestAnnotationProcessor; public class AtmosBlobRequestSigner implements BlobRequestSigner { private final RestAnnotationProcessor processor; private final BlobToObject blobToObject; + private final BlobToHttpGetOptions blob2ObjectGetOptions; + private final Method getMethod; private final Method deleteMethod; private final Method createMethod; @Inject - public AtmosBlobRequestSigner(RestAnnotationProcessor processor, BlobToObject blobToObject) - throws SecurityException, NoSuchMethodException { + public AtmosBlobRequestSigner(RestAnnotationProcessor processor, BlobToObject blobToObject, + BlobToHttpGetOptions blob2ObjectGetOptions) throws SecurityException, NoSuchMethodException { this.processor = checkNotNull(processor, "processor"); this.blobToObject = checkNotNull(blobToObject, "blobToObject"); + this.blob2ObjectGetOptions = checkNotNull(blob2ObjectGetOptions, "blob2ObjectGetOptions"); this.getMethod = AtmosAsyncClient.class.getMethod("readFile", String.class, GetOptions[].class); this.deleteMethod = AtmosAsyncClient.class.getMethod("deletePath", String.class); this.createMethod = AtmosAsyncClient.class.getMethod("createFile", String.class, AtmosObject.class); - } @Override @@ -78,4 +81,10 @@ public class AtmosBlobRequestSigner implements BlobRequestSigner { return checkNotNull(container, "container") + "/" + checkNotNull(name, "name"); } + @Override + public HttpRequest signGetBlob(String container, String name, org.jclouds.blobstore.options.GetOptions options) { + return cleanRequest(processor.createRequest(getMethod, getPath(container, name), blob2ObjectGetOptions + .apply(options))); + } + } diff --git a/apis/s3/src/main/java/org/jclouds/s3/blobstore/S3BlobRequestSigner.java b/apis/s3/src/main/java/org/jclouds/s3/blobstore/S3BlobRequestSigner.java index 1d075910d2..7716a94e2f 100644 --- a/apis/s3/src/main/java/org/jclouds/s3/blobstore/S3BlobRequestSigner.java +++ b/apis/s3/src/main/java/org/jclouds/s3/blobstore/S3BlobRequestSigner.java @@ -27,15 +27,16 @@ import java.lang.reflect.Method; import javax.inject.Inject; import javax.inject.Singleton; +import org.jclouds.blobstore.BlobRequestSigner; +import org.jclouds.blobstore.domain.Blob; +import org.jclouds.blobstore.functions.BlobToHttpGetOptions; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.options.GetOptions; +import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.s3.S3AsyncClient; import org.jclouds.s3.blobstore.functions.BlobToObject; import org.jclouds.s3.domain.S3Object; import org.jclouds.s3.options.PutObjectOptions; -import org.jclouds.blobstore.BlobRequestSigner; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.http.HttpRequest; -import org.jclouds.http.options.GetOptions; -import org.jclouds.rest.internal.RestAnnotationProcessor; /** * @@ -45,15 +46,18 @@ import org.jclouds.rest.internal.RestAnnotationProcessor; public class S3BlobRequestSigner implements BlobRequestSigner { private final RestAnnotationProcessor processor; private final BlobToObject blobToObject; + private final BlobToHttpGetOptions blob2HttpGetOptions; + private final Method getMethod; private final Method deleteMethod; private final Method createMethod; @Inject - public S3BlobRequestSigner(RestAnnotationProcessor processor, BlobToObject blobToObject) - throws SecurityException, NoSuchMethodException { + public S3BlobRequestSigner(RestAnnotationProcessor processor, BlobToObject blobToObject, + BlobToHttpGetOptions blob2HttpGetOptions) throws SecurityException, NoSuchMethodException { this.processor = checkNotNull(processor, "processor"); this.blobToObject = checkNotNull(blobToObject, "blobToObject"); + this.blob2HttpGetOptions = checkNotNull(blob2HttpGetOptions, "blob2HttpGetOptions"); this.getMethod = S3AsyncClient.class.getMethod("getObject", String.class, String.class, GetOptions[].class); this.deleteMethod = S3AsyncClient.class.getMethod("deleteObject", String.class, String.class); this.createMethod = S3AsyncClient.class.getMethod("putObject", String.class, S3Object.class, @@ -76,4 +80,8 @@ public class S3BlobRequestSigner implements BlobRequestSigner { return cleanRequest(processor.createRequest(deleteMethod, container, name)); } + @Override + public HttpRequest signGetBlob(String container, String name, org.jclouds.blobstore.options.GetOptions options) { + return cleanRequest(processor.createRequest(getMethod, container, name, blob2HttpGetOptions.apply(options))); + } } diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/SwiftBlobRequestSigner.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/SwiftBlobRequestSigner.java index 2046f015fd..8cc702ce52 100644 --- a/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/SwiftBlobRequestSigner.java +++ b/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/SwiftBlobRequestSigner.java @@ -29,6 +29,7 @@ import javax.inject.Singleton; import org.jclouds.blobstore.BlobRequestSigner; import org.jclouds.blobstore.domain.Blob; +import org.jclouds.blobstore.functions.BlobToHttpGetOptions; import org.jclouds.http.HttpRequest; import org.jclouds.http.options.GetOptions; import org.jclouds.openstack.swift.CommonSwiftAsyncClient; @@ -44,16 +45,20 @@ import org.jclouds.rest.internal.RestAnnotationProcessor; public class SwiftBlobRequestSigner implements BlobRequestSigner { private final RestAnnotationProcessor processor; private final BlobToObject blobToObject; + private final BlobToHttpGetOptions blob2HttpGetOptions; + private final Method getMethod; private final Method deleteMethod; private final Method createMethod; @Inject - public SwiftBlobRequestSigner(RestAnnotationProcessor processor, BlobToObject blobToObject) - throws SecurityException, NoSuchMethodException { + public SwiftBlobRequestSigner(RestAnnotationProcessor processor, BlobToObject blobToObject, + BlobToHttpGetOptions blob2HttpGetOptions) throws SecurityException, NoSuchMethodException { this.processor = checkNotNull(processor, "processor"); this.blobToObject = checkNotNull(blobToObject, "blobToObject"); - this.getMethod = CommonSwiftAsyncClient.class.getMethod("getObject", String.class, String.class, GetOptions[].class); + this.blob2HttpGetOptions = checkNotNull(blob2HttpGetOptions, "blob2HttpGetOptions"); + this.getMethod = CommonSwiftAsyncClient.class.getMethod("getObject", String.class, String.class, + GetOptions[].class); this.deleteMethod = CommonSwiftAsyncClient.class.getMethod("removeObject", String.class, String.class); this.createMethod = CommonSwiftAsyncClient.class.getMethod("putObject", String.class, SwiftObject.class); @@ -74,4 +79,8 @@ public class SwiftBlobRequestSigner implements BlobRequestSigner { return cleanRequest(processor.createRequest(deleteMethod, container, name)); } + @Override + public HttpRequest signGetBlob(String container, String name, org.jclouds.blobstore.options.GetOptions options) { + return cleanRequest(processor.createRequest(getMethod, container, name, blob2HttpGetOptions.apply(options))); + } } diff --git a/blobstore/src/main/java/org/jclouds/blobstore/BlobRequestSigner.java b/blobstore/src/main/java/org/jclouds/blobstore/BlobRequestSigner.java index 655d15c38c..6f52d43a93 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/BlobRequestSigner.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/BlobRequestSigner.java @@ -22,6 +22,7 @@ package org.jclouds.blobstore; import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.BlobBuilder; import org.jclouds.blobstore.internal.RequestSigningUnsupported; +import org.jclouds.blobstore.options.GetOptions; import org.jclouds.http.HttpRequest; import com.google.inject.ImplementedBy; @@ -47,6 +48,12 @@ public interface BlobRequestSigner { */ HttpRequest signGetBlob(String container, String name); + /** + * @param options + * @see #signGetBlob(String, String) + */ + HttpRequest signGetBlob(String container, String name, GetOptions options); + /** * gets a signed request, including headers as necessary, to delete a blob from an external * client. diff --git a/blobstore/src/main/java/org/jclouds/blobstore/TransientBlobRequestSigner.java b/blobstore/src/main/java/org/jclouds/blobstore/TransientBlobRequestSigner.java index 52ebc4fcc0..7a6e19be5c 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/TransientBlobRequestSigner.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/TransientBlobRequestSigner.java @@ -27,6 +27,8 @@ import javax.inject.Inject; import javax.inject.Singleton; import org.jclouds.blobstore.domain.Blob; +import org.jclouds.blobstore.functions.BlobToHttpGetOptions; +import org.jclouds.blobstore.options.GetOptions; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpUtils; import org.jclouds.http.filters.BasicAuthentication; @@ -39,10 +41,12 @@ import org.jclouds.http.filters.BasicAuthentication; public class TransientBlobRequestSigner implements BlobRequestSigner { private final BasicAuthentication basicAuth; + private final BlobToHttpGetOptions blob2HttpGetOptions; @Inject - public TransientBlobRequestSigner(BasicAuthentication basicAuth) { + public TransientBlobRequestSigner(BasicAuthentication basicAuth, BlobToHttpGetOptions blob2HttpGetOptions) { this.basicAuth = checkNotNull(basicAuth, "basicAuth"); + this.blob2HttpGetOptions = checkNotNull(blob2HttpGetOptions, "blob2HttpGetOptions"); } @Override @@ -53,17 +57,25 @@ public class TransientBlobRequestSigner implements BlobRequestSigner { @Override public HttpRequest signPutBlob(String container, Blob blob) { - HttpRequest request = HttpRequest.builder().method("PUT") - .endpoint(URI.create(String.format("http://localhost/%s/%s", container, blob.getMetadata().getName()))) - .payload(blob.getPayload()) - .headers(HttpUtils.getContentHeadersFromMetadata(blob.getMetadata().getContentMetadata())).build(); + HttpRequest request = HttpRequest.builder().method("PUT").endpoint( + URI.create(String.format("http://localhost/%s/%s", container, blob.getMetadata().getName()))).payload( + blob.getPayload()).headers( + HttpUtils.getContentHeadersFromMetadata(blob.getMetadata().getContentMetadata())).build(); return basicAuth.filter(request); } @Override public HttpRequest signRemoveBlob(String container, String name) { HttpRequest request = new HttpRequest("DELETE", URI.create(String.format("http://localhost/%s/%s", container, - name))); + name))); + return basicAuth.filter(request); + } + + @Override + public HttpRequest signGetBlob(String container, String name, GetOptions options) { + HttpRequest request = HttpRequest.builder().method("GET").endpoint( + URI.create(String.format("http://localhost/%s/%s", container, name))).headers( + blob2HttpGetOptions.apply(options).buildRequestHeaders()).build(); return basicAuth.filter(request); } diff --git a/blobstore/src/main/java/org/jclouds/blobstore/internal/RequestSigningUnsupported.java b/blobstore/src/main/java/org/jclouds/blobstore/internal/RequestSigningUnsupported.java index f455ae1146..320534d6ff 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/internal/RequestSigningUnsupported.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/internal/RequestSigningUnsupported.java @@ -23,6 +23,7 @@ import javax.inject.Singleton; import org.jclouds.blobstore.BlobRequestSigner; import org.jclouds.blobstore.domain.Blob; +import org.jclouds.blobstore.options.GetOptions; import org.jclouds.http.HttpRequest; /** @@ -47,4 +48,9 @@ public class RequestSigningUnsupported implements BlobRequestSigner { throw new UnsupportedOperationException(); } + @Override + public HttpRequest signGetBlob(String container, String name, GetOptions options) { + throw new UnsupportedOperationException(); + } + } diff --git a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobSignerLiveTest.java b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobSignerLiveTest.java index b1604f2bf0..444ed3c830 100644 --- a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobSignerLiveTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobSignerLiveTest.java @@ -19,6 +19,7 @@ package org.jclouds.blobstore.integration.internal; +import static org.jclouds.blobstore.options.GetOptions.Builder.range; import static org.testng.Assert.assertEquals; import org.jclouds.blobstore.domain.Blob; @@ -73,6 +74,24 @@ public class BaseBlobSignerLiveTest extends BaseBlobStoreIntegrationTest { } } + @Test + public void testSignGetUrlOptions() throws Exception { + String name = "hello"; + String text = "fooooooooooooooooooooooo"; + + Blob blob = context.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build(); + String container = getContainerName(); + try { + context.getBlobStore().putBlob(container, blob); + assertConsistencyAwareContainerSize(container, 1); + HttpRequest request = context.getSigner().signGetBlob(container, name, range(0, 1)); + assertEquals(request.getFilters().size(), 0); + assertEquals(Strings2.toStringAndClose(context.utils().http().invoke(request).getPayload().getInput()), "fo"); + } finally { + returnContainer(container); + } + } + @Test public void testSignPutUrl() throws Exception { String name = "hello"; diff --git a/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/AzureBlobRequestSigner.java b/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/AzureBlobRequestSigner.java index 23e21a417c..7731c19139 100644 --- a/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/AzureBlobRequestSigner.java +++ b/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/AzureBlobRequestSigner.java @@ -32,6 +32,7 @@ import org.jclouds.azureblob.blobstore.functions.BlobToAzureBlob; import org.jclouds.azureblob.domain.AzureBlob; import org.jclouds.blobstore.BlobRequestSigner; import org.jclouds.blobstore.domain.Blob; +import org.jclouds.blobstore.functions.BlobToHttpGetOptions; import org.jclouds.http.HttpRequest; import org.jclouds.http.options.GetOptions; import org.jclouds.rest.internal.RestAnnotationProcessor; @@ -44,19 +45,21 @@ import org.jclouds.rest.internal.RestAnnotationProcessor; public class AzureBlobRequestSigner implements BlobRequestSigner { private final RestAnnotationProcessor processor; private final BlobToAzureBlob blobToBlob; + private final BlobToHttpGetOptions blob2HttpGetOptions; + private final Method getMethod; private final Method deleteMethod; private final Method createMethod; @Inject - public AzureBlobRequestSigner(RestAnnotationProcessor processor, BlobToAzureBlob blobToBlob) - throws SecurityException, NoSuchMethodException { + public AzureBlobRequestSigner(RestAnnotationProcessor processor, BlobToAzureBlob blobToBlob, + BlobToHttpGetOptions blob2HttpGetOptions) throws SecurityException, NoSuchMethodException { this.processor = checkNotNull(processor, "processor"); this.blobToBlob = checkNotNull(blobToBlob, "blobToBlob"); + this.blob2HttpGetOptions = checkNotNull(blob2HttpGetOptions, "blob2HttpGetOptions"); this.getMethod = AzureBlobAsyncClient.class.getMethod("getBlob", String.class, String.class, GetOptions[].class); this.deleteMethod = AzureBlobAsyncClient.class.getMethod("deleteBlob", String.class, String.class); this.createMethod = AzureBlobAsyncClient.class.getMethod("putBlob", String.class, AzureBlob.class); - } @Override @@ -74,4 +77,8 @@ public class AzureBlobRequestSigner implements BlobRequestSigner { return cleanRequest(processor.createRequest(deleteMethod, container, name)); } + @Override + public HttpRequest signGetBlob(String container, String name, org.jclouds.blobstore.options.GetOptions options) { + return cleanRequest(processor.createRequest(getMethod, container, name, blob2HttpGetOptions.apply(options))); + } }