From 98230e60a4e47c94ffe65f50470cf5ad51ca3f67 Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Thu, 20 Jun 2013 15:26:23 -0700 Subject: [PATCH] Add Atmos-specific MD5 checksum header Tested that Atmos Online and Synaptic Atmos both enforce this. --- .../jclouds/atmos/binders/BindMetadataToHeaders.java | 12 ++++++++++++ .../org/jclouds/atmos/reference/AtmosHeaders.java | 1 + .../atmos/blobstore/AtmosBlobRequestSignerTest.java | 7 ++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/apis/atmos/src/main/java/org/jclouds/atmos/binders/BindMetadataToHeaders.java b/apis/atmos/src/main/java/org/jclouds/atmos/binders/BindMetadataToHeaders.java index ba852b7948..f0b3d06e13 100644 --- a/apis/atmos/src/main/java/org/jclouds/atmos/binders/BindMetadataToHeaders.java +++ b/apis/atmos/src/main/java/org/jclouds/atmos/binders/BindMetadataToHeaders.java @@ -22,7 +22,10 @@ import static com.google.common.base.Preconditions.checkNotNull; import javax.inject.Inject; import javax.inject.Singleton; +import com.google.common.io.BaseEncoding; + import org.jclouds.atmos.domain.AtmosObject; +import org.jclouds.atmos.reference.AtmosHeaders; import org.jclouds.http.HttpRequest; import org.jclouds.rest.Binder; @@ -47,6 +50,15 @@ public class BindMetadataToHeaders implements Binder { checkNotNull(object.getPayload(), "object payload"); checkArgument(object.getPayload().getContentMetadata().getContentLength() != null, "contentLength must be set, streaming not supported"); + byte[] contentMD5 = object.getContentMetadata().getContentMD5(); + if (contentMD5 != null) { + // Swizzle Content-MD5 to Atmos-specific header + object.getContentMetadata().setContentMD5(null); + request = (R) request.toBuilder() + .addHeader(AtmosHeaders.CHECKSUM, "MD5/0/" + + BaseEncoding.base64().encode(contentMD5)) + .build(); + } return metaBinder.bindToRequest(request, object.getUserMetadata()); } } diff --git a/apis/atmos/src/main/java/org/jclouds/atmos/reference/AtmosHeaders.java b/apis/atmos/src/main/java/org/jclouds/atmos/reference/AtmosHeaders.java index 41b328fcf9..b4d2d3d530 100644 --- a/apis/atmos/src/main/java/org/jclouds/atmos/reference/AtmosHeaders.java +++ b/apis/atmos/src/main/java/org/jclouds/atmos/reference/AtmosHeaders.java @@ -35,5 +35,6 @@ public interface AtmosHeaders { public static final String GROUP_ACL = "x-emc-groupacl"; public static final String UID = "x-emc-uid"; public static final String TOKEN = "x-emc-token"; + public static final String CHECKSUM = "x-emc-wschecksum"; } diff --git a/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/AtmosBlobRequestSignerTest.java b/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/AtmosBlobRequestSignerTest.java index 9644406133..5f3ca335c1 100644 --- a/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/AtmosBlobRequestSignerTest.java +++ b/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/AtmosBlobRequestSignerTest.java @@ -99,7 +99,12 @@ public class AtmosBlobRequestSignerTest extends BaseAsyncClientTest