mirror of https://github.com/apache/jclouds.git
Issue 301: refactored http payload and rewrote crufty tests
This commit is contained in:
parent
31d2da3c6f
commit
e8d0a11cda
|
@ -159,24 +159,9 @@ public class AtmosObjectImpl extends PayloadEnclosingImpl implements AtmosObject
|
|||
public SetMetadataPropertiesPayload(Payload delegate, MutableContentMetadata contentMetadata) {
|
||||
super(delegate);
|
||||
this.contentMetadata = contentMetadata;
|
||||
if (contentMetadata.getContentLength() != null)
|
||||
setContentLength(contentMetadata.getContentLength());
|
||||
setContentMD5(contentMetadata.getContentMD5());
|
||||
setContentType(contentMetadata.getContentType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentLength(Long contentLength) {
|
||||
super.setContentLength(contentLength);
|
||||
contentMetadata.setContentLength(contentLength);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentMD5(byte[] md5) {
|
||||
super.setContentMD5(md5);
|
||||
contentMetadata.setContentMD5(md5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentType(String md5) {
|
||||
super.setContentType(md5);
|
||||
|
@ -207,13 +192,6 @@ public class AtmosObjectImpl extends PayloadEnclosingImpl implements AtmosObject
|
|||
this.object = object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentMD5(byte[] md5) {
|
||||
super.setContentMD5(md5);
|
||||
if (canSetPayload())
|
||||
object.getPayload().setContentMD5(md5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentType(String type) {
|
||||
super.setContentType(type);
|
||||
|
@ -221,13 +199,6 @@ public class AtmosObjectImpl extends PayloadEnclosingImpl implements AtmosObject
|
|||
object.getPayload().setContentType(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentLength(Long size) {
|
||||
super.setContentLength(size);
|
||||
if (canSetPayload())
|
||||
object.getPayload().setContentLength(size);
|
||||
}
|
||||
|
||||
private boolean canSetPayload() {
|
||||
return object != null && object.getPayload() != null;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ import static org.jclouds.Constants.PROPERTY_IDENTITY;
|
|||
import static org.jclouds.util.Patterns.NEWLINE_PATTERN;
|
||||
import static org.jclouds.util.Patterns.TWO_SPACE_PATTERN;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
@ -64,6 +63,8 @@ public class SignRequest implements HttpRequestFilter {
|
|||
private final byte[] key;
|
||||
private final Provider<String> timeStampProvider;
|
||||
private final EncryptionService encryptionService;
|
||||
private final HttpUtils utils;
|
||||
|
||||
@Resource
|
||||
Logger logger = Logger.NULL;
|
||||
|
||||
|
@ -74,19 +75,21 @@ public class SignRequest implements HttpRequestFilter {
|
|||
@Inject
|
||||
public SignRequest(SignatureWire signatureWire, @Named(PROPERTY_IDENTITY) String uid,
|
||||
@Named(PROPERTY_CREDENTIAL) String encodedKey,
|
||||
@TimeStamp Provider<String> timeStampProvider, EncryptionService encryptionService) {
|
||||
@TimeStamp Provider<String> timeStampProvider, EncryptionService encryptionService,
|
||||
HttpUtils utils) {
|
||||
this.signatureWire = signatureWire;
|
||||
this.uid = uid;
|
||||
this.key = encryptionService.fromBase64(encodedKey);
|
||||
this.timeStampProvider = timeStampProvider;
|
||||
this.encryptionService = encryptionService;
|
||||
this.utils = utils;
|
||||
}
|
||||
|
||||
public void filter(HttpRequest request) throws HttpException {
|
||||
String toSign = replaceUIDHeader(request).removeOldSignature(request).replaceDateHeader(
|
||||
request).createStringToSign(request);
|
||||
calculateAndReplaceAuthHeader(request, toSign);
|
||||
HttpUtils.logRequest(signatureLog, request, "<<");
|
||||
utils.logRequest(signatureLog, request, "<<");
|
||||
}
|
||||
|
||||
private SignRequest removeOldSignature(HttpRequest request) {
|
||||
|
@ -95,10 +98,11 @@ public class SignRequest implements HttpRequestFilter {
|
|||
}
|
||||
|
||||
public String createStringToSign(HttpRequest request) {
|
||||
HttpUtils.logRequest(signatureLog, request, ">>");
|
||||
utils.logRequest(signatureLog, request, ">>");
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
// re-sign the request
|
||||
appendMethod(request, buffer);
|
||||
appendPayloadMetadata(request, buffer);
|
||||
appendHttpHeaders(request, buffer);
|
||||
appendCanonicalizedResource(request, buffer);
|
||||
appendCanonicalizedHeaders(request, buffer);
|
||||
|
@ -167,12 +171,19 @@ public class SignRequest implements HttpRequestFilter {
|
|||
toSign.deleteCharAt(toSign.length() - 1);
|
||||
}
|
||||
|
||||
private void appendPayloadMetadata(HttpRequest request, StringBuilder buffer) {
|
||||
buffer.append(
|
||||
utils.valueOrEmpty(request.getPayload() == null ? null : request.getPayload()
|
||||
.getContentType())).append("\n");
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void appendHttpHeaders(HttpRequest request, StringBuilder toSign) {
|
||||
// Only the value is used, not the header
|
||||
// name. If a request does not include the header, this is an empty string.
|
||||
for (String header : new String[] { HttpHeaders.CONTENT_TYPE, "Range" })
|
||||
toSign.append(valueOrEmpty(request.getHeaders().get(header)).toLowerCase()).append("\n");
|
||||
for (String header : new String[] { "Range" })
|
||||
toSign.append(utils.valueOrEmpty(request.getHeaders().get(header)).toLowerCase()).append(
|
||||
"\n");
|
||||
// Standard HTTP header, in UTC format. Only the date value is used, not the header name.
|
||||
toSign.append(request.getHeaders().get(HttpHeaders.DATE).iterator().next()).append("\n");
|
||||
}
|
||||
|
@ -183,7 +194,4 @@ public class SignRequest implements HttpRequestFilter {
|
|||
toSign.append(request.getEndpoint().getRawPath().toLowerCase()).append("\n");
|
||||
}
|
||||
|
||||
private String valueOrEmpty(Collection<String> collection) {
|
||||
return (collection != null && collection.size() >= 1) ? collection.iterator().next() : "";
|
||||
}
|
||||
}
|
|
@ -58,6 +58,6 @@ public class ParseDirectoryListFromContentAndHeaders implements
|
|||
public BoundedSet<DirectoryEntry> apply(HttpResponse from) {
|
||||
String token = from.getFirstHeaderOrNull(AtmosStorageHeaders.TOKEN);
|
||||
return new BoundedHashSet<DirectoryEntry>(factory.create(listHandlerProvider.get()).parse(
|
||||
from.getContent()), token);
|
||||
from.getPayload().getInput()), token);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,15 +18,15 @@
|
|||
*/
|
||||
package org.jclouds.atmosonline.saas.functions;
|
||||
|
||||
import static org.jclouds.http.HttpUtils.attemptToParseSizeAndRangeFromHeaders;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
|
||||
import org.jclouds.atmosonline.saas.domain.AtmosObject;
|
||||
import org.jclouds.blobstore.functions.ParseSystemAndUserMetadataFromHeaders;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
|
@ -61,30 +61,9 @@ public class ParseObjectFromHeadersAndHttpContent implements Function<HttpRespon
|
|||
public AtmosObject apply(HttpResponse from) {
|
||||
AtmosObject object = objectProvider.create(systemMetadataParser.apply(from),
|
||||
userMetadataParser.apply(from));
|
||||
addAllHeadersTo(from, object);
|
||||
if (from.getContent() != null) {
|
||||
object.setPayload(from.getContent());
|
||||
} else if (new Long(0).equals(object.getContentMetadata().getContentLength())) {
|
||||
object.setPayload(new byte[0]);
|
||||
} else {
|
||||
assert false : "no content in " + from;
|
||||
}
|
||||
|
||||
String contentLength = from.getFirstHeaderOrNull(HttpHeaders.CONTENT_LENGTH);
|
||||
if (contentLength != null) {
|
||||
object.getContentMetadata().setContentLength(Long.parseLong(contentLength));
|
||||
}
|
||||
|
||||
String contentType = from.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE);
|
||||
if (contentType != null) {
|
||||
object.getContentMetadata().setContentType(contentType);
|
||||
}
|
||||
object.getAllHeaders().putAll(from.getHeaders());
|
||||
object.setPayload(from.getPayload());
|
||||
object.getContentMetadata().setContentLength(attemptToParseSizeAndRangeFromHeaders(from));
|
||||
return object;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void addAllHeadersTo(HttpResponse from, AtmosObject object) {
|
||||
object.getAllHeaders().putAll(from.getHeaders());
|
||||
}
|
||||
|
||||
}
|
|
@ -18,6 +18,8 @@
|
|||
*/
|
||||
package org.jclouds.atmosonline.saas.handlers;
|
||||
|
||||
import static org.jclouds.http.HttpUtils.releasePayload;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.regex.Matcher;
|
||||
|
@ -41,8 +43,6 @@ import org.jclouds.logging.Logger;
|
|||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.util.Utils;
|
||||
|
||||
import com.google.common.io.Closeables;
|
||||
|
||||
/**
|
||||
* This will parse and set an appropriate exception on the command object.
|
||||
*
|
||||
|
@ -105,15 +105,15 @@ public class ParseAtmosStorageErrorFromXmlContent implements HttpErrorHandler {
|
|||
}
|
||||
}
|
||||
} finally {
|
||||
Closeables.closeQuietly(response.getContent());
|
||||
releasePayload(response);
|
||||
command.setException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
AtmosStorageError parseErrorFromContentOrNull(HttpCommand command, HttpResponse response) {
|
||||
if (response.getContent() != null) {
|
||||
if (response.getPayload() != null) {
|
||||
try {
|
||||
String content = Utils.toStringAndClose(response.getContent());
|
||||
String content = Utils.toStringAndClose(response.getPayload().getInput());
|
||||
if (content != null && content.indexOf('<') >= 0)
|
||||
return utils.parseAtmosStorageErrorFromContent(command, response, Utils
|
||||
.toInputStream(content));
|
||||
|
|
|
@ -42,8 +42,8 @@ import org.jclouds.blobstore.functions.ThrowKeyNotFoundOn404;
|
|||
import org.jclouds.date.TimeStamp;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.RequiresHttp;
|
||||
import org.jclouds.http.functions.CloseContentAndReturn;
|
||||
import org.jclouds.http.functions.ParseURIFromListOrLocationHeaderIf20x;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.http.options.GetOptions;
|
||||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
import org.jclouds.rest.RestClientTest;
|
||||
|
@ -76,8 +76,8 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
|
|||
|
||||
assertRequestLineEquals(request,
|
||||
"GET https://accesspoint.atmosonline.com/rest/namespace HTTP/1.1");
|
||||
assertHeadersEqual(request, HttpHeaders.ACCEPT + ": text/xml\n");
|
||||
assertPayloadEquals(request, null);
|
||||
assertNonPayloadHeadersEqual(request, HttpHeaders.ACCEPT + ": text/xml\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request,
|
||||
ParseDirectoryListFromContentAndHeaders.class);
|
||||
|
@ -94,8 +94,8 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
|
|||
|
||||
assertRequestLineEquals(request,
|
||||
"GET https://accesspoint.atmosonline.com/rest/namespace/directory/ HTTP/1.1");
|
||||
assertHeadersEqual(request, HttpHeaders.ACCEPT + ": text/xml\n");
|
||||
assertPayloadEquals(request, null);
|
||||
assertNonPayloadHeadersEqual(request, HttpHeaders.ACCEPT + ": text/xml\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request,
|
||||
ParseDirectoryListFromContentAndHeaders.class);
|
||||
|
@ -114,9 +114,9 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
|
|||
|
||||
assertRequestLineEquals(request,
|
||||
"GET https://accesspoint.atmosonline.com/rest/namespace HTTP/1.1");
|
||||
assertHeadersEqual(request, HttpHeaders.ACCEPT
|
||||
assertNonPayloadHeadersEqual(request, HttpHeaders.ACCEPT
|
||||
+ ": text/xml\nx-emc-limit: 1\nx-emc-token: asda\n");
|
||||
assertPayloadEquals(request, null);
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request,
|
||||
ParseDirectoryListFromContentAndHeaders.class);
|
||||
|
@ -135,9 +135,9 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
|
|||
|
||||
assertRequestLineEquals(request,
|
||||
"GET https://accesspoint.atmosonline.com/rest/namespace/directory/ HTTP/1.1");
|
||||
assertHeadersEqual(request, HttpHeaders.ACCEPT
|
||||
assertNonPayloadHeadersEqual(request, HttpHeaders.ACCEPT
|
||||
+ ": text/xml\nx-emc-limit: 1\nx-emc-token: asda\n");
|
||||
assertPayloadEquals(request, null);
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request,
|
||||
ParseDirectoryListFromContentAndHeaders.class);
|
||||
|
@ -153,8 +153,8 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
|
|||
|
||||
assertRequestLineEquals(request,
|
||||
"POST https://accesspoint.atmosonline.com/rest/namespace/dir/ HTTP/1.1");
|
||||
assertHeadersEqual(request, HttpHeaders.ACCEPT + ": */*\n");
|
||||
assertPayloadEquals(request, null);
|
||||
assertNonPayloadHeadersEqual(request, HttpHeaders.ACCEPT + ": */*\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseURIFromListOrLocationHeaderIf20x.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -171,9 +171,9 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
|
|||
|
||||
assertRequestLineEquals(request,
|
||||
"POST https://accesspoint.atmosonline.com/rest/namespace/dir/hello HTTP/1.1");
|
||||
assertHeadersEqual(request, HttpHeaders.ACCEPT
|
||||
+ ": */*\nContent-Length: 5\nContent-Type: text/plain\n");
|
||||
assertPayloadEquals(request, "hello");
|
||||
assertNonPayloadHeadersEqual(request, HttpHeaders.ACCEPT
|
||||
+ ": */*\n");
|
||||
assertPayloadEquals(request, "hello", "text/plain", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseURIFromListOrLocationHeaderIf20x.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -190,11 +190,11 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
|
|||
|
||||
assertRequestLineEquals(request,
|
||||
"PUT https://accesspoint.atmosonline.com/rest/namespace/dir/hello HTTP/1.1");
|
||||
assertHeadersEqual(request, HttpHeaders.ACCEPT
|
||||
+ ": */*\nContent-Length: 5\nContent-Type: text/plain\n");
|
||||
assertPayloadEquals(request, "hello");
|
||||
assertNonPayloadHeadersEqual(request, HttpHeaders.ACCEPT
|
||||
+ ": */*\n");
|
||||
assertPayloadEquals(request, "hello", "text/plain", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ThrowKeyNotFoundOn404.class);
|
||||
|
||||
|
@ -208,8 +208,8 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
|
|||
|
||||
assertRequestLineEquals(request,
|
||||
"GET https://accesspoint.atmosonline.com/rest/namespace/dir/file HTTP/1.1");
|
||||
assertHeadersEqual(request, HttpHeaders.ACCEPT + ": */*\n");
|
||||
assertPayloadEquals(request, null);
|
||||
assertNonPayloadHeadersEqual(request, HttpHeaders.ACCEPT + ": */*\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseObjectFromHeadersAndHttpContent.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -224,8 +224,8 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
|
|||
|
||||
assertRequestLineEquals(request,
|
||||
"HEAD https://accesspoint.atmosonline.com/rest/namespace/dir/file HTTP/1.1");
|
||||
assertHeadersEqual(request, HttpHeaders.ACCEPT + ": */*\n");
|
||||
assertPayloadEquals(request, null);
|
||||
assertNonPayloadHeadersEqual(request, HttpHeaders.ACCEPT + ": */*\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSystemMetadataFromHeaders.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -240,10 +240,10 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
|
|||
|
||||
assertRequestLineEquals(request,
|
||||
"DELETE https://accesspoint.atmosonline.com/rest/namespace/dir/file HTTP/1.1");
|
||||
assertHeadersEqual(request, HttpHeaders.ACCEPT + ": */*\n");
|
||||
assertPayloadEquals(request, null);
|
||||
assertNonPayloadHeadersEqual(request, HttpHeaders.ACCEPT + ": */*\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.jclouds.blobstore.internal.BlobStoreContextImpl;
|
|||
import org.jclouds.blobstore.strategy.ContainsValueInListStrategy;
|
||||
import org.jclouds.logging.config.NullLoggingModule;
|
||||
import org.jclouds.rest.RestContextFactory;
|
||||
import org.jclouds.rest.RestClientTest.MockModule;
|
||||
import org.jclouds.rest.BaseRestClientTest.MockModule;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
@ -40,8 +40,8 @@ import com.google.inject.Module;
|
|||
public class AtmosBlobStoreModuleTest {
|
||||
|
||||
Injector createInjector() {
|
||||
return new RestContextFactory().createContextBuilder("atmosonline", "uid", "key", ImmutableSet
|
||||
.<Module> of(new MockModule(), new NullLoggingModule())).buildInjector();
|
||||
return new RestContextFactory().createContextBuilder("atmosonline", "uid", "key",
|
||||
ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule())).buildInjector();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -37,7 +37,7 @@ import org.jclouds.http.RequiresHttp;
|
|||
import org.jclouds.logging.config.NullLoggingModule;
|
||||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
import org.jclouds.rest.RestContextFactory;
|
||||
import org.jclouds.rest.RestClientTest.MockModule;
|
||||
import org.jclouds.rest.BaseRestClientTest.MockModule;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -108,15 +108,17 @@ public class SignRequestTest {
|
|||
|
||||
public HttpRequest newRequest() {
|
||||
HttpRequest request = new HttpRequest("POST", URI.create("http://localhost/rest/objects"));
|
||||
request.setPayload("");
|
||||
request.getPayload().setContentLength(4286l);
|
||||
request.getPayload().setContentType(MediaType.APPLICATION_OCTET_STREAM);
|
||||
|
||||
request.getHeaders().put(AtmosStorageHeaders.LISTABLE_META, "part4/part7/part8=quick");
|
||||
request.getHeaders().put(AtmosStorageHeaders.META, "part1=buy");
|
||||
request.getHeaders().put(HttpHeaders.ACCEPT, "*/*");
|
||||
request.getHeaders().put(AtmosStorageHeaders.USER_ACL, "john=FULL_CONTROL,mary=WRITE");
|
||||
request.getHeaders().put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM);
|
||||
request.getHeaders().put(AtmosStorageHeaders.DATE, "Thu, 05 Jun 2008 16:38:19 GMT");
|
||||
request.getHeaders().put(AtmosStorageHeaders.GROUP_ACL, "other=NONE");
|
||||
request.getHeaders().put(HttpHeaders.HOST, "10.5.115.118");
|
||||
request.getHeaders().put(HttpHeaders.CONTENT_LENGTH, "4286");
|
||||
request.getHeaders().put(AtmosStorageHeaders.UID, "6039ac182f194e15b9261d73ce044939/user1");
|
||||
return request;
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.jclouds.atmosonline.saas.domain.SystemMetadata;
|
|||
import org.jclouds.date.DateService;
|
||||
import org.jclouds.encryption.EncryptionService;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.Payloads;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
|
@ -45,7 +46,7 @@ public class ParseSystemMetadataFromHeadersTest {
|
|||
DateService dateService = injector.getInstance(DateService.class);
|
||||
EncryptionService encryptionService = injector.getInstance(EncryptionService.class);
|
||||
|
||||
HttpResponse response = new HttpResponse();
|
||||
HttpResponse response = new HttpResponse(200, "ok", Payloads.newStringPayload(""));
|
||||
response
|
||||
.getHeaders()
|
||||
.put(
|
||||
|
|
|
@ -27,7 +27,6 @@ import static org.jclouds.aws.ec2.reference.EC2Parameters.SIGNATURE_METHOD;
|
|||
import static org.jclouds.aws.ec2.reference.EC2Parameters.SIGNATURE_VERSION;
|
||||
import static org.jclouds.aws.ec2.reference.EC2Parameters.TIMESTAMP;
|
||||
import static org.jclouds.aws.ec2.reference.EC2Parameters.VERSION;
|
||||
import static org.jclouds.http.HttpUtils.logRequest;
|
||||
import static org.jclouds.http.HttpUtils.makeQueryLine;
|
||||
import static org.jclouds.http.HttpUtils.parseQueryToMap;
|
||||
|
||||
|
@ -49,6 +48,7 @@ import org.jclouds.encryption.EncryptionService;
|
|||
import org.jclouds.http.HttpException;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpRequestFilter;
|
||||
import org.jclouds.http.HttpUtils;
|
||||
import org.jclouds.http.internal.SignatureWire;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.rest.RequestSigner;
|
||||
|
@ -56,7 +56,6 @@ import org.jclouds.util.Utils;
|
|||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
/**
|
||||
|
@ -77,6 +76,8 @@ public class FormSigner implements HttpRequestFilter, RequestSigner {
|
|||
private final String secretKey;
|
||||
private final Provider<String> dateService;
|
||||
private final EncryptionService encryptionService;
|
||||
private final HttpUtils utils;
|
||||
|
||||
@Resource
|
||||
@Named(Constants.LOGGER_SIGNATURE)
|
||||
private Logger signatureLog = Logger.NULL;
|
||||
|
@ -85,12 +86,14 @@ public class FormSigner implements HttpRequestFilter, RequestSigner {
|
|||
public FormSigner(SignatureWire signatureWire,
|
||||
@Named(Constants.PROPERTY_IDENTITY) String accessKey,
|
||||
@Named(Constants.PROPERTY_CREDENTIAL) String secretKey,
|
||||
@TimeStamp Provider<String> dateService, EncryptionService encryptionService) {
|
||||
@TimeStamp Provider<String> dateService, EncryptionService encryptionService,
|
||||
HttpUtils utils) {
|
||||
this.signatureWire = signatureWire;
|
||||
this.accessKey = accessKey;
|
||||
this.secretKey = secretKey;
|
||||
this.dateService = dateService;
|
||||
this.encryptionService = encryptionService;
|
||||
this.utils = utils;
|
||||
}
|
||||
|
||||
public void filter(HttpRequest request) throws HttpException {
|
||||
|
@ -98,14 +101,13 @@ public class FormSigner implements HttpRequestFilter, RequestSigner {
|
|||
"request is not ready to sign; host not present");
|
||||
Multimap<String, String> decodedParams = parseQueryToMap(request.getPayload().getRawContent()
|
||||
.toString());
|
||||
request.getHeaders().removeAll(HttpHeaders.CONTENT_LENGTH);
|
||||
addSigningParams(decodedParams);
|
||||
validateParams(decodedParams);
|
||||
String stringToSign = createStringToSign(request, decodedParams);
|
||||
String signature = sign(stringToSign);
|
||||
addSignature(decodedParams, signature);
|
||||
setPayload(request, decodedParams);
|
||||
logRequest(signatureLog, request, "<<");
|
||||
utils.logRequest(signatureLog, request, "<<");
|
||||
}
|
||||
|
||||
String[] sortForSigning(String queryLine) {
|
||||
|
@ -133,8 +135,7 @@ public class FormSigner implements HttpRequestFilter, RequestSigner {
|
|||
return o1.getKey().compareTo(o2.getKey());
|
||||
}
|
||||
}));
|
||||
request.getHeaders().replaceValues(HttpHeaders.CONTENT_LENGTH,
|
||||
ImmutableSet.of(request.getPayload().getContentLength().toString()));
|
||||
request.getPayload().setContentType("application/x-www-form-urlencoded");
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
@ -166,7 +167,7 @@ public class FormSigner implements HttpRequestFilter, RequestSigner {
|
|||
|
||||
@VisibleForTesting
|
||||
public String createStringToSign(HttpRequest request, Multimap<String, String> decodedParams) {
|
||||
logRequest(signatureLog, request, ">>");
|
||||
utils.logRequest(signatureLog, request, ">>");
|
||||
StringBuilder stringToSign = new StringBuilder();
|
||||
// StringToSign = HTTPVerb + "\n" +
|
||||
stringToSign.append(request.getMethod()).append("\n");
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
*/
|
||||
package org.jclouds.aws.handlers;
|
||||
|
||||
import static org.jclouds.http.HttpUtils.releasePayload;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
@ -40,7 +42,6 @@ import org.jclouds.rest.ResourceNotFoundException;
|
|||
import org.jclouds.util.Utils;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.io.Closeables;
|
||||
|
||||
/**
|
||||
* This will parse and set an appropriate exception on the command object.
|
||||
|
@ -97,15 +98,15 @@ public class ParseAWSErrorFromXmlContent implements HttpErrorHandler {
|
|||
break;
|
||||
}
|
||||
} finally {
|
||||
Closeables.closeQuietly(response.getContent());
|
||||
releasePayload(response);
|
||||
command.setException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
AWSError parseErrorFromContentOrNull(HttpRequest request, HttpResponse response) {
|
||||
if (response.getContent() != null) {
|
||||
if (response.getPayload() != null) {
|
||||
try {
|
||||
String content = Utils.toStringAndClose(response.getContent());
|
||||
String content = Utils.toStringAndClose(response.getPayload().getInput());
|
||||
if (content != null && content.indexOf('<') >= 0)
|
||||
return utils.parseAWSErrorFromContent(request, response, content);
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -20,7 +20,7 @@ package org.jclouds.aws.s3.binders;
|
|||
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
import javax.inject.Singleton;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.xml.parsers.FactoryConfigurationError;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
@ -41,6 +41,7 @@ import com.jamesmurty.utils.XMLBuilder;
|
|||
*
|
||||
* @author James Murty
|
||||
*/
|
||||
@Singleton
|
||||
public class BindACLToXMLPayload implements Binder {
|
||||
|
||||
public void bindToRequest(HttpRequest request, Object payload) {
|
||||
|
@ -49,9 +50,8 @@ public class BindACLToXMLPayload implements Binder {
|
|||
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
|
||||
try {
|
||||
String stringPayload = generateBuilder(from).asString(outputProperties);
|
||||
request.getHeaders().put(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_XML);
|
||||
request.getHeaders().put(HttpHeaders.CONTENT_LENGTH, stringPayload.getBytes().length + "");
|
||||
request.setPayload(stringPayload);
|
||||
request.getPayload().setContentType(MediaType.TEXT_XML);
|
||||
} catch (Exception e) {
|
||||
Throwables.propagateIfPossible(e);
|
||||
throw new RuntimeException("error transforming acl: " + from, e);
|
||||
|
|
|
@ -20,7 +20,7 @@ package org.jclouds.aws.s3.binders;
|
|||
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
import javax.inject.Singleton;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.xml.parsers.FactoryConfigurationError;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
@ -41,6 +41,7 @@ import com.jamesmurty.utils.XMLBuilder;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class BindBucketLoggingToXmlPayload implements Binder {
|
||||
|
||||
public void bindToRequest(HttpRequest request, Object payload) {
|
||||
|
@ -49,9 +50,8 @@ public class BindBucketLoggingToXmlPayload implements Binder {
|
|||
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
|
||||
try {
|
||||
String stringPayload = generateBuilder(from).asString(outputProperties);
|
||||
request.getHeaders().put(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_XML);
|
||||
request.getHeaders().put(HttpHeaders.CONTENT_LENGTH, stringPayload.getBytes().length + "");
|
||||
request.setPayload(stringPayload);
|
||||
request.getPayload().setContentType(MediaType.TEXT_XML);
|
||||
} catch (Exception e) {
|
||||
Throwables.propagateIfPossible(e);
|
||||
throw new RuntimeException("error transforming bucketLogging: " + from, e);
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
package org.jclouds.aws.s3.binders;
|
||||
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
import javax.inject.Singleton;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
|
@ -28,13 +28,13 @@ import org.jclouds.rest.Binder;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class BindNoBucketLoggingToXmlPayload implements Binder {
|
||||
|
||||
public void bindToRequest(HttpRequest request, Object payload) {
|
||||
String stringPayload = "<BucketLoggingStatus xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"/>";
|
||||
request.getHeaders().put(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_XML);
|
||||
request.getHeaders().put(HttpHeaders.CONTENT_LENGTH, stringPayload.getBytes().length + "");
|
||||
request.setPayload(stringPayload);
|
||||
request.getPayload().setContentType(MediaType.TEXT_XML);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -21,9 +21,7 @@ package org.jclouds.aws.s3.binders;
|
|||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
import javax.inject.Singleton;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.aws.s3.domain.Payer;
|
||||
|
@ -35,6 +33,7 @@ import org.jclouds.rest.Binder;
|
|||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
@Singleton
|
||||
public class BindPayerToXmlPayload implements Binder {
|
||||
|
||||
public void bindToRequest(HttpRequest request, Object toBind) {
|
||||
|
@ -45,9 +44,6 @@ public class BindPayerToXmlPayload implements Binder {
|
|||
"<RequestPaymentConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Payer>%s</Payer></RequestPaymentConfiguration>",
|
||||
((Payer) toBind).value());
|
||||
request.setPayload(text);
|
||||
request.getHeaders().replaceValues(HttpHeaders.CONTENT_LENGTH,
|
||||
Collections.singletonList(text.getBytes().length + ""));
|
||||
request.getHeaders().replaceValues(HttpHeaders.CONTENT_TYPE,
|
||||
Collections.singletonList(MediaType.TEXT_XML));
|
||||
request.getPayload().setContentType(MediaType.TEXT_XML);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -329,4 +329,14 @@ public class MutableObjectMetadataImpl implements Serializable, MutableObjectMet
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MutableObjectMetadataImpl [key=" + key + ", cacheControl=" + cacheControl
|
||||
+ ", contentDisposition=" + contentDisposition + ", contentEncoding="
|
||||
+ contentEncoding + ", contentMD5=" + Arrays.toString(contentMD5) + ", contentType="
|
||||
+ contentType + ", eTag=" + eTag + ", lastModified=" + lastModified + ", owner="
|
||||
+ owner + ", size=" + size + ", storageClass=" + storageClass + ", userMetadata="
|
||||
+ userMetadata + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -157,28 +157,9 @@ public class S3ObjectImpl extends PayloadEnclosingImpl implements S3Object, Comp
|
|||
public SetMetadataPropertiesPayload(Payload delegate, MutableObjectMetadata metadata) {
|
||||
super(delegate);
|
||||
this.metadata = checkNotNull(metadata, "metadata");
|
||||
if (metadata.getSize() != null)
|
||||
setContentLength(metadata.getSize());
|
||||
setContentMD5(metadata.getContentMD5());
|
||||
setContentType(metadata.getContentType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentLength(Long contentLength) {
|
||||
super.setContentLength(contentLength);
|
||||
try {
|
||||
metadata.setSize(contentLength);
|
||||
} catch (NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentMD5(byte[] md5) {
|
||||
super.setContentMD5(md5);
|
||||
metadata.setContentMD5(md5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentType(String md5) {
|
||||
super.setContentType(md5);
|
||||
|
@ -208,13 +189,6 @@ public class S3ObjectImpl extends PayloadEnclosingImpl implements S3Object, Comp
|
|||
this.object = object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentMD5(byte[] md5) {
|
||||
super.setContentMD5(md5);
|
||||
if (canSetPayload())
|
||||
object.getPayload().setContentMD5(md5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentType(String type) {
|
||||
super.setContentType(type);
|
||||
|
@ -222,13 +196,6 @@ public class S3ObjectImpl extends PayloadEnclosingImpl implements S3Object, Comp
|
|||
object.getPayload().setContentType(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSize(Long size) {
|
||||
super.setSize(size);
|
||||
if (canSetPayload())
|
||||
object.getPayload().setContentLength(size);
|
||||
}
|
||||
|
||||
private boolean canSetPayload() {
|
||||
return object != null && object.getPayload() != null;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
package org.jclouds.aws.s3.filters;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.http.HttpUtils.logRequest;
|
||||
import static org.jclouds.util.Patterns.NEWLINE_PATTERN;
|
||||
|
||||
import java.util.Collection;
|
||||
|
@ -41,6 +40,7 @@ import org.jclouds.encryption.EncryptionService;
|
|||
import org.jclouds.http.HttpException;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpRequestFilter;
|
||||
import org.jclouds.http.HttpUtils;
|
||||
import org.jclouds.http.internal.SignatureWire;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.rest.RequestSigner;
|
||||
|
@ -58,8 +58,7 @@ import com.google.common.collect.ImmutableSet;
|
|||
*/
|
||||
@Singleton
|
||||
public class RequestAuthorizeSignature implements HttpRequestFilter, RequestSigner {
|
||||
private final String[] firstHeadersToSign = new String[] { "Content-MD5",
|
||||
HttpHeaders.CONTENT_TYPE, HttpHeaders.DATE };
|
||||
private final String[] firstHeadersToSign = new String[] { HttpHeaders.DATE };
|
||||
|
||||
public static Set<String> SPECIAL_QUERIES = ImmutableSet.of("acl", "torrent", "logging",
|
||||
"location", "requestPayment");
|
||||
|
@ -68,6 +67,7 @@ public class RequestAuthorizeSignature implements HttpRequestFilter, RequestSign
|
|||
private final String secretKey;
|
||||
private final Provider<String> timeStampProvider;
|
||||
private final EncryptionService encryptionService;
|
||||
private final HttpUtils utils;
|
||||
|
||||
@Resource
|
||||
@Named(Constants.LOGGER_SIGNATURE)
|
||||
|
@ -84,7 +84,8 @@ public class RequestAuthorizeSignature implements HttpRequestFilter, RequestSign
|
|||
@Named(S3Constants.PROPERTY_S3_HEADER_TAG) String headerTag,
|
||||
@Named(Constants.PROPERTY_IDENTITY) String accessKey,
|
||||
@Named(Constants.PROPERTY_CREDENTIAL) String secretKey,
|
||||
@TimeStamp Provider<String> timeStampProvider, EncryptionService encryptionService) {
|
||||
@TimeStamp Provider<String> timeStampProvider, EncryptionService encryptionService,
|
||||
HttpUtils utils) {
|
||||
this.srvExpr = srvExpr;
|
||||
this.headerTag = headerTag;
|
||||
this.authTag = authTag;
|
||||
|
@ -93,20 +94,22 @@ public class RequestAuthorizeSignature implements HttpRequestFilter, RequestSign
|
|||
this.secretKey = secretKey;
|
||||
this.timeStampProvider = timeStampProvider;
|
||||
this.encryptionService = encryptionService;
|
||||
this.utils = utils;
|
||||
}
|
||||
|
||||
public void filter(HttpRequest request) throws HttpException {
|
||||
replaceDateHeader(request);
|
||||
String toSign = createStringToSign(request);
|
||||
calculateAndReplaceAuthHeader(request, toSign);
|
||||
logRequest(signatureLog, request, "<<");
|
||||
utils.logRequest(signatureLog, request, "<<");
|
||||
}
|
||||
|
||||
public String createStringToSign(HttpRequest request) {
|
||||
logRequest(signatureLog, request, ">>");
|
||||
utils.logRequest(signatureLog, request, ">>");
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
// re-sign the request
|
||||
appendMethod(request, buffer);
|
||||
appendPayloadMetadata(request, buffer);
|
||||
appendHttpHeaders(request, buffer);
|
||||
appendAmzHeaders(request, buffer);
|
||||
appendBucketName(request, buffer);
|
||||
|
@ -159,6 +162,15 @@ public class RequestAuthorizeSignature implements HttpRequestFilter, RequestSign
|
|||
}
|
||||
}
|
||||
|
||||
private void appendPayloadMetadata(HttpRequest request, StringBuilder buffer) {
|
||||
buffer.append(
|
||||
utils.valueOrEmpty(request.getPayload() == null ? null : request.getPayload()
|
||||
.getContentMD5())).append("\n");
|
||||
buffer.append(
|
||||
utils.valueOrEmpty(request.getPayload() == null ? null : request.getPayload()
|
||||
.getContentType())).append("\n");
|
||||
}
|
||||
|
||||
private void appendHttpHeaders(HttpRequest request, StringBuilder toSign) {
|
||||
for (String header : firstHeadersToSign)
|
||||
toSign.append(valueOrEmpty(request.getHeaders().get(header))).append("\n");
|
||||
|
|
|
@ -26,6 +26,7 @@ import static org.jclouds.aws.reference.AWSConstants.PROPERTY_REGIONS;
|
|||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.binders.BindToStringPayload;
|
||||
|
@ -73,6 +74,6 @@ public class BindRegionToXmlPayload extends BindToStringPayload {
|
|||
"<CreateBucketConfiguration><LocationConstraint>%s</LocationConstraint></CreateBucketConfiguration>",
|
||||
value);
|
||||
super.bindToRequest(request, payload);
|
||||
|
||||
request.getPayload().setContentType(MediaType.TEXT_XML);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,10 +19,9 @@
|
|||
package org.jclouds.aws.s3.functions;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
|
||||
import org.jclouds.aws.s3.domain.MutableObjectMetadata;
|
||||
import org.jclouds.aws.s3.domain.S3Object;
|
||||
import org.jclouds.blobstore.functions.ParseSystemAndUserMetadataFromHeaders;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.rest.InvocationContext;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
|
@ -48,38 +47,13 @@ public class ParseObjectFromHeadersAndHttpContent implements Function<HttpRespon
|
|||
this.objectProvider = objectProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* First, calls {@link ParseSystemAndUserMetadataFromHeaders}.
|
||||
*
|
||||
* Then, sets the object size based on the Content-Length header and adds the content to the
|
||||
* {@link S3Object} result.
|
||||
*
|
||||
* @throws org.jclouds.http.HttpException
|
||||
*/
|
||||
public S3Object apply(HttpResponse from) {
|
||||
S3Object object = objectProvider.create(metadataParser.apply(from));
|
||||
MutableObjectMetadata metadata = metadataParser.apply(from);
|
||||
if (metadata.getContentMD5() != null)
|
||||
from.getPayload().setContentMD5(metadata.getContentMD5());
|
||||
S3Object object = objectProvider.create(metadata);
|
||||
object.getAllHeaders().putAll(from.getHeaders());
|
||||
if (from.getContent() != null) {
|
||||
object.setPayload(from.getContent());
|
||||
} else if (new Long(0).equals(object.getMetadata().getSize())) {
|
||||
object.setPayload(new byte[0]);
|
||||
} else {
|
||||
assert false : "no content in " + from;
|
||||
}
|
||||
|
||||
String contentLength = from.getFirstHeaderOrNull(HttpHeaders.CONTENT_LENGTH);
|
||||
String contentRange = from.getFirstHeaderOrNull("Content-Range");
|
||||
|
||||
if (contentLength != null) {
|
||||
object.getPayload().setContentLength(Long.parseLong(contentLength));
|
||||
}
|
||||
|
||||
if (contentRange == null && contentLength != null) {
|
||||
object.getMetadata().setSize(object.getPayload().getContentLength());
|
||||
} else if (contentRange != null) {
|
||||
object.getMetadata().setSize(
|
||||
Long.parseLong(contentRange.substring(contentRange.lastIndexOf('/') + 1)));
|
||||
}
|
||||
object.setPayload(from.getPayload());
|
||||
return object;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
*/
|
||||
package org.jclouds.aws.s3.functions;
|
||||
|
||||
import static org.jclouds.http.HttpUtils.attemptToParseSizeAndRangeFromHeaders;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
|
||||
|
@ -64,6 +66,7 @@ public class ParseObjectMetadataFromHeaders implements
|
|||
BlobMetadata base = blobMetadataParser.apply(from);
|
||||
MutableObjectMetadata to = blobToObjectMetadata.apply(base);
|
||||
addETagTo(from, to);
|
||||
to.setSize(attemptToParseSizeAndRangeFromHeaders(from));
|
||||
to.setContentMD5(encryptionService.fromHex(Utils.replaceAll(to.getETag(), '"', "")));
|
||||
to.setCacheControl(from.getFirstHeaderOrNull(HttpHeaders.CACHE_CONTROL));
|
||||
to.setContentDisposition(from.getFirstHeaderOrNull("Content-Disposition"));
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.jclouds.aws.sqs.xml;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -30,10 +29,9 @@ import org.jclouds.aws.Region;
|
|||
import org.jclouds.aws.sqs.domain.Queue;
|
||||
import org.jclouds.aws.sqs.xml.internal.BaseRegexQueueHandler;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.jclouds.http.functions.ReturnStringIf200;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Throwables;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -44,24 +42,18 @@ import com.google.common.base.Throwables;
|
|||
@Singleton
|
||||
public class RegexListQueuesResponseHandler extends BaseRegexQueueHandler implements
|
||||
Function<HttpResponse, Set<Queue>> {
|
||||
private final ReturnStringIf200 returnStringIf200;
|
||||
|
||||
@Inject
|
||||
RegexListQueuesResponseHandler(@Region Map<String, URI> regionMap) {
|
||||
RegexListQueuesResponseHandler(@Region Map<String, URI> regionMap,
|
||||
ReturnStringIf200 returnStringIf200) {
|
||||
super(regionMap);
|
||||
this.returnStringIf200 = returnStringIf200;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Queue> apply(HttpResponse response) {
|
||||
try {
|
||||
return parse(Utils.toStringAndClose(response.getContent()));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
try {
|
||||
response.getContent().close();
|
||||
} catch (IOException e) {
|
||||
Throwables.propagate(e);
|
||||
}
|
||||
}
|
||||
return parse(returnStringIf200.apply(response));
|
||||
}
|
||||
|
||||
}
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.jclouds.aws.sqs.xml;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
@ -26,10 +25,9 @@ import javax.inject.Inject;
|
|||
|
||||
import org.jclouds.encryption.EncryptionService;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.jclouds.http.functions.ReturnStringIf200;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
/**
|
||||
|
@ -41,29 +39,24 @@ import com.google.inject.Singleton;
|
|||
@Singleton
|
||||
public class RegexMD5Handler implements Function<HttpResponse, byte[]> {
|
||||
Pattern pattern = Pattern.compile("<MD5OfMessageBody>([\\S&&[^<]]+)</MD5OfMessageBody>");
|
||||
private final ReturnStringIf200 returnStringIf200;
|
||||
private final EncryptionService encryptionService;
|
||||
|
||||
@Inject
|
||||
RegexMD5Handler(EncryptionService encryptionService) {
|
||||
RegexMD5Handler(EncryptionService encryptionService, ReturnStringIf200 returnStringIf200) {
|
||||
this.encryptionService = encryptionService;
|
||||
this.returnStringIf200 = returnStringIf200;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] apply(HttpResponse response) {
|
||||
byte[] value = null;
|
||||
try {
|
||||
Matcher matcher = pattern.matcher(Utils.toStringAndClose(response.getContent()));
|
||||
String content = returnStringIf200.apply(response);
|
||||
if (content != null) {
|
||||
Matcher matcher = pattern.matcher(content);
|
||||
if (matcher.find()) {
|
||||
value = encryptionService.fromHex(matcher.group(1));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Throwables.propagate(e);
|
||||
} finally {
|
||||
try {
|
||||
response.getContent().close();
|
||||
} catch (IOException e) {
|
||||
Throwables.propagate(e);
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.jclouds.aws.sqs.xml;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -29,10 +28,9 @@ import org.jclouds.aws.Region;
|
|||
import org.jclouds.aws.sqs.domain.Queue;
|
||||
import org.jclouds.aws.sqs.xml.internal.BaseRegexQueueHandler;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.jclouds.http.functions.ReturnStringIf200;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.inject.internal.Iterables;
|
||||
|
||||
/**
|
||||
|
@ -44,24 +42,16 @@ import com.google.inject.internal.Iterables;
|
|||
@Singleton
|
||||
public class RegexQueueHandler extends BaseRegexQueueHandler implements
|
||||
Function<HttpResponse, Queue> {
|
||||
private final ReturnStringIf200 returnStringIf200;
|
||||
|
||||
@Inject
|
||||
RegexQueueHandler(@Region Map<String, URI> regionMap) {
|
||||
RegexQueueHandler(@Region Map<String, URI> regionMap, ReturnStringIf200 returnStringIf200) {
|
||||
super(regionMap);
|
||||
this.returnStringIf200 = returnStringIf200;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Queue apply(HttpResponse response) {
|
||||
try {
|
||||
return Iterables.getOnlyElement(parse(Utils.toStringAndClose(response.getContent())));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
try {
|
||||
response.getContent().close();
|
||||
} catch (IOException e) {
|
||||
Throwables.propagate(e);
|
||||
return Iterables.getOnlyElement(parse(returnStringIf200.apply(response)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -34,8 +34,8 @@ import org.jclouds.aws.ec2.xml.ImageIdHandler;
|
|||
import org.jclouds.aws.ec2.xml.PermissionHandler;
|
||||
import org.jclouds.aws.ec2.xml.ProductCodesHandler;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.functions.CloseContentAndReturn;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -57,11 +57,10 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
|||
HttpRequest request = processor.createRequest(method, null, "name", "instanceId");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 69\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2009-11-30&Action=CreateImage&InstanceId=instanceId&Name=name");
|
||||
"Version=2009-11-30&Action=CreateImage&InstanceId=instanceId&Name=name",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, ImageIdHandler.class);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
@ -78,12 +77,11 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
|||
new CreateImageOptions().withDescription("description").noReboot());
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 107\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2009-11-30&Action=CreateImage&InstanceId=instanceId&Name=name&Description=description&NoReboot=true");
|
||||
"Version=2009-11-30&Action=CreateImage&InstanceId=instanceId&Name=name&Description=description&NoReboot=true",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, ImageIdHandler.class);
|
||||
|
@ -98,14 +96,14 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
|||
HttpRequest request = processor.createRequest(method, (String) null);
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 40\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2009-11-30&Action=DescribeImages");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2009-11-30&Action=DescribeImages",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
filter.filter(request);
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Action=DescribeImages&Signature=IYist5Mfzd44GO3%2BX8WJ4Ti%2BWe3UmrZQC10XdCkT5Fk%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&Version=2009-11-30&AWSAccessKeyId=identity");
|
||||
"Action=DescribeImages&Signature=IYist5Mfzd44GO3%2BX8WJ4Ti%2BWe3UmrZQC10XdCkT5Fk%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&Version=2009-11-30&AWSAccessKeyId=identity",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, DescribeImagesResponseHandler.class);
|
||||
|
@ -122,12 +120,11 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
|||
"fred", "nancy").imageIds("1", "2"));
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 107\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2009-11-30&Action=DescribeImages&ExecutableBy=me&Owner.1=fred&Owner.2=nancy&ImageId.1=1&ImageId.2=2");
|
||||
"Version=2009-11-30&Action=DescribeImages&ExecutableBy=me&Owner.1=fred&Owner.2=nancy&ImageId.1=1&ImageId.2=2",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, DescribeImagesResponseHandler.class);
|
||||
|
@ -142,12 +139,11 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
|||
HttpRequest request = processor.createRequest(method, null, "imageId");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 57\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2009-11-30&Action=DeregisterImage&ImageId=imageId");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2009-11-30&Action=DeregisterImage&ImageId=imageId",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
@ -162,11 +158,10 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
|||
HttpRequest request = processor.createRequest(method, null, "name", "pathToManifest");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 78\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2009-11-30&Action=RegisterImage&ImageLocation=pathToManifest&Name=name");
|
||||
"Version=2009-11-30&Action=RegisterImage&ImageLocation=pathToManifest&Name=name",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, ImageIdHandler.class);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
@ -183,12 +178,11 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
|||
new RegisterImageOptions().withDescription("description"));
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 102\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2009-11-30&Action=RegisterImage&ImageLocation=pathToManifest&Name=name&Description=description");
|
||||
"Version=2009-11-30&Action=RegisterImage&ImageLocation=pathToManifest&Name=name&Description=description",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, ImageIdHandler.class);
|
||||
|
@ -205,12 +199,11 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
|||
HttpRequest request = processor.createRequest(method, null, "imageName", "snapshotId");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 176\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2009-11-30&Action=RegisterImage&RootDeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.0.DeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.0.Ebs.SnapshotId=snapshotId&Name=imageName");
|
||||
"Version=2009-11-30&Action=RegisterImage&RootDeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.0.DeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.0.Ebs.SnapshotId=snapshotId&Name=imageName",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, ImageIdHandler.class);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
@ -229,12 +222,11 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
|||
.addNewBlockDevice("/dev/newdevice", "newblock", 100));
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 528\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2009-11-30&Action=RegisterImage&RootDeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.0.DeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.0.Ebs.SnapshotId=snapshotId&Name=imageName&Description=description&BlockDeviceMapping.1.Ebs.DeleteOnTermination=false&BlockDeviceMapping.1.DeviceName=%2Fdev%2Fdevice&BlockDeviceMapping.1.Ebs.SnapshotId=snapshot&BlockDeviceMapping.2.Ebs.DeleteOnTermination=false&BlockDeviceMapping.2.DeviceName=%2Fdev%2Fnewdevice&BlockDeviceMapping.2.VirtualName=newblock&BlockDeviceMapping.2.Ebs.VolumeSize=100");
|
||||
"Version=2009-11-30&Action=RegisterImage&RootDeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.0.DeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.0.Ebs.SnapshotId=snapshotId&Name=imageName&Description=description&BlockDeviceMapping.1.Ebs.DeleteOnTermination=false&BlockDeviceMapping.1.DeviceName=%2Fdev%2Fdevice&BlockDeviceMapping.1.Ebs.SnapshotId=snapshot&BlockDeviceMapping.2.Ebs.DeleteOnTermination=false&BlockDeviceMapping.2.DeviceName=%2Fdev%2Fnewdevice&BlockDeviceMapping.2.VirtualName=newblock&BlockDeviceMapping.2.Ebs.VolumeSize=100",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, ImageIdHandler.class);
|
||||
|
@ -250,11 +242,11 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
|||
HttpRequest request = processor.createRequest(method, null, "imageId");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Content-Length: 87\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2009-11-30&Action=DescribeImageAttribute&Attribute=productCodes&ImageId=imageId");
|
||||
"Version=2009-11-30&Action=DescribeImageAttribute&Attribute=productCodes&ImageId=imageId",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, ProductCodesHandler.class);
|
||||
|
@ -270,11 +262,11 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
|||
HttpRequest request = processor.createRequest(method, null, "imageId");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Content-Length: 93\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2009-11-30&Action=DescribeImageAttribute&Attribute=blockDeviceMapping&ImageId=imageId");
|
||||
"Version=2009-11-30&Action=DescribeImageAttribute&Attribute=blockDeviceMapping&ImageId=imageId",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, BlockDeviceMappingHandler.class);
|
||||
|
@ -290,11 +282,11 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
|||
HttpRequest request = processor.createRequest(method, null, "imageId");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Content-Length: 91\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2009-11-30&Action=DescribeImageAttribute&Attribute=launchPermission&ImageId=imageId");
|
||||
"Version=2009-11-30&Action=DescribeImageAttribute&Attribute=launchPermission&ImageId=imageId",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, PermissionHandler.class);
|
||||
|
@ -311,18 +303,18 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
|||
ImmutableList.of("all"), "imageId");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 149\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2009-11-30&Action=ModifyImageAttribute&OperationType=add&Attribute=launchPermission&ImageId=imageId&UserGroup.1=all&UserId.1=bob&UserId.2=sue");
|
||||
"Version=2009-11-30&Action=ModifyImageAttribute&OperationType=add&Attribute=launchPermission&ImageId=imageId&UserGroup.1=all&UserId.1=bob&UserId.2=sue",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
filter.filter(request);
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Action=ModifyImageAttribute&Attribute=launchPermission&ImageId=imageId&OperationType=add&Signature=Nf2oLuEQ%2BDgwhAxNt7Cdicjacz3PYTVR08%2BaGuXMfwU%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&UserGroup.1=all&UserId.1=bob&UserId.2=sue&Version=2009-11-30&AWSAccessKeyId=identity");
|
||||
"Action=ModifyImageAttribute&Attribute=launchPermission&ImageId=imageId&OperationType=add&Signature=Nf2oLuEQ%2BDgwhAxNt7Cdicjacz3PYTVR08%2BaGuXMfwU%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&UserGroup.1=all&UserId.1=bob&UserId.2=sue&Version=2009-11-30&AWSAccessKeyId=identity",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
@ -337,13 +329,12 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
|||
ImmutableList.of("all"), "imageId");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 152\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2009-11-30&Action=ModifyImageAttribute&OperationType=remove&Attribute=launchPermission&ImageId=imageId&UserGroup.1=all&UserId.1=bob&UserId.2=sue");
|
||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
||||
"Version=2009-11-30&Action=ModifyImageAttribute&OperationType=remove&Attribute=launchPermission&ImageId=imageId&UserGroup.1=all&UserId.1=bob&UserId.2=sue",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
@ -357,12 +348,12 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
|||
HttpRequest request = processor.createRequest(method, null, "imageId");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Content-Length: 88\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2009-11-30&Action=ResetImageAttribute&Attribute=launchPermission&ImageId=imageId");
|
||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
||||
"Version=2009-11-30&Action=ResetImageAttribute&Attribute=launchPermission&ImageId=imageId",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
@ -377,14 +368,13 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
|||
.of("code1", "code2"), "imageId");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 143\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2009-11-30&Action=ModifyImageAttribute&OperationType=add&Attribute=productCodes&ImageId=imageId&ProductCode.1=code1&ProductCode.2=code2");
|
||||
"Version=2009-11-30&Action=ModifyImageAttribute&OperationType=add&Attribute=productCodes&ImageId=imageId&ProductCode.1=code1&ProductCode.2=code2",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
@ -399,14 +389,13 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
|||
.of("code1", "code2"), "imageId");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 146\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2009-11-30&Action=ModifyImageAttribute&OperationType=remove&Attribute=productCodes&ImageId=imageId&ProductCode.1=code1&ProductCode.2=code2");
|
||||
"Version=2009-11-30&Action=ModifyImageAttribute&OperationType=remove&Attribute=productCodes&ImageId=imageId&ProductCode.1=code1&ProductCode.2=code2",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
|
|
@ -55,10 +55,9 @@ public class AvailabilityZoneAndRegionAsyncClientTest extends
|
|||
HttpRequest request = processor.createRequest(method, Region.US_WEST_1);
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-west-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 51\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-west-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2009-11-30&Action=DescribeAvailabilityZones");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-west-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2009-11-30&Action=DescribeAvailabilityZones",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, DescribeAvailabilityZonesResponseHandler.class);
|
||||
|
@ -76,11 +75,11 @@ public class AvailabilityZoneAndRegionAsyncClientTest extends
|
|||
AvailabilityZone.US_EAST_1A, AvailabilityZone.US_EAST_1B));
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Content-Length: 95\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2009-11-30&Action=DescribeAvailabilityZones&ZoneName.1=us-east-1a&ZoneName.2=us-east-1b");
|
||||
"Version=2009-11-30&Action=DescribeAvailabilityZones&ZoneName.1=us-east-1a&ZoneName.2=us-east-1b",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, DescribeAvailabilityZonesResponseHandler.class);
|
||||
|
@ -95,10 +94,9 @@ public class AvailabilityZoneAndRegionAsyncClientTest extends
|
|||
HttpRequest request = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 41\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2009-11-30&Action=DescribeRegions");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2009-11-30&Action=DescribeRegions",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, DescribeRegionsResponseHandler.class);
|
||||
|
@ -115,11 +113,11 @@ public class AvailabilityZoneAndRegionAsyncClientTest extends
|
|||
Region.US_WEST_1));
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Content-Length: 87\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2009-11-30&Action=DescribeRegions&RegionName.1=us-east-1&RegionName.2=us-west-1");
|
||||
"Version=2009-11-30&Action=DescribeRegions&RegionName.1=us-east-1&RegionName.2=us-west-1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, DescribeRegionsResponseHandler.class);
|
||||
|
|
|
@ -37,8 +37,8 @@ import org.jclouds.aws.ec2.xml.DescribeVolumesResponseHandler;
|
|||
import org.jclouds.aws.ec2.xml.PermissionHandler;
|
||||
import org.jclouds.aws.ec2.xml.SnapshotHandler;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.functions.CloseContentAndReturn;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -60,11 +60,10 @@ public class ElasticBlockStoreAsyncClientTest extends
|
|||
HttpRequest request = processor.createRequest(method, AvailabilityZone.US_EAST_1A, 20);
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 74\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2009-11-30&Action=CreateVolume&AvailabilityZone=us-east-1a&Size=20");
|
||||
"Version=2009-11-30&Action=CreateVolume&AvailabilityZone=us-east-1a&Size=20",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, CreateVolumeResponseHandler.class);
|
||||
|
@ -81,11 +80,11 @@ public class ElasticBlockStoreAsyncClientTest extends
|
|||
"snapshotId");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Content-Length: 88\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2009-11-30&Action=CreateVolume&AvailabilityZone=us-east-1a&SnapshotId=snapshotId");
|
||||
"Version=2009-11-30&Action=CreateVolume&AvailabilityZone=us-east-1a&SnapshotId=snapshotId",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, CreateVolumeResponseHandler.class);
|
||||
|
@ -102,11 +101,11 @@ public class ElasticBlockStoreAsyncClientTest extends
|
|||
"snapshotId");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Content-Length: 96\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2009-11-30&Action=CreateVolume&AvailabilityZone=us-east-1a&SnapshotId=snapshotId&Size=15");
|
||||
"Version=2009-11-30&Action=CreateVolume&AvailabilityZone=us-east-1a&SnapshotId=snapshotId&Size=15",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, CreateVolumeResponseHandler.class);
|
||||
|
@ -121,12 +120,11 @@ public class ElasticBlockStoreAsyncClientTest extends
|
|||
HttpRequest request = processor.createRequest(method, null, "id");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 50\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2009-11-30&Action=DeleteVolume&VolumeId=id");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2009-11-30&Action=DeleteVolume&VolumeId=id",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
@ -139,10 +137,9 @@ public class ElasticBlockStoreAsyncClientTest extends
|
|||
HttpRequest request = processor.createRequest(method, (String) null);
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 41\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2009-11-30&Action=DescribeVolumes");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2009-11-30&Action=DescribeVolumes",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, DescribeVolumesResponseHandler.class);
|
||||
|
@ -158,11 +155,10 @@ public class ElasticBlockStoreAsyncClientTest extends
|
|||
HttpRequest request = processor.createRequest(method, null, "1", "2");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 67\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2009-11-30&Action=DescribeVolumes&VolumeId.1=1&VolumeId.2=2");
|
||||
"Version=2009-11-30&Action=DescribeVolumes&VolumeId.1=1&VolumeId.2=2",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, DescribeVolumesResponseHandler.class);
|
||||
|
@ -177,11 +173,11 @@ public class ElasticBlockStoreAsyncClientTest extends
|
|||
HttpRequest request = processor.createRequest(method, null, "id", "instanceId", "/device");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Content-Length: 89\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2009-11-30&Action=AttachVolume&InstanceId=instanceId&VolumeId=id&Device=%2Fdevice");
|
||||
"Version=2009-11-30&Action=AttachVolume&InstanceId=instanceId&VolumeId=id&Device=%2Fdevice",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, AttachmentHandler.class);
|
||||
|
@ -197,12 +193,12 @@ public class ElasticBlockStoreAsyncClientTest extends
|
|||
HttpRequest request = processor.createRequest(method, null, "id", false);
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 62\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2009-11-30&Action=DetachVolume&Force=false&VolumeId=id");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2009-11-30&Action=DetachVolume&Force=false&VolumeId=id",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnVoidOnVolumeAvailable.class);
|
||||
|
||||
|
@ -218,14 +214,13 @@ public class ElasticBlockStoreAsyncClientTest extends
|
|||
"instanceId").fromDevice("/device"));
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 100\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2009-11-30&Action=DetachVolume&Force=true&VolumeId=id&InstanceId=instanceId&Device=%2Fdevice");
|
||||
"Version=2009-11-30&Action=DetachVolume&Force=true&VolumeId=id&InstanceId=instanceId&Device=%2Fdevice",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnVoidOnVolumeAvailable.class);
|
||||
|
||||
|
@ -239,10 +234,9 @@ public class ElasticBlockStoreAsyncClientTest extends
|
|||
HttpRequest request = processor.createRequest(method, null, "volumeId");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 58\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2009-11-30&Action=CreateSnapshot&VolumeId=volumeId");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2009-11-30&Action=CreateSnapshot&VolumeId=volumeId",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, SnapshotHandler.class);
|
||||
|
@ -260,11 +254,11 @@ public class ElasticBlockStoreAsyncClientTest extends
|
|||
CreateSnapshotOptions.Builder.withDescription("description"));
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Content-Length: 82\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2009-11-30&Action=CreateSnapshot&VolumeId=volumeId&Description=description");
|
||||
"Version=2009-11-30&Action=CreateSnapshot&VolumeId=volumeId&Description=description",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, SnapshotHandler.class);
|
||||
|
@ -279,10 +273,9 @@ public class ElasticBlockStoreAsyncClientTest extends
|
|||
HttpRequest request = processor.createRequest(method, (String) null);
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 43\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2009-11-30&Action=DescribeSnapshots");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2009-11-30&Action=DescribeSnapshots",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, DescribeSnapshotsResponseHandler.class);
|
||||
|
@ -299,12 +292,11 @@ public class ElasticBlockStoreAsyncClientTest extends
|
|||
"r1", "r2").snapshotIds("s1", "s2"));
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 133\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2009-11-30&Action=DescribeSnapshots&Owner.1=o1&Owner.2=o2&RestorableBy.1=r1&RestorableBy.2=r2&SnapshotId.1=s1&SnapshotId.2=s2");
|
||||
"Version=2009-11-30&Action=DescribeSnapshots&Owner.1=o1&Owner.2=o2&RestorableBy.1=r1&RestorableBy.2=r2&SnapshotId.1=s1&SnapshotId.2=s2",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, DescribeSnapshotsResponseHandler.class);
|
||||
|
@ -320,12 +312,11 @@ public class ElasticBlockStoreAsyncClientTest extends
|
|||
HttpRequest request = processor.createRequest(method, null, "snapshotId");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 106\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2009-11-30&Action=DescribeSnapshotAttribute&Attribute=createVolumePermission&SnapshotId=snapshotId");
|
||||
"Version=2009-11-30&Action=DescribeSnapshotAttribute&Attribute=createVolumePermission&SnapshotId=snapshotId",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, PermissionHandler.class);
|
||||
|
@ -343,14 +334,13 @@ public class ElasticBlockStoreAsyncClientTest extends
|
|||
ImmutableList.of("all"), "snapshotId");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 164\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2009-11-30&Action=ModifySnapshotAttribute&OperationType=add&Attribute=createVolumePermission&SnapshotId=snapshotId&UserGroup.1=all&UserId.1=bob&UserId.2=sue");
|
||||
"Version=2009-11-30&Action=ModifySnapshotAttribute&OperationType=add&Attribute=createVolumePermission&SnapshotId=snapshotId&UserGroup.1=all&UserId.1=bob&UserId.2=sue",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
@ -366,13 +356,12 @@ public class ElasticBlockStoreAsyncClientTest extends
|
|||
ImmutableList.of("all"), "snapshotId");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 167\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2009-11-30&Action=ModifySnapshotAttribute&OperationType=remove&Attribute=createVolumePermission&SnapshotId=snapshotId&UserGroup.1=all&UserId.1=bob&UserId.2=sue");
|
||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
||||
"Version=2009-11-30&Action=ModifySnapshotAttribute&OperationType=remove&Attribute=createVolumePermission&SnapshotId=snapshotId&UserGroup.1=all&UserId.1=bob&UserId.2=sue",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
@ -386,13 +375,12 @@ public class ElasticBlockStoreAsyncClientTest extends
|
|||
HttpRequest request = processor.createRequest(method, null, "snapshotId");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 103\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2009-11-30&Action=ResetSnapshotAttribute&Attribute=createVolumePermission&SnapshotId=snapshotId");
|
||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
||||
"Version=2009-11-30&Action=ResetSnapshotAttribute&Attribute=createVolumePermission&SnapshotId=snapshotId",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
|
|
@ -25,8 +25,8 @@ import java.lang.reflect.Method;
|
|||
import org.jclouds.aws.ec2.xml.AllocateAddressResponseHandler;
|
||||
import org.jclouds.aws.ec2.xml.DescribeAddressesResponseHandler;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.functions.CloseContentAndReturn;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -48,13 +48,12 @@ public class ElasticIPAddressAsyncClientTest extends
|
|||
HttpRequest request = processor.createRequest(method, null, "127.0.0.1");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 64\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2009-11-30&Action=DisassociateAddress&PublicIp=127.0.0.1");
|
||||
"Version=2009-11-30&Action=DisassociateAddress&PublicIp=127.0.0.1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
@ -67,13 +66,12 @@ public class ElasticIPAddressAsyncClientTest extends
|
|||
HttpRequest request = processor.createRequest(method, null, "127.0.0.1", "me");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 75\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2009-11-30&Action=AssociateAddress&InstanceId=me&PublicIp=127.0.0.1");
|
||||
"Version=2009-11-30&Action=AssociateAddress&InstanceId=me&PublicIp=127.0.0.1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
@ -86,12 +84,11 @@ public class ElasticIPAddressAsyncClientTest extends
|
|||
HttpRequest request = processor.createRequest(method, null, "127.0.0.1");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 59\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2009-11-30&Action=ReleaseAddress&PublicIp=127.0.0.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2009-11-30&Action=ReleaseAddress&PublicIp=127.0.0.1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
@ -104,11 +101,10 @@ public class ElasticIPAddressAsyncClientTest extends
|
|||
HttpRequest request = processor.createRequest(method, null, "127.0.0.1");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 64\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2009-11-30&Action=DescribeAddresses&PublicIp.1=127.0.0.1");
|
||||
"Version=2009-11-30&Action=DescribeAddresses&PublicIp.1=127.0.0.1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, DescribeAddressesResponseHandler.class);
|
||||
|
@ -123,10 +119,9 @@ public class ElasticIPAddressAsyncClientTest extends
|
|||
HttpRequest request = processor.createRequest(method, (String) null);
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 41\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2009-11-30&Action=AllocateAddress");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2009-11-30&Action=AllocateAddress",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, AllocateAddressResponseHandler.class);
|
||||
|
|
|
@ -39,8 +39,8 @@ import org.jclouds.aws.ec2.xml.RunInstancesResponseHandler;
|
|||
import org.jclouds.aws.ec2.xml.StringValueHandler;
|
||||
import org.jclouds.aws.ec2.xml.UnencodeStringValueHandler;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.functions.CloseContentAndReturn;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -59,10 +59,9 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
HttpRequest request = processor.createRequest(method, (String) null);
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 43\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2009-11-30&Action=DescribeInstances");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2009-11-30&Action=DescribeInstances",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, DescribeInstancesResponseHandler.class);
|
||||
|
@ -78,11 +77,10 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
HttpRequest request = processor.createRequest(method, null, "1", "2");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 73\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2009-11-30&Action=DescribeInstances&InstanceId.1=1&InstanceId.2=2");
|
||||
"Version=2009-11-30&Action=DescribeInstances&InstanceId.1=1&InstanceId.2=2",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, DescribeInstancesResponseHandler.class);
|
||||
|
@ -98,11 +96,10 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
HttpRequest request = processor.createRequest(method, null, "1", "2");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 74\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2009-11-30&Action=TerminateInstances&InstanceId.1=1&InstanceId.2=2");
|
||||
"Version=2009-11-30&Action=TerminateInstances&InstanceId.1=1&InstanceId.2=2",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, InstanceStateChangeHandler.class);
|
||||
|
@ -118,11 +115,10 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
HttpRequest request = processor.createRequest(method, null, null, "ami-voo", 1, 1);
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 76\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2009-11-30&Action=RunInstances&ImageId=ami-voo&MinCount=1&MaxCount=1");
|
||||
"Version=2009-11-30&Action=RunInstances&ImageId=ami-voo&MinCount=1&MaxCount=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, RunInstancesResponseHandler.class);
|
||||
|
@ -142,12 +138,11 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
"group2"));
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.eu-west-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 202\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.eu-west-1.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.eu-west-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2009-11-30&Action=RunInstances&ImageId=ami-voo&MinCount=1&MaxCount=5&KernelId=kernelId&Monitoring.Enabled=true&SecurityGroup.1=group1&SecurityGroup.2=group2&Placement.AvailabilityZone=eu-west-1a");
|
||||
"Version=2009-11-30&Action=RunInstances&ImageId=ami-voo&MinCount=1&MaxCount=5&KernelId=kernelId&Monitoring.Enabled=true&SecurityGroup.1=group1&SecurityGroup.2=group2&Placement.AvailabilityZone=eu-west-1a",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, RunInstancesResponseHandler.class);
|
||||
|
@ -162,11 +157,10 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
HttpRequest request = processor.createRequest(method, null, true, "1", "2");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 80\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2009-11-30&Action=StopInstances&Force=true&InstanceId.1=1&InstanceId.2=2");
|
||||
"Version=2009-11-30&Action=StopInstances&Force=true&InstanceId.1=1&InstanceId.2=2",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, InstanceStateChangeHandler.class);
|
||||
|
@ -181,13 +175,12 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
HttpRequest request = processor.createRequest(method, null, "1", "2");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 71\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2009-11-30&Action=RebootInstances&InstanceId.1=1&InstanceId.2=2");
|
||||
"Version=2009-11-30&Action=RebootInstances&InstanceId.1=1&InstanceId.2=2",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
@ -200,11 +193,10 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
HttpRequest request = processor.createRequest(method, null, "1", "2");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 70\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2009-11-30&Action=StartInstances&InstanceId.1=1&InstanceId.2=2");
|
||||
"Version=2009-11-30&Action=StartInstances&InstanceId.1=1&InstanceId.2=2",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, InstanceStateChangeHandler.class);
|
||||
|
@ -220,11 +212,11 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
HttpRequest request = processor.createRequest(method, null, "1");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Content-Length: 83\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=userData&InstanceId=1");
|
||||
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=userData&InstanceId=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, UnencodeStringValueHandler.class);
|
||||
|
@ -240,11 +232,11 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
HttpRequest request = processor.createRequest(method, null, "1");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Content-Length: 89\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=rootDeviceName&InstanceId=1");
|
||||
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=rootDeviceName&InstanceId=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, StringValueHandler.class);
|
||||
|
@ -260,11 +252,11 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
HttpRequest request = processor.createRequest(method, null, "1");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Content-Length: 82\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=ramdisk&InstanceId=1");
|
||||
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=ramdisk&InstanceId=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, StringValueHandler.class);
|
||||
|
@ -280,11 +272,11 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
HttpRequest request = processor.createRequest(method, null, "1");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Content-Length: 96\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=disableApiTermination&InstanceId=1");
|
||||
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=disableApiTermination&InstanceId=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, BooleanValueHandler.class);
|
||||
|
@ -300,11 +292,10 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
HttpRequest request = processor.createRequest(method, null, "1");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 81\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=kernel&InstanceId=1");
|
||||
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=kernel&InstanceId=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, StringValueHandler.class);
|
||||
|
@ -320,11 +311,11 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
HttpRequest request = processor.createRequest(method, null, "1");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Content-Length: 87\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=instanceType&InstanceId=1");
|
||||
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=instanceType&InstanceId=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, InstanceTypeHandler.class);
|
||||
|
@ -341,12 +332,11 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
HttpRequest request = processor.createRequest(method, null, "1");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 108\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=instanceInitiatedShutdownBehavior&InstanceId=1");
|
||||
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=instanceInitiatedShutdownBehavior&InstanceId=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, InstanceInitiatedShutdownBehaviorHandler.class);
|
||||
|
@ -362,11 +352,11 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
HttpRequest request = processor.createRequest(method, null, "1");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Content-Length: 93\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=blockDeviceMapping&InstanceId=1");
|
||||
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=blockDeviceMapping&InstanceId=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, BlockDeviceMappingHandler.class);
|
||||
|
@ -382,17 +372,17 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
HttpRequest request = processor.createRequest(method, null, "1", "test".getBytes());
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 100\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2009-11-30&Action=ModifyInstanceAttribute&Attribute=userData&Value=dGVzdA%3D%3D&InstanceId=1");
|
||||
"Version=2009-11-30&Action=ModifyInstanceAttribute&Attribute=userData&Value=dGVzdA%3D%3D&InstanceId=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
filter.filter(request);// ensure encoding worked properly
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Action=ModifyInstanceAttribute&Attribute=userData&InstanceId=1&Signature=ch%2BpeYTRad241GAhjH9Wo2vKWlkgfNa3txM0lhPCBSM%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&Value=dGVzdA%3D%3D&Version=2009-11-30&AWSAccessKeyId=identity");
|
||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
||||
"Action=ModifyInstanceAttribute&Attribute=userData&InstanceId=1&Signature=ch%2BpeYTRad241GAhjH9Wo2vKWlkgfNa3txM0lhPCBSM%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&Value=dGVzdA%3D%3D&Version=2009-11-30&AWSAccessKeyId=identity",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
@ -406,12 +396,12 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
HttpRequest request = processor.createRequest(method, null, "1", "test");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Content-Length: 91\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2009-11-30&Action=ModifyInstanceAttribute&Attribute=ramdisk&Value=test&InstanceId=1");
|
||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
||||
"Version=2009-11-30&Action=ModifyInstanceAttribute&Attribute=ramdisk&Value=test&InstanceId=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
@ -425,12 +415,12 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
HttpRequest request = processor.createRequest(method, null, "1", "test");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Content-Length: 90\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2009-11-30&Action=ModifyInstanceAttribute&Attribute=kernel&Value=test&InstanceId=1");
|
||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
||||
"Version=2009-11-30&Action=ModifyInstanceAttribute&Attribute=kernel&Value=test&InstanceId=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
@ -445,14 +435,13 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
HttpRequest request = processor.createRequest(method, null, "1", true);
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 105\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2009-11-30&Action=ModifyInstanceAttribute&Attribute=disableApiTermination&Value=true&InstanceId=1");
|
||||
"Version=2009-11-30&Action=ModifyInstanceAttribute&Attribute=disableApiTermination&Value=true&InstanceId=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
@ -466,14 +455,13 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
HttpRequest request = processor.createRequest(method, null, "1", InstanceType.C1_MEDIUM);
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 101\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2009-11-30&Action=ModifyInstanceAttribute&Attribute=instanceType&Value=c1.medium&InstanceId=1");
|
||||
"Version=2009-11-30&Action=ModifyInstanceAttribute&Attribute=instanceType&Value=c1.medium&InstanceId=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
@ -489,14 +477,13 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
InstanceInitiatedShutdownBehavior.TERMINATE);
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 122\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2009-11-30&Action=ModifyInstanceAttribute&Attribute=instanceInitiatedShutdownBehavior&Value=terminate&InstanceId=1");
|
||||
"Version=2009-11-30&Action=ModifyInstanceAttribute&Attribute=instanceInitiatedShutdownBehavior&Value=terminate&InstanceId=1",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
@ -515,17 +502,17 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
|||
HttpRequest request = processor.createRequest(method, null, "1", blockDeviceMapping);
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 202\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2009-11-30&Action=ModifyInstanceAttribute&InstanceId=1&BlockDeviceMapping.1.Ebs.VolumeId=vol-test1&BlockDeviceMapping.1.DeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.1.Ebs.DeleteOnTermination=true");
|
||||
"Version=2009-11-30&Action=ModifyInstanceAttribute&InstanceId=1&BlockDeviceMapping.1.Ebs.VolumeId=vol-test1&BlockDeviceMapping.1.DeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.1.Ebs.DeleteOnTermination=true",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
filter.filter(request);// ensure encoding worked properly
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Action=ModifyInstanceAttribute&BlockDeviceMapping.1.DeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.1.Ebs.DeleteOnTermination=true&BlockDeviceMapping.1.Ebs.VolumeId=vol-test1&InstanceId=1&Signature=QOd9dFUmgBAsz3b5rWOE2wWgoB85vmhsVM9yNO2s7cE%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&Version=2009-11-30&AWSAccessKeyId=identity");
|
||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
||||
"Action=ModifyInstanceAttribute&BlockDeviceMapping.1.DeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.1.Ebs.DeleteOnTermination=true&BlockDeviceMapping.1.Ebs.VolumeId=vol-test1&InstanceId=1&Signature=QOd9dFUmgBAsz3b5rWOE2wWgoB85vmhsVM9yNO2s7cE%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&Version=2009-11-30&AWSAccessKeyId=identity",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
|
|
@ -24,8 +24,8 @@ import java.lang.reflect.Method;
|
|||
|
||||
import org.jclouds.aws.ec2.xml.DescribeKeyPairsResponseHandler;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.functions.CloseContentAndReturn;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -45,12 +45,11 @@ public class KeyPairAsyncClientTest extends BaseEC2AsyncClientTest<KeyPairAsyncC
|
|||
HttpRequest request = processor.createRequest(method, null, "mykey");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 53\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2009-11-30&Action=DeleteKeyPair&KeyName=mykey");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2009-11-30&Action=DeleteKeyPair&KeyName=mykey",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
@ -63,10 +62,9 @@ public class KeyPairAsyncClientTest extends BaseEC2AsyncClientTest<KeyPairAsyncC
|
|||
HttpRequest request = processor.createRequest(method, (String) null);
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 42\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2009-11-30&Action=DescribeKeyPairs");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2009-11-30&Action=DescribeKeyPairs",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, DescribeKeyPairsResponseHandler.class);
|
||||
|
@ -82,11 +80,10 @@ public class KeyPairAsyncClientTest extends BaseEC2AsyncClientTest<KeyPairAsyncC
|
|||
HttpRequest request = processor.createRequest(method, null, "1", "2");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 66\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2009-11-30&Action=DescribeKeyPairs&KeyName.1=1&KeyName.2=2");
|
||||
"Version=2009-11-30&Action=DescribeKeyPairs&KeyName.1=1&KeyName.2=2",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, DescribeKeyPairsResponseHandler.class);
|
||||
|
|
|
@ -46,13 +46,8 @@ public class MonitoringAsyncClientTest extends BaseEC2AsyncClientTest<Monitoring
|
|||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
String payload = "Version=2009-11-30&Action=UnmonitorInstances&InstanceId.0=instance1&InstanceId.1=instance2";
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
String
|
||||
.format(
|
||||
"Content-Length: %d\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n",
|
||||
payload.getBytes().length));
|
||||
assertPayloadEquals(request, payload);
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, payload, "application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, MonitoringStateHandler.class);
|
||||
|
@ -67,11 +62,11 @@ public class MonitoringAsyncClientTest extends BaseEC2AsyncClientTest<Monitoring
|
|||
HttpRequest request = processor.createRequest(method, null, "instance1", "instance2");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Content-Length: 88\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2009-11-30&Action=MonitorInstances&InstanceId.0=instance1&InstanceId.1=instance2");
|
||||
"Version=2009-11-30&Action=MonitorInstances&InstanceId.0=instance1&InstanceId.1=instance2",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, MonitoringStateHandler.class);
|
||||
|
|
|
@ -27,7 +27,7 @@ import org.jclouds.aws.ec2.domain.UserIdGroupPair;
|
|||
import org.jclouds.aws.ec2.functions.ReturnVoidOnGroupNotFound;
|
||||
import org.jclouds.aws.ec2.xml.DescribeSecurityGroupsResponseHandler;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.functions.CloseContentAndReturn;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -49,12 +49,11 @@ public class SecurityGroupAsyncClientTest extends BaseEC2AsyncClientTest<Securit
|
|||
HttpRequest request = processor.createRequest(method, null, "name");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 60\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2009-11-30&Action=DeleteSecurityGroup&GroupName=name");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2009-11-30&Action=DeleteSecurityGroup&GroupName=name",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnVoidOnGroupNotFound.class);
|
||||
|
||||
|
@ -68,13 +67,13 @@ public class SecurityGroupAsyncClientTest extends BaseEC2AsyncClientTest<Securit
|
|||
HttpRequest request = processor.createRequest(method, null, "name", "description");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Content-Length: 89\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2009-11-30&Action=CreateSecurityGroup&GroupDescription=description&GroupName=name");
|
||||
"Version=2009-11-30&Action=CreateSecurityGroup&GroupDescription=description&GroupName=name",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
@ -88,10 +87,9 @@ public class SecurityGroupAsyncClientTest extends BaseEC2AsyncClientTest<Securit
|
|||
HttpRequest request = processor.createRequest(method, (String) null);
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 48\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2009-11-30&Action=DescribeSecurityGroups");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2009-11-30&Action=DescribeSecurityGroups",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, DescribeSecurityGroupsResponseHandler.class);
|
||||
|
@ -107,11 +105,10 @@ public class SecurityGroupAsyncClientTest extends BaseEC2AsyncClientTest<Securit
|
|||
HttpRequest request = processor.createRequest(method, null, "1", "2");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 76\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2009-11-30&Action=DescribeSecurityGroups&GroupName.1=1&GroupName.2=2");
|
||||
"Version=2009-11-30&Action=DescribeSecurityGroups&GroupName.1=1&GroupName.2=2",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, DescribeSecurityGroupsResponseHandler.class);
|
||||
|
@ -129,14 +126,13 @@ public class SecurityGroupAsyncClientTest extends BaseEC2AsyncClientTest<Securit
|
|||
"sourceUser", "sourceGroup"));
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 145\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2009-11-30&Action=AuthorizeSecurityGroupIngress&GroupName=group&SourceSecurityGroupOwnerId=sourceUser&SourceSecurityGroupName=sourceGroup");
|
||||
"Version=2009-11-30&Action=AuthorizeSecurityGroupIngress&GroupName=group&SourceSecurityGroupOwnerId=sourceUser&SourceSecurityGroupName=sourceGroup",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
@ -152,14 +148,13 @@ public class SecurityGroupAsyncClientTest extends BaseEC2AsyncClientTest<Securit
|
|||
7000, "0.0.0.0/0");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 131\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2009-11-30&Action=AuthorizeSecurityGroupIngress&CidrIp=0.0.0.0%2F0&IpProtocol=tcp&GroupName=group&FromPort=6000&ToPort=7000");
|
||||
"Version=2009-11-30&Action=AuthorizeSecurityGroupIngress&CidrIp=0.0.0.0%2F0&IpProtocol=tcp&GroupName=group&FromPort=6000&ToPort=7000",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
@ -175,14 +170,13 @@ public class SecurityGroupAsyncClientTest extends BaseEC2AsyncClientTest<Securit
|
|||
"sourceUser", "sourceGroup"));
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 142\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2009-11-30&Action=RevokeSecurityGroupIngress&GroupName=group&SourceSecurityGroupOwnerId=sourceUser&SourceSecurityGroupName=sourceGroup");
|
||||
"Version=2009-11-30&Action=RevokeSecurityGroupIngress&GroupName=group&SourceSecurityGroupOwnerId=sourceUser&SourceSecurityGroupName=sourceGroup",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
@ -198,14 +192,13 @@ public class SecurityGroupAsyncClientTest extends BaseEC2AsyncClientTest<Securit
|
|||
7000, "0.0.0.0/0");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 128\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2009-11-30&Action=RevokeSecurityGroupIngress&CidrIp=0.0.0.0%2F0&IpProtocol=tcp&GroupName=group&FromPort=6000&ToPort=7000");
|
||||
"Version=2009-11-30&Action=RevokeSecurityGroupIngress&CidrIp=0.0.0.0%2F0&IpProtocol=tcp&GroupName=group&FromPort=6000&ToPort=7000",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
|
|
@ -61,12 +61,11 @@ public class ELBAsyncClientTest extends RestClientTest<ELBAsyncClient> {
|
|||
|
||||
assertRequestLineEquals(request,
|
||||
"POST https://elasticloadbalancing.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 130\nContent-Type: application/x-www-form-urlencoded\nHost: elasticloadbalancing.us-east-1.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: elasticloadbalancing.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Version=2009-11-25&Action=RegisterInstancesWithLoadBalancer&LoadBalancerName=ReferenceAP1&Instances.member.1.InstanceId=i-6055fa09");
|
||||
"Version=2009-11-25&Action=RegisterInstancesWithLoadBalancer&LoadBalancerName=ReferenceAP1&Instances.member.1.InstanceId=i-6055fa09",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method,
|
||||
|
|
|
@ -18,33 +18,17 @@
|
|||
*/
|
||||
package org.jclouds.aws.filters;
|
||||
|
||||
import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.concurrent.config.ExecutorServiceModule;
|
||||
import org.jclouds.date.DateService;
|
||||
import org.jclouds.date.TimeStamp;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.jclouds.aws.ec2.services.BaseEC2AsyncClientTest;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.name.Names;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
@Test(groups = "unit", testName = "aws.FormSignerTest")
|
||||
public class FormSignerTest {
|
||||
|
||||
private Injector injector;
|
||||
private FormSigner filter;
|
||||
public class FormSignerTest extends BaseEC2AsyncClientTest<String> {
|
||||
|
||||
@Test
|
||||
void testBuildCanonicalizedString() {
|
||||
|
@ -57,33 +41,9 @@ public class FormSignerTest {
|
|||
"AWSAccessKeyId=foo&Action=DescribeImages&Expires=2008-02-10T12%3A00%3A00Z&ImageId.1=ami-2bb65342&SignatureMethod=HmacSHA256&SignatureVersion=2&Version=2009-11-30");
|
||||
}
|
||||
|
||||
/**
|
||||
* before class, as we need to ensure that the filter is threadsafe.
|
||||
*
|
||||
*/
|
||||
@BeforeClass
|
||||
protected void createFilter() {
|
||||
injector = Guice.createInjector(new ParserModule(), new ExecutorServiceModule(
|
||||
sameThreadExecutor(), sameThreadExecutor()), new AbstractModule() {
|
||||
|
||||
protected void configure() {
|
||||
bindConstant().annotatedWith(Names.named(Constants.PROPERTY_IDENTITY)).to("foo");
|
||||
bindConstant().annotatedWith(Names.named(Constants.PROPERTY_CREDENTIAL)).to("bar");
|
||||
bindConstant().annotatedWith(Names.named(Constants.PROPERTY_SESSION_INTERVAL)).to(30);
|
||||
bindConstant().annotatedWith(Names.named(Constants.PROPERTY_IO_WORKER_THREADS)).to("1");
|
||||
bindConstant().annotatedWith(Names.named(Constants.PROPERTY_USER_THREADS)).to("1");
|
||||
@Override
|
||||
protected TypeLiteral<RestAnnotationProcessor<String>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<String>>() {
|
||||
};
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Provides
|
||||
@TimeStamp
|
||||
protected String provideTimeStamp(final DateService dateService,
|
||||
@Named(Constants.PROPERTY_SESSION_INTERVAL) final int expiration) {
|
||||
return dateService.iso8601DateFormat(new Date(System.currentTimeMillis()
|
||||
+ (expiration * 1000)));
|
||||
}
|
||||
});
|
||||
filter = injector.getInstance(FormSigner.class);
|
||||
}
|
||||
|
||||
}
|
|
@ -12,6 +12,7 @@ import org.easymock.IArgumentMatcher;
|
|||
import org.jclouds.http.HttpCommand;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.Payloads;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.RequestSigner;
|
||||
|
@ -63,9 +64,8 @@ public class ParseAWSErrorFromXmlContentTest {
|
|||
|
||||
HttpCommand command = createMock(HttpCommand.class);
|
||||
HttpRequest request = new HttpRequest(method, uri);
|
||||
HttpResponse response = new HttpResponse(Utils.toInputStream(content));
|
||||
response.setStatusCode(statusCode);
|
||||
response.setMessage(message);
|
||||
HttpResponse response = new HttpResponse(statusCode, message, Payloads
|
||||
.newInputStreamPayload(Utils.toInputStream(content)));
|
||||
|
||||
expect(command.getRequest()).andReturn(request).atLeastOnce();
|
||||
command.setException(classEq(expected));
|
||||
|
|
|
@ -61,7 +61,7 @@ import org.jclouds.blobstore.functions.ThrowKeyNotFoundOn404;
|
|||
import org.jclouds.date.TimeStamp;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.RequiresHttp;
|
||||
import org.jclouds.http.functions.CloseContentAndReturn;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.http.functions.ParseETagHeader;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.ReturnTrueIf2xx;
|
||||
|
@ -102,16 +102,16 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
|||
HttpRequest request = processor.createRequest(method, "bucket");
|
||||
|
||||
assertRequestLineEquals(request, "GET https://bucket.s3.amazonaws.com/?location HTTP/1.1");
|
||||
assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(request, null);
|
||||
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
filter.filter(request);
|
||||
|
||||
assertRequestLineEquals(request, "GET https://bucket.s3.amazonaws.com/?location HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
assertNonPayloadHeadersEqual(
|
||||
request,
|
||||
"Authorization: AWS identity:2fFTeYJTDwiJmaAkKj732RjNbOg=\nDate: 2009-11-08T15:54:08.897Z\nHost: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(request, null);
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, LocationConstraintHandler.class);
|
||||
|
@ -126,8 +126,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
|||
|
||||
assertRequestLineEquals(request,
|
||||
"GET https://bucket.s3.amazonaws.com/?requestPayment HTTP/1.1");
|
||||
assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(request, null);
|
||||
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, PayerHandler.class);
|
||||
|
@ -143,13 +143,13 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
|||
|
||||
assertRequestLineEquals(request,
|
||||
"PUT https://bucket.s3.amazonaws.com/?requestPayment HTTP/1.1");
|
||||
assertHeadersEqual(request,
|
||||
"Content-Length: 133\nContent-Type: text/xml\nHost: bucket.s3.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"<RequestPaymentConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Payer>BucketOwner</Payer></RequestPaymentConfiguration>");
|
||||
"<RequestPaymentConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Payer>BucketOwner</Payer></RequestPaymentConfiguration>",
|
||||
"text/xml", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
@ -163,13 +163,13 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
|||
|
||||
assertRequestLineEquals(request,
|
||||
"PUT https://bucket.s3.amazonaws.com/?requestPayment HTTP/1.1");
|
||||
assertHeadersEqual(request,
|
||||
"Content-Length: 131\nContent-Type: text/xml\nHost: bucket.s3.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"<RequestPaymentConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Payer>Requester</Payer></RequestPaymentConfiguration>");
|
||||
"<RequestPaymentConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Payer>Requester</Payer></RequestPaymentConfiguration>",
|
||||
"text/xml", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
@ -182,8 +182,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
|||
HttpRequest request = processor.createRequest(method, "bucket");
|
||||
|
||||
assertRequestLineEquals(request, "GET https://bucket.s3.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(request, null);
|
||||
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, ListBucketHandler.class);
|
||||
|
@ -197,8 +197,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
|||
HttpRequest request = processor.createRequest(method, "bucket");
|
||||
|
||||
assertRequestLineEquals(request, "HEAD https://bucket.s3.amazonaws.com/?max-keys=0 HTTP/1.1");
|
||||
assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(request, null);
|
||||
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -228,10 +228,10 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
|||
|
||||
assertRequestLineEquals(request,
|
||||
"PUT https://destinationbucket.s3.amazonaws.com/destinationObject HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
assertNonPayloadHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 0\nHost: destinationbucket.s3.amazonaws.com\nx-amz-copy-source: /sourceBucket/sourceObject\n");
|
||||
assertPayloadEquals(request, null);
|
||||
"Host: destinationbucket.s3.amazonaws.com\nx-amz-copy-source: /sourceBucket/sourceObject\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, CopyObjectHandler.class);
|
||||
|
@ -246,8 +246,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
|||
HttpRequest request = processor.createRequest(method, "bucket");
|
||||
|
||||
assertRequestLineEquals(request, "DELETE https://bucket.s3.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(request, null);
|
||||
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -261,10 +261,10 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
|||
HttpRequest request = processor.createRequest(method, "bucket", "object");
|
||||
|
||||
assertRequestLineEquals(request, "DELETE https://bucket.s3.amazonaws.com/object HTTP/1.1");
|
||||
assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(request, null);
|
||||
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
|
||||
|
||||
|
@ -277,8 +277,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
|||
HttpRequest request = processor.createRequest(method, "bucket");
|
||||
|
||||
assertRequestLineEquals(request, "GET https://bucket.s3.amazonaws.com/?acl HTTP/1.1");
|
||||
assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(request, null);
|
||||
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, AccessControlListHandler.class);
|
||||
|
@ -294,8 +294,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
|||
HttpRequest request = processor.createRequest(method, "bucket", "object");
|
||||
|
||||
assertRequestLineEquals(request, "GET https://bucket.s3.amazonaws.com/object HTTP/1.1");
|
||||
assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(request, null);
|
||||
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseObjectFromHeadersAndHttpContent.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -310,8 +310,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
|||
HttpRequest request = processor.createRequest(method, "bucket", "object");
|
||||
|
||||
assertRequestLineEquals(request, "GET https://bucket.s3.amazonaws.com/object?acl HTTP/1.1");
|
||||
assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(request, null);
|
||||
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, AccessControlListHandler.class);
|
||||
|
@ -326,8 +326,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
|||
HttpRequest request = processor.createRequest(method, "bucket", "object");
|
||||
|
||||
assertRequestLineEquals(request, "HEAD https://bucket.s3.amazonaws.com/object HTTP/1.1");
|
||||
assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(request, null);
|
||||
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -342,8 +342,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
|||
HttpRequest request = processor.createRequest(method, "bucket", "object");
|
||||
|
||||
assertRequestLineEquals(request, "HEAD https://bucket.s3.amazonaws.com/object HTTP/1.1");
|
||||
assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(request, null);
|
||||
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseObjectMetadataFromHeaders.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -357,8 +357,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
|||
HttpRequest request = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(request, "GET https://s3.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(request, "Host: s3.amazonaws.com\n");
|
||||
assertPayloadEquals(request, null);
|
||||
assertNonPayloadHeadersEqual(request, "Host: s3.amazonaws.com\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, ListAllMyBucketsHandler.class);
|
||||
|
@ -379,11 +379,11 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
|||
.fromCannedAccessPolicy(CannedAccessPolicy.PRIVATE, "1234"));
|
||||
|
||||
assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/?acl HTTP/1.1");
|
||||
assertHeadersEqual(request,
|
||||
"Content-Length: 321\nContent-Type: text/xml\nHost: bucket.s3.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"<AccessControlPolicy xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Owner><ID>1234</ID></Owner><AccessControlList><Grant><Grantee xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"CanonicalUser\"><ID>1234</ID></Grantee><Permission>FULL_CONTROL</Permission></Grant></AccessControlList></AccessControlPolicy>");
|
||||
"<AccessControlPolicy xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Owner><ID>1234</ID></Owner><AccessControlList><Grant><Grantee xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"CanonicalUser\"><ID>1234</ID></Grantee><Permission>FULL_CONTROL</Permission></Grant></AccessControlList></AccessControlPolicy>",
|
||||
"text/xml", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -399,8 +399,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
|||
HttpRequest request = processor.createRequest(method, (String) null, "bucket");
|
||||
|
||||
assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(request, "Content-Length: 0\nHost: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(request, null);
|
||||
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -416,11 +416,12 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
|||
HttpRequest request = processor.createRequest(method, "EU", "bucket");
|
||||
|
||||
assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(request,
|
||||
"Content-Length: 98\nContent-Type: application/unknown\nHost: bucket.s3.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request,
|
||||
"Host: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"<CreateBucketConfiguration><LocationConstraint>EU</LocationConstraint></CreateBucketConfiguration>");
|
||||
"<CreateBucketConfiguration><LocationConstraint>EU</LocationConstraint></CreateBucketConfiguration>",
|
||||
"text/xml", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -438,9 +439,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
|||
.apply(BindBlobToMultipartFormTest.TEST_BLOB));
|
||||
|
||||
assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/hello HTTP/1.1");
|
||||
assertHeadersEqual(request,
|
||||
"Content-Length: 5\nContent-Type: text/plain\nHost: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "hello");
|
||||
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "hello", "text/plain", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseETagHeader.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -456,11 +456,11 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
|||
.fromCannedAccessPolicy(CannedAccessPolicy.PRIVATE, "1234"));
|
||||
|
||||
assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/key?acl HTTP/1.1");
|
||||
assertHeadersEqual(request,
|
||||
"Content-Length: 321\nContent-Type: text/xml\nHost: bucket.s3.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"<AccessControlPolicy xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Owner><ID>1234</ID></Owner><AccessControlList><Grant><Grantee xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"CanonicalUser\"><ID>1234</ID></Grantee><Permission>FULL_CONTROL</Permission></Grant></AccessControlList></AccessControlPolicy>");
|
||||
"<AccessControlPolicy xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Owner><ID>1234</ID></Owner><AccessControlList><Grant><Grantee xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"CanonicalUser\"><ID>1234</ID></Grantee><Permission>FULL_CONTROL</Permission></Grant></AccessControlList></AccessControlPolicy>",
|
||||
"text/xml", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -474,8 +474,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
|||
HttpRequest request = processor.createRequest(method, "bucket");
|
||||
|
||||
assertRequestLineEquals(request, "GET https://bucket.s3.amazonaws.com/?logging HTTP/1.1");
|
||||
assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(request, null);
|
||||
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, BucketLoggingHandler.class);
|
||||
|
@ -490,12 +490,12 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
|||
HttpRequest request = processor.createRequest(method, "bucket");
|
||||
|
||||
assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/?logging HTTP/1.1");
|
||||
assertHeadersEqual(request,
|
||||
"Content-Length: 70\nContent-Type: text/xml\nHost: bucket.s3.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"<BucketLoggingStatus xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"/>");
|
||||
"<BucketLoggingStatus xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"/>",
|
||||
"text/xml", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
@ -511,12 +511,11 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
|||
"adrian@jclouds.org"), Permission.FULL_CONTROL))));
|
||||
|
||||
assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/?logging HTTP/1.1");
|
||||
assertHeadersEqual(request,
|
||||
"Content-Length: 433\nContent-Type: text/xml\nHost: bucket.s3.amazonaws.com\n");
|
||||
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||
assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||
"/s3/bucket_logging.xml")));
|
||||
"/s3/bucket_logging.xml")), "text/xml", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
|
|
@ -23,8 +23,6 @@ import static org.testng.Assert.assertEquals;
|
|||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
|
||||
import org.jclouds.aws.s3.domain.BucketLogging;
|
||||
import org.jclouds.aws.s3.domain.AccessControlList.EmailAddressGrantee;
|
||||
import org.jclouds.aws.s3.domain.AccessControlList.Grant;
|
||||
|
@ -58,8 +56,7 @@ public class BindBucketLoggingToXmlPayloadTest extends BaseHandlerTest {
|
|||
.getInstance(BindBucketLoggingToXmlPayload.class);
|
||||
|
||||
binder.bindToRequest(request, bucketLogging);
|
||||
assertEquals(request.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE), "text/xml");
|
||||
assertEquals(request.getFirstHeaderOrNull(HttpHeaders.CONTENT_LENGTH), "433");
|
||||
assertEquals(request.getPayload().getContentType(), "text/xml");
|
||||
assertEquals(request.getPayload().getRawContent(), expected);
|
||||
|
||||
}
|
||||
|
|
|
@ -23,8 +23,6 @@ import static org.testng.Assert.assertEquals;
|
|||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.functions.BaseHandlerTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -44,8 +42,7 @@ public class BindNoBucketLoggingToXmlPayloadTest extends BaseHandlerTest {
|
|||
.getInstance(BindNoBucketLoggingToXmlPayload.class);
|
||||
|
||||
binder.bindToRequest(request, null);
|
||||
assertEquals(request.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE), "text/xml");
|
||||
assertEquals(request.getFirstHeaderOrNull(HttpHeaders.CONTENT_LENGTH), "70");
|
||||
assertEquals(request.getPayload().getContentType(), "text/xml");
|
||||
assertEquals(request.getPayload().getRawContent(),
|
||||
"<BucketLoggingStatus xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"/>");
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ import org.jclouds.http.handlers.DelegatingErrorHandler;
|
|||
import org.jclouds.http.handlers.DelegatingRetryHandler;
|
||||
import org.jclouds.logging.config.NullLoggingModule;
|
||||
import org.jclouds.rest.RestContextFactory;
|
||||
import org.jclouds.rest.RestClientTest.MockModule;
|
||||
import org.jclouds.rest.BaseRestClientTest.MockModule;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
|
|
|
@ -31,7 +31,7 @@ import org.jclouds.Constants;
|
|||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.logging.config.NullLoggingModule;
|
||||
import org.jclouds.rest.RestContextFactory;
|
||||
import org.jclouds.rest.RestClientTest.MockModule;
|
||||
import org.jclouds.rest.BaseRestClientTest.MockModule;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
|
|
@ -39,6 +39,7 @@ import org.jclouds.blobstore.functions.ParseSystemAndUserMetadataFromHeaders;
|
|||
import org.jclouds.encryption.EncryptionService;
|
||||
import org.jclouds.encryption.internal.JCEEncryptionService;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.Payloads;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -53,8 +54,9 @@ public class ParseObjectMetadataFromHeadersTest {
|
|||
|
||||
@Test
|
||||
void testNormal() throws Exception {
|
||||
HttpResponse http = new HttpResponse(400, "boa", Payloads.newStringPayload(""));
|
||||
http.getPayload().setContentLength(1025l);
|
||||
|
||||
HttpResponse http = new HttpResponse();
|
||||
http.getHeaders().put(HttpHeaders.CACHE_CONTROL, "cacheControl");
|
||||
http.getHeaders().put("Content-Disposition", "contentDisposition");
|
||||
http.getHeaders().put(HttpHeaders.CONTENT_ENCODING, "encoding");
|
||||
|
@ -67,7 +69,9 @@ public class ParseObjectMetadataFromHeadersTest {
|
|||
@Test
|
||||
void testAmzEtag() throws Exception {
|
||||
|
||||
HttpResponse http = new HttpResponse();
|
||||
HttpResponse http = new HttpResponse(400, "boa", Payloads.newStringPayload(""));
|
||||
http.getPayload().setContentLength(1025l);
|
||||
|
||||
http.getHeaders().put(HttpHeaders.CACHE_CONTROL, "cacheControl");
|
||||
http.getHeaders().put("Content-Disposition", "contentDisposition");
|
||||
http.getHeaders().put(HttpHeaders.CONTENT_ENCODING, "encoding");
|
||||
|
|
|
@ -33,9 +33,10 @@ import org.jclouds.http.HttpCommand;
|
|||
import org.jclouds.http.HttpException;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.Payloads;
|
||||
import org.jclouds.logging.config.NullLoggingModule;
|
||||
import org.jclouds.rest.RestContextFactory;
|
||||
import org.jclouds.rest.RestClientTest.MockModule;
|
||||
import org.jclouds.rest.BaseRestClientTest.MockModule;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.testng.annotations.AfterTest;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
|
@ -63,8 +64,7 @@ public class S3UtilsTest {
|
|||
.buildInjector();
|
||||
|
||||
utils = injector.getInstance(S3Utils.class);
|
||||
response = new HttpResponse();
|
||||
response.setStatusCode(400);
|
||||
response = new HttpResponse(400, "boa", Payloads.newStringPayload(""));
|
||||
response.getHeaders().put(S3Headers.REQUEST_ID, "requestid");
|
||||
response.getHeaders().put(S3Headers.REQUEST_TOKEN, "requesttoken");
|
||||
command = createMock(HttpCommand.class);
|
||||
|
|
|
@ -81,10 +81,9 @@ public class SQSAsyncClientTest extends RestClientTest<SQSAsyncClient> {
|
|||
HttpRequest request = processor.createRequest(method, (String) null);
|
||||
|
||||
assertRequestLineEquals(request, "POST https://sqs.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 36\nContent-Type: application/x-www-form-urlencoded\nHost: sqs.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2009-02-01&Action=ListQueues");
|
||||
assertNonPayloadHeadersEqual(request, "Host: sqs.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2009-02-01&Action=ListQueues",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, RegexListQueuesResponseHandler.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -101,10 +100,9 @@ public class SQSAsyncClientTest extends RestClientTest<SQSAsyncClient> {
|
|||
.queuePrefix("prefix"));
|
||||
|
||||
assertRequestLineEquals(request, "POST https://sqs.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 59\nContent-Type: application/x-www-form-urlencoded\nHost: sqs.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2009-02-01&Action=ListQueues&QueueNamePrefix=prefix");
|
||||
assertNonPayloadHeadersEqual(request, "Host: sqs.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2009-02-01&Action=ListQueues&QueueNamePrefix=prefix",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, RegexListQueuesResponseHandler.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -120,10 +118,9 @@ public class SQSAsyncClientTest extends RestClientTest<SQSAsyncClient> {
|
|||
HttpRequest request = processor.createRequest(method, null, "queueName");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://sqs.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
request,
|
||||
"Content-Length: 57\nContent-Type: application/x-www-form-urlencoded\nHost: sqs.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2009-02-01&Action=CreateQueue&QueueName=queueName");
|
||||
assertNonPayloadHeadersEqual(request, "Host: sqs.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2009-02-01&Action=CreateQueue&QueueName=queueName",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, RegexQueueHandler.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -140,11 +137,11 @@ public class SQSAsyncClientTest extends RestClientTest<SQSAsyncClient> {
|
|||
CreateQueueOptions.Builder.defaultVisibilityTimeout(45));
|
||||
|
||||
assertRequestLineEquals(request, "POST https://sqs.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
assertNonPayloadHeadersEqual(request, "Host: sqs.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"Content-Length: 85\nContent-Type: application/x-www-form-urlencoded\nHost: sqs.us-east-1.amazonaws.com\n");
|
||||
assertPayloadEquals(request,
|
||||
"Version=2009-02-01&Action=CreateQueue&QueueName=queueName&DefaultVisibilityTimeout=45");
|
||||
"Version=2009-02-01&Action=CreateQueue&QueueName=queueName&DefaultVisibilityTimeout=45",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, RegexQueueHandler.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
|
|
@ -32,7 +32,7 @@ import org.jclouds.http.handlers.DelegatingErrorHandler;
|
|||
import org.jclouds.http.handlers.DelegatingRetryHandler;
|
||||
import org.jclouds.logging.config.NullLoggingModule;
|
||||
import org.jclouds.rest.RestContextFactory;
|
||||
import org.jclouds.rest.RestClientTest.MockModule;
|
||||
import org.jclouds.rest.BaseRestClientTest.MockModule;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
@ -48,8 +48,8 @@ import com.google.inject.Module;
|
|||
public class SQSRestClientModuleTest {
|
||||
|
||||
Injector createInjector() {
|
||||
return new RestContextFactory().createContextBuilder("sqs", "uid", "key", ImmutableSet
|
||||
.<Module> of(new MockModule(), new NullLoggingModule())).buildInjector();
|
||||
return new RestContextFactory().createContextBuilder("sqs", "uid", "key",
|
||||
ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule())).buildInjector();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -37,6 +37,7 @@ import org.jclouds.PerformanceTest;
|
|||
import org.jclouds.aws.domain.Region;
|
||||
import org.jclouds.aws.sqs.domain.Queue;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.Payloads;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.ParseSax.Factory;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
|
@ -121,7 +122,8 @@ public class ListQueuesResponseHandlerTest extends PerformanceTest {
|
|||
|
||||
public void testRegex() {
|
||||
try {
|
||||
assertEquals(handler.apply(new HttpResponse(supplier.getInput())), expected);
|
||||
assertEquals(handler.apply(new HttpResponse(200, "ok", Payloads.newPayload(supplier
|
||||
.getInput()))), expected);
|
||||
} catch (IOException e) {
|
||||
Throwables.propagate(e);
|
||||
}
|
||||
|
|
|
@ -138,22 +138,6 @@ public class AzureBlobImpl extends PayloadEnclosingImpl implements AzureBlob, Co
|
|||
public SetMetadataPropertiesPayload(Payload delegate, MutableBlobProperties properties) {
|
||||
super(delegate);
|
||||
this.properties = properties;
|
||||
if (properties.getContentLength() != null)
|
||||
setContentLength(properties.getContentLength());
|
||||
setContentMD5(properties.getContentMD5());
|
||||
setContentType(properties.getContentType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentLength(Long contentLength) {
|
||||
super.setContentLength(contentLength);
|
||||
properties.setContentLength(contentLength);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentMD5(byte[] md5) {
|
||||
super.setContentMD5(md5);
|
||||
properties.setContentMD5(md5);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -185,13 +169,6 @@ public class AzureBlobImpl extends PayloadEnclosingImpl implements AzureBlob, Co
|
|||
this.blob = blob;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentMD5(byte[] md5) {
|
||||
super.setContentMD5(md5);
|
||||
if (canSetPayload())
|
||||
blob.getPayload().setContentMD5(md5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentType(String type) {
|
||||
super.setContentType(type);
|
||||
|
@ -199,13 +176,6 @@ public class AzureBlobImpl extends PayloadEnclosingImpl implements AzureBlob, Co
|
|||
blob.getPayload().setContentType(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentLength(Long size) {
|
||||
super.setContentLength(size);
|
||||
if (canSetPayload())
|
||||
blob.getPayload().setContentLength(size);
|
||||
}
|
||||
|
||||
private boolean canSetPayload() {
|
||||
return blob != null && blob.getPayload() != null;
|
||||
}
|
||||
|
|
|
@ -20,10 +20,9 @@ package org.jclouds.azure.storage.blob.functions;
|
|||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
|
||||
import org.jclouds.azure.storage.blob.domain.AzureBlob;
|
||||
import org.jclouds.blobstore.functions.ParseSystemAndUserMetadataFromHeaders;
|
||||
import org.jclouds.azure.storage.blob.domain.MutableBlobProperties;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.rest.InvocationContext;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
|
@ -41,49 +40,21 @@ public class ParseBlobFromHeadersAndHttpContent implements Function<HttpResponse
|
|||
InvocationContext {
|
||||
|
||||
private final ParseBlobPropertiesFromHeaders metadataParser;
|
||||
private final AzureBlob.Factory objectProvider;
|
||||
private final AzureBlob.Factory blobFactory;
|
||||
|
||||
@Inject
|
||||
public ParseBlobFromHeadersAndHttpContent(ParseBlobPropertiesFromHeaders metadataParser,
|
||||
AzureBlob.Factory objectProvider) {
|
||||
AzureBlob.Factory blobFactory) {
|
||||
this.metadataParser = metadataParser;
|
||||
this.objectProvider = objectProvider;
|
||||
this.blobFactory = blobFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* First, calls {@link ParseSystemAndUserMetadataFromHeaders}.
|
||||
*
|
||||
* Then, sets the object size based on the Content-Length header and adds the content to the
|
||||
* {@link AzureBlob} result.
|
||||
*
|
||||
* @throws org.jclouds.http.HttpException
|
||||
*/
|
||||
public AzureBlob apply(HttpResponse from) {
|
||||
AzureBlob object = objectProvider.create(metadataParser.apply(from));
|
||||
object.getAllHeaders().putAll(from.getHeaders());
|
||||
|
||||
if (from.getContent() != null) {
|
||||
object.setPayload(from.getContent());
|
||||
} else if (new Long(0).equals(object.getProperties().getContentLength())) {
|
||||
object.setPayload(new byte[0]);
|
||||
} else {
|
||||
assert false : "no content in " + from;
|
||||
}
|
||||
|
||||
String contentLength = from.getFirstHeaderOrNull(HttpHeaders.CONTENT_LENGTH);
|
||||
String contentRange = from.getFirstHeaderOrNull("Content-Range");
|
||||
|
||||
if (contentLength != null) {
|
||||
object.getPayload().setContentLength(Long.parseLong(contentLength));
|
||||
}
|
||||
|
||||
if (contentRange == null && contentLength != null) {
|
||||
object.getProperties().setContentLength(object.getPayload().getContentLength());
|
||||
} else if (contentRange != null) {
|
||||
object.getProperties().setContentLength(
|
||||
Long.parseLong(contentRange.substring(contentRange.lastIndexOf('/') + 1)));
|
||||
}
|
||||
return object;
|
||||
MutableBlobProperties metadata = metadataParser.apply(from);
|
||||
AzureBlob blob = blobFactory.create(metadata);
|
||||
blob.getAllHeaders().putAll(from.getHeaders());
|
||||
blob.setPayload(from.getPayload());
|
||||
return blob;
|
||||
}
|
||||
|
||||
public void setContext(GeneratedHttpRequest<?> request) {
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
*/
|
||||
package org.jclouds.azure.storage.blob.functions;
|
||||
|
||||
import static org.jclouds.http.HttpUtils.attemptToParseSizeAndRangeFromHeaders;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
|
||||
|
@ -56,10 +58,7 @@ public class ParseBlobPropertiesFromHeaders implements
|
|||
public MutableBlobProperties apply(HttpResponse from) {
|
||||
BlobMetadata base = blobMetadataParser.apply(from);
|
||||
MutableBlobProperties to = blobToBlobProperties.apply(base);
|
||||
if (from.getFirstHeaderOrNull("Content-Range") != null) {
|
||||
String range = from.getFirstHeaderOrNull("Content-Range");
|
||||
to.setContentLength(Long.parseLong(range.split("/")[1]));
|
||||
}
|
||||
to.setContentLength(attemptToParseSizeAndRangeFromHeaders(from));
|
||||
to.setContentLanguage(from.getFirstHeaderOrNull(HttpHeaders.CONTENT_LANGUAGE));
|
||||
to.setContentEncoding(from.getFirstHeaderOrNull(HttpHeaders.CONTENT_ENCODING));
|
||||
return to;
|
||||
|
|
|
@ -20,7 +20,6 @@ package org.jclouds.azure.storage.filters;
|
|||
|
||||
import static org.jclouds.util.Patterns.NEWLINE_PATTERN;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
@ -54,14 +53,15 @@ import com.google.common.annotations.VisibleForTesting;
|
|||
*/
|
||||
@Singleton
|
||||
public class SharedKeyLiteAuthentication implements HttpRequestFilter {
|
||||
private final String[] firstHeadersToSign = new String[] { "Content-MD5",
|
||||
HttpHeaders.CONTENT_TYPE, HttpHeaders.DATE };
|
||||
private final String[] firstHeadersToSign = new String[] { HttpHeaders.DATE };
|
||||
|
||||
private final SignatureWire signatureWire;
|
||||
private final String identity;
|
||||
private final byte[] key;
|
||||
private final Provider<String> timeStampProvider;
|
||||
private final EncryptionService encryptionService;
|
||||
private final HttpUtils utils;
|
||||
|
||||
@Resource
|
||||
@Named(Constants.LOGGER_SIGNATURE)
|
||||
Logger signatureLog = Logger.NULL;
|
||||
|
@ -70,8 +70,10 @@ public class SharedKeyLiteAuthentication implements HttpRequestFilter {
|
|||
public SharedKeyLiteAuthentication(SignatureWire signatureWire,
|
||||
@Named(Constants.PROPERTY_IDENTITY) String identity,
|
||||
@Named(Constants.PROPERTY_CREDENTIAL) String encodedKey,
|
||||
@TimeStamp Provider<String> timeStampProvider, EncryptionService encryptionService) {
|
||||
@TimeStamp Provider<String> timeStampProvider, EncryptionService encryptionService,
|
||||
HttpUtils utils) {
|
||||
this.encryptionService = encryptionService;
|
||||
this.utils = utils;
|
||||
this.signatureWire = signatureWire;
|
||||
this.identity = identity;
|
||||
this.key = encryptionService.fromBase64(encodedKey);
|
||||
|
@ -82,14 +84,15 @@ public class SharedKeyLiteAuthentication implements HttpRequestFilter {
|
|||
replaceDateHeader(request);
|
||||
String toSign = createStringToSign(request);
|
||||
calculateAndReplaceAuthHeader(request, toSign);
|
||||
HttpUtils.logRequest(signatureLog, request, "<<");
|
||||
utils.logRequest(signatureLog, request, "<<");
|
||||
}
|
||||
|
||||
public String createStringToSign(HttpRequest request) {
|
||||
HttpUtils.logRequest(signatureLog, request, ">>");
|
||||
utils.logRequest(signatureLog, request, ">>");
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
// re-sign the request
|
||||
appendMethod(request, buffer);
|
||||
appendPayloadMetadata(request, buffer);
|
||||
appendHttpHeaders(request, buffer);
|
||||
appendCanonicalizedHeaders(request, buffer);
|
||||
appendCanonicalizedResource(request, buffer);
|
||||
|
@ -98,6 +101,15 @@ public class SharedKeyLiteAuthentication implements HttpRequestFilter {
|
|||
return buffer.toString();
|
||||
}
|
||||
|
||||
private void appendPayloadMetadata(HttpRequest request, StringBuilder buffer) {
|
||||
buffer.append(
|
||||
utils.valueOrEmpty(request.getPayload() == null ? null : request.getPayload()
|
||||
.getContentMD5())).append("\n");
|
||||
buffer.append(
|
||||
utils.valueOrEmpty(request.getPayload() == null ? null : request.getPayload()
|
||||
.getContentType())).append("\n");
|
||||
}
|
||||
|
||||
private void calculateAndReplaceAuthHeader(HttpRequest request, String toSign)
|
||||
throws HttpException {
|
||||
String signature = signString(toSign);
|
||||
|
@ -142,7 +154,7 @@ public class SharedKeyLiteAuthentication implements HttpRequestFilter {
|
|||
|
||||
private void appendHttpHeaders(HttpRequest request, StringBuilder toSign) {
|
||||
for (String header : firstHeadersToSign)
|
||||
toSign.append(valueOrEmpty(request.getHeaders().get(header))).append("\n");
|
||||
toSign.append(utils.valueOrEmpty(request.getHeaders().get(header))).append("\n");
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
@ -181,7 +193,4 @@ public class SharedKeyLiteAuthentication implements HttpRequestFilter {
|
|||
}
|
||||
}
|
||||
|
||||
private String valueOrEmpty(Collection<String> collection) {
|
||||
return (collection != null && collection.size() >= 1) ? collection.iterator().next() : "";
|
||||
}
|
||||
}
|
|
@ -18,6 +18,8 @@
|
|||
*/
|
||||
package org.jclouds.azure.storage.handlers;
|
||||
|
||||
import static org.jclouds.http.HttpUtils.releasePayload;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
@ -38,8 +40,6 @@ import org.jclouds.logging.Logger;
|
|||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.util.Utils;
|
||||
|
||||
import com.google.common.io.Closeables;
|
||||
|
||||
/**
|
||||
* This will parse and set an appropriate exception on the command object.
|
||||
*
|
||||
|
@ -92,15 +92,15 @@ public class ParseAzureStorageErrorFromXmlContent implements HttpErrorHandler {
|
|||
error) : new HttpResponseException(command, response);
|
||||
}
|
||||
} finally {
|
||||
Closeables.closeQuietly(response.getContent());
|
||||
releasePayload(response);
|
||||
command.setException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
AzureStorageError parseErrorFromContentOrNull(HttpCommand command, HttpResponse response) {
|
||||
if (response.getContent() != null) {
|
||||
if (response.getPayload() != null) {
|
||||
try {
|
||||
String content = Utils.toStringAndClose(response.getContent());
|
||||
String content = Utils.toStringAndClose(response.getPayload().getInput());
|
||||
if (content != null && content.indexOf('<') >= 0)
|
||||
return utils.parseAzureStorageErrorFromContent(command, response, Utils
|
||||
.toInputStream(content));
|
||||
|
|
|
@ -22,31 +22,28 @@ import static org.jclouds.azure.storage.blob.options.CreateContainerOptions.Buil
|
|||
import static org.jclouds.azure.storage.options.ListOptions.Builder.maxResults;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.ws.rs.HttpMethod;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
|
||||
import org.jclouds.azure.storage.blob.functions.ParseContainerPropertiesFromHeaders;
|
||||
import org.jclouds.azure.storage.blob.functions.ReturnFalseIfContainerAlreadyExists;
|
||||
import org.jclouds.azure.storage.blob.options.CreateContainerOptions;
|
||||
import org.jclouds.azure.storage.blob.options.ListBlobsOptions;
|
||||
import org.jclouds.azure.storage.blob.xml.AccountNameEnumerationResultsHandler;
|
||||
import org.jclouds.azure.storage.blob.xml.ContainerNameEnumerationResultsHandler;
|
||||
import org.jclouds.azure.storage.filters.SharedKeyLiteAuthentication;
|
||||
import org.jclouds.azure.storage.options.ListOptions;
|
||||
import org.jclouds.blobstore.functions.ReturnNullOnContainerNotFound;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.functions.CloseContentAndReturn;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.http.functions.ReturnTrueIf2xx;
|
||||
import org.jclouds.http.functions.ReturnTrueOn404;
|
||||
import org.jclouds.rest.RestClientTest;
|
||||
import org.jclouds.rest.RestContextFactory;
|
||||
import org.jclouds.rest.RestContextFactory.ContextSpec;
|
||||
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
|
||||
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -63,279 +60,210 @@ import com.google.inject.TypeLiteral;
|
|||
@Test(groups = "unit", testName = "azureblob.AzureBlobAsyncClientTest")
|
||||
public class AzureBlobAsyncClientTest extends RestClientTest<AzureBlobAsyncClient> {
|
||||
|
||||
public void testListContainers() throws SecurityException, NoSuchMethodException {
|
||||
Method method = AzureBlobAsyncClient.class.getMethod("listContainers", Array.newInstance(
|
||||
ListOptions.class, 0).getClass());
|
||||
public void testListContainers() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AzureBlobAsyncClient.class.getMethod("listContainers", ListOptions[].class);
|
||||
HttpRequest request = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"GET https://identity.blob.core.windows.net/?comp=list HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, AccountNameEnumerationResultsHandler.class);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
HttpRequest request = processor.createRequest(method, new Object[] {});
|
||||
assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net");
|
||||
assertEquals(request.getEndpoint().getPath(), "/");
|
||||
assertEquals(request.getEndpoint().getQuery(), "comp=list");
|
||||
assertEquals(request.getMethod(), HttpMethod.GET);
|
||||
assertEquals(request.getHeaders().size(), 1);
|
||||
assertEquals(request.getHeaders().get("x-ms-version"), Collections
|
||||
.singletonList("2009-09-19"));
|
||||
assertEquals(processor.createResponseParser(method, request).getClass(), ParseSax.class);
|
||||
// TODO check generic type of response parser
|
||||
assertEquals(processor
|
||||
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
|
||||
MapHttp4xxCodesToExceptions.class);
|
||||
}
|
||||
|
||||
public void testListContainersOptions() throws SecurityException, NoSuchMethodException {
|
||||
Method method = AzureBlobAsyncClient.class.getMethod("listContainers", Array.newInstance(
|
||||
ListOptions.class, 0).getClass());
|
||||
public void testListContainersOptions() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = AzureBlobAsyncClient.class.getMethod("listContainers", ListOptions[].class);
|
||||
HttpRequest request = processor.createRequest(method, maxResults(1).marker("marker").prefix(
|
||||
"prefix"));
|
||||
|
||||
HttpRequest request = processor.createRequest(method, new Object[] { maxResults(1).marker(
|
||||
"marker").prefix("prefix") });
|
||||
assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net");
|
||||
assertEquals(request.getEndpoint().getPath(), "/");
|
||||
assert request.getEndpoint().getQuery().contains("comp=list");
|
||||
assert request.getEndpoint().getQuery().contains("marker=marker");
|
||||
assert request.getEndpoint().getQuery().contains("maxresults=1");
|
||||
assert request.getEndpoint().getQuery().contains("prefix=prefix");
|
||||
assertEquals(request.getMethod(), HttpMethod.GET);
|
||||
assertEquals(request.getHeaders().size(), 1);
|
||||
assertEquals(request.getHeaders().get("x-ms-version"), Collections
|
||||
.singletonList("2009-09-19"));
|
||||
assertEquals(processor.createResponseParser(method, request).getClass(), ParseSax.class);
|
||||
// TODO check generic type of response parser
|
||||
assertEquals(processor
|
||||
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
|
||||
MapHttp4xxCodesToExceptions.class);
|
||||
assertRequestLineEquals(
|
||||
request,
|
||||
"GET https://identity.blob.core.windows.net/?comp=list&maxresults=1&marker=marker&prefix=prefix HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, AccountNameEnumerationResultsHandler.class);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
}
|
||||
|
||||
public void testCreateContainer() throws SecurityException, NoSuchMethodException {
|
||||
Method method = AzureBlobAsyncClient.class.getMethod("createContainer", String.class, Array
|
||||
.newInstance(CreateContainerOptions.class, 0).getClass());
|
||||
public void testCreateContainer() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AzureBlobAsyncClient.class.getMethod("createContainer", String.class,
|
||||
CreateContainerOptions[].class);
|
||||
HttpRequest request = processor.createRequest(method, "container");
|
||||
|
||||
HttpRequest request = processor.createRequest(method, new Object[] { "container" });
|
||||
assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net");
|
||||
assertEquals(request.getEndpoint().getPath(), "/container");
|
||||
assertEquals(request.getEndpoint().getQuery(), "restype=container");
|
||||
assertEquals(request.getMethod(), HttpMethod.PUT);
|
||||
assertEquals(request.getHeaders().size(), 2);
|
||||
assertEquals(request.getHeaders().get("x-ms-version"), Collections
|
||||
.singletonList("2009-09-19"));
|
||||
assertEquals(request.getHeaders().get("Content-Length"), Collections.singletonList("0"));
|
||||
assertEquals(processor.createResponseParser(method, request).getClass(),
|
||||
ReturnTrueIf2xx.class);
|
||||
// TODO check generic type of response parser
|
||||
assertEquals(processor
|
||||
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
|
||||
ReturnFalseIfContainerAlreadyExists.class);
|
||||
assertRequestLineEquals(request,
|
||||
"PUT https://identity.blob.core.windows.net/container?restype=container HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnFalseIfContainerAlreadyExists.class);
|
||||
}
|
||||
|
||||
public void testDeleteContainer() throws SecurityException, NoSuchMethodException {
|
||||
public void testDeleteContainer() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AzureBlobAsyncClient.class.getMethod("deleteContainer", String.class);
|
||||
HttpRequest request = processor.createRequest(method, "container");
|
||||
|
||||
HttpRequest request = processor.createRequest(method, new Object[] { "container" });
|
||||
assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net");
|
||||
assertEquals(request.getEndpoint().getPath(), "/container");
|
||||
assertEquals(request.getEndpoint().getQuery(), "restype=container");
|
||||
assertEquals(request.getMethod(), HttpMethod.DELETE);
|
||||
assertEquals(request.getHeaders().size(), 1);
|
||||
assertEquals(request.getHeaders().get("x-ms-version"), Collections
|
||||
.singletonList("2009-09-19"));
|
||||
assertEquals(processor.createResponseParser(method, request).getClass(),
|
||||
CloseContentAndReturn.class);
|
||||
// TODO check generic type of response parser
|
||||
assertEquals(processor
|
||||
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
|
||||
ReturnVoidOnNotFoundOr404.class);
|
||||
assertRequestLineEquals(request,
|
||||
"DELETE https://identity.blob.core.windows.net/container?restype=container HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
|
||||
}
|
||||
|
||||
public void testCreateContainerOptions() throws SecurityException, NoSuchMethodException {
|
||||
Method method = AzureBlobAsyncClient.class.getMethod("createContainer", String.class, Array
|
||||
.newInstance(CreateContainerOptions.class, 0).getClass());
|
||||
public void testCreateContainerOptions() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = AzureBlobAsyncClient.class.getMethod("createContainer", String.class,
|
||||
CreateContainerOptions[].class);
|
||||
HttpRequest request = processor.createRequest(method, "container", withPublicAcl()
|
||||
.withMetadata(ImmutableMultimap.of("foo", "bar")));
|
||||
|
||||
HttpRequest request = processor.createRequest(method, new Object[] { "container",
|
||||
withPublicAcl().withMetadata(ImmutableMultimap.of("foo", "bar")) });
|
||||
assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net");
|
||||
assertEquals(request.getEndpoint().getPath(), "/container");
|
||||
assertEquals(request.getEndpoint().getQuery(), "restype=container");
|
||||
assertEquals(request.getMethod(), HttpMethod.PUT);
|
||||
assertEquals(request.getHeaders().size(), 4);
|
||||
assertEquals(request.getHeaders().get("x-ms-version"), Collections
|
||||
.singletonList("2009-09-19"));
|
||||
assertEquals(request.getHeaders().get("x-ms-meta-foo"), Collections.singletonList("bar"));
|
||||
assertEquals(request.getHeaders().get("x-ms-prop-publicaccess"), Collections
|
||||
.singletonList("true"));
|
||||
assertEquals(request.getHeaders().get("Content-Length"), Collections.singletonList("0"));
|
||||
assertEquals(processor.createResponseParser(method, request).getClass(),
|
||||
ReturnTrueIf2xx.class);
|
||||
// TODO check generic type of response parser
|
||||
assertEquals(processor
|
||||
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
|
||||
ReturnFalseIfContainerAlreadyExists.class);
|
||||
assertRequestLineEquals(request,
|
||||
"PUT https://identity.blob.core.windows.net/container?restype=container HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request,
|
||||
"x-ms-meta-foo: bar\nx-ms-prop-publicaccess: true\nx-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnFalseIfContainerAlreadyExists.class);
|
||||
}
|
||||
|
||||
public void testCreateRootContainer() throws SecurityException, NoSuchMethodException {
|
||||
Method method = AzureBlobAsyncClient.class.getMethod("createRootContainer", Array
|
||||
.newInstance(CreateContainerOptions.class, 0).getClass());
|
||||
public void testCreateRootContainer() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = AzureBlobAsyncClient.class.getMethod("createRootContainer",
|
||||
CreateContainerOptions[].class);
|
||||
|
||||
HttpRequest request = processor.createRequest(method, new Object[] {});
|
||||
assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net");
|
||||
assertEquals(request.getEndpoint().getPath(), "/$root");
|
||||
assertEquals(request.getEndpoint().getQuery(), "restype=container");
|
||||
assertEquals(request.getMethod(), HttpMethod.PUT);
|
||||
assertEquals(request.getHeaders().size(), 2);
|
||||
assertEquals(request.getHeaders().get("x-ms-version"), Collections
|
||||
.singletonList("2009-09-19"));
|
||||
assertEquals(request.getHeaders().get("Content-Length"), Collections.singletonList("0"));
|
||||
assertEquals(processor.createResponseParser(method, request).getClass(),
|
||||
ReturnTrueIf2xx.class);
|
||||
// TODO check generic type of response parser
|
||||
assertEquals(processor
|
||||
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
|
||||
ReturnFalseIfContainerAlreadyExists.class);
|
||||
HttpRequest request = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"PUT https://identity.blob.core.windows.net/%24root?restype=container HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnFalseIfContainerAlreadyExists.class);
|
||||
}
|
||||
|
||||
public void testDeleteRootContainer() throws SecurityException, NoSuchMethodException {
|
||||
public void testDeleteRootContainer() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = AzureBlobAsyncClient.class.getMethod("deleteRootContainer");
|
||||
HttpRequest request = processor.createRequest(method);
|
||||
|
||||
HttpRequest request = processor.createRequest(method, new Object[] {});
|
||||
assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net");
|
||||
assertEquals(request.getEndpoint().getPath(), "/$root");
|
||||
assertEquals(request.getEndpoint().getQuery(), "restype=container");
|
||||
assertEquals(request.getMethod(), HttpMethod.DELETE);
|
||||
assertEquals(request.getHeaders().size(), 1);
|
||||
assertEquals(request.getHeaders().get("x-ms-version"), Collections
|
||||
.singletonList("2009-09-19"));
|
||||
assertEquals(processor.createResponseParser(method, request).getClass(),
|
||||
CloseContentAndReturn.class);
|
||||
// TODO check generic type of response parser
|
||||
assertEquals(processor
|
||||
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
|
||||
ReturnTrueOn404.class);
|
||||
assertRequestLineEquals(request,
|
||||
"DELETE https://identity.blob.core.windows.net/%24root?restype=container HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnTrueOn404.class);
|
||||
}
|
||||
|
||||
public void testCreateRootContainerOptions() throws SecurityException, NoSuchMethodException {
|
||||
Method method = AzureBlobAsyncClient.class.getMethod("createRootContainer", Array
|
||||
.newInstance(CreateContainerOptions.class, 0).getClass());
|
||||
public void testCreateRootContainerOptions() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = AzureBlobAsyncClient.class.getMethod("createRootContainer",
|
||||
CreateContainerOptions[].class);
|
||||
HttpRequest request = processor.createRequest(method, withPublicAcl().withMetadata(
|
||||
ImmutableMultimap.of("foo", "bar")));
|
||||
|
||||
HttpRequest request = processor.createRequest(method, new Object[] { withPublicAcl()
|
||||
.withMetadata(ImmutableMultimap.of("foo", "bar")) });
|
||||
assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net");
|
||||
assertEquals(request.getEndpoint().getPath(), "/$root");
|
||||
assertEquals(request.getEndpoint().getQuery(), "restype=container");
|
||||
assertEquals(request.getMethod(), HttpMethod.PUT);
|
||||
assertEquals(request.getHeaders().size(), 4);
|
||||
assertEquals(request.getHeaders().get("x-ms-version"), Collections
|
||||
.singletonList("2009-09-19"));
|
||||
assertEquals(request.getHeaders().get("x-ms-meta-foo"), Collections.singletonList("bar"));
|
||||
assertEquals(request.getHeaders().get("x-ms-prop-publicaccess"), Collections
|
||||
.singletonList("true"));
|
||||
assertEquals(request.getHeaders().get("Content-Length"), Collections.singletonList("0"));
|
||||
assertEquals(processor.createResponseParser(method, request).getClass(),
|
||||
ReturnTrueIf2xx.class);
|
||||
// TODO check generic type of response parser
|
||||
assertEquals(processor
|
||||
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
|
||||
ReturnFalseIfContainerAlreadyExists.class);
|
||||
assertRequestLineEquals(request,
|
||||
"PUT https://identity.blob.core.windows.net/%24root?restype=container HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request,
|
||||
"x-ms-meta-foo: bar\nx-ms-prop-publicaccess: true\nx-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnFalseIfContainerAlreadyExists.class);
|
||||
}
|
||||
|
||||
public void testListBlobs() throws SecurityException, NoSuchMethodException {
|
||||
Method method = AzureBlobAsyncClient.class.getMethod("listBlobs", String.class, Array
|
||||
.newInstance(ListBlobsOptions.class, 0).getClass());
|
||||
public void testListBlobs() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AzureBlobAsyncClient.class.getMethod("listBlobs", String.class,
|
||||
ListBlobsOptions[].class);
|
||||
HttpRequest request = processor.createRequest(method, "container");
|
||||
|
||||
HttpRequest request = processor.createRequest(method, new Object[] { "container" });
|
||||
assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net");
|
||||
assertEquals(request.getEndpoint().getPath(), "/container");
|
||||
assertEquals(request.getEndpoint().getQuery(), "restype=container&comp=list");
|
||||
assertEquals(request.getMethod(), HttpMethod.GET);
|
||||
assertEquals(request.getHeaders().size(), 1);
|
||||
assertEquals(request.getHeaders().get("x-ms-version"), Collections
|
||||
.singletonList("2009-09-19"));
|
||||
assertEquals(processor.createResponseParser(method, request).getClass(), ParseSax.class);
|
||||
// TODO check generic type of response parser
|
||||
assertEquals(processor
|
||||
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
|
||||
MapHttp4xxCodesToExceptions.class);
|
||||
assertRequestLineEquals(request,
|
||||
"GET https://identity.blob.core.windows.net/container?restype=container&comp=list HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, ContainerNameEnumerationResultsHandler.class);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
}
|
||||
|
||||
public void testListRootBlobs() throws SecurityException, NoSuchMethodException {
|
||||
Method method = AzureBlobAsyncClient.class.getMethod("listBlobs", Array.newInstance(
|
||||
ListBlobsOptions.class, 0).getClass());
|
||||
public void testListRootBlobs() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AzureBlobAsyncClient.class.getMethod("listBlobs", ListBlobsOptions[].class);
|
||||
HttpRequest request = processor.createRequest(method);
|
||||
|
||||
HttpRequest request = processor.createRequest(method, new Object[] {});
|
||||
assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net");
|
||||
assertEquals(request.getEndpoint().getPath(), "/$root");
|
||||
assertEquals(request.getEndpoint().getQuery(), "restype=container&comp=list");
|
||||
assertEquals(request.getMethod(), HttpMethod.GET);
|
||||
assertEquals(request.getHeaders().size(), 1);
|
||||
assertEquals(request.getHeaders().get("x-ms-version"), Collections
|
||||
.singletonList("2009-09-19"));
|
||||
assertEquals(processor.createResponseParser(method, request).getClass(), ParseSax.class);
|
||||
// TODO check generic type of response parser
|
||||
assertEquals(processor
|
||||
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
|
||||
MapHttp4xxCodesToExceptions.class);
|
||||
assertRequestLineEquals(request,
|
||||
"GET https://identity.blob.core.windows.net/%24root?restype=container&comp=list HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, ContainerNameEnumerationResultsHandler.class);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
}
|
||||
|
||||
public void testContainerProperties() throws SecurityException, NoSuchMethodException {
|
||||
public void testContainerProperties() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = AzureBlobAsyncClient.class.getMethod("getContainerProperties", String.class);
|
||||
HttpRequest request = processor.createRequest(method, "container");
|
||||
|
||||
HttpRequest request = processor.createRequest(method, new Object[] { "container" });
|
||||
assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net");
|
||||
assertEquals(request.getEndpoint().getPath(), "/container");
|
||||
assertEquals(request.getEndpoint().getQuery(), "restype=container");
|
||||
assertEquals(request.getMethod(), HttpMethod.HEAD);
|
||||
assertEquals(request.getHeaders().size(), 1);
|
||||
assertEquals(request.getHeaders().get("x-ms-version"), Collections
|
||||
.singletonList("2009-09-19"));
|
||||
assertEquals(processor.createResponseParser(method, request).getClass(),
|
||||
ParseContainerPropertiesFromHeaders.class);
|
||||
assertEquals(processor
|
||||
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
|
||||
ReturnNullOnContainerNotFound.class);
|
||||
assertRequestLineEquals(request,
|
||||
"HEAD https://identity.blob.core.windows.net/container?restype=container HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseContainerPropertiesFromHeaders.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnNullOnContainerNotFound.class);
|
||||
}
|
||||
|
||||
public void testSetResourceMetadata() throws SecurityException, NoSuchMethodException {
|
||||
public void testSetResourceMetadata() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = AzureBlobAsyncClient.class.getMethod("setResourceMetadata", String.class,
|
||||
Map.class);
|
||||
|
||||
HttpRequest request = processor.createRequest(method, new Object[] { "container",
|
||||
ImmutableMap.of("key", "value") });
|
||||
assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net");
|
||||
assertEquals(request.getEndpoint().getPath(), "/container");
|
||||
assertEquals(request.getEndpoint().getQuery(), "restype=container&comp=metadata");
|
||||
assertEquals(request.getMethod(), HttpMethod.PUT);
|
||||
assertEquals(request.getHeaders().size(), 3);
|
||||
assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections
|
||||
.singletonList("0"));
|
||||
assertEquals(request.getHeaders().get("x-ms-version"), Collections
|
||||
.singletonList("2009-09-19"));
|
||||
assertEquals(request.getHeaders().get("x-ms-meta-key"), Collections.singletonList("value"));
|
||||
|
||||
assertEquals(processor.createResponseParser(method, request).getClass(),
|
||||
CloseContentAndReturn.class);
|
||||
assertEquals(processor
|
||||
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
|
||||
MapHttp4xxCodesToExceptions.class);
|
||||
assertRequestLineEquals(request,
|
||||
"PUT https://identity.blob.core.windows.net/container?restype=container&comp=metadata HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "x-ms-meta-key: value\nx-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
}
|
||||
|
||||
public void testSetBlobMetadata() throws SecurityException, NoSuchMethodException {
|
||||
public void testSetBlobMetadata() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AzureBlobAsyncClient.class.getMethod("setBlobMetadata", String.class,
|
||||
String.class, Map.class);
|
||||
HttpRequest request = processor.createRequest(method, new Object[] { "container", "blob",
|
||||
ImmutableMap.of("key", "value") });
|
||||
assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net");
|
||||
assertEquals(request.getEndpoint().getPath(), "/container/blob");
|
||||
assertEquals(request.getEndpoint().getQuery(), "comp=metadata");
|
||||
assertEquals(request.getMethod(), HttpMethod.PUT);
|
||||
assertEquals(request.getHeaders().size(), 3);
|
||||
assertEquals(request.getHeaders().get("x-ms-version"), Collections
|
||||
.singletonList("2009-09-19"));
|
||||
assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections
|
||||
.singletonList("0"));
|
||||
assertEquals(request.getHeaders().get("x-ms-meta-key"), Collections.singletonList("value"));
|
||||
HttpRequest request = processor.createRequest(method, "container", "blob", ImmutableMap.of(
|
||||
"key", "value"));
|
||||
|
||||
assertEquals(processor.createResponseParser(method, request).getClass(),
|
||||
CloseContentAndReturn.class);
|
||||
assertEquals(processor
|
||||
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
|
||||
MapHttp4xxCodesToExceptions.class);
|
||||
assertRequestLineEquals(request,
|
||||
"PUT https://identity.blob.core.windows.net/container/blob?comp=metadata HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "x-ms-meta-key: value\nx-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.jclouds.blobstore.internal.BlobStoreContextImpl;
|
|||
import org.jclouds.blobstore.strategy.ContainsValueInListStrategy;
|
||||
import org.jclouds.logging.config.NullLoggingModule;
|
||||
import org.jclouds.rest.RestContextFactory;
|
||||
import org.jclouds.rest.RestClientTest.MockModule;
|
||||
import org.jclouds.rest.BaseRestClientTest.MockModule;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
|
|
@ -36,8 +36,8 @@ import org.jclouds.azure.storage.queue.options.PutMessageOptions;
|
|||
import org.jclouds.azure.storage.queue.xml.AccountNameEnumerationResultsHandler;
|
||||
import org.jclouds.azure.storage.queue.xml.QueueMessagesListHandler;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.functions.CloseContentAndReturn;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.http.functions.ReturnTrueIf2xx;
|
||||
import org.jclouds.rest.RestClientTest;
|
||||
import org.jclouds.rest.RestContextFactory;
|
||||
|
@ -63,8 +63,8 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
|
|||
|
||||
assertRequestLineEquals(request,
|
||||
"GET https://identity.queue.core.windows.net/myqueue/messages HTTP/1.1");
|
||||
assertHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null);
|
||||
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, QueueMessagesListHandler.class);
|
||||
|
@ -83,8 +83,8 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
|
|||
assertRequestLineEquals(
|
||||
request,
|
||||
"GET https://identity.queue.core.windows.net/myqueue/messages?numofmessages=1&visibilitytimeout=30 HTTP/1.1");
|
||||
assertHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null);
|
||||
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, QueueMessagesListHandler.class);
|
||||
|
@ -99,8 +99,8 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
|
|||
|
||||
assertRequestLineEquals(request,
|
||||
"GET https://identity.queue.core.windows.net/?comp=list HTTP/1.1");
|
||||
assertHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null);
|
||||
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, AccountNameEnumerationResultsHandler.class);
|
||||
|
@ -117,8 +117,8 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
|
|||
assertRequestLineEquals(
|
||||
request,
|
||||
"GET https://identity.queue.core.windows.net/?comp=list&maxresults=1&marker=marker&prefix=prefix HTTP/1.1");
|
||||
assertHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null);
|
||||
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, AccountNameEnumerationResultsHandler.class);
|
||||
|
@ -133,8 +133,8 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
|
|||
HttpRequest request = processor.createRequest(method, "queue");
|
||||
|
||||
assertRequestLineEquals(request, "PUT https://identity.queue.core.windows.net/queue HTTP/1.1");
|
||||
assertHeadersEqual(request, "Content-Length: 0\nx-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null);
|
||||
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -152,9 +152,8 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
|
|||
.of("foo", "bar")));
|
||||
|
||||
assertRequestLineEquals(request, "PUT https://identity.queue.core.windows.net/queue HTTP/1.1");
|
||||
assertHeadersEqual(request,
|
||||
"Content-Length: 0\nx-ms-meta-foo: bar\nx-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null);
|
||||
assertNonPayloadHeadersEqual(request, "x-ms-meta-foo: bar\nx-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -170,10 +169,10 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
|
|||
|
||||
assertRequestLineEquals(request,
|
||||
"DELETE https://identity.queue.core.windows.net/queue HTTP/1.1");
|
||||
assertHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null);
|
||||
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
@ -189,12 +188,12 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
|
|||
|
||||
assertRequestLineEquals(request,
|
||||
"POST https://identity.queue.core.windows.net/queue/messages HTTP/1.1");
|
||||
assertHeadersEqual(request,
|
||||
"Content-Length: 63\nContent-Type: application/unknown\nx-ms-version: 2009-09-19\n");
|
||||
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request,
|
||||
"<QueueMessage><MessageText>message</MessageText></QueueMessage>");
|
||||
"<QueueMessage><MessageText>message</MessageText></QueueMessage>",
|
||||
"application/unknown", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
@ -209,12 +208,12 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
|
|||
|
||||
assertRequestLineEquals(request,
|
||||
"POST https://identity.queue.core.windows.net/queue/messages?messagettl=3 HTTP/1.1");
|
||||
assertHeadersEqual(request,
|
||||
"Content-Length: 63\nContent-Type: application/unknown\nx-ms-version: 2009-09-19\n");
|
||||
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request,
|
||||
"<QueueMessage><MessageText>message</MessageText></QueueMessage>");
|
||||
"<QueueMessage><MessageText>message</MessageText></QueueMessage>",
|
||||
"application/unknown", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
@ -228,10 +227,10 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
|
|||
|
||||
assertRequestLineEquals(request,
|
||||
"DELETE https://identity.queue.core.windows.net/queue/messages HTTP/1.1");
|
||||
assertHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null);
|
||||
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
|
|
@ -73,6 +73,10 @@ Options can also be specified for extension modules
|
|||
[blobstore]
|
||||
(.getContext blobstore))
|
||||
|
||||
(defn blob?
|
||||
[object]
|
||||
(instance? Blob))
|
||||
|
||||
(defn blobstore?
|
||||
[object]
|
||||
(or (instance? BlobStore object)
|
||||
|
@ -265,22 +269,27 @@ example:
|
|||
([blobstore container-name dir]
|
||||
(.list (as-blobstore blobstore) container-name
|
||||
(.inDirectory (new ListContainerOptions) dir))))
|
||||
|
||||
(defn md5-blob
|
||||
"add a content md5 to a blob. note that this implies rebuffering, if theisn't repeatable"
|
||||
([blob]
|
||||
(md5-blob *blobstore*))
|
||||
([blob blobstore]
|
||||
(.generateMD5BufferingIfNotRepeatable (.encryption (.utils (blobstore-context blobstore)))
|
||||
blob)))
|
||||
(defn blob
|
||||
"create a new blob with the specified payload"
|
||||
([name payload]
|
||||
([#^String name payload]
|
||||
(blob name payload *blobstore*))
|
||||
([name payload blobstore]
|
||||
([#^String name payload #^BlobStore blobstore]
|
||||
(doto (.newBlob blobstore name)
|
||||
(.setPayload payload))))
|
||||
|
||||
(defn md5-blob
|
||||
"add a content md5 to a blob, or make a new blob that has an md5.
|
||||
note that this implies rebuffering, if the blob's payload isn't repeatable"
|
||||
([#^Blob blob]
|
||||
(md5-blob *blobstore*))
|
||||
([blob-or-name blobstore-or-payload]
|
||||
( if (blobstore? blobstore-or-payload)
|
||||
(.generateMD5BufferingIfNotRepeatable (.encryption (.utils (blobstore-context blobstore-or-payload)))
|
||||
blob-or-name)
|
||||
(md5-blob blob-or-name blobstore-or-payload *blobstore*)))
|
||||
([#^String name payload #^BlobStore blobstore]
|
||||
(md5-blob (blob name payload *blobstore*) *blobstore*)))
|
||||
|
||||
(defn upload-blob
|
||||
"Create anrepresenting text data:
|
||||
container, name, string -> etag"
|
||||
|
@ -288,7 +297,7 @@ container, name, string -> etag"
|
|||
(upload-blob container-name name data *blobstore*))
|
||||
([container-name name data blobstore]
|
||||
(put-blob container-name
|
||||
(md5-blob (blob name data) blobstore) blobstore)))
|
||||
(md5-blob name data blobstore) blobstore)))
|
||||
|
||||
(defmulti #^{:arglists '[[container-name name target]
|
||||
[container-name name target blobstore]]}
|
||||
|
@ -308,7 +317,7 @@ container, name, string -> etag"
|
|||
target (MessageDigest/getInstance "MD5"))]
|
||||
(.writeTo (.getPayload blob) digest-stream)
|
||||
(let [digest (.digest (.getMessageDigest digest-stream))
|
||||
metadata-digest (.getContentMD5 (.getMetadata blob))]
|
||||
metadata-digest (.getContentMD5 (.getPayload blob))]
|
||||
(when-not (Arrays/equals digest metadata-digest)
|
||||
(if (<= (or retries 0) *max-retries*)
|
||||
(recur container-name name target blobstore [(inc (or retries 1))])
|
||||
|
|
|
@ -415,8 +415,7 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore {
|
|||
|
||||
public static HttpResponseException returnResponseException(int code) {
|
||||
HttpResponse response = null;
|
||||
response = new HttpResponse(); // TODO: Get real object URL?
|
||||
response.setStatusCode(code);
|
||||
response = new HttpResponse(code, null, null);
|
||||
return new HttpResponseException(new HttpCommand() {
|
||||
|
||||
public int getRedirectCount() {
|
||||
|
@ -491,6 +490,10 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore {
|
|||
Blob blob = blobFactory.create(copy(object.getMetadata()));
|
||||
blob.setPayload(payload);
|
||||
blob.getMetadata().setLastModified(new Date());
|
||||
blob.getMetadata().setSize(payload.getContentLength());
|
||||
blob.getMetadata().setContentMD5(payload.getContentMD5());
|
||||
blob.getMetadata().setContentType(payload.getContentType());
|
||||
|
||||
String eTag = encryptionService.hex(payload.getContentMD5());
|
||||
blob.getMetadata().setETag(eTag);
|
||||
container.put(blob.getMetadata().getName(), blob);
|
||||
|
@ -499,8 +502,8 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore {
|
|||
blob.getAllHeaders().put(HttpHeaders.LAST_MODIFIED,
|
||||
dateService.rfc822DateFormat(blob.getMetadata().getLastModified()));
|
||||
blob.getAllHeaders().put(HttpHeaders.ETAG, eTag);
|
||||
blob.getAllHeaders().put(HttpHeaders.CONTENT_TYPE, blob.getMetadata().getContentType());
|
||||
blob.getAllHeaders().put(HttpHeaders.CONTENT_LENGTH, blob.getMetadata().getSize() + "");
|
||||
blob.getAllHeaders().put(HttpHeaders.CONTENT_TYPE, payload.getContentType());
|
||||
blob.getAllHeaders().put(HttpHeaders.CONTENT_LENGTH, payload.getContentLength() + "");
|
||||
blob.getAllHeaders().put("Content-MD5", encryptionService.base64(payload.getContentMD5()));
|
||||
blob.getAllHeaders().putAll(Multimaps.forMap(blob.getMetadata().getUserMetadata()));
|
||||
|
||||
|
@ -543,8 +546,7 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore {
|
|||
if (options.getIfModifiedSince() != null) {
|
||||
Date modifiedSince = options.getIfModifiedSince();
|
||||
if (object.getMetadata().getLastModified().before(modifiedSince)) {
|
||||
HttpResponse response = new HttpResponse();
|
||||
response.setStatusCode(304);
|
||||
HttpResponse response = new HttpResponse(304, null, null);
|
||||
return immediateFailedFuture(new HttpResponseException(String.format(
|
||||
"%1$s is before %2$s", object.getMetadata().getLastModified(), modifiedSince),
|
||||
null, response));
|
||||
|
@ -554,8 +556,7 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore {
|
|||
if (options.getIfUnmodifiedSince() != null) {
|
||||
Date unmodifiedSince = options.getIfUnmodifiedSince();
|
||||
if (object.getMetadata().getLastModified().after(unmodifiedSince)) {
|
||||
HttpResponse response = new HttpResponse();
|
||||
response.setStatusCode(412);
|
||||
HttpResponse response = new HttpResponse(412, null, null);
|
||||
return immediateFailedFuture(new HttpResponseException(
|
||||
String.format("%1$s is after %2$s", object.getMetadata().getLastModified(),
|
||||
unmodifiedSince), null, response));
|
||||
|
|
|
@ -142,24 +142,9 @@ public class BlobImpl extends PayloadEnclosingImpl implements Blob, Comparable<B
|
|||
public SetMetadataPropertiesPayload(Payload delegate, MutableBlobMetadata metadata) {
|
||||
super(delegate);
|
||||
this.metadata = metadata;
|
||||
if (metadata.getSize() != null)
|
||||
setContentLength(metadata.getSize());
|
||||
setContentMD5(metadata.getContentMD5());
|
||||
setContentType(metadata.getContentType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentLength(Long contentLength) {
|
||||
super.setContentLength(contentLength);
|
||||
metadata.setSize(contentLength);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentMD5(byte[] md5) {
|
||||
super.setContentMD5(md5);
|
||||
metadata.setContentMD5(md5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentType(String md5) {
|
||||
super.setContentType(md5);
|
||||
|
@ -189,13 +174,6 @@ public class BlobImpl extends PayloadEnclosingImpl implements Blob, Comparable<B
|
|||
this.blob = blob;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentMD5(byte[] md5) {
|
||||
super.setContentMD5(md5);
|
||||
if (canSetPayload())
|
||||
blob.getPayload().setContentMD5(md5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentType(String type) {
|
||||
super.setContentType(type);
|
||||
|
@ -203,13 +181,6 @@ public class BlobImpl extends PayloadEnclosingImpl implements Blob, Comparable<B
|
|||
blob.getPayload().setContentType(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSize(Long size) {
|
||||
super.setSize(size);
|
||||
if (canSetPayload())
|
||||
blob.getPayload().setContentLength(size);
|
||||
}
|
||||
|
||||
private boolean canSetPayload() {
|
||||
return blob != null && blob.getPayload() != null;
|
||||
}
|
||||
|
|
|
@ -19,16 +19,13 @@
|
|||
package org.jclouds.blobstore.functions;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
|
||||
import org.jclouds.blobstore.domain.Blob;
|
||||
import org.jclouds.blobstore.domain.MutableBlobMetadata;
|
||||
import org.jclouds.http.HttpException;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.rest.InvocationContext;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
|
@ -49,44 +46,12 @@ public class ParseBlobFromHeadersAndHttpContent implements Function<HttpResponse
|
|||
this.blobFactory = blobFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* First, calls {@link ParseSystemAndUserMetadataFromHeaders}.
|
||||
*
|
||||
* Then, sets the object size based on the Content-Length header and adds the content to the
|
||||
* {@link Blob} result.
|
||||
*
|
||||
* @throws org.jclouds.http.HttpException
|
||||
*/
|
||||
public Blob apply(HttpResponse from) {
|
||||
MutableBlobMetadata metadata = metadataParser.apply(from);
|
||||
Blob object = blobFactory.create(metadata);
|
||||
addAllHeadersTo(from, object);
|
||||
object.setPayload(from.getContent());
|
||||
assert object.getMetadata() == metadata;
|
||||
attemptToParseSizeAndRangeFromHeaders(from, object);
|
||||
return object;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void attemptToParseSizeAndRangeFromHeaders(HttpResponse from, Blob object) throws HttpException {
|
||||
String contentLength = from.getFirstHeaderOrNull(HttpHeaders.CONTENT_LENGTH);
|
||||
String contentRange = from.getFirstHeaderOrNull("Content-Range");
|
||||
|
||||
if (contentLength != null) {
|
||||
object.getPayload().setContentLength(Long.parseLong(contentLength));
|
||||
}
|
||||
|
||||
if (contentRange == null && contentLength != null) {
|
||||
object.getMetadata().setSize(object.getPayload().getContentLength());
|
||||
} else if (contentRange != null) {
|
||||
object.getMetadata().setSize(
|
||||
Long.parseLong(contentRange.substring(contentRange.lastIndexOf('/') + 1)));
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void addAllHeadersTo(HttpResponse from, Blob object) {
|
||||
object.getAllHeaders().putAll(from.getHeaders());
|
||||
object.setPayload(from.getPayload());
|
||||
return object;
|
||||
}
|
||||
|
||||
public void setContext(GeneratedHttpRequest<?> request) {
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.jclouds.blobstore.functions;
|
|||
|
||||
import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX;
|
||||
import static org.jclouds.blobstore.util.BlobStoreUtils.getKeyFor;
|
||||
import static org.jclouds.http.HttpUtils.attemptToParseSizeAndRangeFromHeaders;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
|
||||
|
@ -30,7 +31,6 @@ import javax.ws.rs.core.HttpHeaders;
|
|||
|
||||
import org.jclouds.blobstore.domain.MutableBlobMetadata;
|
||||
import org.jclouds.date.DateService;
|
||||
import org.jclouds.encryption.EncryptionService;
|
||||
import org.jclouds.http.HttpException;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.rest.InvocationContext;
|
||||
|
@ -47,17 +47,14 @@ public class ParseSystemAndUserMetadataFromHeaders implements
|
|||
private final String metadataPrefix;
|
||||
private final DateService dateParser;
|
||||
private final Provider<MutableBlobMetadata> metadataFactory;
|
||||
private final EncryptionService encryptionService;
|
||||
private GeneratedHttpRequest<?> request;
|
||||
|
||||
@Inject
|
||||
public ParseSystemAndUserMetadataFromHeaders(Provider<MutableBlobMetadata> metadataFactory,
|
||||
DateService dateParser, @Named(PROPERTY_USER_METADATA_PREFIX) String metadataPrefix,
|
||||
EncryptionService encryptionService) {
|
||||
DateService dateParser, @Named(PROPERTY_USER_METADATA_PREFIX) String metadataPrefix) {
|
||||
this.metadataFactory = metadataFactory;
|
||||
this.dateParser = dateParser;
|
||||
this.metadataPrefix = metadataPrefix;
|
||||
this.encryptionService = encryptionService;
|
||||
}
|
||||
|
||||
public MutableBlobMetadata apply(HttpResponse from) {
|
||||
|
@ -85,8 +82,7 @@ public class ParseSystemAndUserMetadataFromHeaders implements
|
|||
|
||||
@VisibleForTesting
|
||||
void setContentLength(HttpResponse from, MutableBlobMetadata metadata) throws HttpException {
|
||||
String contentLength = from.getFirstHeaderOrNull(HttpHeaders.CONTENT_LENGTH);
|
||||
metadata.setSize(contentLength == null ? 0 : Long.parseLong(contentLength));
|
||||
metadata.setSize(attemptToParseSizeAndRangeFromHeaders(from));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
@ -112,20 +108,18 @@ public class ParseSystemAndUserMetadataFromHeaders implements
|
|||
|
||||
@VisibleForTesting
|
||||
protected void addContentMD5To(HttpResponse from, MutableBlobMetadata metadata) {
|
||||
String contentMD5 = from.getFirstHeaderOrNull("Content-MD5");
|
||||
if (contentMD5 != null) {
|
||||
metadata.setContentMD5(encryptionService.fromBase64(contentMD5));
|
||||
}
|
||||
if (from.getPayload() != null)
|
||||
metadata.setContentMD5(from.getPayload().getContentMD5());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void setContentTypeOrThrowException(HttpResponse from, MutableBlobMetadata metadata)
|
||||
throws HttpException {
|
||||
String contentType = from.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE);
|
||||
if (contentType == null)
|
||||
if (from.getPayload() != null)
|
||||
metadata.setContentType(from.getPayload().getContentType());
|
||||
if (metadata.getContentType() == null
|
||||
|| "application/unknown".equals(metadata.getContentType()))
|
||||
throw new HttpException(HttpHeaders.CONTENT_TYPE + " not found in headers");
|
||||
else
|
||||
metadata.setContentType(contentType);
|
||||
}
|
||||
|
||||
public void setContext(GeneratedHttpRequest<?> request) {
|
||||
|
|
|
@ -23,22 +23,21 @@ import static org.easymock.classextension.EasyMock.createMock;
|
|||
import static org.easymock.classextension.EasyMock.replay;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Collections;
|
||||
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
import javax.inject.Provider;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.blobstore.config.BlobStoreObjectModule;
|
||||
import org.jclouds.blobstore.domain.Blob;
|
||||
import org.jclouds.blobstore.domain.MutableBlobMetadata;
|
||||
import org.jclouds.blobstore.domain.internal.MutableBlobMetadataImpl;
|
||||
import org.jclouds.http.HttpException;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.jclouds.http.Payloads;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.inject.Guice;
|
||||
|
||||
/**
|
||||
|
@ -58,62 +57,38 @@ public class ParseBlobFromHeadersAndHttpContentTest {
|
|||
ParseSystemAndUserMetadataFromHeaders metadataParser = createMock(ParseSystemAndUserMetadataFromHeaders.class);
|
||||
ParseBlobFromHeadersAndHttpContent callable = new ParseBlobFromHeadersAndHttpContent(
|
||||
metadataParser, blobProvider);
|
||||
HttpResponse response = createMock(HttpResponse.class);
|
||||
expect(response.getFirstHeaderOrNull("Content-Length")).andReturn("100");
|
||||
expect(response.getFirstHeaderOrNull("Content-Range")).andReturn(null);
|
||||
expect(response.getHeaders()).andReturn(ImmutableMultimap.of("Content-Length", "100"));
|
||||
expect(response.getContent()).andReturn(null);
|
||||
replay(response);
|
||||
HttpResponse response = new HttpResponse(200, null, null);
|
||||
response.getHeaders().put("Content-Range", null);
|
||||
callable.apply(response);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddAllHeadersTo() {
|
||||
ParseSystemAndUserMetadataFromHeaders metadataParser = createMock(ParseSystemAndUserMetadataFromHeaders.class);
|
||||
ParseBlobFromHeadersAndHttpContent callable = new ParseBlobFromHeadersAndHttpContent(
|
||||
metadataParser, blobProvider);
|
||||
Multimap<String, String> allHeaders = ImmutableMultimap.of("key", "value");
|
||||
HttpResponse from = new HttpResponse();
|
||||
from.getHeaders().putAll(allHeaders);
|
||||
Blob object = blobProvider.create(null);
|
||||
callable.addAllHeadersTo(from, object);
|
||||
assertEquals(object.getAllHeaders().get("key"), Collections.singletonList("value"));
|
||||
private Blob.Factory blobProvider;
|
||||
private Provider<MutableBlobMetadata> blobMetadataProvider = new Provider<MutableBlobMetadata>() {
|
||||
|
||||
public MutableBlobMetadata get() {
|
||||
return new MutableBlobMetadataImpl();
|
||||
}
|
||||
|
||||
private Blob.Factory blobProvider;
|
||||
};
|
||||
|
||||
@Test(enabled = false)
|
||||
// TODO.. very complicated test.
|
||||
@Test
|
||||
public void testParseContentLengthWhenContentRangeSet() throws HttpException {
|
||||
ParseSystemAndUserMetadataFromHeaders metadataParser = createMock(ParseSystemAndUserMetadataFromHeaders.class);
|
||||
ParseBlobFromHeadersAndHttpContent callable = new ParseBlobFromHeadersAndHttpContent(
|
||||
metadataParser, blobProvider);
|
||||
HttpResponse response = createMock(HttpResponse.class);
|
||||
MutableBlobMetadata meta = createMock(MutableBlobMetadata.class);
|
||||
|
||||
HttpResponse response = new HttpResponse(200, "ok", Payloads.newStringPayload(""));
|
||||
response.getPayload().setContentType(MediaType.APPLICATION_JSON);
|
||||
response.getPayload().setContentLength(10485760l);
|
||||
response.getHeaders().put("Content-Range", "0-10485759/20232760");
|
||||
|
||||
MutableBlobMetadata meta = blobMetadataProvider.get();
|
||||
expect(metadataParser.apply(response)).andReturn(meta);
|
||||
InputStream test = Utils.toInputStream("test");
|
||||
|
||||
expect(meta.getSize()).andReturn(-1l);
|
||||
meta.setSize(-1l);
|
||||
expect(response.getFirstHeaderOrNull(HttpHeaders.CONTENT_LENGTH)).andReturn("10485760")
|
||||
.atLeastOnce();
|
||||
expect(response.getFirstHeaderOrNull("Content-Range")).andReturn("0-10485759/20232760")
|
||||
.atLeastOnce();
|
||||
expect(response.getHeaders()).andReturn(
|
||||
ImmutableMultimap.of("Content-Length", "10485760", "Content-Range",
|
||||
"0-10485759/20232760"));
|
||||
meta.setSize(20232760l);
|
||||
|
||||
expect(response.getStatusCode()).andReturn(200).atLeastOnce();
|
||||
expect(response.getContent()).andReturn(test);
|
||||
expect(meta.getSize()).andReturn(20232760l);
|
||||
|
||||
replay(response);
|
||||
replay(metadataParser);
|
||||
|
||||
Blob object = callable.apply(response);
|
||||
assertEquals(object.getPayload().getContentLength(), new Long(10485760));
|
||||
assertEquals(object.getMetadata().getSize(), new Long(20232760));
|
||||
assertEquals(object.getMetadata().getSize(), null);// TODO
|
||||
assertEquals(object.getAllHeaders().get("Content-Range"), Collections
|
||||
.singletonList("0-10485759/20232760"));
|
||||
|
||||
|
|
|
@ -33,9 +33,9 @@ import org.jclouds.blobstore.domain.BlobMetadata;
|
|||
import org.jclouds.blobstore.domain.MutableBlobMetadata;
|
||||
import org.jclouds.blobstore.domain.internal.MutableBlobMetadataImpl;
|
||||
import org.jclouds.date.internal.SimpleDateFormatDateService;
|
||||
import org.jclouds.encryption.internal.JCEEncryptionService;
|
||||
import org.jclouds.http.HttpException;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.Payloads;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -58,7 +58,7 @@ public class ParseBlobMetadataFromHeadersTest {
|
|||
void setUp() {
|
||||
|
||||
parser = new ParseSystemAndUserMetadataFromHeaders(blobMetadataProvider,
|
||||
new SimpleDateFormatDateService(), "prefix", new JCEEncryptionService());
|
||||
new SimpleDateFormatDateService(), "prefix");
|
||||
|
||||
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
|
||||
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
|
||||
|
@ -69,25 +69,25 @@ public class ParseBlobMetadataFromHeadersTest {
|
|||
|
||||
@Test
|
||||
public void testApplySetsKey() {
|
||||
HttpResponse from = new HttpResponse();
|
||||
from.getHeaders().put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
|
||||
HttpResponse from = new HttpResponse(200, "ok", Payloads.newStringPayload(""));
|
||||
from.getPayload().setContentType(MediaType.APPLICATION_JSON);
|
||||
from.getHeaders().put(HttpHeaders.LAST_MODIFIED, "Wed, 09 Sep 2009 19:50:23 GMT");
|
||||
from.getHeaders().put(HttpHeaders.CONTENT_LENGTH, "100");
|
||||
from.getPayload().setContentLength(100l);
|
||||
BlobMetadata metadata = parser.apply(from);
|
||||
assertEquals(metadata.getName(), "key");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetContentLength() {
|
||||
HttpResponse from = new HttpResponse();
|
||||
from.getHeaders().put(HttpHeaders.CONTENT_LENGTH, "100");
|
||||
HttpResponse from = new HttpResponse(200, "ok", Payloads.newStringPayload(""));
|
||||
from.getPayload().setContentLength(100l);
|
||||
MutableBlobMetadata metadata = blobMetadataProvider.get();
|
||||
parser.setContentLength(from, metadata);
|
||||
assertEquals(metadata.getSize(), new Long(100));
|
||||
}
|
||||
|
||||
public void testSetContentLengthNoHeader() {
|
||||
HttpResponse from = new HttpResponse();
|
||||
HttpResponse from = new HttpResponse(200, "ok", Payloads.newStringPayload(""));
|
||||
MutableBlobMetadata metadata = blobMetadataProvider.get();
|
||||
parser.setContentLength(from, metadata);
|
||||
assertEquals(metadata.getSize(), new Long(0));
|
||||
|
@ -95,8 +95,8 @@ public class ParseBlobMetadataFromHeadersTest {
|
|||
|
||||
@Test
|
||||
public void testSetContentType() {
|
||||
HttpResponse from = new HttpResponse();
|
||||
from.getHeaders().put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
|
||||
HttpResponse from = new HttpResponse(200, "ok", Payloads.newStringPayload(""));
|
||||
from.getPayload().setContentType(MediaType.APPLICATION_JSON);
|
||||
MutableBlobMetadata metadata = blobMetadataProvider.get();
|
||||
parser.setContentTypeOrThrowException(from, metadata);
|
||||
assertEquals(metadata.getContentType(), MediaType.APPLICATION_JSON);
|
||||
|
@ -104,14 +104,14 @@ public class ParseBlobMetadataFromHeadersTest {
|
|||
|
||||
@Test(expectedExceptions = HttpException.class)
|
||||
public void testSetContentTypeException() {
|
||||
HttpResponse from = new HttpResponse();
|
||||
HttpResponse from = new HttpResponse(200, "ok", Payloads.newStringPayload(""));
|
||||
MutableBlobMetadata metadata = blobMetadataProvider.get();
|
||||
parser.setContentTypeOrThrowException(from, metadata);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetLastModified() {
|
||||
HttpResponse from = new HttpResponse();
|
||||
HttpResponse from = new HttpResponse(200, "ok", Payloads.newStringPayload(""));
|
||||
from.getHeaders().put(HttpHeaders.LAST_MODIFIED, "Wed, 09 Sep 2009 19:50:23 GMT");
|
||||
MutableBlobMetadata metadata = blobMetadataProvider.get();
|
||||
parser.parseLastModifiedOrThrowException(from, metadata);
|
||||
|
@ -121,14 +121,14 @@ public class ParseBlobMetadataFromHeadersTest {
|
|||
|
||||
@Test(expectedExceptions = HttpException.class)
|
||||
public void testSetLastModifiedException() {
|
||||
HttpResponse from = new HttpResponse();
|
||||
HttpResponse from = new HttpResponse(200, "ok", Payloads.newStringPayload(""));
|
||||
MutableBlobMetadata metadata = blobMetadataProvider.get();
|
||||
parser.parseLastModifiedOrThrowException(from, metadata);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddETagTo() {
|
||||
HttpResponse from = new HttpResponse();
|
||||
HttpResponse from = new HttpResponse(200, "ok", Payloads.newStringPayload(""));
|
||||
from.getHeaders().put(HttpHeaders.ETAG, "0xfeb");
|
||||
MutableBlobMetadata metadata = blobMetadataProvider.get();
|
||||
parser.addETagTo(from, metadata);
|
||||
|
@ -138,7 +138,7 @@ public class ParseBlobMetadataFromHeadersTest {
|
|||
@Test
|
||||
public void testAddUserMetadataTo() {
|
||||
Multimap<String, String> allHeaders = ImmutableMultimap.of("prefix" + "key", "value");
|
||||
HttpResponse from = new HttpResponse();
|
||||
HttpResponse from = new HttpResponse(200, "ok", Payloads.newStringPayload(""));
|
||||
from.getHeaders().putAll(allHeaders);
|
||||
MutableBlobMetadata metadata = blobMetadataProvider.get();
|
||||
parser.addUserMetadataTo(from, metadata);
|
||||
|
|
|
@ -66,21 +66,22 @@ public class BoxDotNetErrorHandler implements HttpErrorHandler {
|
|||
break;
|
||||
}
|
||||
} finally {
|
||||
Closeables.closeQuietly(response.getContent());
|
||||
if (response.getPayload() != null)
|
||||
Closeables.closeQuietly(response.getPayload().getInput());
|
||||
command.setException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
public String parseMessage(HttpResponse response) {
|
||||
if (response.getContent() == null)
|
||||
if (response.getPayload() == null)
|
||||
return null;
|
||||
try {
|
||||
return Utils.toStringAndClose(response.getContent());
|
||||
return Utils.toStringAndClose(response.getPayload().getInput());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
try {
|
||||
response.getContent().close();
|
||||
response.getPayload().getInput().close();
|
||||
} catch (IOException e) {
|
||||
Throwables.propagate(e);
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ import java.lang.reflect.Method;
|
|||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.filters.BasicAuthentication;
|
||||
import org.jclouds.http.functions.CloseContentAndReturn;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.http.functions.ReturnStringIf200;
|
||||
import org.jclouds.rest.RestClientTest;
|
||||
import org.jclouds.rest.RestContextFactory.ContextSpec;
|
||||
|
@ -57,8 +57,8 @@ public class BoxDotNetAsyncClientTest extends RestClientTest<BoxDotNetAsyncClien
|
|||
GeneratedHttpRequest<BoxDotNetAsyncClient> httpRequest = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://www.box.net/api/1.0/rest/items HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
// now make sure request filters apply by replaying
|
||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
@ -66,9 +66,9 @@ public class BoxDotNetAsyncClientTest extends RestClientTest<BoxDotNetAsyncClien
|
|||
|
||||
assertRequestLineEquals(httpRequest, "GET https://www.box.net/api/1.0/rest/items HTTP/1.1");
|
||||
// for example, using basic authentication, we should get "only one" header
|
||||
assertHeadersEqual(httpRequest,
|
||||
assertNonPayloadHeadersEqual(httpRequest,
|
||||
"Accept: application/json\nAuthorization: Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==\n");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
// TODO: insert expected response class, which probably extends ParseJson
|
||||
assertResponseParserClassEquals(method, httpRequest, ReturnStringIf200.class);
|
||||
|
@ -84,8 +84,8 @@ public class BoxDotNetAsyncClientTest extends RestClientTest<BoxDotNetAsyncClien
|
|||
GeneratedHttpRequest<BoxDotNetAsyncClient> httpRequest = processor.createRequest(method, 1);
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://www.box.net/api/1.0/rest/items/1 HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
// TODO: insert expected response class, which probably extends ParseJson
|
||||
assertResponseParserClassEquals(method, httpRequest, ReturnStringIf200.class);
|
||||
|
@ -103,10 +103,10 @@ public class BoxDotNetAsyncClientTest extends RestClientTest<BoxDotNetAsyncClien
|
|||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"DELETE https://www.box.net/api/1.0/rest/items/1 HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, CloseContentAndReturn.class);
|
||||
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
|
||||
|
||||
|
|
|
@ -24,14 +24,11 @@
|
|||
package org.jclouds.chef.binders;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.binders.BindToStringPayload;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
|
@ -42,9 +39,8 @@ public class BindClientnameToJsonPayload extends BindToStringPayload {
|
|||
|
||||
@Override
|
||||
public void bindToRequest(HttpRequest request, Object payload) {
|
||||
request.getHeaders().replaceValues(HttpHeaders.CONTENT_TYPE,
|
||||
ImmutableSet.of(MediaType.APPLICATION_JSON));
|
||||
super.bindToRequest(request, String.format("{\"clientname\":\"%s\"}", payload));
|
||||
request.getPayload().setContentType(MediaType.APPLICATION_JSON);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,14 +24,11 @@
|
|||
package org.jclouds.chef.binders;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.binders.BindToStringPayload;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
|
@ -42,10 +39,9 @@ public class BindGenerateKeyForClientToJsonPayload extends BindToStringPayload {
|
|||
|
||||
@Override
|
||||
public void bindToRequest(HttpRequest request, Object payload) {
|
||||
request.getHeaders().replaceValues(HttpHeaders.CONTENT_TYPE,
|
||||
ImmutableSet.of(MediaType.APPLICATION_JSON));
|
||||
super.bindToRequest(request, String.format("{\"clientname\":\"%s\", \"private_key\": true}",
|
||||
payload));
|
||||
request.getPayload().setContentType(MediaType.APPLICATION_JSON);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,14 +29,11 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||
import java.util.Set;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.binders.BindToStringPayload;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
|
@ -59,9 +56,8 @@ public class BindHexEncodedMD5sToJsonPayload extends BindToStringPayload {
|
|||
builder.append(String.format("\"%s\":null,", hexEncodedmd5));
|
||||
builder.deleteCharAt(builder.length() - 1);
|
||||
builder.append("}}");
|
||||
request.getHeaders().replaceValues(HttpHeaders.CONTENT_TYPE,
|
||||
ImmutableSet.of(MediaType.APPLICATION_JSON));
|
||||
super.bindToRequest(request, builder.toString());
|
||||
request.getPayload().setContentType(MediaType.APPLICATION_JSON);
|
||||
}
|
||||
|
||||
}
|
|
@ -24,14 +24,11 @@
|
|||
package org.jclouds.chef.binders;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.binders.BindToStringPayload;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
|
@ -42,9 +39,8 @@ public class BindIsCompletedToJsonPayload extends BindToStringPayload {
|
|||
|
||||
@Override
|
||||
public void bindToRequest(HttpRequest request, Object value) {
|
||||
request.getHeaders().replaceValues(HttpHeaders.CONTENT_TYPE,
|
||||
ImmutableSet.of(MediaType.APPLICATION_JSON));
|
||||
super.bindToRequest(request, String.format("{\"is_completed\":\"%s\"}", value));
|
||||
request.getPayload().setContentType(MediaType.APPLICATION_JSON);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -74,6 +74,7 @@ public class SignedHeaderAuth implements HttpRequestFilter {
|
|||
private final Provider<String> timeStampProvider;
|
||||
private final EncryptionService encryptionService;
|
||||
private final String emptyStringHash;
|
||||
private final HttpUtils utils;
|
||||
|
||||
@Resource
|
||||
@Named(Constants.LOGGER_SIGNATURE)
|
||||
|
@ -82,13 +83,14 @@ public class SignedHeaderAuth implements HttpRequestFilter {
|
|||
@Inject
|
||||
public SignedHeaderAuth(SignatureWire signatureWire, @Named(PROPERTY_IDENTITY) String userId,
|
||||
PrivateKey privateKey, @TimeStamp Provider<String> timeStampProvider,
|
||||
EncryptionService encryptionService) {
|
||||
EncryptionService encryptionService, HttpUtils utils) {
|
||||
this.signatureWire = signatureWire;
|
||||
this.userId = userId;
|
||||
this.privateKey = privateKey;
|
||||
this.timeStampProvider = timeStampProvider;
|
||||
this.encryptionService = encryptionService;
|
||||
this.emptyStringHash = hashBody(Payloads.newStringPayload(""));
|
||||
this.utils = utils;
|
||||
}
|
||||
|
||||
public void filter(HttpRequest request) throws HttpException {
|
||||
|
@ -104,7 +106,7 @@ public class SignedHeaderAuth implements HttpRequestFilter {
|
|||
Collections.singletonList(SIGNING_DESCRIPTION));
|
||||
calculateAndReplaceAuthorizationHeaders(request, toSign);
|
||||
request.getHeaders().replaceValues("X-Ops-Timestamp", Collections.singletonList(timestamp));
|
||||
HttpUtils.logRequest(signatureLog, request, "<<");
|
||||
utils.logRequest(signatureLog, request, "<<");
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
|
|
@ -50,8 +50,7 @@ public class ParseCookbookVersionFromJson extends ParseJson<CookbookVersion> {
|
|||
@Override
|
||||
protected CookbookVersion apply(InputStream stream) {
|
||||
try {
|
||||
return gson.fromJson(new InputStreamReader(stream, "UTF-8"),
|
||||
CookbookVersion.class);
|
||||
return gson.fromJson(new InputStreamReader(stream, "UTF-8"), CookbookVersion.class);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||
}
|
||||
|
|
|
@ -23,17 +23,16 @@
|
|||
*/
|
||||
package org.jclouds.chef.functions;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.jclouds.http.functions.ReturnStringIf200;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Throwables;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -43,22 +42,19 @@ import com.google.common.base.Throwables;
|
|||
@Singleton
|
||||
public class ParseErrorFromJsonOrReturnBody implements Function<HttpResponse, String> {
|
||||
Pattern pattern = Pattern.compile(".*\\[\"([^\"]+)\"\\].*");
|
||||
private final ReturnStringIf200 returnStringIf200;
|
||||
|
||||
@Inject
|
||||
ParseErrorFromJsonOrReturnBody(ReturnStringIf200 returnStringIf200) {
|
||||
this.returnStringIf200 = returnStringIf200;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apply(HttpResponse response) {
|
||||
if (response.getContent() == null)
|
||||
String content = returnStringIf200.apply(response);
|
||||
if (content == null)
|
||||
return null;
|
||||
try {
|
||||
return parse(Utils.toStringAndClose(response.getContent()));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
try {
|
||||
response.getContent().close();
|
||||
} catch (IOException e) {
|
||||
Throwables.propagate(e);
|
||||
}
|
||||
}
|
||||
return parse(content);
|
||||
}
|
||||
|
||||
public String parse(String in) {
|
||||
|
|
|
@ -23,17 +23,16 @@
|
|||
*/
|
||||
package org.jclouds.chef.functions;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.jclouds.http.functions.ReturnStringIf200;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Throwables;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -43,22 +42,22 @@ import com.google.common.base.Throwables;
|
|||
@Singleton
|
||||
public class ParseKeyFromJson implements Function<HttpResponse, String> {
|
||||
Pattern pattern = Pattern.compile(".*private_key\": *\"([^\"]+)\".*");
|
||||
private final ReturnStringIf200 returnStringIf200;
|
||||
|
||||
@Inject
|
||||
ParseKeyFromJson(ReturnStringIf200 returnStringIf200) {
|
||||
this.returnStringIf200 = returnStringIf200;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apply(HttpResponse response) {
|
||||
try {
|
||||
return parse(Utils.toStringAndClose(response.getContent()));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
try {
|
||||
response.getContent().close();
|
||||
} catch (IOException e) {
|
||||
Throwables.propagate(e);
|
||||
}
|
||||
}
|
||||
String content = returnStringIf200.apply(response);
|
||||
if (content == null)
|
||||
return null;
|
||||
return parse(content);
|
||||
}
|
||||
|
||||
|
||||
public String parse(String in) {
|
||||
Matcher matcher = pattern.matcher(in);
|
||||
while (matcher.find()) {
|
||||
|
|
|
@ -50,8 +50,7 @@ public class ParseUploadSiteFromJson extends ParseJson<UploadSandbox> {
|
|||
@Override
|
||||
protected UploadSandbox apply(InputStream stream) {
|
||||
try {
|
||||
return gson.fromJson(new InputStreamReader(stream, "UTF-8"),
|
||||
UploadSandbox.class);
|
||||
return gson.fromJson(new InputStreamReader(stream, "UTF-8"), UploadSandbox.class);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||
}
|
||||
|
|
|
@ -74,8 +74,8 @@ public class ParseValueSetFromJson extends ParseJson<Set<String>> {
|
|||
Type map = new TypeToken<Map<String, Set<String>>>() {
|
||||
}.getType();
|
||||
return Iterables.get(
|
||||
((Map<String, Set<String>>) gson.fromJson(new InputStreamReader(
|
||||
stream, "UTF-8"), map)).entrySet(), 0).getValue();
|
||||
((Map<String, Set<String>>) gson.fromJson(new InputStreamReader(stream, "UTF-8"),
|
||||
map)).entrySet(), 0).getValue();
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||
}
|
||||
|
|
|
@ -68,7 +68,8 @@ public class ChefErrorHandler implements HttpErrorHandler {
|
|||
break;
|
||||
}
|
||||
} finally {
|
||||
Closeables.closeQuietly(response.getContent());
|
||||
if (response.getPayload() != null)
|
||||
Closeables.closeQuietly(response.getPayload().getInput());
|
||||
command.setException(exception);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ import org.jclouds.chef.functions.ParseUploadSiteFromJson;
|
|||
import org.jclouds.date.TimeStamp;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.RequiresHttp;
|
||||
import org.jclouds.http.functions.CloseContentAndReturn;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.http.functions.ReturnStringIf200;
|
||||
import org.jclouds.http.functions.ReturnTrueIf2xx;
|
||||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
|
@ -76,10 +76,8 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||
"0189e76ccc476701d6b374e5a1a27347", true);
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"PUT http://localhost:4000/sandboxes/0189e76ccc476701d6b374e5a1a27347 HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
httpRequest,
|
||||
"Accept: application/json\nContent-Length: 23\nContent-Type: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertPayloadEquals(httpRequest, "{\"is_completed\":\"true\"}");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertPayloadEquals(httpRequest, "{\"is_completed\":\"true\"}", "application/json", false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseSandboxFromJson.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -89,21 +87,19 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||
|
||||
}
|
||||
|
||||
public void testGetUploadSandboxForChecksums() throws SecurityException,
|
||||
NoSuchMethodException, IOException {
|
||||
public void testGetUploadSandboxForChecksums() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
|
||||
Method method = ChefAsyncClient.class.getMethod("getUploadSandboxForChecksums",
|
||||
Set.class);
|
||||
Method method = ChefAsyncClient.class.getMethod("getUploadSandboxForChecksums", Set.class);
|
||||
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method,
|
||||
ImmutableSet.of("0189e76ccc476701d6b374e5a1a27347",
|
||||
"0c5ecd7788cf4f6c7de2a57193897a6c", "1dda05ed139664f1f89b9dec482b77c0"));
|
||||
assertRequestLineEquals(httpRequest, "POST http://localhost:4000/sandboxes HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
httpRequest,
|
||||
"Accept: application/json\nContent-Length: 135\nContent-Type: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertPayloadEquals(
|
||||
httpRequest,
|
||||
"{\"checksums\":{\"0189e76ccc476701d6b374e5a1a27347\":null,\"0c5ecd7788cf4f6c7de2a57193897a6c\":null,\"1dda05ed139664f1f89b9dec482b77c0\":null}}");
|
||||
"{\"checksums\":{\"0189e76ccc476701d6b374e5a1a27347\":null,\"0c5ecd7788cf4f6c7de2a57193897a6c\":null,\"1dda05ed139664f1f89b9dec482b77c0\":null}}",
|
||||
"application/json", false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseUploadSiteFromJson.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -119,8 +115,8 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||
"cookbook", "1.0.0");
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET http://localhost:4000/cookbooks/cookbook/1.0.0 HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseCookbookVersionFromJson.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -136,10 +132,10 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||
"cookbook", "1.0.0");
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"DELETE http://localhost:4000/cookbooks/cookbook/1.0.0 HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, CloseContentAndReturn.class);
|
||||
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
|
||||
|
||||
|
@ -155,13 +151,12 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"PUT http://localhost:4000/cookbooks/cookbook/1.0.1 HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
httpRequest,
|
||||
"Accept: application/json\nContent-Length: 446\nContent-Type: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertPayloadEquals(
|
||||
httpRequest,
|
||||
"{\"name\":\"cookbook-1.0.1\",\"definitions\":[],\"attributes\":[],\"files\":[],\"metadata\":{\"suggestions\":{},\"dependencies\":{},\"conflicting\":{},\"providing\":{},\"platforms\":{},\"recipes\":{},\"replacing\":{},\"groupings\":{},\"attributes\":{},\"recommendations\":{}},\"providers\":[],\"cookbook_name\":\"cookbook\",\"resources\":[],\"templates\":[],\"libraries\":[],\"version\":\"1.0.1\",\"recipes\":[],\"root_files\":[],\"json_class\":\"Chef::CookbookVersion\",\"chef_type\":\"cookbook_version\"}");
|
||||
assertResponseParserClassEquals(method, httpRequest, CloseContentAndReturn.class);
|
||||
"{\"name\":\"cookbook-1.0.1\",\"definitions\":[],\"attributes\":[],\"files\":[],\"metadata\":{\"suggestions\":{},\"dependencies\":{},\"conflicting\":{},\"providing\":{},\"platforms\":{},\"recipes\":{},\"replacing\":{},\"groupings\":{},\"attributes\":{},\"recommendations\":{}},\"providers\":[],\"cookbook_name\":\"cookbook\",\"resources\":[],\"templates\":[],\"libraries\":[],\"version\":\"1.0.1\",\"recipes\":[],\"root_files\":[],\"json_class\":\"Chef::CookbookVersion\",\"chef_type\":\"cookbook_version\"}",
|
||||
"application/json", false);
|
||||
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
|
@ -174,8 +169,8 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET http://localhost:4000/cookbooks HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseKeySetFromJson.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -189,8 +184,8 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||
Method method = ChefAsyncClient.class.getMethod("clientExists", String.class);
|
||||
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method, "client");
|
||||
assertRequestLineEquals(httpRequest, "HEAD http://localhost:4000/clients/client HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ReturnTrueIf2xx.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -204,8 +199,8 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||
Method method = ChefAsyncClient.class.getMethod("deleteClient", String.class);
|
||||
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method, "client");
|
||||
assertRequestLineEquals(httpRequest, "DELETE http://localhost:4000/clients/client HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ReturnStringIf200.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -220,10 +215,9 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||
Method method = ChefAsyncClient.class.getMethod("generateKeyForClient", String.class);
|
||||
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method, "client");
|
||||
assertRequestLineEquals(httpRequest, "PUT http://localhost:4000/clients/client HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
httpRequest,
|
||||
"Accept: application/json\nContent-Length: 44\nContent-Type: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertPayloadEquals(httpRequest, "{\"clientname\":\"client\", \"private_key\": true}");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertPayloadEquals(httpRequest, "{\"clientname\":\"client\", \"private_key\": true}",
|
||||
"application/json", false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseKeyFromJson.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -238,10 +232,9 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method, "client");
|
||||
|
||||
assertRequestLineEquals(httpRequest, "POST http://localhost:4000/clients HTTP/1.1");
|
||||
assertHeadersEqual(
|
||||
httpRequest,
|
||||
"Accept: application/json\nContent-Length: 23\nContent-Type: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertPayloadEquals(httpRequest, "{\"clientname\":\"client\"}");
|
||||
assertNonPayloadHeadersEqual(httpRequest,
|
||||
"Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertPayloadEquals(httpRequest, "{\"clientname\":\"client\"}", "application/json", false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseKeyFromJson.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -256,8 +249,8 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
|||
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET http://localhost:4000/clients HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseKeySetFromJson.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
|
|
@ -41,10 +41,11 @@ import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
|||
import org.bouncycastle.openssl.PEMReader;
|
||||
import org.jclouds.encryption.EncryptionService;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpUtils;
|
||||
import org.jclouds.http.internal.SignatureWire;
|
||||
import org.jclouds.logging.config.NullLoggingModule;
|
||||
import org.jclouds.rest.RestContextFactory;
|
||||
import org.jclouds.rest.RestClientTest.MockModule;
|
||||
import org.jclouds.rest.BaseRestClientTest.MockModule;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -215,6 +216,8 @@ public class SignedHeaderAuthTest {
|
|||
new Properties()).buildInjector();
|
||||
|
||||
encryptionService = injector.getInstance(EncryptionService.class);
|
||||
HttpUtils utils = injector.getInstance(HttpUtils.class);
|
||||
|
||||
Security.addProvider(new BouncyCastleProvider());
|
||||
|
||||
KeyPair pair = KeyPair.class.cast(new PEMReader(new StringReader(PRIVATE_KEY)).readObject());
|
||||
|
@ -229,7 +232,7 @@ public class SignedHeaderAuthTest {
|
|||
return TIMESTAMP_ISO8601;
|
||||
}
|
||||
|
||||
}, encryptionService);
|
||||
}, encryptionService, utils);
|
||||
}
|
||||
|
||||
}
|
|
@ -11,6 +11,7 @@ import org.jclouds.chef.domain.CookbookVersion;
|
|||
import org.jclouds.chef.domain.Metadata;
|
||||
import org.jclouds.chef.domain.Resource;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.Payloads;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
|
@ -39,34 +40,37 @@ public class ParseCookbookVersionFromJsonTest {
|
|||
}
|
||||
|
||||
public void testBrew() throws IOException {
|
||||
CookbookVersion cookbook = handler.apply(new HttpResponse(
|
||||
ParseCookbookVersionFromJsonTest.class.getResourceAsStream("/brew-cookbook.json")));
|
||||
CookbookVersion cookbook = handler.apply(new HttpResponse(200, "ok", Payloads
|
||||
.newPayload(ParseCookbookVersionFromJsonTest.class
|
||||
.getResourceAsStream("/brew-cookbook.json"))));
|
||||
|
||||
assertEquals(cookbook, handler.apply(new HttpResponse(Utils.toInputStream(new Gson()
|
||||
.toJson(cookbook)))));
|
||||
assertEquals(cookbook, handler.apply(new HttpResponse(200, "ok", Payloads.newPayload(Utils
|
||||
.toInputStream(new Gson().toJson(cookbook))))));
|
||||
}
|
||||
|
||||
public void testTomcat() {
|
||||
CookbookVersion cookbook = handler
|
||||
.apply(new HttpResponse(ParseCookbookVersionFromJsonTest.class
|
||||
.getResourceAsStream("/tomcat-cookbook.json")));
|
||||
CookbookVersion cookbook = handler.apply(new HttpResponse(200, "ok", Payloads
|
||||
.newPayload(ParseCookbookVersionFromJsonTest.class
|
||||
.getResourceAsStream("/tomcat-cookbook.json"))));
|
||||
|
||||
assertEquals(cookbook, handler.apply(new HttpResponse(Utils.toInputStream(new Gson()
|
||||
.toJson(cookbook)))));
|
||||
assertEquals(cookbook, handler.apply(new HttpResponse(200, "ok", Payloads.newPayload(Utils
|
||||
.toInputStream(new Gson().toJson(cookbook))))));
|
||||
}
|
||||
|
||||
public void testMysql() throws IOException {
|
||||
CookbookVersion cookbook = handler.apply(new HttpResponse(
|
||||
ParseCookbookVersionFromJsonTest.class.getResourceAsStream("/mysql-cookbook.json")));
|
||||
CookbookVersion cookbook = handler.apply(new HttpResponse(200, "ok", Payloads
|
||||
.newPayload(ParseCookbookVersionFromJsonTest.class
|
||||
.getResourceAsStream("/mysql-cookbook.json"))));
|
||||
|
||||
assertEquals(cookbook, handler.apply(new HttpResponse(Utils.toInputStream(new Gson()
|
||||
.toJson(cookbook)))));
|
||||
assertEquals(cookbook, handler.apply(new HttpResponse(200, "ok", Payloads.newPayload(Utils
|
||||
.toInputStream(new Gson().toJson(cookbook))))));
|
||||
}
|
||||
|
||||
public void testApache() {
|
||||
assertEquals(
|
||||
handler.apply(new HttpResponse(ParseCookbookVersionFromJsonTest.class
|
||||
.getResourceAsStream("/apache-chef-demo-cookbook.json"))),
|
||||
handler.apply(new HttpResponse(200, "ok", Payloads
|
||||
.newPayload(ParseCookbookVersionFromJsonTest.class
|
||||
.getResourceAsStream("/apache-chef-demo-cookbook.json")))),
|
||||
new CookbookVersion(
|
||||
"apache-chef-demo-0.0.0",
|
||||
ImmutableSet.<Resource> of(),
|
||||
|
|
|
@ -22,12 +22,15 @@
|
|||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.chef.functions;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.Payloads;
|
||||
import org.jclouds.http.functions.ReturnStringIf200;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -42,8 +45,9 @@ public class ParseErrorFromJsonOrReturnBodyTest {
|
|||
InputStream is = Utils
|
||||
.toInputStream("{\"error\":[\"invalid tarball: tarball root must contain java-bytearray\"]}");
|
||||
|
||||
ParseErrorFromJsonOrReturnBody parser = new ParseErrorFromJsonOrReturnBody();
|
||||
String response = parser.apply(new HttpResponse(is));
|
||||
ParseErrorFromJsonOrReturnBody parser = new ParseErrorFromJsonOrReturnBody(
|
||||
new ReturnStringIf200());
|
||||
String response = parser.apply(new HttpResponse(200, "ok", Payloads.newPayload(is)));
|
||||
assertEquals(response, "invalid tarball: tarball root must contain java-bytearray");
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import static org.testng.Assert.assertEquals;
|
|||
import java.io.IOException;
|
||||
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.Payloads;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
|
@ -33,15 +34,17 @@ public class ParseKeyFromJsonTest {
|
|||
assertEquals(
|
||||
handler
|
||||
.apply(new HttpResponse(
|
||||
Utils
|
||||
.toInputStream("{\n\"uri\": \"https://api.opscode.com/users/bobo\", \"private_key\": \"RSA_PRIVATE_KEY\",}"))),
|
||||
200,
|
||||
"ok",
|
||||
Payloads
|
||||
.newPayload(Utils
|
||||
.toInputStream("{\n\"uri\": \"https://api.opscode.com/users/bobo\", \"private_key\": \"RSA_PRIVATE_KEY\",}")))),
|
||||
"RSA_PRIVATE_KEY");
|
||||
}
|
||||
|
||||
public void test2() {
|
||||
String key = handler.apply(new HttpResponse(ParseKeyFromJsonTest.class
|
||||
.getResourceAsStream("/newclient.txt")));
|
||||
String key = handler.apply(new HttpResponse(200, "ok", Payloads
|
||||
.newPayload(ParseKeyFromJsonTest.class.getResourceAsStream("/newclient.txt"))));
|
||||
assert key.startsWith("-----BEGIN RSA PRIVATE KEY-----\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import static org.testng.Assert.assertEquals;
|
|||
import java.io.IOException;
|
||||
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.Payloads;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
|
@ -34,8 +35,11 @@ public class ParseKeySetFromJsonTest {
|
|||
assertEquals(
|
||||
handler
|
||||
.apply(new HttpResponse(
|
||||
Utils
|
||||
.toInputStream("{\n\"opscode-validator\": \"https://api.opscode.com/...\", \"pimp-validator\": \"https://api.opscode.com/...\"}"))),
|
||||
ImmutableSet.of("opscode-validator","pimp-validator"));
|
||||
200,
|
||||
"ok",
|
||||
Payloads
|
||||
.newPayload(Utils
|
||||
.toInputStream("{\n\"opscode-validator\": \"https://api.opscode.com/...\", \"pimp-validator\": \"https://api.opscode.com/...\"}")))),
|
||||
ImmutableSet.of("opscode-validator", "pimp-validator"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.io.IOException;
|
|||
|
||||
import org.jclouds.chef.domain.Organization;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.Payloads;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
|
@ -57,6 +58,7 @@ public class ParseOrganizationFromJsonTest {
|
|||
|
||||
String toParse = "{\"name\": \"opscode\",\"full_name\": \"Opscode, Inc.\", \"org_type\": \"Business\",\"clientname\": \"opscode-validator\" }";
|
||||
|
||||
assertEquals(handler.apply(new HttpResponse(Utils.toInputStream(toParse))), org);
|
||||
assertEquals(handler.apply(new HttpResponse(200, "ok", Payloads.newPayload(Utils
|
||||
.toInputStream(toParse)))), org);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import java.io.IOException;
|
|||
import org.jclouds.chef.domain.Sandbox;
|
||||
import org.jclouds.date.DateService;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.Payloads;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.jclouds.http.functions.config.ParserModule.DateAdapter;
|
||||
import org.jclouds.http.functions.config.ParserModule.Iso8601DateAdapter;
|
||||
|
@ -44,9 +45,9 @@ public class ParseSandboxFromJsonTest {
|
|||
}
|
||||
|
||||
public void test() {
|
||||
assertEquals(handler.apply(new HttpResponse(ParseSandboxFromJsonTest.class
|
||||
.getResourceAsStream("/sandbox.json"))), new Sandbox(
|
||||
"1-8c27b0ea4c2b7aaedbb44cfbdfcc11b2", false, dateService
|
||||
assertEquals(handler.apply(new HttpResponse(200, "ok", Payloads
|
||||
.newPayload(ParseSandboxFromJsonTest.class.getResourceAsStream("/sandbox.json")))),
|
||||
new Sandbox("1-8c27b0ea4c2b7aaedbb44cfbdfcc11b2", false, dateService
|
||||
.iso8601SecondsDateParse("2010-07-07T03:36:00+00:00"), ImmutableSet
|
||||
.<String> of(), "f9d6d9b72bae465890aae87969f98a9c",
|
||||
"f9d6d9b72bae465890aae87969f98a9c"));
|
||||
|
|
|
@ -8,6 +8,7 @@ import java.net.URI;
|
|||
import org.jclouds.chef.domain.ChecksumStatus;
|
||||
import org.jclouds.chef.domain.UploadSandbox;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.Payloads;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -34,8 +35,9 @@ public class ParseUploadSiteFromJsonTest {
|
|||
|
||||
public void test() {
|
||||
assertEquals(
|
||||
handler.apply(new HttpResponse(ParseUploadSiteFromJsonTest.class
|
||||
.getResourceAsStream("/upload-site.json"))),
|
||||
handler.apply(new HttpResponse(200, "ok", Payloads
|
||||
.newPayload(ParseUploadSiteFromJsonTest.class
|
||||
.getResourceAsStream("/upload-site.json")))),
|
||||
new UploadSandbox(
|
||||
URI
|
||||
.create("https://api.opscode.com/organizations/jclouds/sandboxes/d454f71e2a5f400c808d0c5d04c2c88c"),
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.io.IOException;
|
|||
|
||||
import org.jclouds.chef.domain.User;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.Payloads;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
|
@ -41,6 +42,7 @@ public class ParseUserFromJsonTest {
|
|||
|
||||
String toParse = "{\n\"username\": \"bobo\",\n\"first_name\": \"Bobo\",\n\"middle_name\": \"Tiberion\",\n\"last_name\": \"Clown\",\n\"display_name\": \"Bobo T. Clown\",\n\"email\": \"bobo@clownco.com\" \n}";
|
||||
|
||||
assertEquals(handler.apply(new HttpResponse(Utils.toInputStream(toParse))), user);
|
||||
assertEquals(handler.apply(new HttpResponse(200, "ok", Payloads.newPayload(Utils
|
||||
.toInputStream(toParse)))), user);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import static org.testng.Assert.assertEquals;
|
|||
import java.io.IOException;
|
||||
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.Payloads;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
|
@ -31,8 +32,8 @@ public class ParseValueSetFromJsonTest {
|
|||
}
|
||||
|
||||
public void testRegex() {
|
||||
assertEquals(handler.apply(new HttpResponse(Utils
|
||||
.toInputStream("{\"runit\":[\"0.7.0\",\"0.7.1\"]}"))), ImmutableSet
|
||||
.of("0.7.0", "0.7.1"));
|
||||
assertEquals(handler.apply(new HttpResponse(200, "ok", Payloads.newPayload(Utils
|
||||
.toInputStream("{\"runit\":[\"0.7.0\",\"0.7.1\"]}")))), ImmutableSet.of("0.7.0",
|
||||
"0.7.1"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ import javax.inject.Named;
|
|||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.internal.ClassMethodArgs;
|
||||
import org.jclouds.rest.annotations.Delegate;
|
||||
import org.jclouds.util.Utils;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
@ -132,20 +133,24 @@ public class SyncProxy implements InvocationHandler {
|
|||
return ((ListenableFuture<?>) methodMap.get(method).invoke(delegate, args)).get(
|
||||
timeoutMap.get(method), TimeUnit.NANOSECONDS);
|
||||
} catch (ExecutionException e) {
|
||||
throw typedExceptionOrPropagate(method.getExceptionTypes(), e.getCause());
|
||||
throw throwTypedExceptionOrCause(method.getExceptionTypes(), e);
|
||||
} catch (Exception e) {
|
||||
throw typedExceptionOrPropagate(method.getExceptionTypes(), e);
|
||||
throw throwTypedExceptionOrCause(method.getExceptionTypes(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Throwable typedExceptionOrPropagate(Class<?>[] exceptionTypes, Throwable throwable) {
|
||||
for (Class<?> type : exceptionTypes) {
|
||||
if (type.isInstance(throwable)) {
|
||||
return throwable;
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Exception throwTypedExceptionOrCause(Class[] exceptionTypes, Exception exception)
|
||||
throws Exception {
|
||||
for (Class type : exceptionTypes) {
|
||||
Throwable throwable = Utils.getFirstThrowableOfType(exception, type);
|
||||
if (throwable != null) {
|
||||
Throwables.throwCause(exception, true);
|
||||
}
|
||||
}
|
||||
return Throwables.propagate(throwable);
|
||||
Throwables.throwCause(exception, true);
|
||||
return exception;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -166,6 +171,6 @@ public class SyncProxy implements InvocationHandler {
|
|||
}
|
||||
|
||||
public String toString() {
|
||||
return "Sync Proxy for: " + delegate.toString();
|
||||
return "Sync Proxy for: " + delegate.getClass().getSimpleName();
|
||||
}
|
||||
}
|
|
@ -19,6 +19,7 @@
|
|||
package org.jclouds.encryption;
|
||||
|
||||
import java.io.FilterOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.security.Key;
|
||||
|
@ -62,6 +63,7 @@ public interface EncryptionService {
|
|||
* <h2>Note</h2>
|
||||
* <p/>
|
||||
* If this is an InputStream, it will be converted to a byte array first.
|
||||
* @throws IOException
|
||||
*/
|
||||
<T extends PayloadEnclosing> T generateMD5BufferingIfNotRepeatable(T payloadEnclosing);
|
||||
|
||||
|
|
|
@ -23,9 +23,12 @@ import static com.google.common.base.Preconditions.checkState;
|
|||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.jclouds.encryption.EncryptionService;
|
||||
import org.jclouds.http.Payload;
|
||||
import org.jclouds.http.PayloadEnclosing;
|
||||
import org.jclouds.logging.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -33,6 +36,12 @@ import org.jclouds.http.PayloadEnclosing;
|
|||
*/
|
||||
public abstract class BaseEncryptionService implements EncryptionService {
|
||||
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
protected static final int BUF_SIZE = 0x2000; // 8
|
||||
|
||||
|
||||
final byte[] HEX_CHAR_TABLE = { (byte) '0', (byte) '1', (byte) '2', (byte) '3', (byte) '4',
|
||||
(byte) '5', (byte) '6', (byte) '7', (byte) '8', (byte) '9', (byte) 'a', (byte) 'b',
|
||||
(byte) 'c', (byte) 'd', (byte) 'e', (byte) 'f' };
|
||||
|
@ -81,6 +90,7 @@ public abstract class BaseEncryptionService implements EncryptionService {
|
|||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @
|
||||
*/
|
||||
@Override
|
||||
public <T extends PayloadEnclosing> T generateMD5BufferingIfNotRepeatable(T payloadEnclosing) {
|
||||
|
|
|
@ -18,6 +18,9 @@
|
|||
*/
|
||||
package org.jclouds.encryption.internal;
|
||||
|
||||
import static com.google.common.base.Throwables.propagate;
|
||||
import static com.google.common.io.Closeables.closeQuietly;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
@ -34,9 +37,6 @@ import javax.crypto.spec.SecretKeySpec;
|
|||
|
||||
import org.jclouds.http.payloads.ByteArrayPayload;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.io.Closeables;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
|
@ -73,7 +73,7 @@ public class JCEEncryptionService extends BaseEncryptionService {
|
|||
@Override
|
||||
public byte[] md5(InputStream toEncode) {
|
||||
MessageDigest eTag = getDigest();
|
||||
byte[] buffer = new byte[1024];
|
||||
byte[] buffer = new byte[BUF_SIZE];
|
||||
int numRead = -1;
|
||||
try {
|
||||
do {
|
||||
|
@ -83,9 +83,9 @@ public class JCEEncryptionService extends BaseEncryptionService {
|
|||
}
|
||||
} while (numRead != -1);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
propagate(e);
|
||||
} finally {
|
||||
Closeables.closeQuietly(toEncode);
|
||||
closeQuietly(toEncode);
|
||||
}
|
||||
return eTag.digest();
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ public class JCEEncryptionService extends BaseEncryptionService {
|
|||
@Override
|
||||
public ByteArrayPayload generatePayloadWithMD5For(InputStream toEncode) {
|
||||
MessageDigest eTag = getDigest();
|
||||
byte[] buffer = new byte[1024];
|
||||
byte[] buffer = new byte[BUF_SIZE];
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
long length = 0;
|
||||
int numRead = -1;
|
||||
|
@ -117,10 +117,10 @@ public class JCEEncryptionService extends BaseEncryptionService {
|
|||
}
|
||||
} while (numRead != -1);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
propagate(e);
|
||||
} finally {
|
||||
Closeables.closeQuietly(out);
|
||||
Closeables.closeQuietly(toEncode);
|
||||
closeQuietly(out);
|
||||
closeQuietly(toEncode);
|
||||
}
|
||||
return new ByteArrayPayload(out.toByteArray(), eTag.digest());
|
||||
}
|
||||
|
@ -167,10 +167,10 @@ public class JCEEncryptionService extends BaseEncryptionService {
|
|||
try {
|
||||
digest = MessageDigest.getInstance(algorithm);
|
||||
} catch (NoSuchAlgorithmException e1) {
|
||||
Throwables.propagate(e1);
|
||||
propagate(e1);
|
||||
return null;
|
||||
}
|
||||
byte[] buffer = new byte[1024];
|
||||
byte[] buffer = new byte[BUF_SIZE];
|
||||
long length = 0;
|
||||
int numRead = -1;
|
||||
try {
|
||||
|
@ -182,9 +182,9 @@ public class JCEEncryptionService extends BaseEncryptionService {
|
|||
}
|
||||
} while (numRead != -1);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
propagate(e);
|
||||
} finally {
|
||||
Closeables.closeQuietly(plainBytes);
|
||||
closeQuietly(plainBytes);
|
||||
}
|
||||
|
||||
return digest.digest();
|
||||
|
@ -198,10 +198,9 @@ public class JCEEncryptionService extends BaseEncryptionService {
|
|||
cipher.init(Cipher.ENCRYPT_MODE, key);
|
||||
return cipher.doFinal(toSign.getBytes());
|
||||
} catch (Exception e) {
|
||||
Throwables.propagate(e);
|
||||
propagate(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.jclouds.http;
|
||||
|
||||
import com.google.common.io.Closeables;
|
||||
|
||||
/**
|
||||
* Responsible for setting an exception on the command relevant to the unrecoverable error in the
|
||||
|
@ -29,8 +28,8 @@ import com.google.common.io.Closeables;
|
|||
public interface HttpErrorHandler {
|
||||
public static final HttpErrorHandler NOOP = new HttpErrorHandler() {
|
||||
public void handleError(HttpCommand command, HttpResponse response) {
|
||||
if (response.getContent() != null)
|
||||
Closeables.closeQuietly(response.getContent());
|
||||
if (response.getPayload() != null)
|
||||
response.getPayload().release();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -20,17 +20,20 @@ package org.jclouds.http;
|
|||
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.jclouds.http.internal.PayloadEnclosingImpl;
|
||||
|
||||
import com.google.common.collect.LinkedHashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.Multimaps;
|
||||
|
||||
/**
|
||||
* Provides base functionality of HTTP requests and responses.
|
||||
* Represents a request that can be executed within {@link HttpCommandExecutorService}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
public class HttpMessage {
|
||||
public class HttpMessage extends PayloadEnclosingImpl {
|
||||
|
||||
/**
|
||||
* synchronized as there is no concurrent version. Headers may change in flight due to redirects.
|
||||
|
@ -42,6 +45,14 @@ public class HttpMessage {
|
|||
return headers;
|
||||
}
|
||||
|
||||
public HttpMessage() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public HttpMessage(@Nullable Payload payload) {
|
||||
super(payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* try to get the value, then try as lowercase.
|
||||
*/
|
||||
|
@ -55,7 +66,7 @@ public class HttpMessage {
|
|||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + ((headers == null) ? 0 : headers.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
@ -64,7 +75,7 @@ public class HttpMessage {
|
|||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
if (!super.equals(obj))
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
|
@ -77,4 +88,9 @@ public class HttpMessage {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[headers=" + headers + ", payload=" + payload + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -24,49 +24,24 @@ import static com.google.inject.internal.Lists.newArrayList;
|
|||
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.jclouds.http.internal.PayloadEnclosingImpl;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.collect.LinkedHashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.Multimaps;
|
||||
import com.google.inject.internal.Nullable;
|
||||
|
||||
/**
|
||||
* Represents a request that can be executed within {@link HttpCommandExecutorService}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class HttpRequest extends PayloadEnclosingImpl implements PayloadEnclosing {
|
||||
public class HttpRequest extends HttpMessage {
|
||||
|
||||
private List<HttpRequestFilter> requestFilters = newArrayList();
|
||||
private String method;
|
||||
private URI endpoint;
|
||||
private Payload payload;
|
||||
private char[] skips;
|
||||
|
||||
/**
|
||||
* synchronized as there is no concurrent version. Headers may change in flight due to redirects.
|
||||
*/
|
||||
private Multimap<String, String> headers = Multimaps.synchronizedMultimap(LinkedHashMultimap
|
||||
.<String, String> create());
|
||||
|
||||
public Multimap<String, String> getHeaders() {
|
||||
return headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* try to get the value, then try as lowercase.
|
||||
*/
|
||||
public String getFirstHeaderOrNull(String string) {
|
||||
Collection<String> values = headers.get(string);
|
||||
if (values.size() == 0)
|
||||
values = headers.get(string.toLowerCase());
|
||||
return (values.size() >= 1) ? values.iterator().next() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param endpoint
|
||||
|
@ -164,6 +139,7 @@ public class HttpRequest extends PayloadEnclosingImpl implements PayloadEnclosin
|
|||
result = prime * result + ((endpoint == null) ? 0 : endpoint.hashCode());
|
||||
result = prime * result + ((method == null) ? 0 : method.hashCode());
|
||||
result = prime * result + ((payload == null) ? 0 : payload.hashCode());
|
||||
result = prime * result + ((headers == null) ? 0 : headers.hashCode());
|
||||
result = prime * result + ((requestFilters == null) ? 0 : requestFilters.hashCode());
|
||||
result = prime * result + Arrays.hashCode(skips);
|
||||
return result;
|
||||
|
@ -193,6 +169,11 @@ public class HttpRequest extends PayloadEnclosingImpl implements PayloadEnclosin
|
|||
return false;
|
||||
} else if (!payload.equals(other.payload))
|
||||
return false;
|
||||
if (headers == null) {
|
||||
if (other.headers != null)
|
||||
return false;
|
||||
} else if (!headers.equals(other.headers))
|
||||
return false;
|
||||
if (requestFilters == null) {
|
||||
if (other.requestFilters != null)
|
||||
return false;
|
||||
|
@ -205,7 +186,8 @@ public class HttpRequest extends PayloadEnclosingImpl implements PayloadEnclosin
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[method=" + method + ", endpoint=" + endpoint + ", headers=" + headers + "]";
|
||||
return "[method=" + method + ", endpoint=" + endpoint + ", headers=" + headers + ", payload="
|
||||
+ payload + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
package org.jclouds.http;
|
||||
|
||||
import java.io.InputStream;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Represents a response produced from {@link HttpCommandExecutorService}
|
||||
|
@ -26,44 +26,28 @@ import java.io.InputStream;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
public class HttpResponse extends HttpMessage {
|
||||
private int statusCode;
|
||||
private String message;
|
||||
private InputStream content;
|
||||
|
||||
public HttpResponse() {
|
||||
}
|
||||
private final int statusCode;
|
||||
private final String message;
|
||||
|
||||
public HttpResponse(InputStream content) {
|
||||
this.content = content;
|
||||
public HttpResponse(int statusCode, String message, @Nullable Payload payload) {
|
||||
super(payload);
|
||||
this.statusCode = statusCode;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public int getStatusCode() {
|
||||
return statusCode;
|
||||
}
|
||||
|
||||
public void setStatusCode(int statusCode) {
|
||||
this.statusCode = statusCode;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public InputStream getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(InputStream content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[message=" + message + ", statusCode=" + statusCode + ", headers=" + headers + "]";
|
||||
return "[message=" + message + ", statusCode=" + statusCode + ", headers=" + headers
|
||||
+ ", payload=" + payload + "]";
|
||||
}
|
||||
|
||||
public String getStatusLine() {
|
||||
|
@ -74,7 +58,8 @@ public class HttpResponse extends HttpMessage {
|
|||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + ((content == null) ? 0 : content.hashCode());
|
||||
result = prime * result + ((payload == null) ? 0 : payload.hashCode());
|
||||
result = prime * result + ((headers == null) ? 0 : headers.hashCode());
|
||||
result = prime * result + ((message == null) ? 0 : message.hashCode());
|
||||
result = prime * result + statusCode;
|
||||
return result;
|
||||
|
@ -89,10 +74,15 @@ public class HttpResponse extends HttpMessage {
|
|||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
HttpResponse other = (HttpResponse) obj;
|
||||
if (content == null) {
|
||||
if (other.content != null)
|
||||
if (payload == null) {
|
||||
if (other.payload != null)
|
||||
return false;
|
||||
} else if (!content.equals(other.content))
|
||||
} else if (!payload.equals(other.payload))
|
||||
return false;
|
||||
if (headers == null) {
|
||||
if (other.headers != null)
|
||||
return false;
|
||||
} else if (!headers.equals(other.headers))
|
||||
return false;
|
||||
if (message == null) {
|
||||
if (other.message != null)
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
*/
|
||||
package org.jclouds.http;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Represents an error obtained from an HttpResponse.
|
||||
*
|
||||
|
@ -31,15 +33,15 @@ public class HttpResponseException extends RuntimeException {
|
|||
protected final HttpResponse response;
|
||||
private String content;
|
||||
|
||||
public HttpResponseException(String message, HttpCommand command, HttpResponse response,
|
||||
Throwable cause) {
|
||||
public HttpResponseException(String message, HttpCommand command,
|
||||
@Nullable HttpResponse response, Throwable cause) {
|
||||
super(message, cause);
|
||||
this.command = command;
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
public HttpResponseException(String message, HttpCommand command, HttpResponse response,
|
||||
String content, Throwable cause) {
|
||||
public HttpResponseException(String message, HttpCommand command,
|
||||
@Nullable HttpResponse response, String content, Throwable cause) {
|
||||
super(message, cause);
|
||||
this.command = command;
|
||||
this.response = response;
|
||||
|
@ -58,14 +60,14 @@ public class HttpResponseException extends RuntimeException {
|
|||
content, cause);
|
||||
}
|
||||
|
||||
public HttpResponseException(String message, HttpCommand command, HttpResponse response) {
|
||||
public HttpResponseException(String message, HttpCommand command, @Nullable HttpResponse response) {
|
||||
super(message);
|
||||
this.command = command;
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
public HttpResponseException(String message, HttpCommand command, HttpResponse response,
|
||||
String content) {
|
||||
public HttpResponseException(String message, HttpCommand command,
|
||||
@Nullable HttpResponse response, String content) {
|
||||
super(message);
|
||||
this.command = command;
|
||||
this.response = response;
|
||||
|
|
|
@ -18,13 +18,17 @@
|
|||
*/
|
||||
package org.jclouds.http;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static com.google.common.base.Throwables.propagate;
|
||||
import static com.google.common.collect.Iterables.any;
|
||||
import static com.google.common.collect.Lists.newArrayList;
|
||||
import static com.google.common.collect.Sets.newTreeSet;
|
||||
import static com.google.common.io.ByteStreams.toByteArray;
|
||||
import static com.google.common.io.Closeables.closeQuietly;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static javax.ws.rs.core.HttpHeaders.CONTENT_LENGTH;
|
||||
import static javax.ws.rs.core.HttpHeaders.CONTENT_TYPE;
|
||||
import static javax.ws.rs.core.HttpHeaders.HOST;
|
||||
import static org.jclouds.http.Payloads.newUrlEncodedFormPayload;
|
||||
import static org.jclouds.util.Patterns.CHAR_TO_ENCODED_PATTERN;
|
||||
|
@ -36,10 +40,8 @@ import static org.jclouds.util.Patterns.URL_ENCODED_PATTERN;
|
|||
import static org.jclouds.util.Patterns._7E_PATTERN;
|
||||
import static org.jclouds.util.Utils.replaceAll;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URI;
|
||||
import java.net.URLDecoder;
|
||||
|
@ -57,12 +59,15 @@ import javax.annotation.Nullable;
|
|||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
import javax.ws.rs.HttpMethod;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
import javax.ws.rs.core.UriBuilder;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.encryption.EncryptionService;
|
||||
import org.jclouds.logging.Logger;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.LinkedListMultimap;
|
||||
|
@ -76,6 +81,7 @@ import com.google.inject.Inject;
|
|||
*/
|
||||
@Singleton
|
||||
public class HttpUtils {
|
||||
|
||||
@Inject(optional = true)
|
||||
@Named(Constants.PROPERTY_RELAX_HOSTNAME)
|
||||
private boolean relaxHostname = false;
|
||||
|
@ -90,6 +96,7 @@ public class HttpUtils {
|
|||
private final int globalMaxConnectionsPerHost;
|
||||
private final int connectionTimeout;
|
||||
private final int soTimeout;
|
||||
private final EncryptionService encryptionService;
|
||||
@Inject(optional = true)
|
||||
@Named(Constants.PROPERTY_PROXY_HOST)
|
||||
private String proxyHost;
|
||||
|
@ -104,10 +111,12 @@ public class HttpUtils {
|
|||
private String proxyPassword;
|
||||
|
||||
@Inject
|
||||
public HttpUtils(@Named(Constants.PROPERTY_CONNECTION_TIMEOUT) int connectionTimeout,
|
||||
public HttpUtils(EncryptionService encryptionService,
|
||||
@Named(Constants.PROPERTY_CONNECTION_TIMEOUT) int connectionTimeout,
|
||||
@Named(Constants.PROPERTY_SO_TIMEOUT) int soTimeout,
|
||||
@Named(Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT) int globalMaxConnections,
|
||||
@Named(Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST) int globalMaxConnectionsPerHost) {
|
||||
this.encryptionService = encryptionService;
|
||||
this.soTimeout = soTimeout;
|
||||
this.connectionTimeout = connectionTimeout;
|
||||
this.globalMaxConnections = globalMaxConnections;
|
||||
|
@ -211,37 +220,34 @@ public class HttpUtils {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Content stream may need to be read. However, we should always close the http stream.
|
||||
*/
|
||||
public static void consumeContent(HttpResponse response) {
|
||||
if (response.getContent() != null) {
|
||||
public static byte[] toByteArrayOrNull(PayloadEnclosing response) {
|
||||
if (response.getPayload() != null) {
|
||||
InputStream input = response.getPayload().getInput();
|
||||
try {
|
||||
toByteArray(response.getContent());
|
||||
return toByteArray(input);
|
||||
} catch (IOException e) {
|
||||
propagate(e);
|
||||
} finally {
|
||||
closeQuietly(response.getContent());
|
||||
closeQuietly(input);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Content stream may need to be read. However, we should always close the http stream.
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public static byte[] closeClientButKeepContentStream(HttpResponse response) {
|
||||
if (response.getContent() != null) {
|
||||
try {
|
||||
byte[] data = toByteArray(response.getContent());
|
||||
response.setContent(new ByteArrayInputStream(data));
|
||||
return data;
|
||||
} catch (IOException e) {
|
||||
propagate(e);
|
||||
} finally {
|
||||
closeQuietly(response.getContent());
|
||||
public static byte[] closeClientButKeepContentStream(PayloadEnclosing response) {
|
||||
byte[] returnVal = toByteArrayOrNull(response);
|
||||
if (returnVal != null && !response.getPayload().isRepeatable()) {
|
||||
Payload newPayload = Payloads.newByteArrayPayload(returnVal);
|
||||
newPayload.setContentMD5(response.getPayload().getContentMD5());
|
||||
newPayload.setContentType(response.getPayload().getContentType());
|
||||
response.setPayload(newPayload);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
public static URI parseEndPoint(String hostHeader) {
|
||||
|
@ -309,40 +315,35 @@ public class HttpUtils {
|
|||
}
|
||||
}
|
||||
|
||||
public static void logRequest(Logger logger, HttpRequest request, String prefix) {
|
||||
public void logRequest(Logger logger, HttpRequest request, String prefix) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("%s %s", prefix, request.getRequestLine().toString());
|
||||
for (Entry<String, String> header : request.getHeaders().entries()) {
|
||||
logMessage(logger, request, prefix);
|
||||
}
|
||||
}
|
||||
|
||||
private void logMessage(Logger logger, HttpMessage message, String prefix) {
|
||||
for (Entry<String, String> header : message.getHeaders().entries()) {
|
||||
if (header.getKey() != null)
|
||||
logger.debug("%s %s: %s", prefix, header.getKey(), header.getValue());
|
||||
}
|
||||
if (message.getPayload() != null) {
|
||||
if (message.getPayload().getContentType() != null)
|
||||
logger.debug("%s %s: %s", prefix, HttpHeaders.CONTENT_TYPE, message.getPayload()
|
||||
.getContentType());
|
||||
if (message.getPayload().getContentLength() != null)
|
||||
logger.debug("%s %s: %s", prefix, HttpHeaders.CONTENT_LENGTH, message.getPayload()
|
||||
.getContentLength());
|
||||
if (message.getPayload().getContentMD5() != null)
|
||||
logger.debug("%s %s: %s", prefix, "Content-MD5", encryptionService.base64(message
|
||||
.getPayload().getContentMD5()));
|
||||
}
|
||||
}
|
||||
|
||||
public static void logResponse(Logger logger, HttpResponse response, String prefix) {
|
||||
public void logResponse(Logger logger, HttpResponse response, String prefix) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("%s %s", prefix, response.getStatusLine().toString());
|
||||
for (Entry<String, String> header : response.getHeaders().entries()) {
|
||||
logger.debug("%s %s: %s", prefix, header.getKey(), header.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void copy(InputStream input, OutputStream output) throws IOException {
|
||||
byte[] buffer = new byte[1024];
|
||||
long length = 0;
|
||||
int numRead = -1;
|
||||
try {
|
||||
do {
|
||||
numRead = input.read(buffer);
|
||||
if (numRead > 0) {
|
||||
length += numRead;
|
||||
output.write(buffer, 0, numRead);
|
||||
}
|
||||
} while (numRead != -1);
|
||||
} finally {
|
||||
output.close();
|
||||
closeQuietly(input);
|
||||
logMessage(logger, response, prefix);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -485,4 +486,80 @@ public class HttpUtils {
|
|||
}
|
||||
return formBuilder.toString();
|
||||
}
|
||||
|
||||
public void setPayloadPropertiesFromHeaders(Multimap<String, String> headers, HttpMessage request) {
|
||||
Payload payload = request.getPayload();
|
||||
boolean chunked = any(headers.entries(), new Predicate<Entry<String, String>>() {
|
||||
@Override
|
||||
public boolean apply(Entry<String, String> input) {
|
||||
return "Transfer-Encoding".equalsIgnoreCase(input.getKey())
|
||||
&& "chunked".equalsIgnoreCase(input.getValue());
|
||||
}
|
||||
});
|
||||
|
||||
for (Entry<String, String> header : headers.entries()) {
|
||||
if (!chunked && CONTENT_LENGTH.equalsIgnoreCase(header.getKey())) {
|
||||
if (payload != null)
|
||||
payload.setContentLength(new Long(header.getValue()));
|
||||
} else if ("Content-MD5".equalsIgnoreCase(header.getKey())) {
|
||||
if (payload != null)
|
||||
payload.setContentMD5(encryptionService.fromBase64(header.getValue()));
|
||||
} else if (CONTENT_TYPE.equalsIgnoreCase(header.getKey())) {
|
||||
if (payload != null)
|
||||
payload.setContentType(header.getValue());
|
||||
} else {
|
||||
request.getHeaders().put(header.getKey(), header.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
String contentRange = request.getFirstHeaderOrNull("Content-Range");
|
||||
if (contentRange != null) {
|
||||
payload.setContentLength(Long.parseLong(contentRange.substring(0, contentRange
|
||||
.lastIndexOf('/'))));
|
||||
}
|
||||
|
||||
checkArgument(
|
||||
request.getPayload() == null || request.getFirstHeaderOrNull(CONTENT_TYPE) == null,
|
||||
"configuration error please use request.getPayload().setContentType(value) as opposed to adding a content type header: "
|
||||
+ request);
|
||||
checkArgument(
|
||||
request.getPayload() == null || request.getFirstHeaderOrNull(CONTENT_LENGTH) == null,
|
||||
"configuration error please use request.getPayload().setContentLength(value) as opposed to adding a content length header: "
|
||||
+ request);
|
||||
checkArgument(request.getPayload() == null || request.getPayload().getContentLength() != null
|
||||
|| "chunked".equalsIgnoreCase(request.getFirstHeaderOrNull("Transfer-Encoding")),
|
||||
"either chunked encoding must be set on the http request or contentlength set on the payload: "
|
||||
+ request);
|
||||
checkArgument(
|
||||
request.getPayload() == null || request.getFirstHeaderOrNull("Content-MD5") == null,
|
||||
"configuration error please use request.getPayload().setContentMD5(value) as opposed to adding a content md5 header: "
|
||||
+ request);
|
||||
}
|
||||
|
||||
public static void releasePayload(HttpResponse from) {
|
||||
if (from.getPayload() != null)
|
||||
from.getPayload().release();
|
||||
}
|
||||
|
||||
public String valueOrEmpty(String in) {
|
||||
return in != null ? in : "";
|
||||
}
|
||||
|
||||
public String valueOrEmpty(byte[] md5) {
|
||||
return md5 != null ? encryptionService.base64(md5) : "";
|
||||
}
|
||||
|
||||
public String valueOrEmpty(Collection<String> collection) {
|
||||
return (collection != null && collection.size() >= 1) ? collection.iterator().next() : "";
|
||||
}
|
||||
|
||||
public static Long attemptToParseSizeAndRangeFromHeaders(HttpResponse from) throws HttpException {
|
||||
String contentRange = from.getFirstHeaderOrNull("Content-Range");
|
||||
if (contentRange == null) {
|
||||
return from.getPayload().getContentLength();
|
||||
} else if (contentRange != null) {
|
||||
return Long.parseLong(contentRange.substring(contentRange.lastIndexOf('/') + 1));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,4 +78,8 @@ public interface Payload extends InputSupplier<InputStream> {
|
|||
@Nullable
|
||||
String getContentType();
|
||||
|
||||
/**
|
||||
* release resources used by this entity. This should be called when data is discarded.
|
||||
*/
|
||||
void release();
|
||||
}
|
|
@ -18,16 +18,16 @@
|
|||
*/
|
||||
package org.jclouds.http.functions;
|
||||
|
||||
import static org.jclouds.http.HttpUtils.releasePayload;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.jclouds.encryption.internal.Base64;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.rest.InvocationContext;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.io.Closeables;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
|
@ -62,10 +62,9 @@ public class ParseContentMD5FromHeaders implements Function<HttpResponse, byte[]
|
|||
private GeneratedHttpRequest<?> request;
|
||||
|
||||
public byte[] apply(HttpResponse from) {
|
||||
Closeables.closeQuietly(from.getContent());
|
||||
String contentMD5 = from.getFirstHeaderOrNull("Content-MD5");
|
||||
if (contentMD5 != null) {
|
||||
return Base64.decode(contentMD5);
|
||||
releasePayload(from);
|
||||
if (from.getPayload() != null) {
|
||||
return from.getPayload().getContentMD5();
|
||||
}
|
||||
throw new NoContentMD5Exception(request, from);
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
*/
|
||||
package org.jclouds.http.functions;
|
||||
|
||||
import static org.jclouds.http.HttpUtils.releasePayload;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
|
||||
|
@ -25,7 +27,6 @@ import org.jclouds.http.HttpException;
|
|||
import org.jclouds.http.HttpResponse;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.io.Closeables;
|
||||
|
||||
/**
|
||||
* Parses an MD5 checksum from the header {@link HttpHeaders#ETAG}.
|
||||
|
@ -36,8 +37,7 @@ import com.google.common.io.Closeables;
|
|||
public class ParseETagHeader implements Function<HttpResponse, String> {
|
||||
|
||||
public String apply(HttpResponse from) {
|
||||
Closeables.closeQuietly(from.getContent());
|
||||
|
||||
releasePayload(from);
|
||||
String eTag = from.getFirstHeaderOrNull(HttpHeaders.ETAG);
|
||||
if (eTag == null) {
|
||||
// TODO: Cloud Files sends incorrectly cased ETag header... Remove this when fixed.
|
||||
|
|
|
@ -18,9 +18,12 @@
|
|||
*/
|
||||
package org.jclouds.http.functions;
|
||||
|
||||
import static org.jclouds.http.HttpUtils.releasePayload;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.http.HttpResponse;
|
||||
|
@ -28,7 +31,6 @@ import org.jclouds.http.HttpResponseException;
|
|||
import org.jclouds.logging.Logger;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.io.Closeables;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
/**
|
||||
|
@ -44,7 +46,8 @@ public abstract class ParseJson<T> implements Function<HttpResponse, T> {
|
|||
protected Logger logger = Logger.NULL;
|
||||
protected final Gson gson;
|
||||
|
||||
public ParseJson(Gson gson) {
|
||||
@Inject
|
||||
public ParseJson(Gson gson){
|
||||
this.gson = gson;
|
||||
}
|
||||
|
||||
|
@ -52,7 +55,7 @@ public abstract class ParseJson<T> implements Function<HttpResponse, T> {
|
|||
* parses the http response body to create a new {@code <T>}.
|
||||
*/
|
||||
public T apply(HttpResponse from) {
|
||||
InputStream gson = from.getContent();
|
||||
InputStream gson = from.getPayload().getInput();
|
||||
try {
|
||||
return apply(gson);
|
||||
} catch (Exception e) {
|
||||
|
@ -61,7 +64,7 @@ public abstract class ParseJson<T> implements Function<HttpResponse, T> {
|
|||
logger.error(e, message.toString());
|
||||
throw new HttpResponseException(message.toString() + "\n" + from, null, from, e);
|
||||
} finally {
|
||||
Closeables.closeQuietly(gson);
|
||||
releasePayload(from);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ public class ParseSax<T> implements Function<HttpResponse, T>,
|
|||
}
|
||||
|
||||
public T apply(HttpResponse from) throws HttpException {
|
||||
return parse(from.getContent());
|
||||
return parse(from.getPayload().getInput());
|
||||
}
|
||||
|
||||
public T parse(InputStream from) throws HttpException {
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package org.jclouds.http.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static org.jclouds.http.HttpUtils.releasePayload;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
@ -58,14 +59,17 @@ public class ParseURIFromListOrLocationHeaderIf20x implements Function<HttpRespo
|
|||
throw new HttpException(String.format("Unhandled status code - %1$s", from));
|
||||
if ("text/uri-list".equals(from.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE))) {
|
||||
try {
|
||||
if (from.getContent() == null)
|
||||
if (from.getPayload().getInput() == null)
|
||||
throw new HttpResponseException("no content", null, from);
|
||||
String toParse = Utils.toStringAndClose(from.getContent());
|
||||
String toParse = Utils.toStringAndClose(from.getPayload().getInput());
|
||||
return URI.create(toParse.trim());
|
||||
} catch (IOException e) {
|
||||
throw new HttpResponseException("couldn't parse uri from content", null, from, e);
|
||||
} finally {
|
||||
releasePayload(from);
|
||||
}
|
||||
} else {
|
||||
releasePayload(from);
|
||||
String location = from.getFirstHeaderOrNull(HttpHeaders.LOCATION);
|
||||
if (location == null)
|
||||
location = from.getFirstHeaderOrNull("location");
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue