diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/functions/ResourceToObjectInfo.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/functions/ResourceToObjectInfo.java
index 56dad87a09..45d8eb4794 100644
--- a/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/functions/ResourceToObjectInfo.java
+++ b/apis/swift/src/main/java/org/jclouds/openstack/swift/blobstore/functions/ResourceToObjectInfo.java
@@ -16,8 +16,6 @@
*/
package org.jclouds.openstack.swift.blobstore.functions;
-import static com.google.common.io.BaseEncoding.base16;
-
import java.util.Map.Entry;
import javax.inject.Singleton;
@@ -29,6 +27,7 @@ import org.jclouds.openstack.swift.domain.MutableObjectInfoWithMetadata;
import org.jclouds.openstack.swift.domain.internal.MutableObjectInfoWithMetadataImpl;
import com.google.common.base.Function;
+import org.jclouds.openstack.swift.utils.ETagUtils;
/**
* @author Adrian Cole
@@ -48,7 +47,7 @@ public class ResourceToObjectInfo implements Function
Not applicable to all ETags, only those of OpenStack objects. According + * to the HTTP spec + * an eTag can be any string, but the + * OpenStack Object Storage Administration Guide + * says that the ETag of an OpenStack object will be an MD5 sum (and MD5 sums + * are conventionally represented as hex strings). This method only accepts + * hex strings as input, not arbitrary strings.
+ */ + public static byte[] convertHexETagToByteArray(String hexETag) { + hexETag = unquote(hexETag); + return base16().lowerCase().decode(hexETag); + } + + @VisibleForTesting + static String unquote(String eTag) { + return QUOTED_STRING.matcher(eTag).replaceAll("$1"); + } +} diff --git a/apis/swift/src/test/java/org/jclouds/openstack/swift/functions/ParseObjectInfoFromHeadersTest.java b/apis/swift/src/test/java/org/jclouds/openstack/swift/functions/ParseObjectInfoFromHeadersTest.java index 7e62800d94..8c30fdbd1c 100644 --- a/apis/swift/src/test/java/org/jclouds/openstack/swift/functions/ParseObjectInfoFromHeadersTest.java +++ b/apis/swift/src/test/java/org/jclouds/openstack/swift/functions/ParseObjectInfoFromHeadersTest.java @@ -16,6 +16,7 @@ */ package org.jclouds.openstack.swift.functions; +import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import org.jclouds.http.HttpResponse; @@ -26,7 +27,7 @@ import org.testng.annotations.Test; import com.google.common.collect.ImmutableList; /** - * Tests behavior of {@code ParseContainerListFromJsonResponse} + * Tests behavior of {@code ParseObjectInfoFromHeaders} * * @author Adrian Cole */ @@ -34,17 +35,30 @@ import com.google.common.collect.ImmutableList; public class ParseObjectInfoFromHeadersTest extends BasePayloadTest { public void testEtagCaseIssue() { + assertETagCanBeParsed("feb1", + new byte[] { (byte) 0xfe, (byte) 0xb1 } + ); + } + + public void testParseEtagWithQuotes() { + assertETagCanBeParsed("\"feb1\"", + new byte[] { (byte) 0xfe, (byte) 0xb1 } + ); + } + + private void assertETagCanBeParsed(String etag, byte[] expectedHash) { ParseObjectInfoFromHeaders parser = i.getInstance(ParseObjectInfoFromHeaders.class); - + parser.setContext(requestForArgs(ImmutableList.