From 85bc4a6b7e20057821c42fc6d49c0724cd414fcf Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Sun, 13 Dec 2015 22:07:04 -0800 Subject: [PATCH] Fix Azure setBlobProperties Also backfill test. --- .../reference/AzureStorageHeaders.java | 5 +++ .../jclouds/azureblob/AzureBlobClient.java | 2 +- .../BindAzureContentMetadataToRequest.java | 23 +++++++++---- .../azureblob/AzureBlobClientLiveTest.java | 34 +++++++++++++++++++ 4 files changed, 57 insertions(+), 7 deletions(-) diff --git a/providers/azureblob/src/main/java/org/jclouds/azure/storage/reference/AzureStorageHeaders.java b/providers/azureblob/src/main/java/org/jclouds/azure/storage/reference/AzureStorageHeaders.java index b57caa9052..9521e37a1b 100644 --- a/providers/azureblob/src/main/java/org/jclouds/azure/storage/reference/AzureStorageHeaders.java +++ b/providers/azureblob/src/main/java/org/jclouds/azure/storage/reference/AzureStorageHeaders.java @@ -23,6 +23,11 @@ package org.jclouds.azure.storage.reference; */ public final class AzureStorageHeaders { + public static final String CONTENT_DISPOSITION = "x-ms-blob-content-disposition"; + public static final String CONTENT_ENCODING = "x-ms-blob-content-encoding"; + public static final String CONTENT_LANGUAGE = "x-ms-blob-content-language"; + public static final String CONTENT_TYPE = "x-ms-blob-content-type"; + public static final String USER_METADATA_PREFIX = "x-ms-meta-"; public static final String COPY_SOURCE = "x-ms-copy-source"; diff --git a/providers/azureblob/src/main/java/org/jclouds/azureblob/AzureBlobClient.java b/providers/azureblob/src/main/java/org/jclouds/azureblob/AzureBlobClient.java index b8a25e5836..b2fa4f5a64 100644 --- a/providers/azureblob/src/main/java/org/jclouds/azureblob/AzureBlobClient.java +++ b/providers/azureblob/src/main/java/org/jclouds/azureblob/AzureBlobClient.java @@ -418,7 +418,7 @@ public interface AzureBlobClient extends Closeable { @Named("SetBlobProperties") @PUT @Path("{container}/{name}") - @QueryParams(keys = { "comp" }, values = { "metadata" }) + @QueryParams(keys = { "comp" }, values = { "properties" }) @ResponseParser(ParseETagHeader.class) String setBlobProperties( @PathParam("container") @ParamValidators(ContainerNameValidator.class) String container, diff --git a/providers/azureblob/src/main/java/org/jclouds/azureblob/binders/BindAzureContentMetadataToRequest.java b/providers/azureblob/src/main/java/org/jclouds/azureblob/binders/BindAzureContentMetadataToRequest.java index 2bf496df87..6568e4da8e 100644 --- a/providers/azureblob/src/main/java/org/jclouds/azureblob/binders/BindAzureContentMetadataToRequest.java +++ b/providers/azureblob/src/main/java/org/jclouds/azureblob/binders/BindAzureContentMetadataToRequest.java @@ -21,6 +21,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import javax.inject.Singleton; +import org.jclouds.azure.storage.reference.AzureStorageHeaders; import org.jclouds.http.HttpRequest; import org.jclouds.io.ContentMetadata; import org.jclouds.rest.Binder; @@ -44,14 +45,24 @@ public class BindAzureContentMetadataToRequest implements Binder { ImmutableMap.Builder headers = ImmutableMap.builder(); - String contentType = contentMetadata.getContentType(); - if (contentType != null) { - headers.put("x-ms-blob-type", contentType); - } - String contentDisposition = contentMetadata.getContentDisposition(); if (contentDisposition != null) { - headers.put("x-ms-blob-content-disposition", contentDisposition); + headers.put(AzureStorageHeaders.CONTENT_DISPOSITION, contentDisposition); + } + + String contentEncoding = contentMetadata.getContentEncoding(); + if (contentEncoding != null) { + headers.put(AzureStorageHeaders.CONTENT_ENCODING, contentEncoding); + } + + String contentLanguage = contentMetadata.getContentLanguage(); + if (contentLanguage != null) { + headers.put(AzureStorageHeaders.CONTENT_LANGUAGE, contentLanguage); + } + + String contentType = contentMetadata.getContentType(); + if (contentType != null) { + headers.put(AzureStorageHeaders.CONTENT_TYPE, contentType); } return (R) request.toBuilder().replaceHeaders(Multimaps.forMap(headers.build())).build(); diff --git a/providers/azureblob/src/test/java/org/jclouds/azureblob/AzureBlobClientLiveTest.java b/providers/azureblob/src/test/java/org/jclouds/azureblob/AzureBlobClientLiveTest.java index db3ef9d323..7bc723604f 100644 --- a/providers/azureblob/src/test/java/org/jclouds/azureblob/AzureBlobClientLiveTest.java +++ b/providers/azureblob/src/test/java/org/jclouds/azureblob/AzureBlobClientLiveTest.java @@ -50,6 +50,8 @@ import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest; import org.jclouds.http.HttpResponseException; import org.jclouds.http.options.GetOptions; import org.jclouds.io.ByteStreams2; +import org.jclouds.io.ContentMetadata; +import org.jclouds.io.ContentMetadataBuilder; import org.jclouds.io.Payloads; import org.jclouds.util.Strings2; import org.jclouds.util.Throwables2; @@ -544,4 +546,36 @@ public class AzureBlobClientLiveTest extends BaseBlobStoreIntegrationTest { AzureBlob getBlob = getApi().getBlob(privateContainer, "to-if-none-match"); assertEquals(ByteStreams2.toByteArrayAndClose(getBlob.getPayload().openStream()), byteSource.read()); } + + @Test + public void testSetBlobProperties() throws Exception { + String blobName = "blob-name"; + ByteSource byteSource = TestUtils.randomByteSource().slice(0, 1024); + String contentDisposition = "attachment; filename=photo.jpg"; + String contentEncoding = "compress"; + String contentLanguage = "en"; + String contentType = "audio/ogg"; + + // create blob + AzureBlob object = getApi().newBlob(); + object.getProperties().setName(blobName); + object.setPayload(byteSource.read()); + getApi().putBlob(privateContainer, object); + + // set properties + getApi().setBlobProperties(privateContainer, blobName, ContentMetadataBuilder.create() + .contentDisposition(contentDisposition) + .contentEncoding(contentEncoding) + .contentLanguage(contentLanguage) + .contentType(contentType) + .build()); + + // get properties + BlobProperties properties = getApi().getBlobProperties(privateContainer, blobName); + ContentMetadata contentMetadata = properties.getContentMetadata(); + assertThat(contentMetadata.getContentDisposition()).isEqualTo(contentDisposition); + assertThat(contentMetadata.getContentEncoding()).isEqualTo(contentEncoding); + assertThat(contentMetadata.getContentLanguage()).isEqualTo(contentLanguage); + assertThat(contentMetadata.getContentType()).isEqualTo(contentType); + } }