continue;
}
String containerName = Iterables.getLast(containers).getName();
final ByteSource input = ByteSource.wrap("str".getBytes());
final HttpClient client = ctx.utils().http();
// test signed put
String blobName = "test-" + UUID.randomUUID();
Blob blob2 = region.blobBuilder(blobName).forSigning()
.contentLength(input.size())
.contentMD5(input.hash(Hashing.md5()).asBytes())
.contentType(MediaType.OCTET_STREAM.toString()).build();
BlobRequestSigner signer = ctx.getSigner(regionId);
HttpResponse response;
try {
HttpRequest putRequest;
putRequest = signer.signPutBlob(containerName, blob2, 600);
MutableContentMetadata metadata = blob2.getMetadata()
.getContentMetadata();
HttpRequest.Builder<?> putRequestBuilder = putRequest.toBuilder()
.addHeader(HttpHeaders.CONTENT_TYPE,
metadata.getContentType());
putRequestBuilder.addHeader(HttpHeaders.CONTENT_LENGTH,
String.valueOf(input.size()));
putRequestBuilder.payload(input);
putRequest = putRequestBuilder.build();
Payload payload = Payloads.newPayload(input.read());
putRequest.setPayload(payload);
assertNotNull(putRequest, "regionId=" + regionId + ", container="
+ containerName + ", blob=" + blobName);
response = client.invoke(putRequest);
if (response.getStatusCode() != 200
&& response.getStatusCode() != 201) {
fail("Signed PUT expected to return 200 or 201 but returned "
+ response.getStatusCode());
}
} catch (Exception e) {
fail("Failed signed put test: " + e);
}
// test signed get
try {
HttpRequest getRequest = signer.signGetBlob(containerName,
blobName);
assertNotNull(getRequest, "regionId=" + regionId + ", container="
+ containerName + ", blob=" + blobName);
response = client.invoke(getRequest);
if (response.getStatusCode() != 200) {
fail("Signed GET expected to return 200 but returned "
+ response.getStatusCode());
}
Payload payload = response.getPayload();