Make AWS-S3 use the right directory suffix.

Fixes #1336.
This commit is contained in:
Shri Javadekar 2013-02-22 23:49:26 -08:00
parent fd42b450af
commit 7bfa6649ce
2 changed files with 19 additions and 2 deletions

View File

@ -22,7 +22,6 @@ import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_RELAX_HOSTNAME; import static org.jclouds.Constants.PROPERTY_RELAX_HOSTNAME;
import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AUTH_TAG; import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AUTH_TAG;
import static org.jclouds.aws.reference.AWSConstants.PROPERTY_HEADER_TAG; import static org.jclouds.aws.reference.AWSConstants.PROPERTY_HEADER_TAG;
import static org.jclouds.blobstore.reference.BlobStoreConstants.DIRECTORY_SUFFIX_FOLDER;
import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_BLOBSTORE_DIRECTORY_SUFFIX; import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_BLOBSTORE_DIRECTORY_SUFFIX;
import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX; import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX;
import static org.jclouds.reflect.Reflection2.typeToken; import static org.jclouds.reflect.Reflection2.typeToken;
@ -88,7 +87,7 @@ public class S3ApiMetadata extends BaseRestApiMetadata {
properties.setProperty(PROPERTY_S3_SERVICE_PATH, "/"); properties.setProperty(PROPERTY_S3_SERVICE_PATH, "/");
properties.setProperty(PROPERTY_S3_VIRTUAL_HOST_BUCKETS, "true"); properties.setProperty(PROPERTY_S3_VIRTUAL_HOST_BUCKETS, "true");
properties.setProperty(PROPERTY_RELAX_HOSTNAME, "true"); properties.setProperty(PROPERTY_RELAX_HOSTNAME, "true");
properties.setProperty(PROPERTY_BLOBSTORE_DIRECTORY_SUFFIX, DIRECTORY_SUFFIX_FOLDER); properties.setProperty(PROPERTY_BLOBSTORE_DIRECTORY_SUFFIX, "/");
properties.setProperty(PROPERTY_USER_METADATA_PREFIX, String.format("x-${%s}-meta-", PROPERTY_HEADER_TAG)); properties.setProperty(PROPERTY_USER_METADATA_PREFIX, String.format("x-${%s}-meta-", PROPERTY_HEADER_TAG));
return properties; return properties;
} }

View File

@ -81,4 +81,22 @@ public class S3ClientMockTest {
assertEquals(request.getHeaders(CONTENT_LENGTH), ImmutableList.of("0")); assertEquals(request.getHeaders(CONTENT_LENGTH), ImmutableList.of("0"));
server.shutdown(); server.shutdown();
} }
public void testDirectorySeparator() throws IOException, InterruptedException {
MockWebServer server = new MockWebServer();
server.enqueue(new MockResponse().setBody("").addHeader(ETAG, "ABCDEF"));
server.play();
S3Client client = getContext(server.getUrl("/")).getApi();
S3Object fileInDir = client.newS3Object();
fileInDir.getMetadata().setKey("someDir/fileName");
fileInDir.setPayload(new byte[] {});
assertEquals(client.putObject("bucket", fileInDir), "ABCDEF");
RecordedRequest request = server.takeRequest();
assertEquals(request.getRequestLine(), "PUT /bucket/someDir/fileName HTTP/1.1");
server.shutdown();
}
} }