Fix Azure setBlobProperties

Also backfill test.
This commit is contained in:
Andrew Gaul 2015-12-13 22:07:04 -08:00
parent 0634da98a7
commit 85bc4a6b7e
4 changed files with 57 additions and 7 deletions

View File

@ -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";

View File

@ -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,

View File

@ -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<String, String> 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();

View File

@ -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);
}
}