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) {
|
public SetMetadataPropertiesPayload(Payload delegate, MutableContentMetadata contentMetadata) {
|
||||||
super(delegate);
|
super(delegate);
|
||||||
this.contentMetadata = contentMetadata;
|
this.contentMetadata = contentMetadata;
|
||||||
if (contentMetadata.getContentLength() != null)
|
|
||||||
setContentLength(contentMetadata.getContentLength());
|
|
||||||
setContentMD5(contentMetadata.getContentMD5());
|
|
||||||
setContentType(contentMetadata.getContentType());
|
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
|
@Override
|
||||||
public void setContentType(String md5) {
|
public void setContentType(String md5) {
|
||||||
super.setContentType(md5);
|
super.setContentType(md5);
|
||||||
|
@ -207,13 +192,6 @@ public class AtmosObjectImpl extends PayloadEnclosingImpl implements AtmosObject
|
||||||
this.object = object;
|
this.object = object;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setContentMD5(byte[] md5) {
|
|
||||||
super.setContentMD5(md5);
|
|
||||||
if (canSetPayload())
|
|
||||||
object.getPayload().setContentMD5(md5);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setContentType(String type) {
|
public void setContentType(String type) {
|
||||||
super.setContentType(type);
|
super.setContentType(type);
|
||||||
|
@ -221,13 +199,6 @@ public class AtmosObjectImpl extends PayloadEnclosingImpl implements AtmosObject
|
||||||
object.getPayload().setContentType(type);
|
object.getPayload().setContentType(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setContentLength(Long size) {
|
|
||||||
super.setContentLength(size);
|
|
||||||
if (canSetPayload())
|
|
||||||
object.getPayload().setContentLength(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean canSetPayload() {
|
private boolean canSetPayload() {
|
||||||
return object != null && object.getPayload() != null;
|
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.NEWLINE_PATTERN;
|
||||||
import static org.jclouds.util.Patterns.TWO_SPACE_PATTERN;
|
import static org.jclouds.util.Patterns.TWO_SPACE_PATTERN;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
@ -64,6 +63,8 @@ public class SignRequest implements HttpRequestFilter {
|
||||||
private final byte[] key;
|
private final byte[] key;
|
||||||
private final Provider<String> timeStampProvider;
|
private final Provider<String> timeStampProvider;
|
||||||
private final EncryptionService encryptionService;
|
private final EncryptionService encryptionService;
|
||||||
|
private final HttpUtils utils;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
Logger logger = Logger.NULL;
|
Logger logger = Logger.NULL;
|
||||||
|
|
||||||
|
@ -74,19 +75,21 @@ public class SignRequest implements HttpRequestFilter {
|
||||||
@Inject
|
@Inject
|
||||||
public SignRequest(SignatureWire signatureWire, @Named(PROPERTY_IDENTITY) String uid,
|
public SignRequest(SignatureWire signatureWire, @Named(PROPERTY_IDENTITY) String uid,
|
||||||
@Named(PROPERTY_CREDENTIAL) String encodedKey,
|
@Named(PROPERTY_CREDENTIAL) String encodedKey,
|
||||||
@TimeStamp Provider<String> timeStampProvider, EncryptionService encryptionService) {
|
@TimeStamp Provider<String> timeStampProvider, EncryptionService encryptionService,
|
||||||
|
HttpUtils utils) {
|
||||||
this.signatureWire = signatureWire;
|
this.signatureWire = signatureWire;
|
||||||
this.uid = uid;
|
this.uid = uid;
|
||||||
this.key = encryptionService.fromBase64(encodedKey);
|
this.key = encryptionService.fromBase64(encodedKey);
|
||||||
this.timeStampProvider = timeStampProvider;
|
this.timeStampProvider = timeStampProvider;
|
||||||
this.encryptionService = encryptionService;
|
this.encryptionService = encryptionService;
|
||||||
|
this.utils = utils;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void filter(HttpRequest request) throws HttpException {
|
public void filter(HttpRequest request) throws HttpException {
|
||||||
String toSign = replaceUIDHeader(request).removeOldSignature(request).replaceDateHeader(
|
String toSign = replaceUIDHeader(request).removeOldSignature(request).replaceDateHeader(
|
||||||
request).createStringToSign(request);
|
request).createStringToSign(request);
|
||||||
calculateAndReplaceAuthHeader(request, toSign);
|
calculateAndReplaceAuthHeader(request, toSign);
|
||||||
HttpUtils.logRequest(signatureLog, request, "<<");
|
utils.logRequest(signatureLog, request, "<<");
|
||||||
}
|
}
|
||||||
|
|
||||||
private SignRequest removeOldSignature(HttpRequest request) {
|
private SignRequest removeOldSignature(HttpRequest request) {
|
||||||
|
@ -95,10 +98,11 @@ public class SignRequest implements HttpRequestFilter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String createStringToSign(HttpRequest request) {
|
public String createStringToSign(HttpRequest request) {
|
||||||
HttpUtils.logRequest(signatureLog, request, ">>");
|
utils.logRequest(signatureLog, request, ">>");
|
||||||
StringBuilder buffer = new StringBuilder();
|
StringBuilder buffer = new StringBuilder();
|
||||||
// re-sign the request
|
// re-sign the request
|
||||||
appendMethod(request, buffer);
|
appendMethod(request, buffer);
|
||||||
|
appendPayloadMetadata(request, buffer);
|
||||||
appendHttpHeaders(request, buffer);
|
appendHttpHeaders(request, buffer);
|
||||||
appendCanonicalizedResource(request, buffer);
|
appendCanonicalizedResource(request, buffer);
|
||||||
appendCanonicalizedHeaders(request, buffer);
|
appendCanonicalizedHeaders(request, buffer);
|
||||||
|
@ -167,12 +171,19 @@ public class SignRequest implements HttpRequestFilter {
|
||||||
toSign.deleteCharAt(toSign.length() - 1);
|
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
|
@VisibleForTesting
|
||||||
void appendHttpHeaders(HttpRequest request, StringBuilder toSign) {
|
void appendHttpHeaders(HttpRequest request, StringBuilder toSign) {
|
||||||
// Only the value is used, not the header
|
// Only the value is used, not the header
|
||||||
// name. If a request does not include the header, this is an empty string.
|
// name. If a request does not include the header, this is an empty string.
|
||||||
for (String header : new String[] { HttpHeaders.CONTENT_TYPE, "Range" })
|
for (String header : new String[] { "Range" })
|
||||||
toSign.append(valueOrEmpty(request.getHeaders().get(header)).toLowerCase()).append("\n");
|
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.
|
// 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");
|
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");
|
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) {
|
public BoundedSet<DirectoryEntry> apply(HttpResponse from) {
|
||||||
String token = from.getFirstHeaderOrNull(AtmosStorageHeaders.TOKEN);
|
String token = from.getFirstHeaderOrNull(AtmosStorageHeaders.TOKEN);
|
||||||
return new BoundedHashSet<DirectoryEntry>(factory.create(listHandlerProvider.get()).parse(
|
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;
|
package org.jclouds.atmosonline.saas.functions;
|
||||||
|
|
||||||
|
import static org.jclouds.http.HttpUtils.attemptToParseSizeAndRangeFromHeaders;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
|
||||||
|
|
||||||
import org.jclouds.atmosonline.saas.domain.AtmosObject;
|
import org.jclouds.atmosonline.saas.domain.AtmosObject;
|
||||||
import org.jclouds.blobstore.functions.ParseSystemAndUserMetadataFromHeaders;
|
import org.jclouds.blobstore.functions.ParseSystemAndUserMetadataFromHeaders;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -61,30 +61,9 @@ public class ParseObjectFromHeadersAndHttpContent implements Function<HttpRespon
|
||||||
public AtmosObject apply(HttpResponse from) {
|
public AtmosObject apply(HttpResponse from) {
|
||||||
AtmosObject object = objectProvider.create(systemMetadataParser.apply(from),
|
AtmosObject object = objectProvider.create(systemMetadataParser.apply(from),
|
||||||
userMetadataParser.apply(from));
|
userMetadataParser.apply(from));
|
||||||
addAllHeadersTo(from, object);
|
object.getAllHeaders().putAll(from.getHeaders());
|
||||||
if (from.getContent() != null) {
|
object.setPayload(from.getPayload());
|
||||||
object.setPayload(from.getContent());
|
object.getContentMetadata().setContentLength(attemptToParseSizeAndRangeFromHeaders(from));
|
||||||
} 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);
|
|
||||||
}
|
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
void addAllHeadersTo(HttpResponse from, AtmosObject object) {
|
|
||||||
object.getAllHeaders().putAll(from.getHeaders());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -18,6 +18,8 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.atmosonline.saas.handlers;
|
package org.jclouds.atmosonline.saas.handlers;
|
||||||
|
|
||||||
|
import static org.jclouds.http.HttpUtils.releasePayload;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
|
@ -41,8 +43,6 @@ import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.rest.AuthorizationException;
|
import org.jclouds.rest.AuthorizationException;
|
||||||
import org.jclouds.util.Utils;
|
import org.jclouds.util.Utils;
|
||||||
|
|
||||||
import com.google.common.io.Closeables;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This will parse and set an appropriate exception on the command object.
|
* This will parse and set an appropriate exception on the command object.
|
||||||
*
|
*
|
||||||
|
@ -105,15 +105,15 @@ public class ParseAtmosStorageErrorFromXmlContent implements HttpErrorHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
Closeables.closeQuietly(response.getContent());
|
releasePayload(response);
|
||||||
command.setException(exception);
|
command.setException(exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AtmosStorageError parseErrorFromContentOrNull(HttpCommand command, HttpResponse response) {
|
AtmosStorageError parseErrorFromContentOrNull(HttpCommand command, HttpResponse response) {
|
||||||
if (response.getContent() != null) {
|
if (response.getPayload() != null) {
|
||||||
try {
|
try {
|
||||||
String content = Utils.toStringAndClose(response.getContent());
|
String content = Utils.toStringAndClose(response.getPayload().getInput());
|
||||||
if (content != null && content.indexOf('<') >= 0)
|
if (content != null && content.indexOf('<') >= 0)
|
||||||
return utils.parseAtmosStorageErrorFromContent(command, response, Utils
|
return utils.parseAtmosStorageErrorFromContent(command, response, Utils
|
||||||
.toInputStream(content));
|
.toInputStream(content));
|
||||||
|
|
|
@ -42,8 +42,8 @@ import org.jclouds.blobstore.functions.ThrowKeyNotFoundOn404;
|
||||||
import org.jclouds.date.TimeStamp;
|
import org.jclouds.date.TimeStamp;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.RequiresHttp;
|
import org.jclouds.http.RequiresHttp;
|
||||||
import org.jclouds.http.functions.CloseContentAndReturn;
|
|
||||||
import org.jclouds.http.functions.ParseURIFromListOrLocationHeaderIf20x;
|
import org.jclouds.http.functions.ParseURIFromListOrLocationHeaderIf20x;
|
||||||
|
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||||
import org.jclouds.http.options.GetOptions;
|
import org.jclouds.http.options.GetOptions;
|
||||||
import org.jclouds.rest.ConfiguresRestClient;
|
import org.jclouds.rest.ConfiguresRestClient;
|
||||||
import org.jclouds.rest.RestClientTest;
|
import org.jclouds.rest.RestClientTest;
|
||||||
|
@ -76,8 +76,8 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
|
||||||
|
|
||||||
assertRequestLineEquals(request,
|
assertRequestLineEquals(request,
|
||||||
"GET https://accesspoint.atmosonline.com/rest/namespace HTTP/1.1");
|
"GET https://accesspoint.atmosonline.com/rest/namespace HTTP/1.1");
|
||||||
assertHeadersEqual(request, HttpHeaders.ACCEPT + ": text/xml\n");
|
assertNonPayloadHeadersEqual(request, HttpHeaders.ACCEPT + ": text/xml\n");
|
||||||
assertPayloadEquals(request, null);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request,
|
assertResponseParserClassEquals(method, request,
|
||||||
ParseDirectoryListFromContentAndHeaders.class);
|
ParseDirectoryListFromContentAndHeaders.class);
|
||||||
|
@ -94,8 +94,8 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
|
||||||
|
|
||||||
assertRequestLineEquals(request,
|
assertRequestLineEquals(request,
|
||||||
"GET https://accesspoint.atmosonline.com/rest/namespace/directory/ HTTP/1.1");
|
"GET https://accesspoint.atmosonline.com/rest/namespace/directory/ HTTP/1.1");
|
||||||
assertHeadersEqual(request, HttpHeaders.ACCEPT + ": text/xml\n");
|
assertNonPayloadHeadersEqual(request, HttpHeaders.ACCEPT + ": text/xml\n");
|
||||||
assertPayloadEquals(request, null);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request,
|
assertResponseParserClassEquals(method, request,
|
||||||
ParseDirectoryListFromContentAndHeaders.class);
|
ParseDirectoryListFromContentAndHeaders.class);
|
||||||
|
@ -114,9 +114,9 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
|
||||||
|
|
||||||
assertRequestLineEquals(request,
|
assertRequestLineEquals(request,
|
||||||
"GET https://accesspoint.atmosonline.com/rest/namespace HTTP/1.1");
|
"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");
|
+ ": text/xml\nx-emc-limit: 1\nx-emc-token: asda\n");
|
||||||
assertPayloadEquals(request, null);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request,
|
assertResponseParserClassEquals(method, request,
|
||||||
ParseDirectoryListFromContentAndHeaders.class);
|
ParseDirectoryListFromContentAndHeaders.class);
|
||||||
|
@ -135,9 +135,9 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
|
||||||
|
|
||||||
assertRequestLineEquals(request,
|
assertRequestLineEquals(request,
|
||||||
"GET https://accesspoint.atmosonline.com/rest/namespace/directory/ HTTP/1.1");
|
"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");
|
+ ": text/xml\nx-emc-limit: 1\nx-emc-token: asda\n");
|
||||||
assertPayloadEquals(request, null);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request,
|
assertResponseParserClassEquals(method, request,
|
||||||
ParseDirectoryListFromContentAndHeaders.class);
|
ParseDirectoryListFromContentAndHeaders.class);
|
||||||
|
@ -153,8 +153,8 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
|
||||||
|
|
||||||
assertRequestLineEquals(request,
|
assertRequestLineEquals(request,
|
||||||
"POST https://accesspoint.atmosonline.com/rest/namespace/dir/ HTTP/1.1");
|
"POST https://accesspoint.atmosonline.com/rest/namespace/dir/ HTTP/1.1");
|
||||||
assertHeadersEqual(request, HttpHeaders.ACCEPT + ": */*\n");
|
assertNonPayloadHeadersEqual(request, HttpHeaders.ACCEPT + ": */*\n");
|
||||||
assertPayloadEquals(request, null);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseURIFromListOrLocationHeaderIf20x.class);
|
assertResponseParserClassEquals(method, request, ParseURIFromListOrLocationHeaderIf20x.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
@ -171,9 +171,9 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
|
||||||
|
|
||||||
assertRequestLineEquals(request,
|
assertRequestLineEquals(request,
|
||||||
"POST https://accesspoint.atmosonline.com/rest/namespace/dir/hello HTTP/1.1");
|
"POST https://accesspoint.atmosonline.com/rest/namespace/dir/hello HTTP/1.1");
|
||||||
assertHeadersEqual(request, HttpHeaders.ACCEPT
|
assertNonPayloadHeadersEqual(request, HttpHeaders.ACCEPT
|
||||||
+ ": */*\nContent-Length: 5\nContent-Type: text/plain\n");
|
+ ": */*\n");
|
||||||
assertPayloadEquals(request, "hello");
|
assertPayloadEquals(request, "hello", "text/plain", false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseURIFromListOrLocationHeaderIf20x.class);
|
assertResponseParserClassEquals(method, request, ParseURIFromListOrLocationHeaderIf20x.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
@ -190,11 +190,11 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
|
||||||
|
|
||||||
assertRequestLineEquals(request,
|
assertRequestLineEquals(request,
|
||||||
"PUT https://accesspoint.atmosonline.com/rest/namespace/dir/hello HTTP/1.1");
|
"PUT https://accesspoint.atmosonline.com/rest/namespace/dir/hello HTTP/1.1");
|
||||||
assertHeadersEqual(request, HttpHeaders.ACCEPT
|
assertNonPayloadHeadersEqual(request, HttpHeaders.ACCEPT
|
||||||
+ ": */*\nContent-Length: 5\nContent-Type: text/plain\n");
|
+ ": */*\n");
|
||||||
assertPayloadEquals(request, "hello");
|
assertPayloadEquals(request, "hello", "text/plain", false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, ThrowKeyNotFoundOn404.class);
|
assertExceptionParserClassEquals(method, ThrowKeyNotFoundOn404.class);
|
||||||
|
|
||||||
|
@ -208,8 +208,8 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
|
||||||
|
|
||||||
assertRequestLineEquals(request,
|
assertRequestLineEquals(request,
|
||||||
"GET https://accesspoint.atmosonline.com/rest/namespace/dir/file HTTP/1.1");
|
"GET https://accesspoint.atmosonline.com/rest/namespace/dir/file HTTP/1.1");
|
||||||
assertHeadersEqual(request, HttpHeaders.ACCEPT + ": */*\n");
|
assertNonPayloadHeadersEqual(request, HttpHeaders.ACCEPT + ": */*\n");
|
||||||
assertPayloadEquals(request, null);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseObjectFromHeadersAndHttpContent.class);
|
assertResponseParserClassEquals(method, request, ParseObjectFromHeadersAndHttpContent.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
@ -224,8 +224,8 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
|
||||||
|
|
||||||
assertRequestLineEquals(request,
|
assertRequestLineEquals(request,
|
||||||
"HEAD https://accesspoint.atmosonline.com/rest/namespace/dir/file HTTP/1.1");
|
"HEAD https://accesspoint.atmosonline.com/rest/namespace/dir/file HTTP/1.1");
|
||||||
assertHeadersEqual(request, HttpHeaders.ACCEPT + ": */*\n");
|
assertNonPayloadHeadersEqual(request, HttpHeaders.ACCEPT + ": */*\n");
|
||||||
assertPayloadEquals(request, null);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseSystemMetadataFromHeaders.class);
|
assertResponseParserClassEquals(method, request, ParseSystemMetadataFromHeaders.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
@ -240,10 +240,10 @@ public class AtmosStorageAsyncClientTest extends RestClientTest<AtmosStorageAsyn
|
||||||
|
|
||||||
assertRequestLineEquals(request,
|
assertRequestLineEquals(request,
|
||||||
"DELETE https://accesspoint.atmosonline.com/rest/namespace/dir/file HTTP/1.1");
|
"DELETE https://accesspoint.atmosonline.com/rest/namespace/dir/file HTTP/1.1");
|
||||||
assertHeadersEqual(request, HttpHeaders.ACCEPT + ": */*\n");
|
assertNonPayloadHeadersEqual(request, HttpHeaders.ACCEPT + ": */*\n");
|
||||||
assertPayloadEquals(request, null);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
|
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ import org.jclouds.blobstore.internal.BlobStoreContextImpl;
|
||||||
import org.jclouds.blobstore.strategy.ContainsValueInListStrategy;
|
import org.jclouds.blobstore.strategy.ContainsValueInListStrategy;
|
||||||
import org.jclouds.logging.config.NullLoggingModule;
|
import org.jclouds.logging.config.NullLoggingModule;
|
||||||
import org.jclouds.rest.RestContextFactory;
|
import org.jclouds.rest.RestContextFactory;
|
||||||
import org.jclouds.rest.RestClientTest.MockModule;
|
import org.jclouds.rest.BaseRestClientTest.MockModule;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
@ -40,8 +40,8 @@ import com.google.inject.Module;
|
||||||
public class AtmosBlobStoreModuleTest {
|
public class AtmosBlobStoreModuleTest {
|
||||||
|
|
||||||
Injector createInjector() {
|
Injector createInjector() {
|
||||||
return new RestContextFactory().createContextBuilder("atmosonline", "uid", "key", ImmutableSet
|
return new RestContextFactory().createContextBuilder("atmosonline", "uid", "key",
|
||||||
.<Module> of(new MockModule(), new NullLoggingModule())).buildInjector();
|
ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule())).buildInjector();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -37,7 +37,7 @@ import org.jclouds.http.RequiresHttp;
|
||||||
import org.jclouds.logging.config.NullLoggingModule;
|
import org.jclouds.logging.config.NullLoggingModule;
|
||||||
import org.jclouds.rest.ConfiguresRestClient;
|
import org.jclouds.rest.ConfiguresRestClient;
|
||||||
import org.jclouds.rest.RestContextFactory;
|
import org.jclouds.rest.RestContextFactory;
|
||||||
import org.jclouds.rest.RestClientTest.MockModule;
|
import org.jclouds.rest.BaseRestClientTest.MockModule;
|
||||||
import org.jclouds.util.Utils;
|
import org.jclouds.util.Utils;
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
@ -108,15 +108,17 @@ public class SignRequestTest {
|
||||||
|
|
||||||
public HttpRequest newRequest() {
|
public HttpRequest newRequest() {
|
||||||
HttpRequest request = new HttpRequest("POST", URI.create("http://localhost/rest/objects"));
|
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.LISTABLE_META, "part4/part7/part8=quick");
|
||||||
request.getHeaders().put(AtmosStorageHeaders.META, "part1=buy");
|
request.getHeaders().put(AtmosStorageHeaders.META, "part1=buy");
|
||||||
request.getHeaders().put(HttpHeaders.ACCEPT, "*/*");
|
request.getHeaders().put(HttpHeaders.ACCEPT, "*/*");
|
||||||
request.getHeaders().put(AtmosStorageHeaders.USER_ACL, "john=FULL_CONTROL,mary=WRITE");
|
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.DATE, "Thu, 05 Jun 2008 16:38:19 GMT");
|
||||||
request.getHeaders().put(AtmosStorageHeaders.GROUP_ACL, "other=NONE");
|
request.getHeaders().put(AtmosStorageHeaders.GROUP_ACL, "other=NONE");
|
||||||
request.getHeaders().put(HttpHeaders.HOST, "10.5.115.118");
|
request.getHeaders().put(HttpHeaders.HOST, "10.5.115.118");
|
||||||
request.getHeaders().put(HttpHeaders.CONTENT_LENGTH, "4286");
|
|
||||||
request.getHeaders().put(AtmosStorageHeaders.UID, "6039ac182f194e15b9261d73ce044939/user1");
|
request.getHeaders().put(AtmosStorageHeaders.UID, "6039ac182f194e15b9261d73ce044939/user1");
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ import org.jclouds.atmosonline.saas.domain.SystemMetadata;
|
||||||
import org.jclouds.date.DateService;
|
import org.jclouds.date.DateService;
|
||||||
import org.jclouds.encryption.EncryptionService;
|
import org.jclouds.encryption.EncryptionService;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
|
import org.jclouds.http.Payloads;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.inject.Guice;
|
import com.google.inject.Guice;
|
||||||
|
@ -45,7 +46,7 @@ public class ParseSystemMetadataFromHeadersTest {
|
||||||
DateService dateService = injector.getInstance(DateService.class);
|
DateService dateService = injector.getInstance(DateService.class);
|
||||||
EncryptionService encryptionService = injector.getInstance(EncryptionService.class);
|
EncryptionService encryptionService = injector.getInstance(EncryptionService.class);
|
||||||
|
|
||||||
HttpResponse response = new HttpResponse();
|
HttpResponse response = new HttpResponse(200, "ok", Payloads.newStringPayload(""));
|
||||||
response
|
response
|
||||||
.getHeaders()
|
.getHeaders()
|
||||||
.put(
|
.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.SIGNATURE_VERSION;
|
||||||
import static org.jclouds.aws.ec2.reference.EC2Parameters.TIMESTAMP;
|
import static org.jclouds.aws.ec2.reference.EC2Parameters.TIMESTAMP;
|
||||||
import static org.jclouds.aws.ec2.reference.EC2Parameters.VERSION;
|
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.makeQueryLine;
|
||||||
import static org.jclouds.http.HttpUtils.parseQueryToMap;
|
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.HttpException;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.HttpRequestFilter;
|
import org.jclouds.http.HttpRequestFilter;
|
||||||
|
import org.jclouds.http.HttpUtils;
|
||||||
import org.jclouds.http.internal.SignatureWire;
|
import org.jclouds.http.internal.SignatureWire;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.rest.RequestSigner;
|
import org.jclouds.rest.RequestSigner;
|
||||||
|
@ -56,7 +56,6 @@ import org.jclouds.util.Utils;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableSet;
|
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -77,6 +76,8 @@ public class FormSigner implements HttpRequestFilter, RequestSigner {
|
||||||
private final String secretKey;
|
private final String secretKey;
|
||||||
private final Provider<String> dateService;
|
private final Provider<String> dateService;
|
||||||
private final EncryptionService encryptionService;
|
private final EncryptionService encryptionService;
|
||||||
|
private final HttpUtils utils;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
@Named(Constants.LOGGER_SIGNATURE)
|
@Named(Constants.LOGGER_SIGNATURE)
|
||||||
private Logger signatureLog = Logger.NULL;
|
private Logger signatureLog = Logger.NULL;
|
||||||
|
@ -85,12 +86,14 @@ public class FormSigner implements HttpRequestFilter, RequestSigner {
|
||||||
public FormSigner(SignatureWire signatureWire,
|
public FormSigner(SignatureWire signatureWire,
|
||||||
@Named(Constants.PROPERTY_IDENTITY) String accessKey,
|
@Named(Constants.PROPERTY_IDENTITY) String accessKey,
|
||||||
@Named(Constants.PROPERTY_CREDENTIAL) String secretKey,
|
@Named(Constants.PROPERTY_CREDENTIAL) String secretKey,
|
||||||
@TimeStamp Provider<String> dateService, EncryptionService encryptionService) {
|
@TimeStamp Provider<String> dateService, EncryptionService encryptionService,
|
||||||
|
HttpUtils utils) {
|
||||||
this.signatureWire = signatureWire;
|
this.signatureWire = signatureWire;
|
||||||
this.accessKey = accessKey;
|
this.accessKey = accessKey;
|
||||||
this.secretKey = secretKey;
|
this.secretKey = secretKey;
|
||||||
this.dateService = dateService;
|
this.dateService = dateService;
|
||||||
this.encryptionService = encryptionService;
|
this.encryptionService = encryptionService;
|
||||||
|
this.utils = utils;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void filter(HttpRequest request) throws HttpException {
|
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");
|
"request is not ready to sign; host not present");
|
||||||
Multimap<String, String> decodedParams = parseQueryToMap(request.getPayload().getRawContent()
|
Multimap<String, String> decodedParams = parseQueryToMap(request.getPayload().getRawContent()
|
||||||
.toString());
|
.toString());
|
||||||
request.getHeaders().removeAll(HttpHeaders.CONTENT_LENGTH);
|
|
||||||
addSigningParams(decodedParams);
|
addSigningParams(decodedParams);
|
||||||
validateParams(decodedParams);
|
validateParams(decodedParams);
|
||||||
String stringToSign = createStringToSign(request, decodedParams);
|
String stringToSign = createStringToSign(request, decodedParams);
|
||||||
String signature = sign(stringToSign);
|
String signature = sign(stringToSign);
|
||||||
addSignature(decodedParams, signature);
|
addSignature(decodedParams, signature);
|
||||||
setPayload(request, decodedParams);
|
setPayload(request, decodedParams);
|
||||||
logRequest(signatureLog, request, "<<");
|
utils.logRequest(signatureLog, request, "<<");
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] sortForSigning(String queryLine) {
|
String[] sortForSigning(String queryLine) {
|
||||||
|
@ -133,8 +135,7 @@ public class FormSigner implements HttpRequestFilter, RequestSigner {
|
||||||
return o1.getKey().compareTo(o2.getKey());
|
return o1.getKey().compareTo(o2.getKey());
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
request.getHeaders().replaceValues(HttpHeaders.CONTENT_LENGTH,
|
request.getPayload().setContentType("application/x-www-form-urlencoded");
|
||||||
ImmutableSet.of(request.getPayload().getContentLength().toString()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
@ -166,7 +167,7 @@ public class FormSigner implements HttpRequestFilter, RequestSigner {
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public String createStringToSign(HttpRequest request, Multimap<String, String> decodedParams) {
|
public String createStringToSign(HttpRequest request, Multimap<String, String> decodedParams) {
|
||||||
logRequest(signatureLog, request, ">>");
|
utils.logRequest(signatureLog, request, ">>");
|
||||||
StringBuilder stringToSign = new StringBuilder();
|
StringBuilder stringToSign = new StringBuilder();
|
||||||
// StringToSign = HTTPVerb + "\n" +
|
// StringToSign = HTTPVerb + "\n" +
|
||||||
stringToSign.append(request.getMethod()).append("\n");
|
stringToSign.append(request.getMethod()).append("\n");
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.aws.handlers;
|
package org.jclouds.aws.handlers;
|
||||||
|
|
||||||
|
import static org.jclouds.http.HttpUtils.releasePayload;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
@ -40,7 +42,6 @@ import org.jclouds.rest.ResourceNotFoundException;
|
||||||
import org.jclouds.util.Utils;
|
import org.jclouds.util.Utils;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.io.Closeables;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This will parse and set an appropriate exception on the command object.
|
* This will parse and set an appropriate exception on the command object.
|
||||||
|
@ -97,15 +98,15 @@ public class ParseAWSErrorFromXmlContent implements HttpErrorHandler {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
Closeables.closeQuietly(response.getContent());
|
releasePayload(response);
|
||||||
command.setException(exception);
|
command.setException(exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AWSError parseErrorFromContentOrNull(HttpRequest request, HttpResponse response) {
|
AWSError parseErrorFromContentOrNull(HttpRequest request, HttpResponse response) {
|
||||||
if (response.getContent() != null) {
|
if (response.getPayload() != null) {
|
||||||
try {
|
try {
|
||||||
String content = Utils.toStringAndClose(response.getContent());
|
String content = Utils.toStringAndClose(response.getPayload().getInput());
|
||||||
if (content != null && content.indexOf('<') >= 0)
|
if (content != null && content.indexOf('<') >= 0)
|
||||||
return utils.parseAWSErrorFromContent(request, response, content);
|
return utils.parseAWSErrorFromContent(request, response, content);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
|
@ -20,7 +20,7 @@ package org.jclouds.aws.s3.binders;
|
||||||
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
import javax.inject.Singleton;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.xml.parsers.FactoryConfigurationError;
|
import javax.xml.parsers.FactoryConfigurationError;
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
@ -41,6 +41,7 @@ import com.jamesmurty.utils.XMLBuilder;
|
||||||
*
|
*
|
||||||
* @author James Murty
|
* @author James Murty
|
||||||
*/
|
*/
|
||||||
|
@Singleton
|
||||||
public class BindACLToXMLPayload implements Binder {
|
public class BindACLToXMLPayload implements Binder {
|
||||||
|
|
||||||
public void bindToRequest(HttpRequest request, Object payload) {
|
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");
|
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
|
||||||
try {
|
try {
|
||||||
String stringPayload = generateBuilder(from).asString(outputProperties);
|
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.setPayload(stringPayload);
|
||||||
|
request.getPayload().setContentType(MediaType.TEXT_XML);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Throwables.propagateIfPossible(e);
|
Throwables.propagateIfPossible(e);
|
||||||
throw new RuntimeException("error transforming acl: " + from, e);
|
throw new RuntimeException("error transforming acl: " + from, e);
|
||||||
|
|
|
@ -20,7 +20,7 @@ package org.jclouds.aws.s3.binders;
|
||||||
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
import javax.inject.Singleton;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.xml.parsers.FactoryConfigurationError;
|
import javax.xml.parsers.FactoryConfigurationError;
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
@ -41,6 +41,7 @@ import com.jamesmurty.utils.XMLBuilder;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
|
@Singleton
|
||||||
public class BindBucketLoggingToXmlPayload implements Binder {
|
public class BindBucketLoggingToXmlPayload implements Binder {
|
||||||
|
|
||||||
public void bindToRequest(HttpRequest request, Object payload) {
|
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");
|
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
|
||||||
try {
|
try {
|
||||||
String stringPayload = generateBuilder(from).asString(outputProperties);
|
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.setPayload(stringPayload);
|
||||||
|
request.getPayload().setContentType(MediaType.TEXT_XML);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Throwables.propagateIfPossible(e);
|
Throwables.propagateIfPossible(e);
|
||||||
throw new RuntimeException("error transforming bucketLogging: " + from, e);
|
throw new RuntimeException("error transforming bucketLogging: " + from, e);
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.aws.s3.binders;
|
package org.jclouds.aws.s3.binders;
|
||||||
|
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
import javax.inject.Singleton;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
|
@ -28,13 +28,13 @@ import org.jclouds.rest.Binder;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
|
@Singleton
|
||||||
public class BindNoBucketLoggingToXmlPayload implements Binder {
|
public class BindNoBucketLoggingToXmlPayload implements Binder {
|
||||||
|
|
||||||
public void bindToRequest(HttpRequest request, Object payload) {
|
public void bindToRequest(HttpRequest request, Object payload) {
|
||||||
String stringPayload = "<BucketLoggingStatus xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"/>";
|
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.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.checkArgument;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import java.util.Collections;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
import org.jclouds.aws.s3.domain.Payer;
|
import org.jclouds.aws.s3.domain.Payer;
|
||||||
|
@ -35,6 +33,7 @@ import org.jclouds.rest.Binder;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@Singleton
|
||||||
public class BindPayerToXmlPayload implements Binder {
|
public class BindPayerToXmlPayload implements Binder {
|
||||||
|
|
||||||
public void bindToRequest(HttpRequest request, Object toBind) {
|
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>",
|
"<RequestPaymentConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Payer>%s</Payer></RequestPaymentConfiguration>",
|
||||||
((Payer) toBind).value());
|
((Payer) toBind).value());
|
||||||
request.setPayload(text);
|
request.setPayload(text);
|
||||||
request.getHeaders().replaceValues(HttpHeaders.CONTENT_LENGTH,
|
request.getPayload().setContentType(MediaType.TEXT_XML);
|
||||||
Collections.singletonList(text.getBytes().length + ""));
|
|
||||||
request.getHeaders().replaceValues(HttpHeaders.CONTENT_TYPE,
|
|
||||||
Collections.singletonList(MediaType.TEXT_XML));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -329,4 +329,14 @@ public class MutableObjectMetadataImpl implements Serializable, MutableObjectMet
|
||||||
return true;
|
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) {
|
public SetMetadataPropertiesPayload(Payload delegate, MutableObjectMetadata metadata) {
|
||||||
super(delegate);
|
super(delegate);
|
||||||
this.metadata = checkNotNull(metadata, "metadata");
|
this.metadata = checkNotNull(metadata, "metadata");
|
||||||
if (metadata.getSize() != null)
|
|
||||||
setContentLength(metadata.getSize());
|
|
||||||
setContentMD5(metadata.getContentMD5());
|
|
||||||
setContentType(metadata.getContentType());
|
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
|
@Override
|
||||||
public void setContentType(String md5) {
|
public void setContentType(String md5) {
|
||||||
super.setContentType(md5);
|
super.setContentType(md5);
|
||||||
|
@ -208,13 +189,6 @@ public class S3ObjectImpl extends PayloadEnclosingImpl implements S3Object, Comp
|
||||||
this.object = object;
|
this.object = object;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setContentMD5(byte[] md5) {
|
|
||||||
super.setContentMD5(md5);
|
|
||||||
if (canSetPayload())
|
|
||||||
object.getPayload().setContentMD5(md5);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setContentType(String type) {
|
public void setContentType(String type) {
|
||||||
super.setContentType(type);
|
super.setContentType(type);
|
||||||
|
@ -222,13 +196,6 @@ public class S3ObjectImpl extends PayloadEnclosingImpl implements S3Object, Comp
|
||||||
object.getPayload().setContentType(type);
|
object.getPayload().setContentType(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setSize(Long size) {
|
|
||||||
super.setSize(size);
|
|
||||||
if (canSetPayload())
|
|
||||||
object.getPayload().setContentLength(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean canSetPayload() {
|
private boolean canSetPayload() {
|
||||||
return object != null && object.getPayload() != null;
|
return object != null && object.getPayload() != null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
package org.jclouds.aws.s3.filters;
|
package org.jclouds.aws.s3.filters;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static org.jclouds.http.HttpUtils.logRequest;
|
|
||||||
import static org.jclouds.util.Patterns.NEWLINE_PATTERN;
|
import static org.jclouds.util.Patterns.NEWLINE_PATTERN;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
@ -41,6 +40,7 @@ import org.jclouds.encryption.EncryptionService;
|
||||||
import org.jclouds.http.HttpException;
|
import org.jclouds.http.HttpException;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.HttpRequestFilter;
|
import org.jclouds.http.HttpRequestFilter;
|
||||||
|
import org.jclouds.http.HttpUtils;
|
||||||
import org.jclouds.http.internal.SignatureWire;
|
import org.jclouds.http.internal.SignatureWire;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.rest.RequestSigner;
|
import org.jclouds.rest.RequestSigner;
|
||||||
|
@ -58,8 +58,7 @@ import com.google.common.collect.ImmutableSet;
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
public class RequestAuthorizeSignature implements HttpRequestFilter, RequestSigner {
|
public class RequestAuthorizeSignature implements HttpRequestFilter, RequestSigner {
|
||||||
private final String[] firstHeadersToSign = new String[] { "Content-MD5",
|
private final String[] firstHeadersToSign = new String[] { HttpHeaders.DATE };
|
||||||
HttpHeaders.CONTENT_TYPE, HttpHeaders.DATE };
|
|
||||||
|
|
||||||
public static Set<String> SPECIAL_QUERIES = ImmutableSet.of("acl", "torrent", "logging",
|
public static Set<String> SPECIAL_QUERIES = ImmutableSet.of("acl", "torrent", "logging",
|
||||||
"location", "requestPayment");
|
"location", "requestPayment");
|
||||||
|
@ -68,6 +67,7 @@ public class RequestAuthorizeSignature implements HttpRequestFilter, RequestSign
|
||||||
private final String secretKey;
|
private final String secretKey;
|
||||||
private final Provider<String> timeStampProvider;
|
private final Provider<String> timeStampProvider;
|
||||||
private final EncryptionService encryptionService;
|
private final EncryptionService encryptionService;
|
||||||
|
private final HttpUtils utils;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
@Named(Constants.LOGGER_SIGNATURE)
|
@Named(Constants.LOGGER_SIGNATURE)
|
||||||
|
@ -84,7 +84,8 @@ public class RequestAuthorizeSignature implements HttpRequestFilter, RequestSign
|
||||||
@Named(S3Constants.PROPERTY_S3_HEADER_TAG) String headerTag,
|
@Named(S3Constants.PROPERTY_S3_HEADER_TAG) String headerTag,
|
||||||
@Named(Constants.PROPERTY_IDENTITY) String accessKey,
|
@Named(Constants.PROPERTY_IDENTITY) String accessKey,
|
||||||
@Named(Constants.PROPERTY_CREDENTIAL) String secretKey,
|
@Named(Constants.PROPERTY_CREDENTIAL) String secretKey,
|
||||||
@TimeStamp Provider<String> timeStampProvider, EncryptionService encryptionService) {
|
@TimeStamp Provider<String> timeStampProvider, EncryptionService encryptionService,
|
||||||
|
HttpUtils utils) {
|
||||||
this.srvExpr = srvExpr;
|
this.srvExpr = srvExpr;
|
||||||
this.headerTag = headerTag;
|
this.headerTag = headerTag;
|
||||||
this.authTag = authTag;
|
this.authTag = authTag;
|
||||||
|
@ -93,20 +94,22 @@ public class RequestAuthorizeSignature implements HttpRequestFilter, RequestSign
|
||||||
this.secretKey = secretKey;
|
this.secretKey = secretKey;
|
||||||
this.timeStampProvider = timeStampProvider;
|
this.timeStampProvider = timeStampProvider;
|
||||||
this.encryptionService = encryptionService;
|
this.encryptionService = encryptionService;
|
||||||
|
this.utils = utils;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void filter(HttpRequest request) throws HttpException {
|
public void filter(HttpRequest request) throws HttpException {
|
||||||
replaceDateHeader(request);
|
replaceDateHeader(request);
|
||||||
String toSign = createStringToSign(request);
|
String toSign = createStringToSign(request);
|
||||||
calculateAndReplaceAuthHeader(request, toSign);
|
calculateAndReplaceAuthHeader(request, toSign);
|
||||||
logRequest(signatureLog, request, "<<");
|
utils.logRequest(signatureLog, request, "<<");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String createStringToSign(HttpRequest request) {
|
public String createStringToSign(HttpRequest request) {
|
||||||
logRequest(signatureLog, request, ">>");
|
utils.logRequest(signatureLog, request, ">>");
|
||||||
StringBuilder buffer = new StringBuilder();
|
StringBuilder buffer = new StringBuilder();
|
||||||
// re-sign the request
|
// re-sign the request
|
||||||
appendMethod(request, buffer);
|
appendMethod(request, buffer);
|
||||||
|
appendPayloadMetadata(request, buffer);
|
||||||
appendHttpHeaders(request, buffer);
|
appendHttpHeaders(request, buffer);
|
||||||
appendAmzHeaders(request, buffer);
|
appendAmzHeaders(request, buffer);
|
||||||
appendBucketName(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) {
|
private void appendHttpHeaders(HttpRequest request, StringBuilder toSign) {
|
||||||
for (String header : firstHeadersToSign)
|
for (String header : firstHeadersToSign)
|
||||||
toSign.append(valueOrEmpty(request.getHeaders().get(header))).append("\n");
|
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.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.rest.binders.BindToStringPayload;
|
import org.jclouds.rest.binders.BindToStringPayload;
|
||||||
|
@ -73,6 +74,6 @@ public class BindRegionToXmlPayload extends BindToStringPayload {
|
||||||
"<CreateBucketConfiguration><LocationConstraint>%s</LocationConstraint></CreateBucketConfiguration>",
|
"<CreateBucketConfiguration><LocationConstraint>%s</LocationConstraint></CreateBucketConfiguration>",
|
||||||
value);
|
value);
|
||||||
super.bindToRequest(request, payload);
|
super.bindToRequest(request, payload);
|
||||||
|
request.getPayload().setContentType(MediaType.TEXT_XML);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,10 +19,9 @@
|
||||||
package org.jclouds.aws.s3.functions;
|
package org.jclouds.aws.s3.functions;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
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.aws.s3.domain.S3Object;
|
||||||
import org.jclouds.blobstore.functions.ParseSystemAndUserMetadataFromHeaders;
|
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
import org.jclouds.rest.InvocationContext;
|
import org.jclouds.rest.InvocationContext;
|
||||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||||
|
@ -48,38 +47,13 @@ public class ParseObjectFromHeadersAndHttpContent implements Function<HttpRespon
|
||||||
this.objectProvider = objectProvider;
|
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) {
|
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());
|
object.getAllHeaders().putAll(from.getHeaders());
|
||||||
if (from.getContent() != null) {
|
object.setPayload(from.getPayload());
|
||||||
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)));
|
|
||||||
}
|
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.aws.s3.functions;
|
package org.jclouds.aws.s3.functions;
|
||||||
|
|
||||||
|
import static org.jclouds.http.HttpUtils.attemptToParseSizeAndRangeFromHeaders;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
|
|
||||||
|
@ -64,6 +66,7 @@ public class ParseObjectMetadataFromHeaders implements
|
||||||
BlobMetadata base = blobMetadataParser.apply(from);
|
BlobMetadata base = blobMetadataParser.apply(from);
|
||||||
MutableObjectMetadata to = blobToObjectMetadata.apply(base);
|
MutableObjectMetadata to = blobToObjectMetadata.apply(base);
|
||||||
addETagTo(from, to);
|
addETagTo(from, to);
|
||||||
|
to.setSize(attemptToParseSizeAndRangeFromHeaders(from));
|
||||||
to.setContentMD5(encryptionService.fromHex(Utils.replaceAll(to.getETag(), '"', "")));
|
to.setContentMD5(encryptionService.fromHex(Utils.replaceAll(to.getETag(), '"', "")));
|
||||||
to.setCacheControl(from.getFirstHeaderOrNull(HttpHeaders.CACHE_CONTROL));
|
to.setCacheControl(from.getFirstHeaderOrNull(HttpHeaders.CACHE_CONTROL));
|
||||||
to.setContentDisposition(from.getFirstHeaderOrNull("Content-Disposition"));
|
to.setContentDisposition(from.getFirstHeaderOrNull("Content-Disposition"));
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.aws.sqs.xml;
|
package org.jclouds.aws.sqs.xml;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
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.domain.Queue;
|
||||||
import org.jclouds.aws.sqs.xml.internal.BaseRegexQueueHandler;
|
import org.jclouds.aws.sqs.xml.internal.BaseRegexQueueHandler;
|
||||||
import org.jclouds.http.HttpResponse;
|
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.Function;
|
||||||
import com.google.common.base.Throwables;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -44,24 +42,18 @@ import com.google.common.base.Throwables;
|
||||||
@Singleton
|
@Singleton
|
||||||
public class RegexListQueuesResponseHandler extends BaseRegexQueueHandler implements
|
public class RegexListQueuesResponseHandler extends BaseRegexQueueHandler implements
|
||||||
Function<HttpResponse, Set<Queue>> {
|
Function<HttpResponse, Set<Queue>> {
|
||||||
|
private final ReturnStringIf200 returnStringIf200;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
RegexListQueuesResponseHandler(@Region Map<String, URI> regionMap) {
|
RegexListQueuesResponseHandler(@Region Map<String, URI> regionMap,
|
||||||
|
ReturnStringIf200 returnStringIf200) {
|
||||||
super(regionMap);
|
super(regionMap);
|
||||||
|
this.returnStringIf200 = returnStringIf200;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Queue> apply(HttpResponse response) {
|
public Set<Queue> apply(HttpResponse response) {
|
||||||
try {
|
return parse(returnStringIf200.apply(response));
|
||||||
return parse(Utils.toStringAndClose(response.getContent()));
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
response.getContent().close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
Throwables.propagate(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -18,7 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.aws.sqs.xml;
|
package org.jclouds.aws.sqs.xml;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
@ -26,10 +25,9 @@ import javax.inject.Inject;
|
||||||
|
|
||||||
import org.jclouds.encryption.EncryptionService;
|
import org.jclouds.encryption.EncryptionService;
|
||||||
import org.jclouds.http.HttpResponse;
|
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.Function;
|
||||||
import com.google.common.base.Throwables;
|
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -41,29 +39,24 @@ import com.google.inject.Singleton;
|
||||||
@Singleton
|
@Singleton
|
||||||
public class RegexMD5Handler implements Function<HttpResponse, byte[]> {
|
public class RegexMD5Handler implements Function<HttpResponse, byte[]> {
|
||||||
Pattern pattern = Pattern.compile("<MD5OfMessageBody>([\\S&&[^<]]+)</MD5OfMessageBody>");
|
Pattern pattern = Pattern.compile("<MD5OfMessageBody>([\\S&&[^<]]+)</MD5OfMessageBody>");
|
||||||
|
private final ReturnStringIf200 returnStringIf200;
|
||||||
private final EncryptionService encryptionService;
|
private final EncryptionService encryptionService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
RegexMD5Handler(EncryptionService encryptionService) {
|
RegexMD5Handler(EncryptionService encryptionService, ReturnStringIf200 returnStringIf200) {
|
||||||
this.encryptionService = encryptionService;
|
this.encryptionService = encryptionService;
|
||||||
|
this.returnStringIf200 = returnStringIf200;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] apply(HttpResponse response) {
|
public byte[] apply(HttpResponse response) {
|
||||||
byte[] value = null;
|
byte[] value = null;
|
||||||
try {
|
String content = returnStringIf200.apply(response);
|
||||||
Matcher matcher = pattern.matcher(Utils.toStringAndClose(response.getContent()));
|
if (content != null) {
|
||||||
|
Matcher matcher = pattern.matcher(content);
|
||||||
if (matcher.find()) {
|
if (matcher.find()) {
|
||||||
value = encryptionService.fromHex(matcher.group(1));
|
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;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.aws.sqs.xml;
|
package org.jclouds.aws.sqs.xml;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Map;
|
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.domain.Queue;
|
||||||
import org.jclouds.aws.sqs.xml.internal.BaseRegexQueueHandler;
|
import org.jclouds.aws.sqs.xml.internal.BaseRegexQueueHandler;
|
||||||
import org.jclouds.http.HttpResponse;
|
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.Function;
|
||||||
import com.google.common.base.Throwables;
|
|
||||||
import com.google.inject.internal.Iterables;
|
import com.google.inject.internal.Iterables;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -44,24 +42,16 @@ import com.google.inject.internal.Iterables;
|
||||||
@Singleton
|
@Singleton
|
||||||
public class RegexQueueHandler extends BaseRegexQueueHandler implements
|
public class RegexQueueHandler extends BaseRegexQueueHandler implements
|
||||||
Function<HttpResponse, Queue> {
|
Function<HttpResponse, Queue> {
|
||||||
|
private final ReturnStringIf200 returnStringIf200;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
RegexQueueHandler(@Region Map<String, URI> regionMap) {
|
RegexQueueHandler(@Region Map<String, URI> regionMap, ReturnStringIf200 returnStringIf200) {
|
||||||
super(regionMap);
|
super(regionMap);
|
||||||
|
this.returnStringIf200 = returnStringIf200;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Queue apply(HttpResponse response) {
|
public Queue apply(HttpResponse response) {
|
||||||
try {
|
return Iterables.getOnlyElement(parse(returnStringIf200.apply(response)));
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -34,8 +34,8 @@ import org.jclouds.aws.ec2.xml.ImageIdHandler;
|
||||||
import org.jclouds.aws.ec2.xml.PermissionHandler;
|
import org.jclouds.aws.ec2.xml.PermissionHandler;
|
||||||
import org.jclouds.aws.ec2.xml.ProductCodesHandler;
|
import org.jclouds.aws.ec2.xml.ProductCodesHandler;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.functions.CloseContentAndReturn;
|
|
||||||
import org.jclouds.http.functions.ParseSax;
|
import org.jclouds.http.functions.ParseSax;
|
||||||
|
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -57,11 +57,10 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
||||||
HttpRequest request = processor.createRequest(method, null, "name", "instanceId");
|
HttpRequest request = processor.createRequest(method, null, "name", "instanceId");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
|
||||||
"Content-Length: 69\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(request,
|
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);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, ImageIdHandler.class);
|
assertSaxResponseParserClassEquals(method, ImageIdHandler.class);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
@ -78,12 +77,11 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
||||||
new CreateImageOptions().withDescription("description").noReboot());
|
new CreateImageOptions().withDescription("description").noReboot());
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
|
||||||
"Content-Length: 107\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
request,
|
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);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, ImageIdHandler.class);
|
assertSaxResponseParserClassEquals(method, ImageIdHandler.class);
|
||||||
|
@ -98,14 +96,14 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
||||||
HttpRequest request = processor.createRequest(method, (String) null);
|
HttpRequest request = processor.createRequest(method, (String) null);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
assertPayloadEquals(request, "Version=2009-11-30&Action=DescribeImages",
|
||||||
"Content-Length: 40\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
"application/x-www-form-urlencoded", false);
|
||||||
assertPayloadEquals(request, "Version=2009-11-30&Action=DescribeImages");
|
|
||||||
filter.filter(request);
|
filter.filter(request);
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
request,
|
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);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, DescribeImagesResponseHandler.class);
|
assertSaxResponseParserClassEquals(method, DescribeImagesResponseHandler.class);
|
||||||
|
@ -122,12 +120,11 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
||||||
"fred", "nancy").imageIds("1", "2"));
|
"fred", "nancy").imageIds("1", "2"));
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
|
||||||
"Content-Length: 107\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
request,
|
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);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, DescribeImagesResponseHandler.class);
|
assertSaxResponseParserClassEquals(method, DescribeImagesResponseHandler.class);
|
||||||
|
@ -142,12 +139,11 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
||||||
HttpRequest request = processor.createRequest(method, null, "imageId");
|
HttpRequest request = processor.createRequest(method, null, "imageId");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
assertPayloadEquals(request, "Version=2009-11-30&Action=DeregisterImage&ImageId=imageId",
|
||||||
"Content-Length: 57\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
"application/x-www-form-urlencoded", false);
|
||||||
assertPayloadEquals(request, "Version=2009-11-30&Action=DeregisterImage&ImageId=imageId");
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
@ -162,11 +158,10 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
||||||
HttpRequest request = processor.createRequest(method, null, "name", "pathToManifest");
|
HttpRequest request = processor.createRequest(method, null, "name", "pathToManifest");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
|
||||||
"Content-Length: 78\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(request,
|
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);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, ImageIdHandler.class);
|
assertSaxResponseParserClassEquals(method, ImageIdHandler.class);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
@ -183,12 +178,11 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
||||||
new RegisterImageOptions().withDescription("description"));
|
new RegisterImageOptions().withDescription("description"));
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
|
||||||
"Content-Length: 102\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
request,
|
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);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, ImageIdHandler.class);
|
assertSaxResponseParserClassEquals(method, ImageIdHandler.class);
|
||||||
|
@ -205,12 +199,11 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
||||||
HttpRequest request = processor.createRequest(method, null, "imageName", "snapshotId");
|
HttpRequest request = processor.createRequest(method, null, "imageName", "snapshotId");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
|
||||||
"Content-Length: 176\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
request,
|
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);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, ImageIdHandler.class);
|
assertSaxResponseParserClassEquals(method, ImageIdHandler.class);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
@ -229,12 +222,11 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
||||||
.addNewBlockDevice("/dev/newdevice", "newblock", 100));
|
.addNewBlockDevice("/dev/newdevice", "newblock", 100));
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
|
||||||
"Content-Length: 528\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
request,
|
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);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, ImageIdHandler.class);
|
assertSaxResponseParserClassEquals(method, ImageIdHandler.class);
|
||||||
|
@ -250,11 +242,11 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
||||||
HttpRequest request = processor.createRequest(method, null, "imageId");
|
HttpRequest request = processor.createRequest(method, null, "imageId");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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,
|
request,
|
||||||
"Content-Length: 87\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
"Version=2009-11-30&Action=DescribeImageAttribute&Attribute=productCodes&ImageId=imageId",
|
||||||
assertPayloadEquals(request,
|
"application/x-www-form-urlencoded", false);
|
||||||
"Version=2009-11-30&Action=DescribeImageAttribute&Attribute=productCodes&ImageId=imageId");
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, ProductCodesHandler.class);
|
assertSaxResponseParserClassEquals(method, ProductCodesHandler.class);
|
||||||
|
@ -270,11 +262,11 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
||||||
HttpRequest request = processor.createRequest(method, null, "imageId");
|
HttpRequest request = processor.createRequest(method, null, "imageId");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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,
|
request,
|
||||||
"Content-Length: 93\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
"Version=2009-11-30&Action=DescribeImageAttribute&Attribute=blockDeviceMapping&ImageId=imageId",
|
||||||
assertPayloadEquals(request,
|
"application/x-www-form-urlencoded", false);
|
||||||
"Version=2009-11-30&Action=DescribeImageAttribute&Attribute=blockDeviceMapping&ImageId=imageId");
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, BlockDeviceMappingHandler.class);
|
assertSaxResponseParserClassEquals(method, BlockDeviceMappingHandler.class);
|
||||||
|
@ -290,11 +282,11 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
||||||
HttpRequest request = processor.createRequest(method, null, "imageId");
|
HttpRequest request = processor.createRequest(method, null, "imageId");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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,
|
request,
|
||||||
"Content-Length: 91\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
"Version=2009-11-30&Action=DescribeImageAttribute&Attribute=launchPermission&ImageId=imageId",
|
||||||
assertPayloadEquals(request,
|
"application/x-www-form-urlencoded", false);
|
||||||
"Version=2009-11-30&Action=DescribeImageAttribute&Attribute=launchPermission&ImageId=imageId");
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, PermissionHandler.class);
|
assertSaxResponseParserClassEquals(method, PermissionHandler.class);
|
||||||
|
@ -311,18 +303,18 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
||||||
ImmutableList.of("all"), "imageId");
|
ImmutableList.of("all"), "imageId");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
|
||||||
"Content-Length: 149\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
request,
|
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);
|
filter.filter(request);
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
request,
|
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);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
@ -337,13 +329,12 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
||||||
ImmutableList.of("all"), "imageId");
|
ImmutableList.of("all"), "imageId");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
|
||||||
"Content-Length: 152\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
request,
|
request,
|
||||||
"Version=2009-11-30&Action=ModifyImageAttribute&OperationType=remove&Attribute=launchPermission&ImageId=imageId&UserGroup.1=all&UserId.1=bob&UserId.2=sue");
|
"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);
|
"application/x-www-form-urlencoded", false);
|
||||||
|
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
@ -357,12 +348,12 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
||||||
HttpRequest request = processor.createRequest(method, null, "imageId");
|
HttpRequest request = processor.createRequest(method, null, "imageId");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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,
|
request,
|
||||||
"Content-Length: 88\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
"Version=2009-11-30&Action=ResetImageAttribute&Attribute=launchPermission&ImageId=imageId",
|
||||||
assertPayloadEquals(request,
|
"application/x-www-form-urlencoded", false);
|
||||||
"Version=2009-11-30&Action=ResetImageAttribute&Attribute=launchPermission&ImageId=imageId");
|
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
@ -377,14 +368,13 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
||||||
.of("code1", "code2"), "imageId");
|
.of("code1", "code2"), "imageId");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
|
||||||
"Content-Length: 143\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
request,
|
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);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
@ -399,14 +389,13 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
|
||||||
.of("code1", "code2"), "imageId");
|
.of("code1", "code2"), "imageId");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
|
||||||
"Content-Length: 146\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
request,
|
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);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
|
|
@ -55,10 +55,9 @@ public class AvailabilityZoneAndRegionAsyncClientTest extends
|
||||||
HttpRequest request = processor.createRequest(method, Region.US_WEST_1);
|
HttpRequest request = processor.createRequest(method, Region.US_WEST_1);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-west-1.amazonaws.com/ HTTP/1.1");
|
assertRequestLineEquals(request, "POST https://ec2.us-west-1.amazonaws.com/ HTTP/1.1");
|
||||||
assertHeadersEqual(
|
assertNonPayloadHeadersEqual(request, "Host: ec2.us-west-1.amazonaws.com\n");
|
||||||
request,
|
assertPayloadEquals(request, "Version=2009-11-30&Action=DescribeAvailabilityZones",
|
||||||
"Content-Length: 51\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-west-1.amazonaws.com\n");
|
"application/x-www-form-urlencoded", false);
|
||||||
assertPayloadEquals(request, "Version=2009-11-30&Action=DescribeAvailabilityZones");
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, DescribeAvailabilityZonesResponseHandler.class);
|
assertSaxResponseParserClassEquals(method, DescribeAvailabilityZonesResponseHandler.class);
|
||||||
|
@ -76,11 +75,11 @@ public class AvailabilityZoneAndRegionAsyncClientTest extends
|
||||||
AvailabilityZone.US_EAST_1A, AvailabilityZone.US_EAST_1B));
|
AvailabilityZone.US_EAST_1A, AvailabilityZone.US_EAST_1B));
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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,
|
request,
|
||||||
"Content-Length: 95\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
"Version=2009-11-30&Action=DescribeAvailabilityZones&ZoneName.1=us-east-1a&ZoneName.2=us-east-1b",
|
||||||
assertPayloadEquals(request,
|
"application/x-www-form-urlencoded", false);
|
||||||
"Version=2009-11-30&Action=DescribeAvailabilityZones&ZoneName.1=us-east-1a&ZoneName.2=us-east-1b");
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, DescribeAvailabilityZonesResponseHandler.class);
|
assertSaxResponseParserClassEquals(method, DescribeAvailabilityZonesResponseHandler.class);
|
||||||
|
@ -95,10 +94,9 @@ public class AvailabilityZoneAndRegionAsyncClientTest extends
|
||||||
HttpRequest request = processor.createRequest(method);
|
HttpRequest request = processor.createRequest(method);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
assertPayloadEquals(request, "Version=2009-11-30&Action=DescribeRegions",
|
||||||
"Content-Length: 41\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
"application/x-www-form-urlencoded", false);
|
||||||
assertPayloadEquals(request, "Version=2009-11-30&Action=DescribeRegions");
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, DescribeRegionsResponseHandler.class);
|
assertSaxResponseParserClassEquals(method, DescribeRegionsResponseHandler.class);
|
||||||
|
@ -115,11 +113,11 @@ public class AvailabilityZoneAndRegionAsyncClientTest extends
|
||||||
Region.US_WEST_1));
|
Region.US_WEST_1));
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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,
|
request,
|
||||||
"Content-Length: 87\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
"Version=2009-11-30&Action=DescribeRegions&RegionName.1=us-east-1&RegionName.2=us-west-1",
|
||||||
assertPayloadEquals(request,
|
"application/x-www-form-urlencoded", false);
|
||||||
"Version=2009-11-30&Action=DescribeRegions&RegionName.1=us-east-1&RegionName.2=us-west-1");
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, DescribeRegionsResponseHandler.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.PermissionHandler;
|
||||||
import org.jclouds.aws.ec2.xml.SnapshotHandler;
|
import org.jclouds.aws.ec2.xml.SnapshotHandler;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.functions.CloseContentAndReturn;
|
|
||||||
import org.jclouds.http.functions.ParseSax;
|
import org.jclouds.http.functions.ParseSax;
|
||||||
|
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -60,11 +60,10 @@ public class ElasticBlockStoreAsyncClientTest extends
|
||||||
HttpRequest request = processor.createRequest(method, AvailabilityZone.US_EAST_1A, 20);
|
HttpRequest request = processor.createRequest(method, AvailabilityZone.US_EAST_1A, 20);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
|
||||||
"Content-Length: 74\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(request,
|
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);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, CreateVolumeResponseHandler.class);
|
assertSaxResponseParserClassEquals(method, CreateVolumeResponseHandler.class);
|
||||||
|
@ -81,11 +80,11 @@ public class ElasticBlockStoreAsyncClientTest extends
|
||||||
"snapshotId");
|
"snapshotId");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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,
|
request,
|
||||||
"Content-Length: 88\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
"Version=2009-11-30&Action=CreateVolume&AvailabilityZone=us-east-1a&SnapshotId=snapshotId",
|
||||||
assertPayloadEquals(request,
|
"application/x-www-form-urlencoded", false);
|
||||||
"Version=2009-11-30&Action=CreateVolume&AvailabilityZone=us-east-1a&SnapshotId=snapshotId");
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, CreateVolumeResponseHandler.class);
|
assertSaxResponseParserClassEquals(method, CreateVolumeResponseHandler.class);
|
||||||
|
@ -102,11 +101,11 @@ public class ElasticBlockStoreAsyncClientTest extends
|
||||||
"snapshotId");
|
"snapshotId");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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,
|
request,
|
||||||
"Content-Length: 96\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
"Version=2009-11-30&Action=CreateVolume&AvailabilityZone=us-east-1a&SnapshotId=snapshotId&Size=15",
|
||||||
assertPayloadEquals(request,
|
"application/x-www-form-urlencoded", false);
|
||||||
"Version=2009-11-30&Action=CreateVolume&AvailabilityZone=us-east-1a&SnapshotId=snapshotId&Size=15");
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, CreateVolumeResponseHandler.class);
|
assertSaxResponseParserClassEquals(method, CreateVolumeResponseHandler.class);
|
||||||
|
@ -121,12 +120,11 @@ public class ElasticBlockStoreAsyncClientTest extends
|
||||||
HttpRequest request = processor.createRequest(method, null, "id");
|
HttpRequest request = processor.createRequest(method, null, "id");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
assertPayloadEquals(request, "Version=2009-11-30&Action=DeleteVolume&VolumeId=id",
|
||||||
"Content-Length: 50\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
"application/x-www-form-urlencoded", false);
|
||||||
assertPayloadEquals(request, "Version=2009-11-30&Action=DeleteVolume&VolumeId=id");
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
@ -139,10 +137,9 @@ public class ElasticBlockStoreAsyncClientTest extends
|
||||||
HttpRequest request = processor.createRequest(method, (String) null);
|
HttpRequest request = processor.createRequest(method, (String) null);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
assertPayloadEquals(request, "Version=2009-11-30&Action=DescribeVolumes",
|
||||||
"Content-Length: 41\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
"application/x-www-form-urlencoded", false);
|
||||||
assertPayloadEquals(request, "Version=2009-11-30&Action=DescribeVolumes");
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, DescribeVolumesResponseHandler.class);
|
assertSaxResponseParserClassEquals(method, DescribeVolumesResponseHandler.class);
|
||||||
|
@ -158,11 +155,10 @@ public class ElasticBlockStoreAsyncClientTest extends
|
||||||
HttpRequest request = processor.createRequest(method, null, "1", "2");
|
HttpRequest request = processor.createRequest(method, null, "1", "2");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
|
||||||
"Content-Length: 67\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(request,
|
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);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, DescribeVolumesResponseHandler.class);
|
assertSaxResponseParserClassEquals(method, DescribeVolumesResponseHandler.class);
|
||||||
|
@ -177,11 +173,11 @@ public class ElasticBlockStoreAsyncClientTest extends
|
||||||
HttpRequest request = processor.createRequest(method, null, "id", "instanceId", "/device");
|
HttpRequest request = processor.createRequest(method, null, "id", "instanceId", "/device");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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,
|
request,
|
||||||
"Content-Length: 89\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
"Version=2009-11-30&Action=AttachVolume&InstanceId=instanceId&VolumeId=id&Device=%2Fdevice",
|
||||||
assertPayloadEquals(request,
|
"application/x-www-form-urlencoded", false);
|
||||||
"Version=2009-11-30&Action=AttachVolume&InstanceId=instanceId&VolumeId=id&Device=%2Fdevice");
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, AttachmentHandler.class);
|
assertSaxResponseParserClassEquals(method, AttachmentHandler.class);
|
||||||
|
@ -197,12 +193,12 @@ public class ElasticBlockStoreAsyncClientTest extends
|
||||||
HttpRequest request = processor.createRequest(method, null, "id", false);
|
HttpRequest request = processor.createRequest(method, null, "id", false);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
assertPayloadEquals(request,
|
||||||
"Content-Length: 62\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
"Version=2009-11-30&Action=DetachVolume&Force=false&VolumeId=id",
|
||||||
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);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, ReturnVoidOnVolumeAvailable.class);
|
assertExceptionParserClassEquals(method, ReturnVoidOnVolumeAvailable.class);
|
||||||
|
|
||||||
|
@ -218,14 +214,13 @@ public class ElasticBlockStoreAsyncClientTest extends
|
||||||
"instanceId").fromDevice("/device"));
|
"instanceId").fromDevice("/device"));
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
|
||||||
"Content-Length: 100\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
request,
|
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);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, ReturnVoidOnVolumeAvailable.class);
|
assertExceptionParserClassEquals(method, ReturnVoidOnVolumeAvailable.class);
|
||||||
|
|
||||||
|
@ -239,10 +234,9 @@ public class ElasticBlockStoreAsyncClientTest extends
|
||||||
HttpRequest request = processor.createRequest(method, null, "volumeId");
|
HttpRequest request = processor.createRequest(method, null, "volumeId");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
assertPayloadEquals(request, "Version=2009-11-30&Action=CreateSnapshot&VolumeId=volumeId",
|
||||||
"Content-Length: 58\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
"application/x-www-form-urlencoded", false);
|
||||||
assertPayloadEquals(request, "Version=2009-11-30&Action=CreateSnapshot&VolumeId=volumeId");
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, SnapshotHandler.class);
|
assertSaxResponseParserClassEquals(method, SnapshotHandler.class);
|
||||||
|
@ -260,11 +254,11 @@ public class ElasticBlockStoreAsyncClientTest extends
|
||||||
CreateSnapshotOptions.Builder.withDescription("description"));
|
CreateSnapshotOptions.Builder.withDescription("description"));
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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,
|
request,
|
||||||
"Content-Length: 82\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
"Version=2009-11-30&Action=CreateSnapshot&VolumeId=volumeId&Description=description",
|
||||||
assertPayloadEquals(request,
|
"application/x-www-form-urlencoded", false);
|
||||||
"Version=2009-11-30&Action=CreateSnapshot&VolumeId=volumeId&Description=description");
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, SnapshotHandler.class);
|
assertSaxResponseParserClassEquals(method, SnapshotHandler.class);
|
||||||
|
@ -279,10 +273,9 @@ public class ElasticBlockStoreAsyncClientTest extends
|
||||||
HttpRequest request = processor.createRequest(method, (String) null);
|
HttpRequest request = processor.createRequest(method, (String) null);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
assertPayloadEquals(request, "Version=2009-11-30&Action=DescribeSnapshots",
|
||||||
"Content-Length: 43\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
"application/x-www-form-urlencoded", false);
|
||||||
assertPayloadEquals(request, "Version=2009-11-30&Action=DescribeSnapshots");
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, DescribeSnapshotsResponseHandler.class);
|
assertSaxResponseParserClassEquals(method, DescribeSnapshotsResponseHandler.class);
|
||||||
|
@ -299,12 +292,11 @@ public class ElasticBlockStoreAsyncClientTest extends
|
||||||
"r1", "r2").snapshotIds("s1", "s2"));
|
"r1", "r2").snapshotIds("s1", "s2"));
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
|
||||||
"Content-Length: 133\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
request,
|
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);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, DescribeSnapshotsResponseHandler.class);
|
assertSaxResponseParserClassEquals(method, DescribeSnapshotsResponseHandler.class);
|
||||||
|
@ -320,12 +312,11 @@ public class ElasticBlockStoreAsyncClientTest extends
|
||||||
HttpRequest request = processor.createRequest(method, null, "snapshotId");
|
HttpRequest request = processor.createRequest(method, null, "snapshotId");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
|
||||||
"Content-Length: 106\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
request,
|
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);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, PermissionHandler.class);
|
assertSaxResponseParserClassEquals(method, PermissionHandler.class);
|
||||||
|
@ -343,14 +334,13 @@ public class ElasticBlockStoreAsyncClientTest extends
|
||||||
ImmutableList.of("all"), "snapshotId");
|
ImmutableList.of("all"), "snapshotId");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
|
||||||
"Content-Length: 164\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
request,
|
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);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
@ -366,13 +356,12 @@ public class ElasticBlockStoreAsyncClientTest extends
|
||||||
ImmutableList.of("all"), "snapshotId");
|
ImmutableList.of("all"), "snapshotId");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
|
||||||
"Content-Length: 167\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
request,
|
request,
|
||||||
"Version=2009-11-30&Action=ModifySnapshotAttribute&OperationType=remove&Attribute=createVolumePermission&SnapshotId=snapshotId&UserGroup.1=all&UserId.1=bob&UserId.2=sue");
|
"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);
|
"application/x-www-form-urlencoded", false);
|
||||||
|
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
@ -386,13 +375,12 @@ public class ElasticBlockStoreAsyncClientTest extends
|
||||||
HttpRequest request = processor.createRequest(method, null, "snapshotId");
|
HttpRequest request = processor.createRequest(method, null, "snapshotId");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
|
||||||
"Content-Length: 103\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
request,
|
request,
|
||||||
"Version=2009-11-30&Action=ResetSnapshotAttribute&Attribute=createVolumePermission&SnapshotId=snapshotId");
|
"Version=2009-11-30&Action=ResetSnapshotAttribute&Attribute=createVolumePermission&SnapshotId=snapshotId",
|
||||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
"application/x-www-form-urlencoded", false);
|
||||||
|
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(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.AllocateAddressResponseHandler;
|
||||||
import org.jclouds.aws.ec2.xml.DescribeAddressesResponseHandler;
|
import org.jclouds.aws.ec2.xml.DescribeAddressesResponseHandler;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.functions.CloseContentAndReturn;
|
|
||||||
import org.jclouds.http.functions.ParseSax;
|
import org.jclouds.http.functions.ParseSax;
|
||||||
|
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -48,13 +48,12 @@ public class ElasticIPAddressAsyncClientTest extends
|
||||||
HttpRequest request = processor.createRequest(method, null, "127.0.0.1");
|
HttpRequest request = processor.createRequest(method, null, "127.0.0.1");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
|
||||||
"Content-Length: 64\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(request,
|
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);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
@ -67,13 +66,12 @@ public class ElasticIPAddressAsyncClientTest extends
|
||||||
HttpRequest request = processor.createRequest(method, null, "127.0.0.1", "me");
|
HttpRequest request = processor.createRequest(method, null, "127.0.0.1", "me");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
|
||||||
"Content-Length: 75\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(request,
|
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);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
@ -86,12 +84,11 @@ public class ElasticIPAddressAsyncClientTest extends
|
||||||
HttpRequest request = processor.createRequest(method, null, "127.0.0.1");
|
HttpRequest request = processor.createRequest(method, null, "127.0.0.1");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
assertPayloadEquals(request, "Version=2009-11-30&Action=ReleaseAddress&PublicIp=127.0.0.1",
|
||||||
"Content-Length: 59\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
"application/x-www-form-urlencoded", false);
|
||||||
assertPayloadEquals(request, "Version=2009-11-30&Action=ReleaseAddress&PublicIp=127.0.0.1");
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
@ -104,11 +101,10 @@ public class ElasticIPAddressAsyncClientTest extends
|
||||||
HttpRequest request = processor.createRequest(method, null, "127.0.0.1");
|
HttpRequest request = processor.createRequest(method, null, "127.0.0.1");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
|
||||||
"Content-Length: 64\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(request,
|
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);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, DescribeAddressesResponseHandler.class);
|
assertSaxResponseParserClassEquals(method, DescribeAddressesResponseHandler.class);
|
||||||
|
@ -123,10 +119,9 @@ public class ElasticIPAddressAsyncClientTest extends
|
||||||
HttpRequest request = processor.createRequest(method, (String) null);
|
HttpRequest request = processor.createRequest(method, (String) null);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
assertPayloadEquals(request, "Version=2009-11-30&Action=AllocateAddress",
|
||||||
"Content-Length: 41\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
"application/x-www-form-urlencoded", false);
|
||||||
assertPayloadEquals(request, "Version=2009-11-30&Action=AllocateAddress");
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, AllocateAddressResponseHandler.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.StringValueHandler;
|
||||||
import org.jclouds.aws.ec2.xml.UnencodeStringValueHandler;
|
import org.jclouds.aws.ec2.xml.UnencodeStringValueHandler;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.functions.CloseContentAndReturn;
|
|
||||||
import org.jclouds.http.functions.ParseSax;
|
import org.jclouds.http.functions.ParseSax;
|
||||||
|
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -59,10 +59,9 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
||||||
HttpRequest request = processor.createRequest(method, (String) null);
|
HttpRequest request = processor.createRequest(method, (String) null);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
assertPayloadEquals(request, "Version=2009-11-30&Action=DescribeInstances",
|
||||||
"Content-Length: 43\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
"application/x-www-form-urlencoded", false);
|
||||||
assertPayloadEquals(request, "Version=2009-11-30&Action=DescribeInstances");
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, DescribeInstancesResponseHandler.class);
|
assertSaxResponseParserClassEquals(method, DescribeInstancesResponseHandler.class);
|
||||||
|
@ -78,11 +77,10 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
||||||
HttpRequest request = processor.createRequest(method, null, "1", "2");
|
HttpRequest request = processor.createRequest(method, null, "1", "2");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
|
||||||
"Content-Length: 73\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(request,
|
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);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, DescribeInstancesResponseHandler.class);
|
assertSaxResponseParserClassEquals(method, DescribeInstancesResponseHandler.class);
|
||||||
|
@ -98,11 +96,10 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
||||||
HttpRequest request = processor.createRequest(method, null, "1", "2");
|
HttpRequest request = processor.createRequest(method, null, "1", "2");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
|
||||||
"Content-Length: 74\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(request,
|
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);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, InstanceStateChangeHandler.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);
|
HttpRequest request = processor.createRequest(method, null, null, "ami-voo", 1, 1);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
|
||||||
"Content-Length: 76\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(request,
|
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);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, RunInstancesResponseHandler.class);
|
assertSaxResponseParserClassEquals(method, RunInstancesResponseHandler.class);
|
||||||
|
@ -142,12 +138,11 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
||||||
"group2"));
|
"group2"));
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.eu-west-1.amazonaws.com/ HTTP/1.1");
|
assertRequestLineEquals(request, "POST https://ec2.eu-west-1.amazonaws.com/ HTTP/1.1");
|
||||||
assertHeadersEqual(
|
assertNonPayloadHeadersEqual(request, "Host: ec2.eu-west-1.amazonaws.com\n");
|
||||||
request,
|
|
||||||
"Content-Length: 202\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.eu-west-1.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
request,
|
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);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, RunInstancesResponseHandler.class);
|
assertSaxResponseParserClassEquals(method, RunInstancesResponseHandler.class);
|
||||||
|
@ -162,11 +157,10 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
||||||
HttpRequest request = processor.createRequest(method, null, true, "1", "2");
|
HttpRequest request = processor.createRequest(method, null, true, "1", "2");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
|
||||||
"Content-Length: 80\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(request,
|
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);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, InstanceStateChangeHandler.class);
|
assertSaxResponseParserClassEquals(method, InstanceStateChangeHandler.class);
|
||||||
|
@ -181,13 +175,12 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
||||||
HttpRequest request = processor.createRequest(method, null, "1", "2");
|
HttpRequest request = processor.createRequest(method, null, "1", "2");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
|
||||||
"Content-Length: 71\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(request,
|
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);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
@ -200,11 +193,10 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
||||||
HttpRequest request = processor.createRequest(method, null, "1", "2");
|
HttpRequest request = processor.createRequest(method, null, "1", "2");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
|
||||||
"Content-Length: 70\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(request,
|
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);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, InstanceStateChangeHandler.class);
|
assertSaxResponseParserClassEquals(method, InstanceStateChangeHandler.class);
|
||||||
|
@ -220,11 +212,11 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
||||||
HttpRequest request = processor.createRequest(method, null, "1");
|
HttpRequest request = processor.createRequest(method, null, "1");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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,
|
request,
|
||||||
"Content-Length: 83\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=userData&InstanceId=1",
|
||||||
assertPayloadEquals(request,
|
"application/x-www-form-urlencoded", false);
|
||||||
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=userData&InstanceId=1");
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, UnencodeStringValueHandler.class);
|
assertSaxResponseParserClassEquals(method, UnencodeStringValueHandler.class);
|
||||||
|
@ -240,11 +232,11 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
||||||
HttpRequest request = processor.createRequest(method, null, "1");
|
HttpRequest request = processor.createRequest(method, null, "1");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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,
|
request,
|
||||||
"Content-Length: 89\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=rootDeviceName&InstanceId=1",
|
||||||
assertPayloadEquals(request,
|
"application/x-www-form-urlencoded", false);
|
||||||
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=rootDeviceName&InstanceId=1");
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, StringValueHandler.class);
|
assertSaxResponseParserClassEquals(method, StringValueHandler.class);
|
||||||
|
@ -260,11 +252,11 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
||||||
HttpRequest request = processor.createRequest(method, null, "1");
|
HttpRequest request = processor.createRequest(method, null, "1");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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,
|
request,
|
||||||
"Content-Length: 82\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=ramdisk&InstanceId=1",
|
||||||
assertPayloadEquals(request,
|
"application/x-www-form-urlencoded", false);
|
||||||
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=ramdisk&InstanceId=1");
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, StringValueHandler.class);
|
assertSaxResponseParserClassEquals(method, StringValueHandler.class);
|
||||||
|
@ -280,11 +272,11 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
||||||
HttpRequest request = processor.createRequest(method, null, "1");
|
HttpRequest request = processor.createRequest(method, null, "1");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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,
|
request,
|
||||||
"Content-Length: 96\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=disableApiTermination&InstanceId=1",
|
||||||
assertPayloadEquals(request,
|
"application/x-www-form-urlencoded", false);
|
||||||
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=disableApiTermination&InstanceId=1");
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, BooleanValueHandler.class);
|
assertSaxResponseParserClassEquals(method, BooleanValueHandler.class);
|
||||||
|
@ -300,11 +292,10 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
||||||
HttpRequest request = processor.createRequest(method, null, "1");
|
HttpRequest request = processor.createRequest(method, null, "1");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
|
||||||
"Content-Length: 81\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(request,
|
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);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, StringValueHandler.class);
|
assertSaxResponseParserClassEquals(method, StringValueHandler.class);
|
||||||
|
@ -320,11 +311,11 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
||||||
HttpRequest request = processor.createRequest(method, null, "1");
|
HttpRequest request = processor.createRequest(method, null, "1");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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,
|
request,
|
||||||
"Content-Length: 87\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=instanceType&InstanceId=1",
|
||||||
assertPayloadEquals(request,
|
"application/x-www-form-urlencoded", false);
|
||||||
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=instanceType&InstanceId=1");
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, InstanceTypeHandler.class);
|
assertSaxResponseParserClassEquals(method, InstanceTypeHandler.class);
|
||||||
|
@ -341,12 +332,11 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
||||||
HttpRequest request = processor.createRequest(method, null, "1");
|
HttpRequest request = processor.createRequest(method, null, "1");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
|
||||||
"Content-Length: 108\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
request,
|
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);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, InstanceInitiatedShutdownBehaviorHandler.class);
|
assertSaxResponseParserClassEquals(method, InstanceInitiatedShutdownBehaviorHandler.class);
|
||||||
|
@ -362,11 +352,11 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
||||||
HttpRequest request = processor.createRequest(method, null, "1");
|
HttpRequest request = processor.createRequest(method, null, "1");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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,
|
request,
|
||||||
"Content-Length: 93\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=blockDeviceMapping&InstanceId=1",
|
||||||
assertPayloadEquals(request,
|
"application/x-www-form-urlencoded", false);
|
||||||
"Version=2009-11-30&Action=DescribeInstanceAttribute&Attribute=blockDeviceMapping&InstanceId=1");
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, BlockDeviceMappingHandler.class);
|
assertSaxResponseParserClassEquals(method, BlockDeviceMappingHandler.class);
|
||||||
|
@ -382,17 +372,17 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
||||||
HttpRequest request = processor.createRequest(method, null, "1", "test".getBytes());
|
HttpRequest request = processor.createRequest(method, null, "1", "test".getBytes());
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
|
||||||
"Content-Length: 100\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
request,
|
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
|
filter.filter(request);// ensure encoding worked properly
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
request,
|
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");
|
"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);
|
"application/x-www-form-urlencoded", false);
|
||||||
|
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
@ -406,12 +396,12 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
||||||
HttpRequest request = processor.createRequest(method, null, "1", "test");
|
HttpRequest request = processor.createRequest(method, null, "1", "test");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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,
|
request,
|
||||||
"Content-Length: 91\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
"Version=2009-11-30&Action=ModifyInstanceAttribute&Attribute=ramdisk&Value=test&InstanceId=1",
|
||||||
assertPayloadEquals(request,
|
"application/x-www-form-urlencoded", false);
|
||||||
"Version=2009-11-30&Action=ModifyInstanceAttribute&Attribute=ramdisk&Value=test&InstanceId=1");
|
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
@ -425,12 +415,12 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
||||||
HttpRequest request = processor.createRequest(method, null, "1", "test");
|
HttpRequest request = processor.createRequest(method, null, "1", "test");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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,
|
request,
|
||||||
"Content-Length: 90\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
"Version=2009-11-30&Action=ModifyInstanceAttribute&Attribute=kernel&Value=test&InstanceId=1",
|
||||||
assertPayloadEquals(request,
|
"application/x-www-form-urlencoded", false);
|
||||||
"Version=2009-11-30&Action=ModifyInstanceAttribute&Attribute=kernel&Value=test&InstanceId=1");
|
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
@ -445,14 +435,13 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
||||||
HttpRequest request = processor.createRequest(method, null, "1", true);
|
HttpRequest request = processor.createRequest(method, null, "1", true);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
|
||||||
"Content-Length: 105\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
request,
|
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);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(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);
|
HttpRequest request = processor.createRequest(method, null, "1", InstanceType.C1_MEDIUM);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
|
||||||
"Content-Length: 101\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
request,
|
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);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
@ -489,14 +477,13 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
||||||
InstanceInitiatedShutdownBehavior.TERMINATE);
|
InstanceInitiatedShutdownBehavior.TERMINATE);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
|
||||||
"Content-Length: 122\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
request,
|
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);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
@ -515,17 +502,17 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
|
||||||
HttpRequest request = processor.createRequest(method, null, "1", blockDeviceMapping);
|
HttpRequest request = processor.createRequest(method, null, "1", blockDeviceMapping);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
|
||||||
"Content-Length: 202\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
request,
|
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
|
filter.filter(request);// ensure encoding worked properly
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
request,
|
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");
|
"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);
|
"application/x-www-form-urlencoded", false);
|
||||||
|
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,8 @@ import java.lang.reflect.Method;
|
||||||
|
|
||||||
import org.jclouds.aws.ec2.xml.DescribeKeyPairsResponseHandler;
|
import org.jclouds.aws.ec2.xml.DescribeKeyPairsResponseHandler;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.functions.CloseContentAndReturn;
|
|
||||||
import org.jclouds.http.functions.ParseSax;
|
import org.jclouds.http.functions.ParseSax;
|
||||||
|
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -45,12 +45,11 @@ public class KeyPairAsyncClientTest extends BaseEC2AsyncClientTest<KeyPairAsyncC
|
||||||
HttpRequest request = processor.createRequest(method, null, "mykey");
|
HttpRequest request = processor.createRequest(method, null, "mykey");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
assertPayloadEquals(request, "Version=2009-11-30&Action=DeleteKeyPair&KeyName=mykey",
|
||||||
"Content-Length: 53\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
"application/x-www-form-urlencoded", false);
|
||||||
assertPayloadEquals(request, "Version=2009-11-30&Action=DeleteKeyPair&KeyName=mykey");
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
@ -63,10 +62,9 @@ public class KeyPairAsyncClientTest extends BaseEC2AsyncClientTest<KeyPairAsyncC
|
||||||
HttpRequest request = processor.createRequest(method, (String) null);
|
HttpRequest request = processor.createRequest(method, (String) null);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
assertPayloadEquals(request, "Version=2009-11-30&Action=DescribeKeyPairs",
|
||||||
"Content-Length: 42\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
"application/x-www-form-urlencoded", false);
|
||||||
assertPayloadEquals(request, "Version=2009-11-30&Action=DescribeKeyPairs");
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, DescribeKeyPairsResponseHandler.class);
|
assertSaxResponseParserClassEquals(method, DescribeKeyPairsResponseHandler.class);
|
||||||
|
@ -82,11 +80,10 @@ public class KeyPairAsyncClientTest extends BaseEC2AsyncClientTest<KeyPairAsyncC
|
||||||
HttpRequest request = processor.createRequest(method, null, "1", "2");
|
HttpRequest request = processor.createRequest(method, null, "1", "2");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
|
||||||
"Content-Length: 66\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(request,
|
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);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, DescribeKeyPairsResponseHandler.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");
|
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";
|
String payload = "Version=2009-11-30&Action=UnmonitorInstances&InstanceId.0=instance1&InstanceId.1=instance2";
|
||||||
assertHeadersEqual(
|
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
|
||||||
request,
|
assertPayloadEquals(request, payload, "application/x-www-form-urlencoded", false);
|
||||||
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);
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, MonitoringStateHandler.class);
|
assertSaxResponseParserClassEquals(method, MonitoringStateHandler.class);
|
||||||
|
@ -67,11 +62,11 @@ public class MonitoringAsyncClientTest extends BaseEC2AsyncClientTest<Monitoring
|
||||||
HttpRequest request = processor.createRequest(method, null, "instance1", "instance2");
|
HttpRequest request = processor.createRequest(method, null, "instance1", "instance2");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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,
|
request,
|
||||||
"Content-Length: 88\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
"Version=2009-11-30&Action=MonitorInstances&InstanceId.0=instance1&InstanceId.1=instance2",
|
||||||
assertPayloadEquals(request,
|
"application/x-www-form-urlencoded", false);
|
||||||
"Version=2009-11-30&Action=MonitorInstances&InstanceId.0=instance1&InstanceId.1=instance2");
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, MonitoringStateHandler.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.functions.ReturnVoidOnGroupNotFound;
|
||||||
import org.jclouds.aws.ec2.xml.DescribeSecurityGroupsResponseHandler;
|
import org.jclouds.aws.ec2.xml.DescribeSecurityGroupsResponseHandler;
|
||||||
import org.jclouds.http.HttpRequest;
|
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.http.functions.ParseSax;
|
||||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
@ -49,12 +49,11 @@ public class SecurityGroupAsyncClientTest extends BaseEC2AsyncClientTest<Securit
|
||||||
HttpRequest request = processor.createRequest(method, null, "name");
|
HttpRequest request = processor.createRequest(method, null, "name");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
assertPayloadEquals(request, "Version=2009-11-30&Action=DeleteSecurityGroup&GroupName=name",
|
||||||
"Content-Length: 60\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
"application/x-www-form-urlencoded", false);
|
||||||
assertPayloadEquals(request, "Version=2009-11-30&Action=DeleteSecurityGroup&GroupName=name");
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, ReturnVoidOnGroupNotFound.class);
|
assertExceptionParserClassEquals(method, ReturnVoidOnGroupNotFound.class);
|
||||||
|
|
||||||
|
@ -68,13 +67,13 @@ public class SecurityGroupAsyncClientTest extends BaseEC2AsyncClientTest<Securit
|
||||||
HttpRequest request = processor.createRequest(method, null, "name", "description");
|
HttpRequest request = processor.createRequest(method, null, "name", "description");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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,
|
request,
|
||||||
"Content-Length: 89\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
"Version=2009-11-30&Action=CreateSecurityGroup&GroupDescription=description&GroupName=name",
|
||||||
assertPayloadEquals(request,
|
"application/x-www-form-urlencoded", false);
|
||||||
"Version=2009-11-30&Action=CreateSecurityGroup&GroupDescription=description&GroupName=name");
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
@ -88,10 +87,9 @@ public class SecurityGroupAsyncClientTest extends BaseEC2AsyncClientTest<Securit
|
||||||
HttpRequest request = processor.createRequest(method, (String) null);
|
HttpRequest request = processor.createRequest(method, (String) null);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
assertPayloadEquals(request, "Version=2009-11-30&Action=DescribeSecurityGroups",
|
||||||
"Content-Length: 48\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
"application/x-www-form-urlencoded", false);
|
||||||
assertPayloadEquals(request, "Version=2009-11-30&Action=DescribeSecurityGroups");
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, DescribeSecurityGroupsResponseHandler.class);
|
assertSaxResponseParserClassEquals(method, DescribeSecurityGroupsResponseHandler.class);
|
||||||
|
@ -107,11 +105,10 @@ public class SecurityGroupAsyncClientTest extends BaseEC2AsyncClientTest<Securit
|
||||||
HttpRequest request = processor.createRequest(method, null, "1", "2");
|
HttpRequest request = processor.createRequest(method, null, "1", "2");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
|
||||||
"Content-Length: 76\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(request,
|
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);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, DescribeSecurityGroupsResponseHandler.class);
|
assertSaxResponseParserClassEquals(method, DescribeSecurityGroupsResponseHandler.class);
|
||||||
|
@ -129,14 +126,13 @@ public class SecurityGroupAsyncClientTest extends BaseEC2AsyncClientTest<Securit
|
||||||
"sourceUser", "sourceGroup"));
|
"sourceUser", "sourceGroup"));
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
|
||||||
"Content-Length: 145\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
request,
|
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);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
@ -152,14 +148,13 @@ public class SecurityGroupAsyncClientTest extends BaseEC2AsyncClientTest<Securit
|
||||||
7000, "0.0.0.0/0");
|
7000, "0.0.0.0/0");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
|
||||||
"Content-Length: 131\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
request,
|
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);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
@ -175,14 +170,13 @@ public class SecurityGroupAsyncClientTest extends BaseEC2AsyncClientTest<Securit
|
||||||
"sourceUser", "sourceGroup"));
|
"sourceUser", "sourceGroup"));
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
|
||||||
"Content-Length: 142\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
request,
|
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);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
@ -198,14 +192,13 @@ public class SecurityGroupAsyncClientTest extends BaseEC2AsyncClientTest<Securit
|
||||||
7000, "0.0.0.0/0");
|
7000, "0.0.0.0/0");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.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");
|
||||||
request,
|
|
||||||
"Content-Length: 128\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.us-east-1.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
request,
|
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);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
|
|
@ -61,12 +61,11 @@ public class ELBAsyncClientTest extends RestClientTest<ELBAsyncClient> {
|
||||||
|
|
||||||
assertRequestLineEquals(request,
|
assertRequestLineEquals(request,
|
||||||
"POST https://elasticloadbalancing.us-east-1.amazonaws.com/ HTTP/1.1");
|
"POST https://elasticloadbalancing.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||||
assertHeadersEqual(
|
assertNonPayloadHeadersEqual(request, "Host: elasticloadbalancing.us-east-1.amazonaws.com\n");
|
||||||
request,
|
|
||||||
"Content-Length: 130\nContent-Type: application/x-www-form-urlencoded\nHost: elasticloadbalancing.us-east-1.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
request,
|
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);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method,
|
assertSaxResponseParserClassEquals(method,
|
||||||
|
|
|
@ -18,33 +18,17 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.aws.filters;
|
package org.jclouds.aws.filters;
|
||||||
|
|
||||||
import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor;
|
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import java.util.Date;
|
import org.jclouds.aws.ec2.services.BaseEC2AsyncClientTest;
|
||||||
|
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||||
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.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMultimap;
|
import com.google.common.collect.ImmutableMultimap;
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.TypeLiteral;
|
||||||
import com.google.inject.Guice;
|
|
||||||
import com.google.inject.Injector;
|
|
||||||
import com.google.inject.Provides;
|
|
||||||
import com.google.inject.name.Names;
|
|
||||||
|
|
||||||
@Test(groups = "unit", testName = "aws.FormSignerTest")
|
@Test(groups = "unit", testName = "aws.FormSignerTest")
|
||||||
public class FormSignerTest {
|
public class FormSignerTest extends BaseEC2AsyncClientTest<String> {
|
||||||
|
|
||||||
private Injector injector;
|
|
||||||
private FormSigner filter;
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testBuildCanonicalizedString() {
|
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");
|
"AWSAccessKeyId=foo&Action=DescribeImages&Expires=2008-02-10T12%3A00%3A00Z&ImageId.1=ami-2bb65342&SignatureMethod=HmacSHA256&SignatureVersion=2&Version=2009-11-30");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* before class, as we need to ensure that the filter is threadsafe.
|
protected TypeLiteral<RestAnnotationProcessor<String>> createTypeLiteral() {
|
||||||
*
|
return new TypeLiteral<RestAnnotationProcessor<String>>() {
|
||||||
*/
|
};
|
||||||
@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");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@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.HttpCommand;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
|
import org.jclouds.http.Payloads;
|
||||||
import org.jclouds.http.functions.config.ParserModule;
|
import org.jclouds.http.functions.config.ParserModule;
|
||||||
import org.jclouds.rest.AuthorizationException;
|
import org.jclouds.rest.AuthorizationException;
|
||||||
import org.jclouds.rest.RequestSigner;
|
import org.jclouds.rest.RequestSigner;
|
||||||
|
@ -63,9 +64,8 @@ public class ParseAWSErrorFromXmlContentTest {
|
||||||
|
|
||||||
HttpCommand command = createMock(HttpCommand.class);
|
HttpCommand command = createMock(HttpCommand.class);
|
||||||
HttpRequest request = new HttpRequest(method, uri);
|
HttpRequest request = new HttpRequest(method, uri);
|
||||||
HttpResponse response = new HttpResponse(Utils.toInputStream(content));
|
HttpResponse response = new HttpResponse(statusCode, message, Payloads
|
||||||
response.setStatusCode(statusCode);
|
.newInputStreamPayload(Utils.toInputStream(content)));
|
||||||
response.setMessage(message);
|
|
||||||
|
|
||||||
expect(command.getRequest()).andReturn(request).atLeastOnce();
|
expect(command.getRequest()).andReturn(request).atLeastOnce();
|
||||||
command.setException(classEq(expected));
|
command.setException(classEq(expected));
|
||||||
|
|
|
@ -61,7 +61,7 @@ import org.jclouds.blobstore.functions.ThrowKeyNotFoundOn404;
|
||||||
import org.jclouds.date.TimeStamp;
|
import org.jclouds.date.TimeStamp;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.RequiresHttp;
|
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.ParseETagHeader;
|
||||||
import org.jclouds.http.functions.ParseSax;
|
import org.jclouds.http.functions.ParseSax;
|
||||||
import org.jclouds.http.functions.ReturnTrueIf2xx;
|
import org.jclouds.http.functions.ReturnTrueIf2xx;
|
||||||
|
@ -102,16 +102,16 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
||||||
HttpRequest request = processor.createRequest(method, "bucket");
|
HttpRequest request = processor.createRequest(method, "bucket");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "GET https://bucket.s3.amazonaws.com/?location HTTP/1.1");
|
assertRequestLineEquals(request, "GET https://bucket.s3.amazonaws.com/?location HTTP/1.1");
|
||||||
assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||||
assertPayloadEquals(request, null);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
filter.filter(request);
|
filter.filter(request);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "GET https://bucket.s3.amazonaws.com/?location HTTP/1.1");
|
assertRequestLineEquals(request, "GET https://bucket.s3.amazonaws.com/?location HTTP/1.1");
|
||||||
assertHeadersEqual(
|
assertNonPayloadHeadersEqual(
|
||||||
request,
|
request,
|
||||||
"Authorization: AWS identity:2fFTeYJTDwiJmaAkKj732RjNbOg=\nDate: 2009-11-08T15:54:08.897Z\nHost: bucket.s3.amazonaws.com\n");
|
"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);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, LocationConstraintHandler.class);
|
assertSaxResponseParserClassEquals(method, LocationConstraintHandler.class);
|
||||||
|
@ -126,8 +126,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
||||||
|
|
||||||
assertRequestLineEquals(request,
|
assertRequestLineEquals(request,
|
||||||
"GET https://bucket.s3.amazonaws.com/?requestPayment HTTP/1.1");
|
"GET https://bucket.s3.amazonaws.com/?requestPayment HTTP/1.1");
|
||||||
assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||||
assertPayloadEquals(request, null);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, PayerHandler.class);
|
assertSaxResponseParserClassEquals(method, PayerHandler.class);
|
||||||
|
@ -143,13 +143,13 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
||||||
|
|
||||||
assertRequestLineEquals(request,
|
assertRequestLineEquals(request,
|
||||||
"PUT https://bucket.s3.amazonaws.com/?requestPayment HTTP/1.1");
|
"PUT https://bucket.s3.amazonaws.com/?requestPayment HTTP/1.1");
|
||||||
assertHeadersEqual(request,
|
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||||
"Content-Length: 133\nContent-Type: text/xml\nHost: bucket.s3.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
request,
|
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);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
@ -163,13 +163,13 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
||||||
|
|
||||||
assertRequestLineEquals(request,
|
assertRequestLineEquals(request,
|
||||||
"PUT https://bucket.s3.amazonaws.com/?requestPayment HTTP/1.1");
|
"PUT https://bucket.s3.amazonaws.com/?requestPayment HTTP/1.1");
|
||||||
assertHeadersEqual(request,
|
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||||
"Content-Length: 131\nContent-Type: text/xml\nHost: bucket.s3.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
request,
|
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);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
@ -182,8 +182,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
||||||
HttpRequest request = processor.createRequest(method, "bucket");
|
HttpRequest request = processor.createRequest(method, "bucket");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "GET https://bucket.s3.amazonaws.com/ HTTP/1.1");
|
assertRequestLineEquals(request, "GET https://bucket.s3.amazonaws.com/ HTTP/1.1");
|
||||||
assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||||
assertPayloadEquals(request, null);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, ListBucketHandler.class);
|
assertSaxResponseParserClassEquals(method, ListBucketHandler.class);
|
||||||
|
@ -197,8 +197,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
||||||
HttpRequest request = processor.createRequest(method, "bucket");
|
HttpRequest request = processor.createRequest(method, "bucket");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "HEAD https://bucket.s3.amazonaws.com/?max-keys=0 HTTP/1.1");
|
assertRequestLineEquals(request, "HEAD https://bucket.s3.amazonaws.com/?max-keys=0 HTTP/1.1");
|
||||||
assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||||
assertPayloadEquals(request, null);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
|
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
@ -228,10 +228,10 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
||||||
|
|
||||||
assertRequestLineEquals(request,
|
assertRequestLineEquals(request,
|
||||||
"PUT https://destinationbucket.s3.amazonaws.com/destinationObject HTTP/1.1");
|
"PUT https://destinationbucket.s3.amazonaws.com/destinationObject HTTP/1.1");
|
||||||
assertHeadersEqual(
|
assertNonPayloadHeadersEqual(
|
||||||
request,
|
request,
|
||||||
"Content-Length: 0\nHost: destinationbucket.s3.amazonaws.com\nx-amz-copy-source: /sourceBucket/sourceObject\n");
|
"Host: destinationbucket.s3.amazonaws.com\nx-amz-copy-source: /sourceBucket/sourceObject\n");
|
||||||
assertPayloadEquals(request, null);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, CopyObjectHandler.class);
|
assertSaxResponseParserClassEquals(method, CopyObjectHandler.class);
|
||||||
|
@ -246,8 +246,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
||||||
HttpRequest request = processor.createRequest(method, "bucket");
|
HttpRequest request = processor.createRequest(method, "bucket");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "DELETE https://bucket.s3.amazonaws.com/ HTTP/1.1");
|
assertRequestLineEquals(request, "DELETE https://bucket.s3.amazonaws.com/ HTTP/1.1");
|
||||||
assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||||
assertPayloadEquals(request, null);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
|
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
@ -261,10 +261,10 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
||||||
HttpRequest request = processor.createRequest(method, "bucket", "object");
|
HttpRequest request = processor.createRequest(method, "bucket", "object");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "DELETE https://bucket.s3.amazonaws.com/object HTTP/1.1");
|
assertRequestLineEquals(request, "DELETE https://bucket.s3.amazonaws.com/object HTTP/1.1");
|
||||||
assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||||
assertPayloadEquals(request, null);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
|
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
|
||||||
|
|
||||||
|
@ -277,8 +277,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
||||||
HttpRequest request = processor.createRequest(method, "bucket");
|
HttpRequest request = processor.createRequest(method, "bucket");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "GET https://bucket.s3.amazonaws.com/?acl HTTP/1.1");
|
assertRequestLineEquals(request, "GET https://bucket.s3.amazonaws.com/?acl HTTP/1.1");
|
||||||
assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||||
assertPayloadEquals(request, null);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, AccessControlListHandler.class);
|
assertSaxResponseParserClassEquals(method, AccessControlListHandler.class);
|
||||||
|
@ -294,8 +294,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
||||||
HttpRequest request = processor.createRequest(method, "bucket", "object");
|
HttpRequest request = processor.createRequest(method, "bucket", "object");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "GET https://bucket.s3.amazonaws.com/object HTTP/1.1");
|
assertRequestLineEquals(request, "GET https://bucket.s3.amazonaws.com/object HTTP/1.1");
|
||||||
assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||||
assertPayloadEquals(request, null);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseObjectFromHeadersAndHttpContent.class);
|
assertResponseParserClassEquals(method, request, ParseObjectFromHeadersAndHttpContent.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
@ -310,8 +310,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
||||||
HttpRequest request = processor.createRequest(method, "bucket", "object");
|
HttpRequest request = processor.createRequest(method, "bucket", "object");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "GET https://bucket.s3.amazonaws.com/object?acl HTTP/1.1");
|
assertRequestLineEquals(request, "GET https://bucket.s3.amazonaws.com/object?acl HTTP/1.1");
|
||||||
assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||||
assertPayloadEquals(request, null);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, AccessControlListHandler.class);
|
assertSaxResponseParserClassEquals(method, AccessControlListHandler.class);
|
||||||
|
@ -326,8 +326,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
||||||
HttpRequest request = processor.createRequest(method, "bucket", "object");
|
HttpRequest request = processor.createRequest(method, "bucket", "object");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "HEAD https://bucket.s3.amazonaws.com/object HTTP/1.1");
|
assertRequestLineEquals(request, "HEAD https://bucket.s3.amazonaws.com/object HTTP/1.1");
|
||||||
assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||||
assertPayloadEquals(request, null);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
|
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
@ -342,8 +342,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
||||||
HttpRequest request = processor.createRequest(method, "bucket", "object");
|
HttpRequest request = processor.createRequest(method, "bucket", "object");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "HEAD https://bucket.s3.amazonaws.com/object HTTP/1.1");
|
assertRequestLineEquals(request, "HEAD https://bucket.s3.amazonaws.com/object HTTP/1.1");
|
||||||
assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||||
assertPayloadEquals(request, null);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseObjectMetadataFromHeaders.class);
|
assertResponseParserClassEquals(method, request, ParseObjectMetadataFromHeaders.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
@ -357,8 +357,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
||||||
HttpRequest request = processor.createRequest(method);
|
HttpRequest request = processor.createRequest(method);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "GET https://s3.amazonaws.com/ HTTP/1.1");
|
assertRequestLineEquals(request, "GET https://s3.amazonaws.com/ HTTP/1.1");
|
||||||
assertHeadersEqual(request, "Host: s3.amazonaws.com\n");
|
assertNonPayloadHeadersEqual(request, "Host: s3.amazonaws.com\n");
|
||||||
assertPayloadEquals(request, null);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, ListAllMyBucketsHandler.class);
|
assertSaxResponseParserClassEquals(method, ListAllMyBucketsHandler.class);
|
||||||
|
@ -379,11 +379,11 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
||||||
.fromCannedAccessPolicy(CannedAccessPolicy.PRIVATE, "1234"));
|
.fromCannedAccessPolicy(CannedAccessPolicy.PRIVATE, "1234"));
|
||||||
|
|
||||||
assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/?acl HTTP/1.1");
|
assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/?acl HTTP/1.1");
|
||||||
assertHeadersEqual(request,
|
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||||
"Content-Length: 321\nContent-Type: text/xml\nHost: bucket.s3.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
request,
|
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);
|
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
@ -399,8 +399,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
||||||
HttpRequest request = processor.createRequest(method, (String) null, "bucket");
|
HttpRequest request = processor.createRequest(method, (String) null, "bucket");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/ HTTP/1.1");
|
assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/ HTTP/1.1");
|
||||||
assertHeadersEqual(request, "Content-Length: 0\nHost: bucket.s3.amazonaws.com\n");
|
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||||
assertPayloadEquals(request, null);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
|
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
@ -416,11 +416,12 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
||||||
HttpRequest request = processor.createRequest(method, "EU", "bucket");
|
HttpRequest request = processor.createRequest(method, "EU", "bucket");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/ HTTP/1.1");
|
assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/ HTTP/1.1");
|
||||||
assertHeadersEqual(request,
|
assertNonPayloadHeadersEqual(request,
|
||||||
"Content-Length: 98\nContent-Type: application/unknown\nHost: bucket.s3.amazonaws.com\n");
|
"Host: bucket.s3.amazonaws.com\n");
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
request,
|
request,
|
||||||
"<CreateBucketConfiguration><LocationConstraint>EU</LocationConstraint></CreateBucketConfiguration>");
|
"<CreateBucketConfiguration><LocationConstraint>EU</LocationConstraint></CreateBucketConfiguration>",
|
||||||
|
"text/xml", false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
|
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
@ -438,9 +439,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
||||||
.apply(BindBlobToMultipartFormTest.TEST_BLOB));
|
.apply(BindBlobToMultipartFormTest.TEST_BLOB));
|
||||||
|
|
||||||
assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/hello HTTP/1.1");
|
assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/hello HTTP/1.1");
|
||||||
assertHeadersEqual(request,
|
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||||
"Content-Length: 5\nContent-Type: text/plain\nHost: bucket.s3.amazonaws.com\n");
|
assertPayloadEquals(request, "hello", "text/plain", false);
|
||||||
assertPayloadEquals(request, "hello");
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseETagHeader.class);
|
assertResponseParserClassEquals(method, request, ParseETagHeader.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
@ -456,11 +456,11 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
||||||
.fromCannedAccessPolicy(CannedAccessPolicy.PRIVATE, "1234"));
|
.fromCannedAccessPolicy(CannedAccessPolicy.PRIVATE, "1234"));
|
||||||
|
|
||||||
assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/key?acl HTTP/1.1");
|
assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/key?acl HTTP/1.1");
|
||||||
assertHeadersEqual(request,
|
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||||
"Content-Length: 321\nContent-Type: text/xml\nHost: bucket.s3.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
request,
|
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);
|
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
@ -474,8 +474,8 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
||||||
HttpRequest request = processor.createRequest(method, "bucket");
|
HttpRequest request = processor.createRequest(method, "bucket");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "GET https://bucket.s3.amazonaws.com/?logging HTTP/1.1");
|
assertRequestLineEquals(request, "GET https://bucket.s3.amazonaws.com/?logging HTTP/1.1");
|
||||||
assertHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||||
assertPayloadEquals(request, null);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, BucketLoggingHandler.class);
|
assertSaxResponseParserClassEquals(method, BucketLoggingHandler.class);
|
||||||
|
@ -490,12 +490,12 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
||||||
HttpRequest request = processor.createRequest(method, "bucket");
|
HttpRequest request = processor.createRequest(method, "bucket");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/?logging HTTP/1.1");
|
assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/?logging HTTP/1.1");
|
||||||
assertHeadersEqual(request,
|
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||||
"Content-Length: 70\nContent-Type: text/xml\nHost: bucket.s3.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(request,
|
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);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
@ -511,12 +511,11 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
|
||||||
"adrian@jclouds.org"), Permission.FULL_CONTROL))));
|
"adrian@jclouds.org"), Permission.FULL_CONTROL))));
|
||||||
|
|
||||||
assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/?logging HTTP/1.1");
|
assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/?logging HTTP/1.1");
|
||||||
assertHeadersEqual(request,
|
assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
|
||||||
"Content-Length: 433\nContent-Type: text/xml\nHost: bucket.s3.amazonaws.com\n");
|
|
||||||
assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream(
|
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);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
|
|
@ -23,8 +23,6 @@ import static org.testng.Assert.assertEquals;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
|
||||||
|
|
||||||
import org.jclouds.aws.s3.domain.BucketLogging;
|
import org.jclouds.aws.s3.domain.BucketLogging;
|
||||||
import org.jclouds.aws.s3.domain.AccessControlList.EmailAddressGrantee;
|
import org.jclouds.aws.s3.domain.AccessControlList.EmailAddressGrantee;
|
||||||
import org.jclouds.aws.s3.domain.AccessControlList.Grant;
|
import org.jclouds.aws.s3.domain.AccessControlList.Grant;
|
||||||
|
@ -58,8 +56,7 @@ public class BindBucketLoggingToXmlPayloadTest extends BaseHandlerTest {
|
||||||
.getInstance(BindBucketLoggingToXmlPayload.class);
|
.getInstance(BindBucketLoggingToXmlPayload.class);
|
||||||
|
|
||||||
binder.bindToRequest(request, bucketLogging);
|
binder.bindToRequest(request, bucketLogging);
|
||||||
assertEquals(request.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE), "text/xml");
|
assertEquals(request.getPayload().getContentType(), "text/xml");
|
||||||
assertEquals(request.getFirstHeaderOrNull(HttpHeaders.CONTENT_LENGTH), "433");
|
|
||||||
assertEquals(request.getPayload().getRawContent(), expected);
|
assertEquals(request.getPayload().getRawContent(), expected);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,8 +23,6 @@ import static org.testng.Assert.assertEquals;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
|
||||||
|
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.functions.BaseHandlerTest;
|
import org.jclouds.http.functions.BaseHandlerTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
@ -44,8 +42,7 @@ public class BindNoBucketLoggingToXmlPayloadTest extends BaseHandlerTest {
|
||||||
.getInstance(BindNoBucketLoggingToXmlPayload.class);
|
.getInstance(BindNoBucketLoggingToXmlPayload.class);
|
||||||
|
|
||||||
binder.bindToRequest(request, null);
|
binder.bindToRequest(request, null);
|
||||||
assertEquals(request.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE), "text/xml");
|
assertEquals(request.getPayload().getContentType(), "text/xml");
|
||||||
assertEquals(request.getFirstHeaderOrNull(HttpHeaders.CONTENT_LENGTH), "70");
|
|
||||||
assertEquals(request.getPayload().getRawContent(),
|
assertEquals(request.getPayload().getRawContent(),
|
||||||
"<BucketLoggingStatus xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"/>");
|
"<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.http.handlers.DelegatingRetryHandler;
|
||||||
import org.jclouds.logging.config.NullLoggingModule;
|
import org.jclouds.logging.config.NullLoggingModule;
|
||||||
import org.jclouds.rest.RestContextFactory;
|
import org.jclouds.rest.RestContextFactory;
|
||||||
import org.jclouds.rest.RestClientTest.MockModule;
|
import org.jclouds.rest.BaseRestClientTest.MockModule;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
|
|
|
@ -31,7 +31,7 @@ import org.jclouds.Constants;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.logging.config.NullLoggingModule;
|
import org.jclouds.logging.config.NullLoggingModule;
|
||||||
import org.jclouds.rest.RestContextFactory;
|
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.BeforeClass;
|
||||||
import org.testng.annotations.DataProvider;
|
import org.testng.annotations.DataProvider;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
|
@ -39,6 +39,7 @@ import org.jclouds.blobstore.functions.ParseSystemAndUserMetadataFromHeaders;
|
||||||
import org.jclouds.encryption.EncryptionService;
|
import org.jclouds.encryption.EncryptionService;
|
||||||
import org.jclouds.encryption.internal.JCEEncryptionService;
|
import org.jclouds.encryption.internal.JCEEncryptionService;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
|
import org.jclouds.http.Payloads;
|
||||||
import org.testng.annotations.BeforeTest;
|
import org.testng.annotations.BeforeTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -53,8 +54,9 @@ public class ParseObjectMetadataFromHeadersTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testNormal() throws Exception {
|
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(HttpHeaders.CACHE_CONTROL, "cacheControl");
|
||||||
http.getHeaders().put("Content-Disposition", "contentDisposition");
|
http.getHeaders().put("Content-Disposition", "contentDisposition");
|
||||||
http.getHeaders().put(HttpHeaders.CONTENT_ENCODING, "encoding");
|
http.getHeaders().put(HttpHeaders.CONTENT_ENCODING, "encoding");
|
||||||
|
@ -67,7 +69,9 @@ public class ParseObjectMetadataFromHeadersTest {
|
||||||
@Test
|
@Test
|
||||||
void testAmzEtag() throws Exception {
|
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(HttpHeaders.CACHE_CONTROL, "cacheControl");
|
||||||
http.getHeaders().put("Content-Disposition", "contentDisposition");
|
http.getHeaders().put("Content-Disposition", "contentDisposition");
|
||||||
http.getHeaders().put(HttpHeaders.CONTENT_ENCODING, "encoding");
|
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.HttpException;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
|
import org.jclouds.http.Payloads;
|
||||||
import org.jclouds.logging.config.NullLoggingModule;
|
import org.jclouds.logging.config.NullLoggingModule;
|
||||||
import org.jclouds.rest.RestContextFactory;
|
import org.jclouds.rest.RestContextFactory;
|
||||||
import org.jclouds.rest.RestClientTest.MockModule;
|
import org.jclouds.rest.BaseRestClientTest.MockModule;
|
||||||
import org.jclouds.util.Utils;
|
import org.jclouds.util.Utils;
|
||||||
import org.testng.annotations.AfterTest;
|
import org.testng.annotations.AfterTest;
|
||||||
import org.testng.annotations.BeforeTest;
|
import org.testng.annotations.BeforeTest;
|
||||||
|
@ -63,8 +64,7 @@ public class S3UtilsTest {
|
||||||
.buildInjector();
|
.buildInjector();
|
||||||
|
|
||||||
utils = injector.getInstance(S3Utils.class);
|
utils = injector.getInstance(S3Utils.class);
|
||||||
response = new HttpResponse();
|
response = new HttpResponse(400, "boa", Payloads.newStringPayload(""));
|
||||||
response.setStatusCode(400);
|
|
||||||
response.getHeaders().put(S3Headers.REQUEST_ID, "requestid");
|
response.getHeaders().put(S3Headers.REQUEST_ID, "requestid");
|
||||||
response.getHeaders().put(S3Headers.REQUEST_TOKEN, "requesttoken");
|
response.getHeaders().put(S3Headers.REQUEST_TOKEN, "requesttoken");
|
||||||
command = createMock(HttpCommand.class);
|
command = createMock(HttpCommand.class);
|
||||||
|
|
|
@ -81,10 +81,9 @@ public class SQSAsyncClientTest extends RestClientTest<SQSAsyncClient> {
|
||||||
HttpRequest request = processor.createRequest(method, (String) null);
|
HttpRequest request = processor.createRequest(method, (String) null);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://sqs.us-east-1.amazonaws.com/ HTTP/1.1");
|
assertRequestLineEquals(request, "POST https://sqs.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||||
assertHeadersEqual(
|
assertNonPayloadHeadersEqual(request, "Host: sqs.us-east-1.amazonaws.com\n");
|
||||||
request,
|
assertPayloadEquals(request, "Version=2009-02-01&Action=ListQueues",
|
||||||
"Content-Length: 36\nContent-Type: application/x-www-form-urlencoded\nHost: sqs.us-east-1.amazonaws.com\n");
|
"application/x-www-form-urlencoded", false);
|
||||||
assertPayloadEquals(request, "Version=2009-02-01&Action=ListQueues");
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, RegexListQueuesResponseHandler.class);
|
assertResponseParserClassEquals(method, request, RegexListQueuesResponseHandler.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
@ -101,10 +100,9 @@ public class SQSAsyncClientTest extends RestClientTest<SQSAsyncClient> {
|
||||||
.queuePrefix("prefix"));
|
.queuePrefix("prefix"));
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://sqs.us-east-1.amazonaws.com/ HTTP/1.1");
|
assertRequestLineEquals(request, "POST https://sqs.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||||
assertHeadersEqual(
|
assertNonPayloadHeadersEqual(request, "Host: sqs.us-east-1.amazonaws.com\n");
|
||||||
request,
|
assertPayloadEquals(request, "Version=2009-02-01&Action=ListQueues&QueueNamePrefix=prefix",
|
||||||
"Content-Length: 59\nContent-Type: application/x-www-form-urlencoded\nHost: sqs.us-east-1.amazonaws.com\n");
|
"application/x-www-form-urlencoded", false);
|
||||||
assertPayloadEquals(request, "Version=2009-02-01&Action=ListQueues&QueueNamePrefix=prefix");
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, RegexListQueuesResponseHandler.class);
|
assertResponseParserClassEquals(method, request, RegexListQueuesResponseHandler.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
@ -120,10 +118,9 @@ public class SQSAsyncClientTest extends RestClientTest<SQSAsyncClient> {
|
||||||
HttpRequest request = processor.createRequest(method, null, "queueName");
|
HttpRequest request = processor.createRequest(method, null, "queueName");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://sqs.us-east-1.amazonaws.com/ HTTP/1.1");
|
assertRequestLineEquals(request, "POST https://sqs.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||||
assertHeadersEqual(
|
assertNonPayloadHeadersEqual(request, "Host: sqs.us-east-1.amazonaws.com\n");
|
||||||
request,
|
assertPayloadEquals(request, "Version=2009-02-01&Action=CreateQueue&QueueName=queueName",
|
||||||
"Content-Length: 57\nContent-Type: application/x-www-form-urlencoded\nHost: sqs.us-east-1.amazonaws.com\n");
|
"application/x-www-form-urlencoded", false);
|
||||||
assertPayloadEquals(request, "Version=2009-02-01&Action=CreateQueue&QueueName=queueName");
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, RegexQueueHandler.class);
|
assertResponseParserClassEquals(method, request, RegexQueueHandler.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
@ -140,11 +137,11 @@ public class SQSAsyncClientTest extends RestClientTest<SQSAsyncClient> {
|
||||||
CreateQueueOptions.Builder.defaultVisibilityTimeout(45));
|
CreateQueueOptions.Builder.defaultVisibilityTimeout(45));
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://sqs.us-east-1.amazonaws.com/ HTTP/1.1");
|
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,
|
request,
|
||||||
"Content-Length: 85\nContent-Type: application/x-www-form-urlencoded\nHost: sqs.us-east-1.amazonaws.com\n");
|
"Version=2009-02-01&Action=CreateQueue&QueueName=queueName&DefaultVisibilityTimeout=45",
|
||||||
assertPayloadEquals(request,
|
"application/x-www-form-urlencoded", false);
|
||||||
"Version=2009-02-01&Action=CreateQueue&QueueName=queueName&DefaultVisibilityTimeout=45");
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, RegexQueueHandler.class);
|
assertResponseParserClassEquals(method, request, RegexQueueHandler.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
|
|
@ -32,7 +32,7 @@ import org.jclouds.http.handlers.DelegatingErrorHandler;
|
||||||
import org.jclouds.http.handlers.DelegatingRetryHandler;
|
import org.jclouds.http.handlers.DelegatingRetryHandler;
|
||||||
import org.jclouds.logging.config.NullLoggingModule;
|
import org.jclouds.logging.config.NullLoggingModule;
|
||||||
import org.jclouds.rest.RestContextFactory;
|
import org.jclouds.rest.RestContextFactory;
|
||||||
import org.jclouds.rest.RestClientTest.MockModule;
|
import org.jclouds.rest.BaseRestClientTest.MockModule;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
@ -48,8 +48,8 @@ import com.google.inject.Module;
|
||||||
public class SQSRestClientModuleTest {
|
public class SQSRestClientModuleTest {
|
||||||
|
|
||||||
Injector createInjector() {
|
Injector createInjector() {
|
||||||
return new RestContextFactory().createContextBuilder("sqs", "uid", "key", ImmutableSet
|
return new RestContextFactory().createContextBuilder("sqs", "uid", "key",
|
||||||
.<Module> of(new MockModule(), new NullLoggingModule())).buildInjector();
|
ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule())).buildInjector();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -37,6 +37,7 @@ import org.jclouds.PerformanceTest;
|
||||||
import org.jclouds.aws.domain.Region;
|
import org.jclouds.aws.domain.Region;
|
||||||
import org.jclouds.aws.sqs.domain.Queue;
|
import org.jclouds.aws.sqs.domain.Queue;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
|
import org.jclouds.http.Payloads;
|
||||||
import org.jclouds.http.functions.ParseSax;
|
import org.jclouds.http.functions.ParseSax;
|
||||||
import org.jclouds.http.functions.ParseSax.Factory;
|
import org.jclouds.http.functions.ParseSax.Factory;
|
||||||
import org.jclouds.http.functions.config.ParserModule;
|
import org.jclouds.http.functions.config.ParserModule;
|
||||||
|
@ -121,7 +122,8 @@ public class ListQueuesResponseHandlerTest extends PerformanceTest {
|
||||||
|
|
||||||
public void testRegex() {
|
public void testRegex() {
|
||||||
try {
|
try {
|
||||||
assertEquals(handler.apply(new HttpResponse(supplier.getInput())), expected);
|
assertEquals(handler.apply(new HttpResponse(200, "ok", Payloads.newPayload(supplier
|
||||||
|
.getInput()))), expected);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Throwables.propagate(e);
|
Throwables.propagate(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,22 +138,6 @@ public class AzureBlobImpl extends PayloadEnclosingImpl implements AzureBlob, Co
|
||||||
public SetMetadataPropertiesPayload(Payload delegate, MutableBlobProperties properties) {
|
public SetMetadataPropertiesPayload(Payload delegate, MutableBlobProperties properties) {
|
||||||
super(delegate);
|
super(delegate);
|
||||||
this.properties = properties;
|
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
|
@Override
|
||||||
|
@ -185,13 +169,6 @@ public class AzureBlobImpl extends PayloadEnclosingImpl implements AzureBlob, Co
|
||||||
this.blob = blob;
|
this.blob = blob;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setContentMD5(byte[] md5) {
|
|
||||||
super.setContentMD5(md5);
|
|
||||||
if (canSetPayload())
|
|
||||||
blob.getPayload().setContentMD5(md5);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setContentType(String type) {
|
public void setContentType(String type) {
|
||||||
super.setContentType(type);
|
super.setContentType(type);
|
||||||
|
@ -199,13 +176,6 @@ public class AzureBlobImpl extends PayloadEnclosingImpl implements AzureBlob, Co
|
||||||
blob.getPayload().setContentType(type);
|
blob.getPayload().setContentType(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setContentLength(Long size) {
|
|
||||||
super.setContentLength(size);
|
|
||||||
if (canSetPayload())
|
|
||||||
blob.getPayload().setContentLength(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean canSetPayload() {
|
private boolean canSetPayload() {
|
||||||
return blob != null && blob.getPayload() != null;
|
return blob != null && blob.getPayload() != null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,10 +20,9 @@ package org.jclouds.azure.storage.blob.functions;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
|
||||||
|
|
||||||
import org.jclouds.azure.storage.blob.domain.AzureBlob;
|
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.http.HttpResponse;
|
||||||
import org.jclouds.rest.InvocationContext;
|
import org.jclouds.rest.InvocationContext;
|
||||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||||
|
@ -41,49 +40,21 @@ public class ParseBlobFromHeadersAndHttpContent implements Function<HttpResponse
|
||||||
InvocationContext {
|
InvocationContext {
|
||||||
|
|
||||||
private final ParseBlobPropertiesFromHeaders metadataParser;
|
private final ParseBlobPropertiesFromHeaders metadataParser;
|
||||||
private final AzureBlob.Factory objectProvider;
|
private final AzureBlob.Factory blobFactory;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public ParseBlobFromHeadersAndHttpContent(ParseBlobPropertiesFromHeaders metadataParser,
|
public ParseBlobFromHeadersAndHttpContent(ParseBlobPropertiesFromHeaders metadataParser,
|
||||||
AzureBlob.Factory objectProvider) {
|
AzureBlob.Factory blobFactory) {
|
||||||
this.metadataParser = metadataParser;
|
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) {
|
public AzureBlob apply(HttpResponse from) {
|
||||||
AzureBlob object = objectProvider.create(metadataParser.apply(from));
|
MutableBlobProperties metadata = metadataParser.apply(from);
|
||||||
object.getAllHeaders().putAll(from.getHeaders());
|
AzureBlob blob = blobFactory.create(metadata);
|
||||||
|
blob.getAllHeaders().putAll(from.getHeaders());
|
||||||
if (from.getContent() != null) {
|
blob.setPayload(from.getPayload());
|
||||||
object.setPayload(from.getContent());
|
return blob;
|
||||||
} 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setContext(GeneratedHttpRequest<?> request) {
|
public void setContext(GeneratedHttpRequest<?> request) {
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.azure.storage.blob.functions;
|
package org.jclouds.azure.storage.blob.functions;
|
||||||
|
|
||||||
|
import static org.jclouds.http.HttpUtils.attemptToParseSizeAndRangeFromHeaders;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
|
|
||||||
|
@ -56,10 +58,7 @@ public class ParseBlobPropertiesFromHeaders implements
|
||||||
public MutableBlobProperties apply(HttpResponse from) {
|
public MutableBlobProperties apply(HttpResponse from) {
|
||||||
BlobMetadata base = blobMetadataParser.apply(from);
|
BlobMetadata base = blobMetadataParser.apply(from);
|
||||||
MutableBlobProperties to = blobToBlobProperties.apply(base);
|
MutableBlobProperties to = blobToBlobProperties.apply(base);
|
||||||
if (from.getFirstHeaderOrNull("Content-Range") != null) {
|
to.setContentLength(attemptToParseSizeAndRangeFromHeaders(from));
|
||||||
String range = from.getFirstHeaderOrNull("Content-Range");
|
|
||||||
to.setContentLength(Long.parseLong(range.split("/")[1]));
|
|
||||||
}
|
|
||||||
to.setContentLanguage(from.getFirstHeaderOrNull(HttpHeaders.CONTENT_LANGUAGE));
|
to.setContentLanguage(from.getFirstHeaderOrNull(HttpHeaders.CONTENT_LANGUAGE));
|
||||||
to.setContentEncoding(from.getFirstHeaderOrNull(HttpHeaders.CONTENT_ENCODING));
|
to.setContentEncoding(from.getFirstHeaderOrNull(HttpHeaders.CONTENT_ENCODING));
|
||||||
return to;
|
return to;
|
||||||
|
|
|
@ -20,7 +20,6 @@ package org.jclouds.azure.storage.filters;
|
||||||
|
|
||||||
import static org.jclouds.util.Patterns.NEWLINE_PATTERN;
|
import static org.jclouds.util.Patterns.NEWLINE_PATTERN;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
@ -54,14 +53,15 @@ import com.google.common.annotations.VisibleForTesting;
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
public class SharedKeyLiteAuthentication implements HttpRequestFilter {
|
public class SharedKeyLiteAuthentication implements HttpRequestFilter {
|
||||||
private final String[] firstHeadersToSign = new String[] { "Content-MD5",
|
private final String[] firstHeadersToSign = new String[] { HttpHeaders.DATE };
|
||||||
HttpHeaders.CONTENT_TYPE, HttpHeaders.DATE };
|
|
||||||
|
|
||||||
private final SignatureWire signatureWire;
|
private final SignatureWire signatureWire;
|
||||||
private final String identity;
|
private final String identity;
|
||||||
private final byte[] key;
|
private final byte[] key;
|
||||||
private final Provider<String> timeStampProvider;
|
private final Provider<String> timeStampProvider;
|
||||||
private final EncryptionService encryptionService;
|
private final EncryptionService encryptionService;
|
||||||
|
private final HttpUtils utils;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
@Named(Constants.LOGGER_SIGNATURE)
|
@Named(Constants.LOGGER_SIGNATURE)
|
||||||
Logger signatureLog = Logger.NULL;
|
Logger signatureLog = Logger.NULL;
|
||||||
|
@ -70,8 +70,10 @@ public class SharedKeyLiteAuthentication implements HttpRequestFilter {
|
||||||
public SharedKeyLiteAuthentication(SignatureWire signatureWire,
|
public SharedKeyLiteAuthentication(SignatureWire signatureWire,
|
||||||
@Named(Constants.PROPERTY_IDENTITY) String identity,
|
@Named(Constants.PROPERTY_IDENTITY) String identity,
|
||||||
@Named(Constants.PROPERTY_CREDENTIAL) String encodedKey,
|
@Named(Constants.PROPERTY_CREDENTIAL) String encodedKey,
|
||||||
@TimeStamp Provider<String> timeStampProvider, EncryptionService encryptionService) {
|
@TimeStamp Provider<String> timeStampProvider, EncryptionService encryptionService,
|
||||||
|
HttpUtils utils) {
|
||||||
this.encryptionService = encryptionService;
|
this.encryptionService = encryptionService;
|
||||||
|
this.utils = utils;
|
||||||
this.signatureWire = signatureWire;
|
this.signatureWire = signatureWire;
|
||||||
this.identity = identity;
|
this.identity = identity;
|
||||||
this.key = encryptionService.fromBase64(encodedKey);
|
this.key = encryptionService.fromBase64(encodedKey);
|
||||||
|
@ -82,14 +84,15 @@ public class SharedKeyLiteAuthentication implements HttpRequestFilter {
|
||||||
replaceDateHeader(request);
|
replaceDateHeader(request);
|
||||||
String toSign = createStringToSign(request);
|
String toSign = createStringToSign(request);
|
||||||
calculateAndReplaceAuthHeader(request, toSign);
|
calculateAndReplaceAuthHeader(request, toSign);
|
||||||
HttpUtils.logRequest(signatureLog, request, "<<");
|
utils.logRequest(signatureLog, request, "<<");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String createStringToSign(HttpRequest request) {
|
public String createStringToSign(HttpRequest request) {
|
||||||
HttpUtils.logRequest(signatureLog, request, ">>");
|
utils.logRequest(signatureLog, request, ">>");
|
||||||
StringBuilder buffer = new StringBuilder();
|
StringBuilder buffer = new StringBuilder();
|
||||||
// re-sign the request
|
// re-sign the request
|
||||||
appendMethod(request, buffer);
|
appendMethod(request, buffer);
|
||||||
|
appendPayloadMetadata(request, buffer);
|
||||||
appendHttpHeaders(request, buffer);
|
appendHttpHeaders(request, buffer);
|
||||||
appendCanonicalizedHeaders(request, buffer);
|
appendCanonicalizedHeaders(request, buffer);
|
||||||
appendCanonicalizedResource(request, buffer);
|
appendCanonicalizedResource(request, buffer);
|
||||||
|
@ -98,6 +101,15 @@ public class SharedKeyLiteAuthentication implements HttpRequestFilter {
|
||||||
return buffer.toString();
|
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)
|
private void calculateAndReplaceAuthHeader(HttpRequest request, String toSign)
|
||||||
throws HttpException {
|
throws HttpException {
|
||||||
String signature = signString(toSign);
|
String signature = signString(toSign);
|
||||||
|
@ -142,7 +154,7 @@ public class SharedKeyLiteAuthentication implements HttpRequestFilter {
|
||||||
|
|
||||||
private void appendHttpHeaders(HttpRequest request, StringBuilder toSign) {
|
private void appendHttpHeaders(HttpRequest request, StringBuilder toSign) {
|
||||||
for (String header : firstHeadersToSign)
|
for (String header : firstHeadersToSign)
|
||||||
toSign.append(valueOrEmpty(request.getHeaders().get(header))).append("\n");
|
toSign.append(utils.valueOrEmpty(request.getHeaders().get(header))).append("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@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;
|
package org.jclouds.azure.storage.handlers;
|
||||||
|
|
||||||
|
import static org.jclouds.http.HttpUtils.releasePayload;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
@ -38,8 +40,6 @@ import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.rest.AuthorizationException;
|
import org.jclouds.rest.AuthorizationException;
|
||||||
import org.jclouds.util.Utils;
|
import org.jclouds.util.Utils;
|
||||||
|
|
||||||
import com.google.common.io.Closeables;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This will parse and set an appropriate exception on the command object.
|
* 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);
|
error) : new HttpResponseException(command, response);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
Closeables.closeQuietly(response.getContent());
|
releasePayload(response);
|
||||||
command.setException(exception);
|
command.setException(exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AzureStorageError parseErrorFromContentOrNull(HttpCommand command, HttpResponse response) {
|
AzureStorageError parseErrorFromContentOrNull(HttpCommand command, HttpResponse response) {
|
||||||
if (response.getContent() != null) {
|
if (response.getPayload() != null) {
|
||||||
try {
|
try {
|
||||||
String content = Utils.toStringAndClose(response.getContent());
|
String content = Utils.toStringAndClose(response.getPayload().getInput());
|
||||||
if (content != null && content.indexOf('<') >= 0)
|
if (content != null && content.indexOf('<') >= 0)
|
||||||
return utils.parseAzureStorageErrorFromContent(command, response, Utils
|
return utils.parseAzureStorageErrorFromContent(command, response, Utils
|
||||||
.toInputStream(content));
|
.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.jclouds.azure.storage.options.ListOptions.Builder.maxResults;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import java.lang.reflect.Array;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
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.ParseContainerPropertiesFromHeaders;
|
||||||
import org.jclouds.azure.storage.blob.functions.ReturnFalseIfContainerAlreadyExists;
|
import org.jclouds.azure.storage.blob.functions.ReturnFalseIfContainerAlreadyExists;
|
||||||
import org.jclouds.azure.storage.blob.options.CreateContainerOptions;
|
import org.jclouds.azure.storage.blob.options.CreateContainerOptions;
|
||||||
import org.jclouds.azure.storage.blob.options.ListBlobsOptions;
|
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.filters.SharedKeyLiteAuthentication;
|
||||||
import org.jclouds.azure.storage.options.ListOptions;
|
import org.jclouds.azure.storage.options.ListOptions;
|
||||||
import org.jclouds.blobstore.functions.ReturnNullOnContainerNotFound;
|
import org.jclouds.blobstore.functions.ReturnNullOnContainerNotFound;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.functions.CloseContentAndReturn;
|
|
||||||
import org.jclouds.http.functions.ParseSax;
|
import org.jclouds.http.functions.ParseSax;
|
||||||
|
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||||
import org.jclouds.http.functions.ReturnTrueIf2xx;
|
import org.jclouds.http.functions.ReturnTrueIf2xx;
|
||||||
import org.jclouds.http.functions.ReturnTrueOn404;
|
import org.jclouds.http.functions.ReturnTrueOn404;
|
||||||
import org.jclouds.rest.RestClientTest;
|
import org.jclouds.rest.RestClientTest;
|
||||||
import org.jclouds.rest.RestContextFactory;
|
import org.jclouds.rest.RestContextFactory;
|
||||||
import org.jclouds.rest.RestContextFactory.ContextSpec;
|
import org.jclouds.rest.RestContextFactory.ContextSpec;
|
||||||
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
|
|
||||||
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
|
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
|
||||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
@ -63,279 +60,210 @@ import com.google.inject.TypeLiteral;
|
||||||
@Test(groups = "unit", testName = "azureblob.AzureBlobAsyncClientTest")
|
@Test(groups = "unit", testName = "azureblob.AzureBlobAsyncClientTest")
|
||||||
public class AzureBlobAsyncClientTest extends RestClientTest<AzureBlobAsyncClient> {
|
public class AzureBlobAsyncClientTest extends RestClientTest<AzureBlobAsyncClient> {
|
||||||
|
|
||||||
public void testListContainers() throws SecurityException, NoSuchMethodException {
|
public void testListContainers() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
Method method = AzureBlobAsyncClient.class.getMethod("listContainers", Array.newInstance(
|
Method method = AzureBlobAsyncClient.class.getMethod("listContainers", ListOptions[].class);
|
||||||
ListOptions.class, 0).getClass());
|
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 {
|
public void testListContainersOptions() throws SecurityException, NoSuchMethodException,
|
||||||
Method method = AzureBlobAsyncClient.class.getMethod("listContainers", Array.newInstance(
|
IOException {
|
||||||
ListOptions.class, 0).getClass());
|
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(
|
assertRequestLineEquals(
|
||||||
"marker").prefix("prefix") });
|
request,
|
||||||
assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net");
|
"GET https://identity.blob.core.windows.net/?comp=list&maxresults=1&marker=marker&prefix=prefix HTTP/1.1");
|
||||||
assertEquals(request.getEndpoint().getPath(), "/");
|
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||||
assert request.getEndpoint().getQuery().contains("comp=list");
|
assertPayloadEquals(request, null, null, false);
|
||||||
assert request.getEndpoint().getQuery().contains("marker=marker");
|
|
||||||
assert request.getEndpoint().getQuery().contains("maxresults=1");
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assert request.getEndpoint().getQuery().contains("prefix=prefix");
|
assertSaxResponseParserClassEquals(method, AccountNameEnumerationResultsHandler.class);
|
||||||
assertEquals(request.getMethod(), HttpMethod.GET);
|
assertExceptionParserClassEquals(method, null);
|
||||||
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 testCreateContainer() throws SecurityException, NoSuchMethodException {
|
public void testCreateContainer() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
Method method = AzureBlobAsyncClient.class.getMethod("createContainer", String.class, Array
|
Method method = AzureBlobAsyncClient.class.getMethod("createContainer", String.class,
|
||||||
.newInstance(CreateContainerOptions.class, 0).getClass());
|
CreateContainerOptions[].class);
|
||||||
|
HttpRequest request = processor.createRequest(method, "container");
|
||||||
|
|
||||||
HttpRequest request = processor.createRequest(method, new Object[] { "container" });
|
assertRequestLineEquals(request,
|
||||||
assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net");
|
"PUT https://identity.blob.core.windows.net/container?restype=container HTTP/1.1");
|
||||||
assertEquals(request.getEndpoint().getPath(), "/container");
|
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||||
assertEquals(request.getEndpoint().getQuery(), "restype=container");
|
assertPayloadEquals(request, null, null, false);
|
||||||
assertEquals(request.getMethod(), HttpMethod.PUT);
|
|
||||||
assertEquals(request.getHeaders().size(), 2);
|
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
|
||||||
assertEquals(request.getHeaders().get("x-ms-version"), Collections
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
.singletonList("2009-09-19"));
|
assertExceptionParserClassEquals(method, ReturnFalseIfContainerAlreadyExists.class);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDeleteContainer() throws SecurityException, NoSuchMethodException {
|
public void testDeleteContainer() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
Method method = AzureBlobAsyncClient.class.getMethod("deleteContainer", String.class);
|
Method method = AzureBlobAsyncClient.class.getMethod("deleteContainer", String.class);
|
||||||
|
HttpRequest request = processor.createRequest(method, "container");
|
||||||
|
|
||||||
HttpRequest request = processor.createRequest(method, new Object[] { "container" });
|
assertRequestLineEquals(request,
|
||||||
assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net");
|
"DELETE https://identity.blob.core.windows.net/container?restype=container HTTP/1.1");
|
||||||
assertEquals(request.getEndpoint().getPath(), "/container");
|
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||||
assertEquals(request.getEndpoint().getQuery(), "restype=container");
|
assertPayloadEquals(request, null, null, false);
|
||||||
assertEquals(request.getMethod(), HttpMethod.DELETE);
|
|
||||||
assertEquals(request.getHeaders().size(), 1);
|
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||||
assertEquals(request.getHeaders().get("x-ms-version"), Collections
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
.singletonList("2009-09-19"));
|
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
|
||||||
assertEquals(processor.createResponseParser(method, request).getClass(),
|
|
||||||
CloseContentAndReturn.class);
|
|
||||||
// TODO check generic type of response parser
|
|
||||||
assertEquals(processor
|
|
||||||
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
|
|
||||||
ReturnVoidOnNotFoundOr404.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCreateContainerOptions() throws SecurityException, NoSuchMethodException {
|
public void testCreateContainerOptions() throws SecurityException, NoSuchMethodException,
|
||||||
Method method = AzureBlobAsyncClient.class.getMethod("createContainer", String.class, Array
|
IOException {
|
||||||
.newInstance(CreateContainerOptions.class, 0).getClass());
|
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",
|
assertRequestLineEquals(request,
|
||||||
withPublicAcl().withMetadata(ImmutableMultimap.of("foo", "bar")) });
|
"PUT https://identity.blob.core.windows.net/container?restype=container HTTP/1.1");
|
||||||
assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net");
|
assertNonPayloadHeadersEqual(request,
|
||||||
assertEquals(request.getEndpoint().getPath(), "/container");
|
"x-ms-meta-foo: bar\nx-ms-prop-publicaccess: true\nx-ms-version: 2009-09-19\n");
|
||||||
assertEquals(request.getEndpoint().getQuery(), "restype=container");
|
assertPayloadEquals(request, null, null, false);
|
||||||
assertEquals(request.getMethod(), HttpMethod.PUT);
|
|
||||||
assertEquals(request.getHeaders().size(), 4);
|
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
|
||||||
assertEquals(request.getHeaders().get("x-ms-version"), Collections
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
.singletonList("2009-09-19"));
|
assertExceptionParserClassEquals(method, ReturnFalseIfContainerAlreadyExists.class);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCreateRootContainer() throws SecurityException, NoSuchMethodException {
|
public void testCreateRootContainer() throws SecurityException, NoSuchMethodException,
|
||||||
Method method = AzureBlobAsyncClient.class.getMethod("createRootContainer", Array
|
IOException {
|
||||||
.newInstance(CreateContainerOptions.class, 0).getClass());
|
Method method = AzureBlobAsyncClient.class.getMethod("createRootContainer",
|
||||||
|
CreateContainerOptions[].class);
|
||||||
|
|
||||||
HttpRequest request = processor.createRequest(method, new Object[] {});
|
HttpRequest request = processor.createRequest(method);
|
||||||
assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net");
|
|
||||||
assertEquals(request.getEndpoint().getPath(), "/$root");
|
assertRequestLineEquals(request,
|
||||||
assertEquals(request.getEndpoint().getQuery(), "restype=container");
|
"PUT https://identity.blob.core.windows.net/%24root?restype=container HTTP/1.1");
|
||||||
assertEquals(request.getMethod(), HttpMethod.PUT);
|
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||||
assertEquals(request.getHeaders().size(), 2);
|
assertPayloadEquals(request, null, null, false);
|
||||||
assertEquals(request.getHeaders().get("x-ms-version"), Collections
|
|
||||||
.singletonList("2009-09-19"));
|
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
|
||||||
assertEquals(request.getHeaders().get("Content-Length"), Collections.singletonList("0"));
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertEquals(processor.createResponseParser(method, request).getClass(),
|
assertExceptionParserClassEquals(method, ReturnFalseIfContainerAlreadyExists.class);
|
||||||
ReturnTrueIf2xx.class);
|
|
||||||
// TODO check generic type of response parser
|
|
||||||
assertEquals(processor
|
|
||||||
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
|
|
||||||
ReturnFalseIfContainerAlreadyExists.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDeleteRootContainer() throws SecurityException, NoSuchMethodException {
|
public void testDeleteRootContainer() throws SecurityException, NoSuchMethodException,
|
||||||
|
IOException {
|
||||||
Method method = AzureBlobAsyncClient.class.getMethod("deleteRootContainer");
|
Method method = AzureBlobAsyncClient.class.getMethod("deleteRootContainer");
|
||||||
|
HttpRequest request = processor.createRequest(method);
|
||||||
|
|
||||||
HttpRequest request = processor.createRequest(method, new Object[] {});
|
assertRequestLineEquals(request,
|
||||||
assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net");
|
"DELETE https://identity.blob.core.windows.net/%24root?restype=container HTTP/1.1");
|
||||||
assertEquals(request.getEndpoint().getPath(), "/$root");
|
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||||
assertEquals(request.getEndpoint().getQuery(), "restype=container");
|
assertPayloadEquals(request, null, null, false);
|
||||||
assertEquals(request.getMethod(), HttpMethod.DELETE);
|
|
||||||
assertEquals(request.getHeaders().size(), 1);
|
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||||
assertEquals(request.getHeaders().get("x-ms-version"), Collections
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
.singletonList("2009-09-19"));
|
assertExceptionParserClassEquals(method, ReturnTrueOn404.class);
|
||||||
assertEquals(processor.createResponseParser(method, request).getClass(),
|
|
||||||
CloseContentAndReturn.class);
|
|
||||||
// TODO check generic type of response parser
|
|
||||||
assertEquals(processor
|
|
||||||
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
|
|
||||||
ReturnTrueOn404.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCreateRootContainerOptions() throws SecurityException, NoSuchMethodException {
|
public void testCreateRootContainerOptions() throws SecurityException, NoSuchMethodException,
|
||||||
Method method = AzureBlobAsyncClient.class.getMethod("createRootContainer", Array
|
IOException {
|
||||||
.newInstance(CreateContainerOptions.class, 0).getClass());
|
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()
|
assertRequestLineEquals(request,
|
||||||
.withMetadata(ImmutableMultimap.of("foo", "bar")) });
|
"PUT https://identity.blob.core.windows.net/%24root?restype=container HTTP/1.1");
|
||||||
assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net");
|
assertNonPayloadHeadersEqual(request,
|
||||||
assertEquals(request.getEndpoint().getPath(), "/$root");
|
"x-ms-meta-foo: bar\nx-ms-prop-publicaccess: true\nx-ms-version: 2009-09-19\n");
|
||||||
assertEquals(request.getEndpoint().getQuery(), "restype=container");
|
assertPayloadEquals(request, null, null, false);
|
||||||
assertEquals(request.getMethod(), HttpMethod.PUT);
|
|
||||||
assertEquals(request.getHeaders().size(), 4);
|
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
|
||||||
assertEquals(request.getHeaders().get("x-ms-version"), Collections
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
.singletonList("2009-09-19"));
|
assertExceptionParserClassEquals(method, ReturnFalseIfContainerAlreadyExists.class);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testListBlobs() throws SecurityException, NoSuchMethodException {
|
public void testListBlobs() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
Method method = AzureBlobAsyncClient.class.getMethod("listBlobs", String.class, Array
|
Method method = AzureBlobAsyncClient.class.getMethod("listBlobs", String.class,
|
||||||
.newInstance(ListBlobsOptions.class, 0).getClass());
|
ListBlobsOptions[].class);
|
||||||
|
HttpRequest request = processor.createRequest(method, "container");
|
||||||
|
|
||||||
HttpRequest request = processor.createRequest(method, new Object[] { "container" });
|
assertRequestLineEquals(request,
|
||||||
assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net");
|
"GET https://identity.blob.core.windows.net/container?restype=container&comp=list HTTP/1.1");
|
||||||
assertEquals(request.getEndpoint().getPath(), "/container");
|
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||||
assertEquals(request.getEndpoint().getQuery(), "restype=container&comp=list");
|
assertPayloadEquals(request, null, null, false);
|
||||||
assertEquals(request.getMethod(), HttpMethod.GET);
|
|
||||||
assertEquals(request.getHeaders().size(), 1);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertEquals(request.getHeaders().get("x-ms-version"), Collections
|
assertSaxResponseParserClassEquals(method, ContainerNameEnumerationResultsHandler.class);
|
||||||
.singletonList("2009-09-19"));
|
assertExceptionParserClassEquals(method, null);
|
||||||
assertEquals(processor.createResponseParser(method, request).getClass(), ParseSax.class);
|
|
||||||
// TODO check generic type of response parser
|
|
||||||
assertEquals(processor
|
|
||||||
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
|
|
||||||
MapHttp4xxCodesToExceptions.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testListRootBlobs() throws SecurityException, NoSuchMethodException {
|
public void testListRootBlobs() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
Method method = AzureBlobAsyncClient.class.getMethod("listBlobs", Array.newInstance(
|
Method method = AzureBlobAsyncClient.class.getMethod("listBlobs", ListBlobsOptions[].class);
|
||||||
ListBlobsOptions.class, 0).getClass());
|
HttpRequest request = processor.createRequest(method);
|
||||||
|
|
||||||
HttpRequest request = processor.createRequest(method, new Object[] {});
|
assertRequestLineEquals(request,
|
||||||
assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net");
|
"GET https://identity.blob.core.windows.net/%24root?restype=container&comp=list HTTP/1.1");
|
||||||
assertEquals(request.getEndpoint().getPath(), "/$root");
|
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||||
assertEquals(request.getEndpoint().getQuery(), "restype=container&comp=list");
|
assertPayloadEquals(request, null, null, false);
|
||||||
assertEquals(request.getMethod(), HttpMethod.GET);
|
|
||||||
assertEquals(request.getHeaders().size(), 1);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertEquals(request.getHeaders().get("x-ms-version"), Collections
|
assertSaxResponseParserClassEquals(method, ContainerNameEnumerationResultsHandler.class);
|
||||||
.singletonList("2009-09-19"));
|
assertExceptionParserClassEquals(method, null);
|
||||||
assertEquals(processor.createResponseParser(method, request).getClass(), ParseSax.class);
|
|
||||||
// TODO check generic type of response parser
|
|
||||||
assertEquals(processor
|
|
||||||
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
|
|
||||||
MapHttp4xxCodesToExceptions.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testContainerProperties() throws SecurityException, NoSuchMethodException {
|
public void testContainerProperties() throws SecurityException, NoSuchMethodException,
|
||||||
|
IOException {
|
||||||
Method method = AzureBlobAsyncClient.class.getMethod("getContainerProperties", String.class);
|
Method method = AzureBlobAsyncClient.class.getMethod("getContainerProperties", String.class);
|
||||||
|
HttpRequest request = processor.createRequest(method, "container");
|
||||||
|
|
||||||
HttpRequest request = processor.createRequest(method, new Object[] { "container" });
|
assertRequestLineEquals(request,
|
||||||
assertEquals(request.getEndpoint().getHost(), "identity.blob.core.windows.net");
|
"HEAD https://identity.blob.core.windows.net/container?restype=container HTTP/1.1");
|
||||||
assertEquals(request.getEndpoint().getPath(), "/container");
|
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||||
assertEquals(request.getEndpoint().getQuery(), "restype=container");
|
assertPayloadEquals(request, null, null, false);
|
||||||
assertEquals(request.getMethod(), HttpMethod.HEAD);
|
|
||||||
assertEquals(request.getHeaders().size(), 1);
|
assertResponseParserClassEquals(method, request, ParseContainerPropertiesFromHeaders.class);
|
||||||
assertEquals(request.getHeaders().get("x-ms-version"), Collections
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
.singletonList("2009-09-19"));
|
assertExceptionParserClassEquals(method, ReturnNullOnContainerNotFound.class);
|
||||||
assertEquals(processor.createResponseParser(method, request).getClass(),
|
|
||||||
ParseContainerPropertiesFromHeaders.class);
|
|
||||||
assertEquals(processor
|
|
||||||
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
|
|
||||||
ReturnNullOnContainerNotFound.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSetResourceMetadata() throws SecurityException, NoSuchMethodException {
|
public void testSetResourceMetadata() throws SecurityException, NoSuchMethodException,
|
||||||
|
IOException {
|
||||||
Method method = AzureBlobAsyncClient.class.getMethod("setResourceMetadata", String.class,
|
Method method = AzureBlobAsyncClient.class.getMethod("setResourceMetadata", String.class,
|
||||||
Map.class);
|
Map.class);
|
||||||
|
|
||||||
HttpRequest request = processor.createRequest(method, new Object[] { "container",
|
HttpRequest request = processor.createRequest(method, new Object[] { "container",
|
||||||
ImmutableMap.of("key", "value") });
|
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(),
|
assertRequestLineEquals(request,
|
||||||
CloseContentAndReturn.class);
|
"PUT https://identity.blob.core.windows.net/container?restype=container&comp=metadata HTTP/1.1");
|
||||||
assertEquals(processor
|
assertNonPayloadHeadersEqual(request, "x-ms-meta-key: value\nx-ms-version: 2009-09-19\n");
|
||||||
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
|
assertPayloadEquals(request, null, null, false);
|
||||||
MapHttp4xxCodesToExceptions.class);
|
|
||||||
|
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,
|
Method method = AzureBlobAsyncClient.class.getMethod("setBlobMetadata", String.class,
|
||||||
String.class, Map.class);
|
String.class, Map.class);
|
||||||
HttpRequest request = processor.createRequest(method, new Object[] { "container", "blob",
|
HttpRequest request = processor.createRequest(method, "container", "blob", ImmutableMap.of(
|
||||||
ImmutableMap.of("key", "value") });
|
"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"));
|
|
||||||
|
|
||||||
assertEquals(processor.createResponseParser(method, request).getClass(),
|
assertRequestLineEquals(request,
|
||||||
CloseContentAndReturn.class);
|
"PUT https://identity.blob.core.windows.net/container/blob?comp=metadata HTTP/1.1");
|
||||||
assertEquals(processor
|
assertNonPayloadHeadersEqual(request, "x-ms-meta-key: value\nx-ms-version: 2009-09-19\n");
|
||||||
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
|
assertPayloadEquals(request, null, null, false);
|
||||||
MapHttp4xxCodesToExceptions.class);
|
|
||||||
|
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||||
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
assertExceptionParserClassEquals(method, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -26,7 +26,7 @@ import org.jclouds.blobstore.internal.BlobStoreContextImpl;
|
||||||
import org.jclouds.blobstore.strategy.ContainsValueInListStrategy;
|
import org.jclouds.blobstore.strategy.ContainsValueInListStrategy;
|
||||||
import org.jclouds.logging.config.NullLoggingModule;
|
import org.jclouds.logging.config.NullLoggingModule;
|
||||||
import org.jclouds.rest.RestContextFactory;
|
import org.jclouds.rest.RestContextFactory;
|
||||||
import org.jclouds.rest.RestClientTest.MockModule;
|
import org.jclouds.rest.BaseRestClientTest.MockModule;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
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.AccountNameEnumerationResultsHandler;
|
||||||
import org.jclouds.azure.storage.queue.xml.QueueMessagesListHandler;
|
import org.jclouds.azure.storage.queue.xml.QueueMessagesListHandler;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.functions.CloseContentAndReturn;
|
|
||||||
import org.jclouds.http.functions.ParseSax;
|
import org.jclouds.http.functions.ParseSax;
|
||||||
|
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||||
import org.jclouds.http.functions.ReturnTrueIf2xx;
|
import org.jclouds.http.functions.ReturnTrueIf2xx;
|
||||||
import org.jclouds.rest.RestClientTest;
|
import org.jclouds.rest.RestClientTest;
|
||||||
import org.jclouds.rest.RestContextFactory;
|
import org.jclouds.rest.RestContextFactory;
|
||||||
|
@ -63,8 +63,8 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
|
||||||
|
|
||||||
assertRequestLineEquals(request,
|
assertRequestLineEquals(request,
|
||||||
"GET https://identity.queue.core.windows.net/myqueue/messages HTTP/1.1");
|
"GET https://identity.queue.core.windows.net/myqueue/messages HTTP/1.1");
|
||||||
assertHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||||
assertPayloadEquals(request, null);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, QueueMessagesListHandler.class);
|
assertSaxResponseParserClassEquals(method, QueueMessagesListHandler.class);
|
||||||
|
@ -83,8 +83,8 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
|
||||||
assertRequestLineEquals(
|
assertRequestLineEquals(
|
||||||
request,
|
request,
|
||||||
"GET https://identity.queue.core.windows.net/myqueue/messages?numofmessages=1&visibilitytimeout=30 HTTP/1.1");
|
"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");
|
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||||
assertPayloadEquals(request, null);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, QueueMessagesListHandler.class);
|
assertSaxResponseParserClassEquals(method, QueueMessagesListHandler.class);
|
||||||
|
@ -99,8 +99,8 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
|
||||||
|
|
||||||
assertRequestLineEquals(request,
|
assertRequestLineEquals(request,
|
||||||
"GET https://identity.queue.core.windows.net/?comp=list HTTP/1.1");
|
"GET https://identity.queue.core.windows.net/?comp=list HTTP/1.1");
|
||||||
assertHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||||
assertPayloadEquals(request, null);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, AccountNameEnumerationResultsHandler.class);
|
assertSaxResponseParserClassEquals(method, AccountNameEnumerationResultsHandler.class);
|
||||||
|
@ -117,8 +117,8 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
|
||||||
assertRequestLineEquals(
|
assertRequestLineEquals(
|
||||||
request,
|
request,
|
||||||
"GET https://identity.queue.core.windows.net/?comp=list&maxresults=1&marker=marker&prefix=prefix HTTP/1.1");
|
"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");
|
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||||
assertPayloadEquals(request, null);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||||
assertSaxResponseParserClassEquals(method, AccountNameEnumerationResultsHandler.class);
|
assertSaxResponseParserClassEquals(method, AccountNameEnumerationResultsHandler.class);
|
||||||
|
@ -133,8 +133,8 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
|
||||||
HttpRequest request = processor.createRequest(method, "queue");
|
HttpRequest request = processor.createRequest(method, "queue");
|
||||||
|
|
||||||
assertRequestLineEquals(request, "PUT https://identity.queue.core.windows.net/queue HTTP/1.1");
|
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");
|
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||||
assertPayloadEquals(request, null);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
|
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
@ -152,9 +152,8 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
|
||||||
.of("foo", "bar")));
|
.of("foo", "bar")));
|
||||||
|
|
||||||
assertRequestLineEquals(request, "PUT https://identity.queue.core.windows.net/queue HTTP/1.1");
|
assertRequestLineEquals(request, "PUT https://identity.queue.core.windows.net/queue HTTP/1.1");
|
||||||
assertHeadersEqual(request,
|
assertNonPayloadHeadersEqual(request, "x-ms-meta-foo: bar\nx-ms-version: 2009-09-19\n");
|
||||||
"Content-Length: 0\nx-ms-meta-foo: bar\nx-ms-version: 2009-09-19\n");
|
assertPayloadEquals(request, null, null, false);
|
||||||
assertPayloadEquals(request, null);
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
|
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
@ -170,10 +169,10 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
|
||||||
|
|
||||||
assertRequestLineEquals(request,
|
assertRequestLineEquals(request,
|
||||||
"DELETE https://identity.queue.core.windows.net/queue HTTP/1.1");
|
"DELETE https://identity.queue.core.windows.net/queue HTTP/1.1");
|
||||||
assertHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||||
assertPayloadEquals(request, null);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
@ -189,12 +188,12 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
|
||||||
|
|
||||||
assertRequestLineEquals(request,
|
assertRequestLineEquals(request,
|
||||||
"POST https://identity.queue.core.windows.net/queue/messages HTTP/1.1");
|
"POST https://identity.queue.core.windows.net/queue/messages HTTP/1.1");
|
||||||
assertHeadersEqual(request,
|
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||||
"Content-Length: 63\nContent-Type: application/unknown\nx-ms-version: 2009-09-19\n");
|
|
||||||
assertPayloadEquals(request,
|
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);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
@ -209,12 +208,12 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
|
||||||
|
|
||||||
assertRequestLineEquals(request,
|
assertRequestLineEquals(request,
|
||||||
"POST https://identity.queue.core.windows.net/queue/messages?messagettl=3 HTTP/1.1");
|
"POST https://identity.queue.core.windows.net/queue/messages?messagettl=3 HTTP/1.1");
|
||||||
assertHeadersEqual(request,
|
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||||
"Content-Length: 63\nContent-Type: application/unknown\nx-ms-version: 2009-09-19\n");
|
|
||||||
assertPayloadEquals(request,
|
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);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
@ -228,10 +227,10 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
|
||||||
|
|
||||||
assertRequestLineEquals(request,
|
assertRequestLineEquals(request,
|
||||||
"DELETE https://identity.queue.core.windows.net/queue/messages HTTP/1.1");
|
"DELETE https://identity.queue.core.windows.net/queue/messages HTTP/1.1");
|
||||||
assertHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
assertNonPayloadHeadersEqual(request, "x-ms-version: 2009-09-19\n");
|
||||||
assertPayloadEquals(request, null);
|
assertPayloadEquals(request, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, CloseContentAndReturn.class);
|
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
|
|
@ -73,6 +73,10 @@ Options can also be specified for extension modules
|
||||||
[blobstore]
|
[blobstore]
|
||||||
(.getContext blobstore))
|
(.getContext blobstore))
|
||||||
|
|
||||||
|
(defn blob?
|
||||||
|
[object]
|
||||||
|
(instance? Blob))
|
||||||
|
|
||||||
(defn blobstore?
|
(defn blobstore?
|
||||||
[object]
|
[object]
|
||||||
(or (instance? BlobStore object)
|
(or (instance? BlobStore object)
|
||||||
|
@ -265,22 +269,27 @@ example:
|
||||||
([blobstore container-name dir]
|
([blobstore container-name dir]
|
||||||
(.list (as-blobstore blobstore) container-name
|
(.list (as-blobstore blobstore) container-name
|
||||||
(.inDirectory (new ListContainerOptions) dir))))
|
(.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
|
(defn blob
|
||||||
"create a new blob with the specified payload"
|
"create a new blob with the specified payload"
|
||||||
([name payload]
|
([#^String name payload]
|
||||||
(blob name payload *blobstore*))
|
(blob name payload *blobstore*))
|
||||||
([name payload blobstore]
|
([#^String name payload #^BlobStore blobstore]
|
||||||
(doto (.newBlob blobstore name)
|
(doto (.newBlob blobstore name)
|
||||||
(.setPayload payload))))
|
(.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
|
(defn upload-blob
|
||||||
"Create anrepresenting text data:
|
"Create anrepresenting text data:
|
||||||
container, name, string -> etag"
|
container, name, string -> etag"
|
||||||
|
@ -288,7 +297,7 @@ container, name, string -> etag"
|
||||||
(upload-blob container-name name data *blobstore*))
|
(upload-blob container-name name data *blobstore*))
|
||||||
([container-name name data blobstore]
|
([container-name name data blobstore]
|
||||||
(put-blob container-name
|
(put-blob container-name
|
||||||
(md5-blob (blob name data) blobstore) blobstore)))
|
(md5-blob name data blobstore) blobstore)))
|
||||||
|
|
||||||
(defmulti #^{:arglists '[[container-name name target]
|
(defmulti #^{:arglists '[[container-name name target]
|
||||||
[container-name name target blobstore]]}
|
[container-name name target blobstore]]}
|
||||||
|
@ -308,7 +317,7 @@ container, name, string -> etag"
|
||||||
target (MessageDigest/getInstance "MD5"))]
|
target (MessageDigest/getInstance "MD5"))]
|
||||||
(.writeTo (.getPayload blob) digest-stream)
|
(.writeTo (.getPayload blob) digest-stream)
|
||||||
(let [digest (.digest (.getMessageDigest 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)
|
(when-not (Arrays/equals digest metadata-digest)
|
||||||
(if (<= (or retries 0) *max-retries*)
|
(if (<= (or retries 0) *max-retries*)
|
||||||
(recur container-name name target blobstore [(inc (or retries 1))])
|
(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) {
|
public static HttpResponseException returnResponseException(int code) {
|
||||||
HttpResponse response = null;
|
HttpResponse response = null;
|
||||||
response = new HttpResponse(); // TODO: Get real object URL?
|
response = new HttpResponse(code, null, null);
|
||||||
response.setStatusCode(code);
|
|
||||||
return new HttpResponseException(new HttpCommand() {
|
return new HttpResponseException(new HttpCommand() {
|
||||||
|
|
||||||
public int getRedirectCount() {
|
public int getRedirectCount() {
|
||||||
|
@ -491,6 +490,10 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
Blob blob = blobFactory.create(copy(object.getMetadata()));
|
Blob blob = blobFactory.create(copy(object.getMetadata()));
|
||||||
blob.setPayload(payload);
|
blob.setPayload(payload);
|
||||||
blob.getMetadata().setLastModified(new Date());
|
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());
|
String eTag = encryptionService.hex(payload.getContentMD5());
|
||||||
blob.getMetadata().setETag(eTag);
|
blob.getMetadata().setETag(eTag);
|
||||||
container.put(blob.getMetadata().getName(), blob);
|
container.put(blob.getMetadata().getName(), blob);
|
||||||
|
@ -499,8 +502,8 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
blob.getAllHeaders().put(HttpHeaders.LAST_MODIFIED,
|
blob.getAllHeaders().put(HttpHeaders.LAST_MODIFIED,
|
||||||
dateService.rfc822DateFormat(blob.getMetadata().getLastModified()));
|
dateService.rfc822DateFormat(blob.getMetadata().getLastModified()));
|
||||||
blob.getAllHeaders().put(HttpHeaders.ETAG, eTag);
|
blob.getAllHeaders().put(HttpHeaders.ETAG, eTag);
|
||||||
blob.getAllHeaders().put(HttpHeaders.CONTENT_TYPE, blob.getMetadata().getContentType());
|
blob.getAllHeaders().put(HttpHeaders.CONTENT_TYPE, payload.getContentType());
|
||||||
blob.getAllHeaders().put(HttpHeaders.CONTENT_LENGTH, blob.getMetadata().getSize() + "");
|
blob.getAllHeaders().put(HttpHeaders.CONTENT_LENGTH, payload.getContentLength() + "");
|
||||||
blob.getAllHeaders().put("Content-MD5", encryptionService.base64(payload.getContentMD5()));
|
blob.getAllHeaders().put("Content-MD5", encryptionService.base64(payload.getContentMD5()));
|
||||||
blob.getAllHeaders().putAll(Multimaps.forMap(blob.getMetadata().getUserMetadata()));
|
blob.getAllHeaders().putAll(Multimaps.forMap(blob.getMetadata().getUserMetadata()));
|
||||||
|
|
||||||
|
@ -543,8 +546,7 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
if (options.getIfModifiedSince() != null) {
|
if (options.getIfModifiedSince() != null) {
|
||||||
Date modifiedSince = options.getIfModifiedSince();
|
Date modifiedSince = options.getIfModifiedSince();
|
||||||
if (object.getMetadata().getLastModified().before(modifiedSince)) {
|
if (object.getMetadata().getLastModified().before(modifiedSince)) {
|
||||||
HttpResponse response = new HttpResponse();
|
HttpResponse response = new HttpResponse(304, null, null);
|
||||||
response.setStatusCode(304);
|
|
||||||
return immediateFailedFuture(new HttpResponseException(String.format(
|
return immediateFailedFuture(new HttpResponseException(String.format(
|
||||||
"%1$s is before %2$s", object.getMetadata().getLastModified(), modifiedSince),
|
"%1$s is before %2$s", object.getMetadata().getLastModified(), modifiedSince),
|
||||||
null, response));
|
null, response));
|
||||||
|
@ -554,8 +556,7 @@ public class TransientAsyncBlobStore extends BaseAsyncBlobStore {
|
||||||
if (options.getIfUnmodifiedSince() != null) {
|
if (options.getIfUnmodifiedSince() != null) {
|
||||||
Date unmodifiedSince = options.getIfUnmodifiedSince();
|
Date unmodifiedSince = options.getIfUnmodifiedSince();
|
||||||
if (object.getMetadata().getLastModified().after(unmodifiedSince)) {
|
if (object.getMetadata().getLastModified().after(unmodifiedSince)) {
|
||||||
HttpResponse response = new HttpResponse();
|
HttpResponse response = new HttpResponse(412, null, null);
|
||||||
response.setStatusCode(412);
|
|
||||||
return immediateFailedFuture(new HttpResponseException(
|
return immediateFailedFuture(new HttpResponseException(
|
||||||
String.format("%1$s is after %2$s", object.getMetadata().getLastModified(),
|
String.format("%1$s is after %2$s", object.getMetadata().getLastModified(),
|
||||||
unmodifiedSince), null, response));
|
unmodifiedSince), null, response));
|
||||||
|
|
|
@ -142,24 +142,9 @@ public class BlobImpl extends PayloadEnclosingImpl implements Blob, Comparable<B
|
||||||
public SetMetadataPropertiesPayload(Payload delegate, MutableBlobMetadata metadata) {
|
public SetMetadataPropertiesPayload(Payload delegate, MutableBlobMetadata metadata) {
|
||||||
super(delegate);
|
super(delegate);
|
||||||
this.metadata = metadata;
|
this.metadata = metadata;
|
||||||
if (metadata.getSize() != null)
|
|
||||||
setContentLength(metadata.getSize());
|
|
||||||
setContentMD5(metadata.getContentMD5());
|
|
||||||
setContentType(metadata.getContentType());
|
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
|
@Override
|
||||||
public void setContentType(String md5) {
|
public void setContentType(String md5) {
|
||||||
super.setContentType(md5);
|
super.setContentType(md5);
|
||||||
|
@ -189,13 +174,6 @@ public class BlobImpl extends PayloadEnclosingImpl implements Blob, Comparable<B
|
||||||
this.blob = blob;
|
this.blob = blob;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setContentMD5(byte[] md5) {
|
|
||||||
super.setContentMD5(md5);
|
|
||||||
if (canSetPayload())
|
|
||||||
blob.getPayload().setContentMD5(md5);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setContentType(String type) {
|
public void setContentType(String type) {
|
||||||
super.setContentType(type);
|
super.setContentType(type);
|
||||||
|
@ -203,13 +181,6 @@ public class BlobImpl extends PayloadEnclosingImpl implements Blob, Comparable<B
|
||||||
blob.getPayload().setContentType(type);
|
blob.getPayload().setContentType(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setSize(Long size) {
|
|
||||||
super.setSize(size);
|
|
||||||
if (canSetPayload())
|
|
||||||
blob.getPayload().setContentLength(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean canSetPayload() {
|
private boolean canSetPayload() {
|
||||||
return blob != null && blob.getPayload() != null;
|
return blob != null && blob.getPayload() != null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,16 +19,13 @@
|
||||||
package org.jclouds.blobstore.functions;
|
package org.jclouds.blobstore.functions;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
|
||||||
|
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.domain.MutableBlobMetadata;
|
import org.jclouds.blobstore.domain.MutableBlobMetadata;
|
||||||
import org.jclouds.http.HttpException;
|
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
import org.jclouds.rest.InvocationContext;
|
import org.jclouds.rest.InvocationContext;
|
||||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -49,44 +46,12 @@ public class ParseBlobFromHeadersAndHttpContent implements Function<HttpResponse
|
||||||
this.blobFactory = blobFactory;
|
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) {
|
public Blob apply(HttpResponse from) {
|
||||||
MutableBlobMetadata metadata = metadataParser.apply(from);
|
MutableBlobMetadata metadata = metadataParser.apply(from);
|
||||||
Blob object = blobFactory.create(metadata);
|
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.getAllHeaders().putAll(from.getHeaders());
|
||||||
|
object.setPayload(from.getPayload());
|
||||||
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setContext(GeneratedHttpRequest<?> request) {
|
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.reference.BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX;
|
||||||
import static org.jclouds.blobstore.util.BlobStoreUtils.getKeyFor;
|
import static org.jclouds.blobstore.util.BlobStoreUtils.getKeyFor;
|
||||||
|
import static org.jclouds.http.HttpUtils.attemptToParseSizeAndRangeFromHeaders;
|
||||||
|
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
@ -30,7 +31,6 @@ import javax.ws.rs.core.HttpHeaders;
|
||||||
|
|
||||||
import org.jclouds.blobstore.domain.MutableBlobMetadata;
|
import org.jclouds.blobstore.domain.MutableBlobMetadata;
|
||||||
import org.jclouds.date.DateService;
|
import org.jclouds.date.DateService;
|
||||||
import org.jclouds.encryption.EncryptionService;
|
|
||||||
import org.jclouds.http.HttpException;
|
import org.jclouds.http.HttpException;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
import org.jclouds.rest.InvocationContext;
|
import org.jclouds.rest.InvocationContext;
|
||||||
|
@ -47,17 +47,14 @@ public class ParseSystemAndUserMetadataFromHeaders implements
|
||||||
private final String metadataPrefix;
|
private final String metadataPrefix;
|
||||||
private final DateService dateParser;
|
private final DateService dateParser;
|
||||||
private final Provider<MutableBlobMetadata> metadataFactory;
|
private final Provider<MutableBlobMetadata> metadataFactory;
|
||||||
private final EncryptionService encryptionService;
|
|
||||||
private GeneratedHttpRequest<?> request;
|
private GeneratedHttpRequest<?> request;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public ParseSystemAndUserMetadataFromHeaders(Provider<MutableBlobMetadata> metadataFactory,
|
public ParseSystemAndUserMetadataFromHeaders(Provider<MutableBlobMetadata> metadataFactory,
|
||||||
DateService dateParser, @Named(PROPERTY_USER_METADATA_PREFIX) String metadataPrefix,
|
DateService dateParser, @Named(PROPERTY_USER_METADATA_PREFIX) String metadataPrefix) {
|
||||||
EncryptionService encryptionService) {
|
|
||||||
this.metadataFactory = metadataFactory;
|
this.metadataFactory = metadataFactory;
|
||||||
this.dateParser = dateParser;
|
this.dateParser = dateParser;
|
||||||
this.metadataPrefix = metadataPrefix;
|
this.metadataPrefix = metadataPrefix;
|
||||||
this.encryptionService = encryptionService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public MutableBlobMetadata apply(HttpResponse from) {
|
public MutableBlobMetadata apply(HttpResponse from) {
|
||||||
|
@ -85,8 +82,7 @@ public class ParseSystemAndUserMetadataFromHeaders implements
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void setContentLength(HttpResponse from, MutableBlobMetadata metadata) throws HttpException {
|
void setContentLength(HttpResponse from, MutableBlobMetadata metadata) throws HttpException {
|
||||||
String contentLength = from.getFirstHeaderOrNull(HttpHeaders.CONTENT_LENGTH);
|
metadata.setSize(attemptToParseSizeAndRangeFromHeaders(from));
|
||||||
metadata.setSize(contentLength == null ? 0 : Long.parseLong(contentLength));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
@ -112,20 +108,18 @@ public class ParseSystemAndUserMetadataFromHeaders implements
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
protected void addContentMD5To(HttpResponse from, MutableBlobMetadata metadata) {
|
protected void addContentMD5To(HttpResponse from, MutableBlobMetadata metadata) {
|
||||||
String contentMD5 = from.getFirstHeaderOrNull("Content-MD5");
|
if (from.getPayload() != null)
|
||||||
if (contentMD5 != null) {
|
metadata.setContentMD5(from.getPayload().getContentMD5());
|
||||||
metadata.setContentMD5(encryptionService.fromBase64(contentMD5));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void setContentTypeOrThrowException(HttpResponse from, MutableBlobMetadata metadata)
|
void setContentTypeOrThrowException(HttpResponse from, MutableBlobMetadata metadata)
|
||||||
throws HttpException {
|
throws HttpException {
|
||||||
String contentType = from.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE);
|
if (from.getPayload() != null)
|
||||||
if (contentType == 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");
|
throw new HttpException(HttpHeaders.CONTENT_TYPE + " not found in headers");
|
||||||
else
|
|
||||||
metadata.setContentType(contentType);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setContext(GeneratedHttpRequest<?> request) {
|
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.easymock.classextension.EasyMock.replay;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.Collections;
|
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.config.BlobStoreObjectModule;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.domain.MutableBlobMetadata;
|
import org.jclouds.blobstore.domain.MutableBlobMetadata;
|
||||||
|
import org.jclouds.blobstore.domain.internal.MutableBlobMetadataImpl;
|
||||||
import org.jclouds.http.HttpException;
|
import org.jclouds.http.HttpException;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
import org.jclouds.util.Utils;
|
import org.jclouds.http.Payloads;
|
||||||
import org.testng.annotations.BeforeTest;
|
import org.testng.annotations.BeforeTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMultimap;
|
|
||||||
import com.google.common.collect.Multimap;
|
|
||||||
import com.google.inject.Guice;
|
import com.google.inject.Guice;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -58,62 +57,38 @@ public class ParseBlobFromHeadersAndHttpContentTest {
|
||||||
ParseSystemAndUserMetadataFromHeaders metadataParser = createMock(ParseSystemAndUserMetadataFromHeaders.class);
|
ParseSystemAndUserMetadataFromHeaders metadataParser = createMock(ParseSystemAndUserMetadataFromHeaders.class);
|
||||||
ParseBlobFromHeadersAndHttpContent callable = new ParseBlobFromHeadersAndHttpContent(
|
ParseBlobFromHeadersAndHttpContent callable = new ParseBlobFromHeadersAndHttpContent(
|
||||||
metadataParser, blobProvider);
|
metadataParser, blobProvider);
|
||||||
HttpResponse response = createMock(HttpResponse.class);
|
HttpResponse response = new HttpResponse(200, null, null);
|
||||||
expect(response.getFirstHeaderOrNull("Content-Length")).andReturn("100");
|
response.getHeaders().put("Content-Range", null);
|
||||||
expect(response.getFirstHeaderOrNull("Content-Range")).andReturn(null);
|
|
||||||
expect(response.getHeaders()).andReturn(ImmutableMultimap.of("Content-Length", "100"));
|
|
||||||
expect(response.getContent()).andReturn(null);
|
|
||||||
replay(response);
|
|
||||||
callable.apply(response);
|
callable.apply(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
private Blob.Factory blobProvider;
|
||||||
public void testAddAllHeadersTo() {
|
private Provider<MutableBlobMetadata> blobMetadataProvider = new Provider<MutableBlobMetadata>() {
|
||||||
ParseSystemAndUserMetadataFromHeaders metadataParser = createMock(ParseSystemAndUserMetadataFromHeaders.class);
|
|
||||||
ParseBlobFromHeadersAndHttpContent callable = new ParseBlobFromHeadersAndHttpContent(
|
public MutableBlobMetadata get() {
|
||||||
metadataParser, blobProvider);
|
return new MutableBlobMetadataImpl();
|
||||||
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;
|
};
|
||||||
|
|
||||||
@Test(enabled = false)
|
@Test
|
||||||
// TODO.. very complicated test.
|
|
||||||
public void testParseContentLengthWhenContentRangeSet() throws HttpException {
|
public void testParseContentLengthWhenContentRangeSet() throws HttpException {
|
||||||
ParseSystemAndUserMetadataFromHeaders metadataParser = createMock(ParseSystemAndUserMetadataFromHeaders.class);
|
ParseSystemAndUserMetadataFromHeaders metadataParser = createMock(ParseSystemAndUserMetadataFromHeaders.class);
|
||||||
ParseBlobFromHeadersAndHttpContent callable = new ParseBlobFromHeadersAndHttpContent(
|
ParseBlobFromHeadersAndHttpContent callable = new ParseBlobFromHeadersAndHttpContent(
|
||||||
metadataParser, blobProvider);
|
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);
|
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);
|
replay(metadataParser);
|
||||||
|
|
||||||
Blob object = callable.apply(response);
|
Blob object = callable.apply(response);
|
||||||
assertEquals(object.getPayload().getContentLength(), new Long(10485760));
|
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
|
assertEquals(object.getAllHeaders().get("Content-Range"), Collections
|
||||||
.singletonList("0-10485759/20232760"));
|
.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.MutableBlobMetadata;
|
||||||
import org.jclouds.blobstore.domain.internal.MutableBlobMetadataImpl;
|
import org.jclouds.blobstore.domain.internal.MutableBlobMetadataImpl;
|
||||||
import org.jclouds.date.internal.SimpleDateFormatDateService;
|
import org.jclouds.date.internal.SimpleDateFormatDateService;
|
||||||
import org.jclouds.encryption.internal.JCEEncryptionService;
|
|
||||||
import org.jclouds.http.HttpException;
|
import org.jclouds.http.HttpException;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
|
import org.jclouds.http.Payloads;
|
||||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||||
import org.testng.annotations.BeforeTest;
|
import org.testng.annotations.BeforeTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
@ -58,7 +58,7 @@ public class ParseBlobMetadataFromHeadersTest {
|
||||||
void setUp() {
|
void setUp() {
|
||||||
|
|
||||||
parser = new ParseSystemAndUserMetadataFromHeaders(blobMetadataProvider,
|
parser = new ParseSystemAndUserMetadataFromHeaders(blobMetadataProvider,
|
||||||
new SimpleDateFormatDateService(), "prefix", new JCEEncryptionService());
|
new SimpleDateFormatDateService(), "prefix");
|
||||||
|
|
||||||
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
|
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
|
||||||
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
|
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
|
||||||
|
@ -69,25 +69,25 @@ public class ParseBlobMetadataFromHeadersTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testApplySetsKey() {
|
public void testApplySetsKey() {
|
||||||
HttpResponse from = new HttpResponse();
|
HttpResponse from = new HttpResponse(200, "ok", Payloads.newStringPayload(""));
|
||||||
from.getHeaders().put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
|
from.getPayload().setContentType(MediaType.APPLICATION_JSON);
|
||||||
from.getHeaders().put(HttpHeaders.LAST_MODIFIED, "Wed, 09 Sep 2009 19:50:23 GMT");
|
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);
|
BlobMetadata metadata = parser.apply(from);
|
||||||
assertEquals(metadata.getName(), "key");
|
assertEquals(metadata.getName(), "key");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetContentLength() {
|
public void testSetContentLength() {
|
||||||
HttpResponse from = new HttpResponse();
|
HttpResponse from = new HttpResponse(200, "ok", Payloads.newStringPayload(""));
|
||||||
from.getHeaders().put(HttpHeaders.CONTENT_LENGTH, "100");
|
from.getPayload().setContentLength(100l);
|
||||||
MutableBlobMetadata metadata = blobMetadataProvider.get();
|
MutableBlobMetadata metadata = blobMetadataProvider.get();
|
||||||
parser.setContentLength(from, metadata);
|
parser.setContentLength(from, metadata);
|
||||||
assertEquals(metadata.getSize(), new Long(100));
|
assertEquals(metadata.getSize(), new Long(100));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSetContentLengthNoHeader() {
|
public void testSetContentLengthNoHeader() {
|
||||||
HttpResponse from = new HttpResponse();
|
HttpResponse from = new HttpResponse(200, "ok", Payloads.newStringPayload(""));
|
||||||
MutableBlobMetadata metadata = blobMetadataProvider.get();
|
MutableBlobMetadata metadata = blobMetadataProvider.get();
|
||||||
parser.setContentLength(from, metadata);
|
parser.setContentLength(from, metadata);
|
||||||
assertEquals(metadata.getSize(), new Long(0));
|
assertEquals(metadata.getSize(), new Long(0));
|
||||||
|
@ -95,8 +95,8 @@ public class ParseBlobMetadataFromHeadersTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetContentType() {
|
public void testSetContentType() {
|
||||||
HttpResponse from = new HttpResponse();
|
HttpResponse from = new HttpResponse(200, "ok", Payloads.newStringPayload(""));
|
||||||
from.getHeaders().put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
|
from.getPayload().setContentType(MediaType.APPLICATION_JSON);
|
||||||
MutableBlobMetadata metadata = blobMetadataProvider.get();
|
MutableBlobMetadata metadata = blobMetadataProvider.get();
|
||||||
parser.setContentTypeOrThrowException(from, metadata);
|
parser.setContentTypeOrThrowException(from, metadata);
|
||||||
assertEquals(metadata.getContentType(), MediaType.APPLICATION_JSON);
|
assertEquals(metadata.getContentType(), MediaType.APPLICATION_JSON);
|
||||||
|
@ -104,14 +104,14 @@ public class ParseBlobMetadataFromHeadersTest {
|
||||||
|
|
||||||
@Test(expectedExceptions = HttpException.class)
|
@Test(expectedExceptions = HttpException.class)
|
||||||
public void testSetContentTypeException() {
|
public void testSetContentTypeException() {
|
||||||
HttpResponse from = new HttpResponse();
|
HttpResponse from = new HttpResponse(200, "ok", Payloads.newStringPayload(""));
|
||||||
MutableBlobMetadata metadata = blobMetadataProvider.get();
|
MutableBlobMetadata metadata = blobMetadataProvider.get();
|
||||||
parser.setContentTypeOrThrowException(from, metadata);
|
parser.setContentTypeOrThrowException(from, metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetLastModified() {
|
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");
|
from.getHeaders().put(HttpHeaders.LAST_MODIFIED, "Wed, 09 Sep 2009 19:50:23 GMT");
|
||||||
MutableBlobMetadata metadata = blobMetadataProvider.get();
|
MutableBlobMetadata metadata = blobMetadataProvider.get();
|
||||||
parser.parseLastModifiedOrThrowException(from, metadata);
|
parser.parseLastModifiedOrThrowException(from, metadata);
|
||||||
|
@ -121,14 +121,14 @@ public class ParseBlobMetadataFromHeadersTest {
|
||||||
|
|
||||||
@Test(expectedExceptions = HttpException.class)
|
@Test(expectedExceptions = HttpException.class)
|
||||||
public void testSetLastModifiedException() {
|
public void testSetLastModifiedException() {
|
||||||
HttpResponse from = new HttpResponse();
|
HttpResponse from = new HttpResponse(200, "ok", Payloads.newStringPayload(""));
|
||||||
MutableBlobMetadata metadata = blobMetadataProvider.get();
|
MutableBlobMetadata metadata = blobMetadataProvider.get();
|
||||||
parser.parseLastModifiedOrThrowException(from, metadata);
|
parser.parseLastModifiedOrThrowException(from, metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddETagTo() {
|
public void testAddETagTo() {
|
||||||
HttpResponse from = new HttpResponse();
|
HttpResponse from = new HttpResponse(200, "ok", Payloads.newStringPayload(""));
|
||||||
from.getHeaders().put(HttpHeaders.ETAG, "0xfeb");
|
from.getHeaders().put(HttpHeaders.ETAG, "0xfeb");
|
||||||
MutableBlobMetadata metadata = blobMetadataProvider.get();
|
MutableBlobMetadata metadata = blobMetadataProvider.get();
|
||||||
parser.addETagTo(from, metadata);
|
parser.addETagTo(from, metadata);
|
||||||
|
@ -138,7 +138,7 @@ public class ParseBlobMetadataFromHeadersTest {
|
||||||
@Test
|
@Test
|
||||||
public void testAddUserMetadataTo() {
|
public void testAddUserMetadataTo() {
|
||||||
Multimap<String, String> allHeaders = ImmutableMultimap.of("prefix" + "key", "value");
|
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);
|
from.getHeaders().putAll(allHeaders);
|
||||||
MutableBlobMetadata metadata = blobMetadataProvider.get();
|
MutableBlobMetadata metadata = blobMetadataProvider.get();
|
||||||
parser.addUserMetadataTo(from, metadata);
|
parser.addUserMetadataTo(from, metadata);
|
||||||
|
|
|
@ -66,21 +66,22 @@ public class BoxDotNetErrorHandler implements HttpErrorHandler {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
Closeables.closeQuietly(response.getContent());
|
if (response.getPayload() != null)
|
||||||
|
Closeables.closeQuietly(response.getPayload().getInput());
|
||||||
command.setException(exception);
|
command.setException(exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String parseMessage(HttpResponse response) {
|
public String parseMessage(HttpResponse response) {
|
||||||
if (response.getContent() == null)
|
if (response.getPayload() == null)
|
||||||
return null;
|
return null;
|
||||||
try {
|
try {
|
||||||
return Utils.toStringAndClose(response.getContent());
|
return Utils.toStringAndClose(response.getPayload().getInput());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
response.getContent().close();
|
response.getPayload().getInput().close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Throwables.propagate(e);
|
Throwables.propagate(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ import java.lang.reflect.Method;
|
||||||
|
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.filters.BasicAuthentication;
|
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.http.functions.ReturnStringIf200;
|
||||||
import org.jclouds.rest.RestClientTest;
|
import org.jclouds.rest.RestClientTest;
|
||||||
import org.jclouds.rest.RestContextFactory.ContextSpec;
|
import org.jclouds.rest.RestContextFactory.ContextSpec;
|
||||||
|
@ -57,8 +57,8 @@ public class BoxDotNetAsyncClientTest extends RestClientTest<BoxDotNetAsyncClien
|
||||||
GeneratedHttpRequest<BoxDotNetAsyncClient> httpRequest = processor.createRequest(method);
|
GeneratedHttpRequest<BoxDotNetAsyncClient> httpRequest = processor.createRequest(method);
|
||||||
|
|
||||||
assertRequestLineEquals(httpRequest, "GET https://www.box.net/api/1.0/rest/items HTTP/1.1");
|
assertRequestLineEquals(httpRequest, "GET https://www.box.net/api/1.0/rest/items HTTP/1.1");
|
||||||
assertHeadersEqual(httpRequest, "Accept: application/json\n");
|
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||||
assertPayloadEquals(httpRequest, null);
|
assertPayloadEquals(httpRequest, null, null, false);
|
||||||
|
|
||||||
// now make sure request filters apply by replaying
|
// now make sure request filters apply by replaying
|
||||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
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");
|
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
|
// for example, using basic authentication, we should get "only one" header
|
||||||
assertHeadersEqual(httpRequest,
|
assertNonPayloadHeadersEqual(httpRequest,
|
||||||
"Accept: application/json\nAuthorization: Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==\n");
|
"Accept: application/json\nAuthorization: Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==\n");
|
||||||
assertPayloadEquals(httpRequest, null);
|
assertPayloadEquals(httpRequest, null, null, false);
|
||||||
|
|
||||||
// TODO: insert expected response class, which probably extends ParseJson
|
// TODO: insert expected response class, which probably extends ParseJson
|
||||||
assertResponseParserClassEquals(method, httpRequest, ReturnStringIf200.class);
|
assertResponseParserClassEquals(method, httpRequest, ReturnStringIf200.class);
|
||||||
|
@ -84,8 +84,8 @@ public class BoxDotNetAsyncClientTest extends RestClientTest<BoxDotNetAsyncClien
|
||||||
GeneratedHttpRequest<BoxDotNetAsyncClient> httpRequest = processor.createRequest(method, 1);
|
GeneratedHttpRequest<BoxDotNetAsyncClient> httpRequest = processor.createRequest(method, 1);
|
||||||
|
|
||||||
assertRequestLineEquals(httpRequest, "GET https://www.box.net/api/1.0/rest/items/1 HTTP/1.1");
|
assertRequestLineEquals(httpRequest, "GET https://www.box.net/api/1.0/rest/items/1 HTTP/1.1");
|
||||||
assertHeadersEqual(httpRequest, "Accept: application/json\n");
|
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||||
assertPayloadEquals(httpRequest, null);
|
assertPayloadEquals(httpRequest, null, null, false);
|
||||||
|
|
||||||
// TODO: insert expected response class, which probably extends ParseJson
|
// TODO: insert expected response class, which probably extends ParseJson
|
||||||
assertResponseParserClassEquals(method, httpRequest, ReturnStringIf200.class);
|
assertResponseParserClassEquals(method, httpRequest, ReturnStringIf200.class);
|
||||||
|
@ -103,10 +103,10 @@ public class BoxDotNetAsyncClientTest extends RestClientTest<BoxDotNetAsyncClien
|
||||||
|
|
||||||
assertRequestLineEquals(httpRequest,
|
assertRequestLineEquals(httpRequest,
|
||||||
"DELETE https://www.box.net/api/1.0/rest/items/1 HTTP/1.1");
|
"DELETE https://www.box.net/api/1.0/rest/items/1 HTTP/1.1");
|
||||||
assertHeadersEqual(httpRequest, "Accept: application/json\n");
|
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||||
assertPayloadEquals(httpRequest, null);
|
assertPayloadEquals(httpRequest, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, CloseContentAndReturn.class);
|
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
|
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
|
||||||
|
|
||||||
|
|
|
@ -24,14 +24,11 @@
|
||||||
package org.jclouds.chef.binders;
|
package org.jclouds.chef.binders;
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.rest.binders.BindToStringPayload;
|
import org.jclouds.rest.binders.BindToStringPayload;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
|
@ -42,9 +39,8 @@ public class BindClientnameToJsonPayload extends BindToStringPayload {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bindToRequest(HttpRequest request, Object payload) {
|
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));
|
super.bindToRequest(request, String.format("{\"clientname\":\"%s\"}", payload));
|
||||||
|
request.getPayload().setContentType(MediaType.APPLICATION_JSON);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,14 +24,11 @@
|
||||||
package org.jclouds.chef.binders;
|
package org.jclouds.chef.binders;
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.rest.binders.BindToStringPayload;
|
import org.jclouds.rest.binders.BindToStringPayload;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
|
@ -42,10 +39,9 @@ public class BindGenerateKeyForClientToJsonPayload extends BindToStringPayload {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bindToRequest(HttpRequest request, Object payload) {
|
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}",
|
super.bindToRequest(request, String.format("{\"clientname\":\"%s\", \"private_key\": true}",
|
||||||
payload));
|
payload));
|
||||||
|
request.getPayload().setContentType(MediaType.APPLICATION_JSON);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,14 +29,11 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.rest.binders.BindToStringPayload;
|
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.append(String.format("\"%s\":null,", hexEncodedmd5));
|
||||||
builder.deleteCharAt(builder.length() - 1);
|
builder.deleteCharAt(builder.length() - 1);
|
||||||
builder.append("}}");
|
builder.append("}}");
|
||||||
request.getHeaders().replaceValues(HttpHeaders.CONTENT_TYPE,
|
|
||||||
ImmutableSet.of(MediaType.APPLICATION_JSON));
|
|
||||||
super.bindToRequest(request, builder.toString());
|
super.bindToRequest(request, builder.toString());
|
||||||
|
request.getPayload().setContentType(MediaType.APPLICATION_JSON);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -24,14 +24,11 @@
|
||||||
package org.jclouds.chef.binders;
|
package org.jclouds.chef.binders;
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.rest.binders.BindToStringPayload;
|
import org.jclouds.rest.binders.BindToStringPayload;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
|
@ -42,9 +39,8 @@ public class BindIsCompletedToJsonPayload extends BindToStringPayload {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bindToRequest(HttpRequest request, Object value) {
|
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));
|
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 Provider<String> timeStampProvider;
|
||||||
private final EncryptionService encryptionService;
|
private final EncryptionService encryptionService;
|
||||||
private final String emptyStringHash;
|
private final String emptyStringHash;
|
||||||
|
private final HttpUtils utils;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
@Named(Constants.LOGGER_SIGNATURE)
|
@Named(Constants.LOGGER_SIGNATURE)
|
||||||
|
@ -82,13 +83,14 @@ public class SignedHeaderAuth implements HttpRequestFilter {
|
||||||
@Inject
|
@Inject
|
||||||
public SignedHeaderAuth(SignatureWire signatureWire, @Named(PROPERTY_IDENTITY) String userId,
|
public SignedHeaderAuth(SignatureWire signatureWire, @Named(PROPERTY_IDENTITY) String userId,
|
||||||
PrivateKey privateKey, @TimeStamp Provider<String> timeStampProvider,
|
PrivateKey privateKey, @TimeStamp Provider<String> timeStampProvider,
|
||||||
EncryptionService encryptionService) {
|
EncryptionService encryptionService, HttpUtils utils) {
|
||||||
this.signatureWire = signatureWire;
|
this.signatureWire = signatureWire;
|
||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
this.privateKey = privateKey;
|
this.privateKey = privateKey;
|
||||||
this.timeStampProvider = timeStampProvider;
|
this.timeStampProvider = timeStampProvider;
|
||||||
this.encryptionService = encryptionService;
|
this.encryptionService = encryptionService;
|
||||||
this.emptyStringHash = hashBody(Payloads.newStringPayload(""));
|
this.emptyStringHash = hashBody(Payloads.newStringPayload(""));
|
||||||
|
this.utils = utils;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void filter(HttpRequest request) throws HttpException {
|
public void filter(HttpRequest request) throws HttpException {
|
||||||
|
@ -104,7 +106,7 @@ public class SignedHeaderAuth implements HttpRequestFilter {
|
||||||
Collections.singletonList(SIGNING_DESCRIPTION));
|
Collections.singletonList(SIGNING_DESCRIPTION));
|
||||||
calculateAndReplaceAuthorizationHeaders(request, toSign);
|
calculateAndReplaceAuthorizationHeaders(request, toSign);
|
||||||
request.getHeaders().replaceValues("X-Ops-Timestamp", Collections.singletonList(timestamp));
|
request.getHeaders().replaceValues("X-Ops-Timestamp", Collections.singletonList(timestamp));
|
||||||
HttpUtils.logRequest(signatureLog, request, "<<");
|
utils.logRequest(signatureLog, request, "<<");
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
|
|
@ -50,8 +50,7 @@ public class ParseCookbookVersionFromJson extends ParseJson<CookbookVersion> {
|
||||||
@Override
|
@Override
|
||||||
protected CookbookVersion apply(InputStream stream) {
|
protected CookbookVersion apply(InputStream stream) {
|
||||||
try {
|
try {
|
||||||
return gson.fromJson(new InputStreamReader(stream, "UTF-8"),
|
return gson.fromJson(new InputStreamReader(stream, "UTF-8"), CookbookVersion.class);
|
||||||
CookbookVersion.class);
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,17 +23,16 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.chef.functions;
|
package org.jclouds.chef.functions;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.http.HttpResponse;
|
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.Function;
|
||||||
import com.google.common.base.Throwables;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -43,22 +42,19 @@ import com.google.common.base.Throwables;
|
||||||
@Singleton
|
@Singleton
|
||||||
public class ParseErrorFromJsonOrReturnBody implements Function<HttpResponse, String> {
|
public class ParseErrorFromJsonOrReturnBody implements Function<HttpResponse, String> {
|
||||||
Pattern pattern = Pattern.compile(".*\\[\"([^\"]+)\"\\].*");
|
Pattern pattern = Pattern.compile(".*\\[\"([^\"]+)\"\\].*");
|
||||||
|
private final ReturnStringIf200 returnStringIf200;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
ParseErrorFromJsonOrReturnBody(ReturnStringIf200 returnStringIf200) {
|
||||||
|
this.returnStringIf200 = returnStringIf200;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String apply(HttpResponse response) {
|
public String apply(HttpResponse response) {
|
||||||
if (response.getContent() == null)
|
String content = returnStringIf200.apply(response);
|
||||||
|
if (content == null)
|
||||||
return null;
|
return null;
|
||||||
try {
|
return parse(content);
|
||||||
return parse(Utils.toStringAndClose(response.getContent()));
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
response.getContent().close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
Throwables.propagate(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String parse(String in) {
|
public String parse(String in) {
|
||||||
|
|
|
@ -23,17 +23,16 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.chef.functions;
|
package org.jclouds.chef.functions;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.http.HttpResponse;
|
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.Function;
|
||||||
import com.google.common.base.Throwables;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -43,22 +42,22 @@ import com.google.common.base.Throwables;
|
||||||
@Singleton
|
@Singleton
|
||||||
public class ParseKeyFromJson implements Function<HttpResponse, String> {
|
public class ParseKeyFromJson implements Function<HttpResponse, String> {
|
||||||
Pattern pattern = Pattern.compile(".*private_key\": *\"([^\"]+)\".*");
|
Pattern pattern = Pattern.compile(".*private_key\": *\"([^\"]+)\".*");
|
||||||
|
private final ReturnStringIf200 returnStringIf200;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
ParseKeyFromJson(ReturnStringIf200 returnStringIf200) {
|
||||||
|
this.returnStringIf200 = returnStringIf200;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String apply(HttpResponse response) {
|
public String apply(HttpResponse response) {
|
||||||
try {
|
String content = returnStringIf200.apply(response);
|
||||||
return parse(Utils.toStringAndClose(response.getContent()));
|
if (content == null)
|
||||||
} catch (IOException e) {
|
return null;
|
||||||
throw new RuntimeException(e);
|
return parse(content);
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
response.getContent().close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
Throwables.propagate(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String parse(String in) {
|
public String parse(String in) {
|
||||||
Matcher matcher = pattern.matcher(in);
|
Matcher matcher = pattern.matcher(in);
|
||||||
while (matcher.find()) {
|
while (matcher.find()) {
|
||||||
|
|
|
@ -50,8 +50,7 @@ public class ParseUploadSiteFromJson extends ParseJson<UploadSandbox> {
|
||||||
@Override
|
@Override
|
||||||
protected UploadSandbox apply(InputStream stream) {
|
protected UploadSandbox apply(InputStream stream) {
|
||||||
try {
|
try {
|
||||||
return gson.fromJson(new InputStreamReader(stream, "UTF-8"),
|
return gson.fromJson(new InputStreamReader(stream, "UTF-8"), UploadSandbox.class);
|
||||||
UploadSandbox.class);
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
throw new RuntimeException("jclouds requires UTF-8 encoding", 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>>>() {
|
Type map = new TypeToken<Map<String, Set<String>>>() {
|
||||||
}.getType();
|
}.getType();
|
||||||
return Iterables.get(
|
return Iterables.get(
|
||||||
((Map<String, Set<String>>) gson.fromJson(new InputStreamReader(
|
((Map<String, Set<String>>) gson.fromJson(new InputStreamReader(stream, "UTF-8"),
|
||||||
stream, "UTF-8"), map)).entrySet(), 0).getValue();
|
map)).entrySet(), 0).getValue();
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,8 @@ public class ChefErrorHandler implements HttpErrorHandler {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
Closeables.closeQuietly(response.getContent());
|
if (response.getPayload() != null)
|
||||||
|
Closeables.closeQuietly(response.getPayload().getInput());
|
||||||
command.setException(exception);
|
command.setException(exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ import org.jclouds.chef.functions.ParseUploadSiteFromJson;
|
||||||
import org.jclouds.date.TimeStamp;
|
import org.jclouds.date.TimeStamp;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.RequiresHttp;
|
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.ReturnStringIf200;
|
||||||
import org.jclouds.http.functions.ReturnTrueIf2xx;
|
import org.jclouds.http.functions.ReturnTrueIf2xx;
|
||||||
import org.jclouds.rest.ConfiguresRestClient;
|
import org.jclouds.rest.ConfiguresRestClient;
|
||||||
|
@ -76,10 +76,8 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
||||||
"0189e76ccc476701d6b374e5a1a27347", true);
|
"0189e76ccc476701d6b374e5a1a27347", true);
|
||||||
assertRequestLineEquals(httpRequest,
|
assertRequestLineEquals(httpRequest,
|
||||||
"PUT http://localhost:4000/sandboxes/0189e76ccc476701d6b374e5a1a27347 HTTP/1.1");
|
"PUT http://localhost:4000/sandboxes/0189e76ccc476701d6b374e5a1a27347 HTTP/1.1");
|
||||||
assertHeadersEqual(
|
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||||
httpRequest,
|
assertPayloadEquals(httpRequest, "{\"is_completed\":\"true\"}", "application/json", false);
|
||||||
"Accept: application/json\nContent-Length: 23\nContent-Type: application/json\nX-Chef-Version: 0.9.6\n");
|
|
||||||
assertPayloadEquals(httpRequest, "{\"is_completed\":\"true\"}");
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, ParseSandboxFromJson.class);
|
assertResponseParserClassEquals(method, httpRequest, ParseSandboxFromJson.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
@ -89,21 +87,19 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetUploadSandboxForChecksums() throws SecurityException,
|
public void testGetUploadSandboxForChecksums() throws SecurityException, NoSuchMethodException,
|
||||||
NoSuchMethodException, IOException {
|
IOException {
|
||||||
|
|
||||||
Method method = ChefAsyncClient.class.getMethod("getUploadSandboxForChecksums",
|
Method method = ChefAsyncClient.class.getMethod("getUploadSandboxForChecksums", Set.class);
|
||||||
Set.class);
|
|
||||||
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method,
|
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method,
|
||||||
ImmutableSet.of("0189e76ccc476701d6b374e5a1a27347",
|
ImmutableSet.of("0189e76ccc476701d6b374e5a1a27347",
|
||||||
"0c5ecd7788cf4f6c7de2a57193897a6c", "1dda05ed139664f1f89b9dec482b77c0"));
|
"0c5ecd7788cf4f6c7de2a57193897a6c", "1dda05ed139664f1f89b9dec482b77c0"));
|
||||||
assertRequestLineEquals(httpRequest, "POST http://localhost:4000/sandboxes HTTP/1.1");
|
assertRequestLineEquals(httpRequest, "POST http://localhost:4000/sandboxes HTTP/1.1");
|
||||||
assertHeadersEqual(
|
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||||
httpRequest,
|
|
||||||
"Accept: application/json\nContent-Length: 135\nContent-Type: application/json\nX-Chef-Version: 0.9.6\n");
|
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
httpRequest,
|
httpRequest,
|
||||||
"{\"checksums\":{\"0189e76ccc476701d6b374e5a1a27347\":null,\"0c5ecd7788cf4f6c7de2a57193897a6c\":null,\"1dda05ed139664f1f89b9dec482b77c0\":null}}");
|
"{\"checksums\":{\"0189e76ccc476701d6b374e5a1a27347\":null,\"0c5ecd7788cf4f6c7de2a57193897a6c\":null,\"1dda05ed139664f1f89b9dec482b77c0\":null}}",
|
||||||
|
"application/json", false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, ParseUploadSiteFromJson.class);
|
assertResponseParserClassEquals(method, httpRequest, ParseUploadSiteFromJson.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
@ -119,8 +115,8 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
||||||
"cookbook", "1.0.0");
|
"cookbook", "1.0.0");
|
||||||
assertRequestLineEquals(httpRequest,
|
assertRequestLineEquals(httpRequest,
|
||||||
"GET http://localhost:4000/cookbooks/cookbook/1.0.0 HTTP/1.1");
|
"GET http://localhost:4000/cookbooks/cookbook/1.0.0 HTTP/1.1");
|
||||||
assertHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||||
assertPayloadEquals(httpRequest, null);
|
assertPayloadEquals(httpRequest, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, ParseCookbookVersionFromJson.class);
|
assertResponseParserClassEquals(method, httpRequest, ParseCookbookVersionFromJson.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
@ -136,10 +132,10 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
||||||
"cookbook", "1.0.0");
|
"cookbook", "1.0.0");
|
||||||
assertRequestLineEquals(httpRequest,
|
assertRequestLineEquals(httpRequest,
|
||||||
"DELETE http://localhost:4000/cookbooks/cookbook/1.0.0 HTTP/1.1");
|
"DELETE http://localhost:4000/cookbooks/cookbook/1.0.0 HTTP/1.1");
|
||||||
assertHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||||
assertPayloadEquals(httpRequest, null);
|
assertPayloadEquals(httpRequest, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, CloseContentAndReturn.class);
|
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
|
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
|
||||||
|
|
||||||
|
@ -155,13 +151,12 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
||||||
|
|
||||||
assertRequestLineEquals(httpRequest,
|
assertRequestLineEquals(httpRequest,
|
||||||
"PUT http://localhost:4000/cookbooks/cookbook/1.0.1 HTTP/1.1");
|
"PUT http://localhost:4000/cookbooks/cookbook/1.0.1 HTTP/1.1");
|
||||||
assertHeadersEqual(
|
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||||
httpRequest,
|
|
||||||
"Accept: application/json\nContent-Length: 446\nContent-Type: application/json\nX-Chef-Version: 0.9.6\n");
|
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
httpRequest,
|
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\"}");
|
"{\"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);
|
"application/json", false);
|
||||||
|
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
assertExceptionParserClassEquals(method, null);
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
@ -174,8 +169,8 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
||||||
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method);
|
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method);
|
||||||
|
|
||||||
assertRequestLineEquals(httpRequest, "GET http://localhost:4000/cookbooks HTTP/1.1");
|
assertRequestLineEquals(httpRequest, "GET http://localhost:4000/cookbooks HTTP/1.1");
|
||||||
assertHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||||
assertPayloadEquals(httpRequest, null);
|
assertPayloadEquals(httpRequest, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, ParseKeySetFromJson.class);
|
assertResponseParserClassEquals(method, httpRequest, ParseKeySetFromJson.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
@ -189,8 +184,8 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
||||||
Method method = ChefAsyncClient.class.getMethod("clientExists", String.class);
|
Method method = ChefAsyncClient.class.getMethod("clientExists", String.class);
|
||||||
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method, "client");
|
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method, "client");
|
||||||
assertRequestLineEquals(httpRequest, "HEAD http://localhost:4000/clients/client HTTP/1.1");
|
assertRequestLineEquals(httpRequest, "HEAD http://localhost:4000/clients/client HTTP/1.1");
|
||||||
assertHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||||
assertPayloadEquals(httpRequest, null);
|
assertPayloadEquals(httpRequest, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, ReturnTrueIf2xx.class);
|
assertResponseParserClassEquals(method, httpRequest, ReturnTrueIf2xx.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
@ -204,8 +199,8 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
||||||
Method method = ChefAsyncClient.class.getMethod("deleteClient", String.class);
|
Method method = ChefAsyncClient.class.getMethod("deleteClient", String.class);
|
||||||
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method, "client");
|
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method, "client");
|
||||||
assertRequestLineEquals(httpRequest, "DELETE http://localhost:4000/clients/client HTTP/1.1");
|
assertRequestLineEquals(httpRequest, "DELETE http://localhost:4000/clients/client HTTP/1.1");
|
||||||
assertHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||||
assertPayloadEquals(httpRequest, null);
|
assertPayloadEquals(httpRequest, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, ReturnStringIf200.class);
|
assertResponseParserClassEquals(method, httpRequest, ReturnStringIf200.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
@ -220,10 +215,9 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
||||||
Method method = ChefAsyncClient.class.getMethod("generateKeyForClient", String.class);
|
Method method = ChefAsyncClient.class.getMethod("generateKeyForClient", String.class);
|
||||||
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method, "client");
|
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method, "client");
|
||||||
assertRequestLineEquals(httpRequest, "PUT http://localhost:4000/clients/client HTTP/1.1");
|
assertRequestLineEquals(httpRequest, "PUT http://localhost:4000/clients/client HTTP/1.1");
|
||||||
assertHeadersEqual(
|
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||||
httpRequest,
|
assertPayloadEquals(httpRequest, "{\"clientname\":\"client\", \"private_key\": true}",
|
||||||
"Accept: application/json\nContent-Length: 44\nContent-Type: application/json\nX-Chef-Version: 0.9.6\n");
|
"application/json", false);
|
||||||
assertPayloadEquals(httpRequest, "{\"clientname\":\"client\", \"private_key\": true}");
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, ParseKeyFromJson.class);
|
assertResponseParserClassEquals(method, httpRequest, ParseKeyFromJson.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
@ -238,10 +232,9 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
||||||
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method, "client");
|
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method, "client");
|
||||||
|
|
||||||
assertRequestLineEquals(httpRequest, "POST http://localhost:4000/clients HTTP/1.1");
|
assertRequestLineEquals(httpRequest, "POST http://localhost:4000/clients HTTP/1.1");
|
||||||
assertHeadersEqual(
|
assertNonPayloadHeadersEqual(httpRequest,
|
||||||
httpRequest,
|
"Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||||
"Accept: application/json\nContent-Length: 23\nContent-Type: application/json\nX-Chef-Version: 0.9.6\n");
|
assertPayloadEquals(httpRequest, "{\"clientname\":\"client\"}", "application/json", false);
|
||||||
assertPayloadEquals(httpRequest, "{\"clientname\":\"client\"}");
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, ParseKeyFromJson.class);
|
assertResponseParserClassEquals(method, httpRequest, ParseKeyFromJson.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
@ -256,8 +249,8 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
|
||||||
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method);
|
GeneratedHttpRequest<ChefAsyncClient> httpRequest = processor.createRequest(method);
|
||||||
|
|
||||||
assertRequestLineEquals(httpRequest, "GET http://localhost:4000/clients HTTP/1.1");
|
assertRequestLineEquals(httpRequest, "GET http://localhost:4000/clients HTTP/1.1");
|
||||||
assertHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: 0.9.6\n");
|
||||||
assertPayloadEquals(httpRequest, null);
|
assertPayloadEquals(httpRequest, null, null, false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, ParseKeySetFromJson.class);
|
assertResponseParserClassEquals(method, httpRequest, ParseKeySetFromJson.class);
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
|
|
@ -41,10 +41,11 @@ import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||||
import org.bouncycastle.openssl.PEMReader;
|
import org.bouncycastle.openssl.PEMReader;
|
||||||
import org.jclouds.encryption.EncryptionService;
|
import org.jclouds.encryption.EncryptionService;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
|
import org.jclouds.http.HttpUtils;
|
||||||
import org.jclouds.http.internal.SignatureWire;
|
import org.jclouds.http.internal.SignatureWire;
|
||||||
import org.jclouds.logging.config.NullLoggingModule;
|
import org.jclouds.logging.config.NullLoggingModule;
|
||||||
import org.jclouds.rest.RestContextFactory;
|
import org.jclouds.rest.RestContextFactory;
|
||||||
import org.jclouds.rest.RestClientTest.MockModule;
|
import org.jclouds.rest.BaseRestClientTest.MockModule;
|
||||||
import org.jclouds.util.Utils;
|
import org.jclouds.util.Utils;
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
@ -215,6 +216,8 @@ public class SignedHeaderAuthTest {
|
||||||
new Properties()).buildInjector();
|
new Properties()).buildInjector();
|
||||||
|
|
||||||
encryptionService = injector.getInstance(EncryptionService.class);
|
encryptionService = injector.getInstance(EncryptionService.class);
|
||||||
|
HttpUtils utils = injector.getInstance(HttpUtils.class);
|
||||||
|
|
||||||
Security.addProvider(new BouncyCastleProvider());
|
Security.addProvider(new BouncyCastleProvider());
|
||||||
|
|
||||||
KeyPair pair = KeyPair.class.cast(new PEMReader(new StringReader(PRIVATE_KEY)).readObject());
|
KeyPair pair = KeyPair.class.cast(new PEMReader(new StringReader(PRIVATE_KEY)).readObject());
|
||||||
|
@ -229,7 +232,7 @@ public class SignedHeaderAuthTest {
|
||||||
return TIMESTAMP_ISO8601;
|
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.Metadata;
|
||||||
import org.jclouds.chef.domain.Resource;
|
import org.jclouds.chef.domain.Resource;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
|
import org.jclouds.http.Payloads;
|
||||||
import org.jclouds.http.functions.config.ParserModule;
|
import org.jclouds.http.functions.config.ParserModule;
|
||||||
import org.jclouds.util.Utils;
|
import org.jclouds.util.Utils;
|
||||||
import org.testng.annotations.BeforeTest;
|
import org.testng.annotations.BeforeTest;
|
||||||
|
@ -39,34 +40,37 @@ public class ParseCookbookVersionFromJsonTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBrew() throws IOException {
|
public void testBrew() throws IOException {
|
||||||
CookbookVersion cookbook = handler.apply(new HttpResponse(
|
CookbookVersion cookbook = handler.apply(new HttpResponse(200, "ok", Payloads
|
||||||
ParseCookbookVersionFromJsonTest.class.getResourceAsStream("/brew-cookbook.json")));
|
.newPayload(ParseCookbookVersionFromJsonTest.class
|
||||||
|
.getResourceAsStream("/brew-cookbook.json"))));
|
||||||
|
|
||||||
assertEquals(cookbook, handler.apply(new HttpResponse(Utils.toInputStream(new Gson()
|
assertEquals(cookbook, handler.apply(new HttpResponse(200, "ok", Payloads.newPayload(Utils
|
||||||
.toJson(cookbook)))));
|
.toInputStream(new Gson().toJson(cookbook))))));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testTomcat() {
|
public void testTomcat() {
|
||||||
CookbookVersion cookbook = handler
|
CookbookVersion cookbook = handler.apply(new HttpResponse(200, "ok", Payloads
|
||||||
.apply(new HttpResponse(ParseCookbookVersionFromJsonTest.class
|
.newPayload(ParseCookbookVersionFromJsonTest.class
|
||||||
.getResourceAsStream("/tomcat-cookbook.json")));
|
.getResourceAsStream("/tomcat-cookbook.json"))));
|
||||||
|
|
||||||
assertEquals(cookbook, handler.apply(new HttpResponse(Utils.toInputStream(new Gson()
|
assertEquals(cookbook, handler.apply(new HttpResponse(200, "ok", Payloads.newPayload(Utils
|
||||||
.toJson(cookbook)))));
|
.toInputStream(new Gson().toJson(cookbook))))));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMysql() throws IOException {
|
public void testMysql() throws IOException {
|
||||||
CookbookVersion cookbook = handler.apply(new HttpResponse(
|
CookbookVersion cookbook = handler.apply(new HttpResponse(200, "ok", Payloads
|
||||||
ParseCookbookVersionFromJsonTest.class.getResourceAsStream("/mysql-cookbook.json")));
|
.newPayload(ParseCookbookVersionFromJsonTest.class
|
||||||
|
.getResourceAsStream("/mysql-cookbook.json"))));
|
||||||
|
|
||||||
assertEquals(cookbook, handler.apply(new HttpResponse(Utils.toInputStream(new Gson()
|
assertEquals(cookbook, handler.apply(new HttpResponse(200, "ok", Payloads.newPayload(Utils
|
||||||
.toJson(cookbook)))));
|
.toInputStream(new Gson().toJson(cookbook))))));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testApache() {
|
public void testApache() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
handler.apply(new HttpResponse(ParseCookbookVersionFromJsonTest.class
|
handler.apply(new HttpResponse(200, "ok", Payloads
|
||||||
.getResourceAsStream("/apache-chef-demo-cookbook.json"))),
|
.newPayload(ParseCookbookVersionFromJsonTest.class
|
||||||
|
.getResourceAsStream("/apache-chef-demo-cookbook.json")))),
|
||||||
new CookbookVersion(
|
new CookbookVersion(
|
||||||
"apache-chef-demo-0.0.0",
|
"apache-chef-demo-0.0.0",
|
||||||
ImmutableSet.<Resource> of(),
|
ImmutableSet.<Resource> of(),
|
||||||
|
|
|
@ -22,12 +22,15 @@
|
||||||
* ====================================================================
|
* ====================================================================
|
||||||
*/
|
*/
|
||||||
package org.jclouds.chef.functions;
|
package org.jclouds.chef.functions;
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
|
import org.jclouds.http.Payloads;
|
||||||
|
import org.jclouds.http.functions.ReturnStringIf200;
|
||||||
import org.jclouds.util.Utils;
|
import org.jclouds.util.Utils;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -42,8 +45,9 @@ public class ParseErrorFromJsonOrReturnBodyTest {
|
||||||
InputStream is = Utils
|
InputStream is = Utils
|
||||||
.toInputStream("{\"error\":[\"invalid tarball: tarball root must contain java-bytearray\"]}");
|
.toInputStream("{\"error\":[\"invalid tarball: tarball root must contain java-bytearray\"]}");
|
||||||
|
|
||||||
ParseErrorFromJsonOrReturnBody parser = new ParseErrorFromJsonOrReturnBody();
|
ParseErrorFromJsonOrReturnBody parser = new ParseErrorFromJsonOrReturnBody(
|
||||||
String response = parser.apply(new HttpResponse(is));
|
new ReturnStringIf200());
|
||||||
|
String response = parser.apply(new HttpResponse(200, "ok", Payloads.newPayload(is)));
|
||||||
assertEquals(response, "invalid tarball: tarball root must contain java-bytearray");
|
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 java.io.IOException;
|
||||||
|
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
|
import org.jclouds.http.Payloads;
|
||||||
import org.jclouds.http.functions.config.ParserModule;
|
import org.jclouds.http.functions.config.ParserModule;
|
||||||
import org.jclouds.util.Utils;
|
import org.jclouds.util.Utils;
|
||||||
import org.testng.annotations.BeforeTest;
|
import org.testng.annotations.BeforeTest;
|
||||||
|
@ -33,15 +34,17 @@ public class ParseKeyFromJsonTest {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
handler
|
handler
|
||||||
.apply(new HttpResponse(
|
.apply(new HttpResponse(
|
||||||
Utils
|
200,
|
||||||
.toInputStream("{\n\"uri\": \"https://api.opscode.com/users/bobo\", \"private_key\": \"RSA_PRIVATE_KEY\",}"))),
|
"ok",
|
||||||
|
Payloads
|
||||||
|
.newPayload(Utils
|
||||||
|
.toInputStream("{\n\"uri\": \"https://api.opscode.com/users/bobo\", \"private_key\": \"RSA_PRIVATE_KEY\",}")))),
|
||||||
"RSA_PRIVATE_KEY");
|
"RSA_PRIVATE_KEY");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void test2() {
|
public void test2() {
|
||||||
String key = handler.apply(new HttpResponse(ParseKeyFromJsonTest.class
|
String key = handler.apply(new HttpResponse(200, "ok", Payloads
|
||||||
.getResourceAsStream("/newclient.txt")));
|
.newPayload(ParseKeyFromJsonTest.class.getResourceAsStream("/newclient.txt"))));
|
||||||
assert key.startsWith("-----BEGIN RSA PRIVATE KEY-----\n");
|
assert key.startsWith("-----BEGIN RSA PRIVATE KEY-----\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import static org.testng.Assert.assertEquals;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
|
import org.jclouds.http.Payloads;
|
||||||
import org.jclouds.http.functions.config.ParserModule;
|
import org.jclouds.http.functions.config.ParserModule;
|
||||||
import org.jclouds.util.Utils;
|
import org.jclouds.util.Utils;
|
||||||
import org.testng.annotations.BeforeTest;
|
import org.testng.annotations.BeforeTest;
|
||||||
|
@ -34,8 +35,11 @@ public class ParseKeySetFromJsonTest {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
handler
|
handler
|
||||||
.apply(new HttpResponse(
|
.apply(new HttpResponse(
|
||||||
Utils
|
200,
|
||||||
.toInputStream("{\n\"opscode-validator\": \"https://api.opscode.com/...\", \"pimp-validator\": \"https://api.opscode.com/...\"}"))),
|
"ok",
|
||||||
ImmutableSet.of("opscode-validator","pimp-validator"));
|
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.chef.domain.Organization;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
|
import org.jclouds.http.Payloads;
|
||||||
import org.jclouds.http.functions.config.ParserModule;
|
import org.jclouds.http.functions.config.ParserModule;
|
||||||
import org.jclouds.util.Utils;
|
import org.jclouds.util.Utils;
|
||||||
import org.testng.annotations.BeforeTest;
|
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\" }";
|
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.chef.domain.Sandbox;
|
||||||
import org.jclouds.date.DateService;
|
import org.jclouds.date.DateService;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
|
import org.jclouds.http.Payloads;
|
||||||
import org.jclouds.http.functions.config.ParserModule;
|
import org.jclouds.http.functions.config.ParserModule;
|
||||||
import org.jclouds.http.functions.config.ParserModule.DateAdapter;
|
import org.jclouds.http.functions.config.ParserModule.DateAdapter;
|
||||||
import org.jclouds.http.functions.config.ParserModule.Iso8601DateAdapter;
|
import org.jclouds.http.functions.config.ParserModule.Iso8601DateAdapter;
|
||||||
|
@ -44,9 +45,9 @@ public class ParseSandboxFromJsonTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void test() {
|
public void test() {
|
||||||
assertEquals(handler.apply(new HttpResponse(ParseSandboxFromJsonTest.class
|
assertEquals(handler.apply(new HttpResponse(200, "ok", Payloads
|
||||||
.getResourceAsStream("/sandbox.json"))), new Sandbox(
|
.newPayload(ParseSandboxFromJsonTest.class.getResourceAsStream("/sandbox.json")))),
|
||||||
"1-8c27b0ea4c2b7aaedbb44cfbdfcc11b2", false, dateService
|
new Sandbox("1-8c27b0ea4c2b7aaedbb44cfbdfcc11b2", false, dateService
|
||||||
.iso8601SecondsDateParse("2010-07-07T03:36:00+00:00"), ImmutableSet
|
.iso8601SecondsDateParse("2010-07-07T03:36:00+00:00"), ImmutableSet
|
||||||
.<String> of(), "f9d6d9b72bae465890aae87969f98a9c",
|
.<String> of(), "f9d6d9b72bae465890aae87969f98a9c",
|
||||||
"f9d6d9b72bae465890aae87969f98a9c"));
|
"f9d6d9b72bae465890aae87969f98a9c"));
|
||||||
|
|
|
@ -8,6 +8,7 @@ import java.net.URI;
|
||||||
import org.jclouds.chef.domain.ChecksumStatus;
|
import org.jclouds.chef.domain.ChecksumStatus;
|
||||||
import org.jclouds.chef.domain.UploadSandbox;
|
import org.jclouds.chef.domain.UploadSandbox;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
|
import org.jclouds.http.Payloads;
|
||||||
import org.jclouds.http.functions.config.ParserModule;
|
import org.jclouds.http.functions.config.ParserModule;
|
||||||
import org.testng.annotations.BeforeTest;
|
import org.testng.annotations.BeforeTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
@ -34,8 +35,9 @@ public class ParseUploadSiteFromJsonTest {
|
||||||
|
|
||||||
public void test() {
|
public void test() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
handler.apply(new HttpResponse(ParseUploadSiteFromJsonTest.class
|
handler.apply(new HttpResponse(200, "ok", Payloads
|
||||||
.getResourceAsStream("/upload-site.json"))),
|
.newPayload(ParseUploadSiteFromJsonTest.class
|
||||||
|
.getResourceAsStream("/upload-site.json")))),
|
||||||
new UploadSandbox(
|
new UploadSandbox(
|
||||||
URI
|
URI
|
||||||
.create("https://api.opscode.com/organizations/jclouds/sandboxes/d454f71e2a5f400c808d0c5d04c2c88c"),
|
.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.chef.domain.User;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
|
import org.jclouds.http.Payloads;
|
||||||
import org.jclouds.http.functions.config.ParserModule;
|
import org.jclouds.http.functions.config.ParserModule;
|
||||||
import org.jclouds.util.Utils;
|
import org.jclouds.util.Utils;
|
||||||
import org.testng.annotations.BeforeTest;
|
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}";
|
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 java.io.IOException;
|
||||||
|
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
|
import org.jclouds.http.Payloads;
|
||||||
import org.jclouds.http.functions.config.ParserModule;
|
import org.jclouds.http.functions.config.ParserModule;
|
||||||
import org.jclouds.util.Utils;
|
import org.jclouds.util.Utils;
|
||||||
import org.testng.annotations.BeforeTest;
|
import org.testng.annotations.BeforeTest;
|
||||||
|
@ -31,8 +32,8 @@ public class ParseValueSetFromJsonTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRegex() {
|
public void testRegex() {
|
||||||
assertEquals(handler.apply(new HttpResponse(Utils
|
assertEquals(handler.apply(new HttpResponse(200, "ok", Payloads.newPayload(Utils
|
||||||
.toInputStream("{\"runit\":[\"0.7.0\",\"0.7.1\"]}"))), ImmutableSet
|
.toInputStream("{\"runit\":[\"0.7.0\",\"0.7.1\"]}")))), ImmutableSet.of("0.7.0",
|
||||||
.of("0.7.0", "0.7.1"));
|
"0.7.1"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@ import javax.inject.Named;
|
||||||
import org.jclouds.concurrent.Timeout;
|
import org.jclouds.concurrent.Timeout;
|
||||||
import org.jclouds.internal.ClassMethodArgs;
|
import org.jclouds.internal.ClassMethodArgs;
|
||||||
import org.jclouds.rest.annotations.Delegate;
|
import org.jclouds.rest.annotations.Delegate;
|
||||||
|
import org.jclouds.util.Utils;
|
||||||
|
|
||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
@ -132,20 +133,24 @@ public class SyncProxy implements InvocationHandler {
|
||||||
return ((ListenableFuture<?>) methodMap.get(method).invoke(delegate, args)).get(
|
return ((ListenableFuture<?>) methodMap.get(method).invoke(delegate, args)).get(
|
||||||
timeoutMap.get(method), TimeUnit.NANOSECONDS);
|
timeoutMap.get(method), TimeUnit.NANOSECONDS);
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
throw typedExceptionOrPropagate(method.getExceptionTypes(), e.getCause());
|
throw throwTypedExceptionOrCause(method.getExceptionTypes(), e);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw typedExceptionOrPropagate(method.getExceptionTypes(), e);
|
throw throwTypedExceptionOrCause(method.getExceptionTypes(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Throwable typedExceptionOrPropagate(Class<?>[] exceptionTypes, Throwable throwable) {
|
@SuppressWarnings("unchecked")
|
||||||
for (Class<?> type : exceptionTypes) {
|
public static Exception throwTypedExceptionOrCause(Class[] exceptionTypes, Exception exception)
|
||||||
if (type.isInstance(throwable)) {
|
throws Exception {
|
||||||
return throwable;
|
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
|
@Override
|
||||||
|
@ -166,6 +171,6 @@ public class SyncProxy implements InvocationHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Sync Proxy for: " + delegate.toString();
|
return "Sync Proxy for: " + delegate.getClass().getSimpleName();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -19,6 +19,7 @@
|
||||||
package org.jclouds.encryption;
|
package org.jclouds.encryption;
|
||||||
|
|
||||||
import java.io.FilterOutputStream;
|
import java.io.FilterOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.security.Key;
|
import java.security.Key;
|
||||||
|
@ -62,6 +63,7 @@ public interface EncryptionService {
|
||||||
* <h2>Note</h2>
|
* <h2>Note</h2>
|
||||||
* <p/>
|
* <p/>
|
||||||
* If this is an InputStream, it will be converted to a byte array first.
|
* If this is an InputStream, it will be converted to a byte array first.
|
||||||
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
<T extends PayloadEnclosing> T generateMD5BufferingIfNotRepeatable(T payloadEnclosing);
|
<T extends PayloadEnclosing> T generateMD5BufferingIfNotRepeatable(T payloadEnclosing);
|
||||||
|
|
||||||
|
|
|
@ -23,9 +23,12 @@ import static com.google.common.base.Preconditions.checkState;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
import org.jclouds.encryption.EncryptionService;
|
import org.jclouds.encryption.EncryptionService;
|
||||||
import org.jclouds.http.Payload;
|
import org.jclouds.http.Payload;
|
||||||
import org.jclouds.http.PayloadEnclosing;
|
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 {
|
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',
|
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) '5', (byte) '6', (byte) '7', (byte) '8', (byte) '9', (byte) 'a', (byte) 'b',
|
||||||
(byte) 'c', (byte) 'd', (byte) 'e', (byte) 'f' };
|
(byte) 'c', (byte) 'd', (byte) 'e', (byte) 'f' };
|
||||||
|
@ -81,6 +90,7 @@ public abstract class BaseEncryptionService implements EncryptionService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
|
* @
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public <T extends PayloadEnclosing> T generateMD5BufferingIfNotRepeatable(T payloadEnclosing) {
|
public <T extends PayloadEnclosing> T generateMD5BufferingIfNotRepeatable(T payloadEnclosing) {
|
||||||
|
|
|
@ -18,6 +18,9 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.encryption.internal;
|
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.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -34,9 +37,6 @@ import javax.crypto.spec.SecretKeySpec;
|
||||||
|
|
||||||
import org.jclouds.http.payloads.ByteArrayPayload;
|
import org.jclouds.http.payloads.ByteArrayPayload;
|
||||||
|
|
||||||
import com.google.common.base.Throwables;
|
|
||||||
import com.google.common.io.Closeables;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
|
@ -73,7 +73,7 @@ public class JCEEncryptionService extends BaseEncryptionService {
|
||||||
@Override
|
@Override
|
||||||
public byte[] md5(InputStream toEncode) {
|
public byte[] md5(InputStream toEncode) {
|
||||||
MessageDigest eTag = getDigest();
|
MessageDigest eTag = getDigest();
|
||||||
byte[] buffer = new byte[1024];
|
byte[] buffer = new byte[BUF_SIZE];
|
||||||
int numRead = -1;
|
int numRead = -1;
|
||||||
try {
|
try {
|
||||||
do {
|
do {
|
||||||
|
@ -83,9 +83,9 @@ public class JCEEncryptionService extends BaseEncryptionService {
|
||||||
}
|
}
|
||||||
} while (numRead != -1);
|
} while (numRead != -1);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
propagate(e);
|
||||||
} finally {
|
} finally {
|
||||||
Closeables.closeQuietly(toEncode);
|
closeQuietly(toEncode);
|
||||||
}
|
}
|
||||||
return eTag.digest();
|
return eTag.digest();
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,7 @@ public class JCEEncryptionService extends BaseEncryptionService {
|
||||||
@Override
|
@Override
|
||||||
public ByteArrayPayload generatePayloadWithMD5For(InputStream toEncode) {
|
public ByteArrayPayload generatePayloadWithMD5For(InputStream toEncode) {
|
||||||
MessageDigest eTag = getDigest();
|
MessageDigest eTag = getDigest();
|
||||||
byte[] buffer = new byte[1024];
|
byte[] buffer = new byte[BUF_SIZE];
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
long length = 0;
|
long length = 0;
|
||||||
int numRead = -1;
|
int numRead = -1;
|
||||||
|
@ -117,10 +117,10 @@ public class JCEEncryptionService extends BaseEncryptionService {
|
||||||
}
|
}
|
||||||
} while (numRead != -1);
|
} while (numRead != -1);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
propagate(e);
|
||||||
} finally {
|
} finally {
|
||||||
Closeables.closeQuietly(out);
|
closeQuietly(out);
|
||||||
Closeables.closeQuietly(toEncode);
|
closeQuietly(toEncode);
|
||||||
}
|
}
|
||||||
return new ByteArrayPayload(out.toByteArray(), eTag.digest());
|
return new ByteArrayPayload(out.toByteArray(), eTag.digest());
|
||||||
}
|
}
|
||||||
|
@ -167,10 +167,10 @@ public class JCEEncryptionService extends BaseEncryptionService {
|
||||||
try {
|
try {
|
||||||
digest = MessageDigest.getInstance(algorithm);
|
digest = MessageDigest.getInstance(algorithm);
|
||||||
} catch (NoSuchAlgorithmException e1) {
|
} catch (NoSuchAlgorithmException e1) {
|
||||||
Throwables.propagate(e1);
|
propagate(e1);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
byte[] buffer = new byte[1024];
|
byte[] buffer = new byte[BUF_SIZE];
|
||||||
long length = 0;
|
long length = 0;
|
||||||
int numRead = -1;
|
int numRead = -1;
|
||||||
try {
|
try {
|
||||||
|
@ -182,9 +182,9 @@ public class JCEEncryptionService extends BaseEncryptionService {
|
||||||
}
|
}
|
||||||
} while (numRead != -1);
|
} while (numRead != -1);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
propagate(e);
|
||||||
} finally {
|
} finally {
|
||||||
Closeables.closeQuietly(plainBytes);
|
closeQuietly(plainBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
return digest.digest();
|
return digest.digest();
|
||||||
|
@ -198,10 +198,9 @@ public class JCEEncryptionService extends BaseEncryptionService {
|
||||||
cipher.init(Cipher.ENCRYPT_MODE, key);
|
cipher.init(Cipher.ENCRYPT_MODE, key);
|
||||||
return cipher.doFinal(toSign.getBytes());
|
return cipher.doFinal(toSign.getBytes());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Throwables.propagate(e);
|
propagate(e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.http;
|
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
|
* 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 interface HttpErrorHandler {
|
||||||
public static final HttpErrorHandler NOOP = new HttpErrorHandler() {
|
public static final HttpErrorHandler NOOP = new HttpErrorHandler() {
|
||||||
public void handleError(HttpCommand command, HttpResponse response) {
|
public void handleError(HttpCommand command, HttpResponse response) {
|
||||||
if (response.getContent() != null)
|
if (response.getPayload() != null)
|
||||||
Closeables.closeQuietly(response.getContent());
|
response.getPayload().release();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -20,17 +20,20 @@ package org.jclouds.http;
|
||||||
|
|
||||||
import java.util.Collection;
|
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.LinkedHashMultimap;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
import com.google.common.collect.Multimaps;
|
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
|
* @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.
|
* synchronized as there is no concurrent version. Headers may change in flight due to redirects.
|
||||||
|
@ -42,6 +45,14 @@ public class HttpMessage {
|
||||||
return headers;
|
return headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public HttpMessage() {
|
||||||
|
this(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public HttpMessage(@Nullable Payload payload) {
|
||||||
|
super(payload);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* try to get the value, then try as lowercase.
|
* try to get the value, then try as lowercase.
|
||||||
*/
|
*/
|
||||||
|
@ -55,7 +66,7 @@ public class HttpMessage {
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
int result = 1;
|
int result = super.hashCode();
|
||||||
result = prime * result + ((headers == null) ? 0 : headers.hashCode());
|
result = prime * result + ((headers == null) ? 0 : headers.hashCode());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -64,7 +75,7 @@ public class HttpMessage {
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj)
|
if (this == obj)
|
||||||
return true;
|
return true;
|
||||||
if (obj == null)
|
if (!super.equals(obj))
|
||||||
return false;
|
return false;
|
||||||
if (getClass() != obj.getClass())
|
if (getClass() != obj.getClass())
|
||||||
return false;
|
return false;
|
||||||
|
@ -77,4 +88,9 @@ public class HttpMessage {
|
||||||
return true;
|
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.net.URI;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
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.Multimap;
|
||||||
import com.google.common.collect.Multimaps;
|
|
||||||
import com.google.inject.internal.Nullable;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a request that can be executed within {@link HttpCommandExecutorService}
|
* Represents a request that can be executed within {@link HttpCommandExecutorService}
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class HttpRequest extends PayloadEnclosingImpl implements PayloadEnclosing {
|
public class HttpRequest extends HttpMessage {
|
||||||
|
|
||||||
private List<HttpRequestFilter> requestFilters = newArrayList();
|
private List<HttpRequestFilter> requestFilters = newArrayList();
|
||||||
private String method;
|
private String method;
|
||||||
private URI endpoint;
|
private URI endpoint;
|
||||||
private Payload payload;
|
|
||||||
private char[] skips;
|
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
|
* @param endpoint
|
||||||
|
@ -164,6 +139,7 @@ public class HttpRequest extends PayloadEnclosingImpl implements PayloadEnclosin
|
||||||
result = prime * result + ((endpoint == null) ? 0 : endpoint.hashCode());
|
result = prime * result + ((endpoint == null) ? 0 : endpoint.hashCode());
|
||||||
result = prime * result + ((method == null) ? 0 : method.hashCode());
|
result = prime * result + ((method == null) ? 0 : method.hashCode());
|
||||||
result = prime * result + ((payload == null) ? 0 : payload.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 + ((requestFilters == null) ? 0 : requestFilters.hashCode());
|
||||||
result = prime * result + Arrays.hashCode(skips);
|
result = prime * result + Arrays.hashCode(skips);
|
||||||
return result;
|
return result;
|
||||||
|
@ -193,6 +169,11 @@ public class HttpRequest extends PayloadEnclosingImpl implements PayloadEnclosin
|
||||||
return false;
|
return false;
|
||||||
} else if (!payload.equals(other.payload))
|
} else if (!payload.equals(other.payload))
|
||||||
return false;
|
return false;
|
||||||
|
if (headers == null) {
|
||||||
|
if (other.headers != null)
|
||||||
|
return false;
|
||||||
|
} else if (!headers.equals(other.headers))
|
||||||
|
return false;
|
||||||
if (requestFilters == null) {
|
if (requestFilters == null) {
|
||||||
if (other.requestFilters != null)
|
if (other.requestFilters != null)
|
||||||
return false;
|
return false;
|
||||||
|
@ -205,7 +186,8 @@ public class HttpRequest extends PayloadEnclosingImpl implements PayloadEnclosin
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
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;
|
package org.jclouds.http;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a response produced from {@link HttpCommandExecutorService}
|
* Represents a response produced from {@link HttpCommandExecutorService}
|
||||||
|
@ -26,44 +26,28 @@ import java.io.InputStream;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class HttpResponse extends HttpMessage {
|
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) {
|
public HttpResponse(int statusCode, String message, @Nullable Payload payload) {
|
||||||
this.content = content;
|
super(payload);
|
||||||
|
this.statusCode = statusCode;
|
||||||
|
this.message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getStatusCode() {
|
public int getStatusCode() {
|
||||||
return statusCode;
|
return statusCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStatusCode(int statusCode) {
|
|
||||||
this.statusCode = statusCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMessage() {
|
public String getMessage() {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMessage(String message) {
|
|
||||||
this.message = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public InputStream getContent() {
|
|
||||||
return content;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setContent(InputStream content) {
|
|
||||||
this.content = content;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "[message=" + message + ", statusCode=" + statusCode + ", headers=" + headers + "]";
|
return "[message=" + message + ", statusCode=" + statusCode + ", headers=" + headers
|
||||||
|
+ ", payload=" + payload + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getStatusLine() {
|
public String getStatusLine() {
|
||||||
|
@ -74,7 +58,8 @@ public class HttpResponse extends HttpMessage {
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
int result = super.hashCode();
|
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 + ((message == null) ? 0 : message.hashCode());
|
||||||
result = prime * result + statusCode;
|
result = prime * result + statusCode;
|
||||||
return result;
|
return result;
|
||||||
|
@ -89,10 +74,15 @@ public class HttpResponse extends HttpMessage {
|
||||||
if (getClass() != obj.getClass())
|
if (getClass() != obj.getClass())
|
||||||
return false;
|
return false;
|
||||||
HttpResponse other = (HttpResponse) obj;
|
HttpResponse other = (HttpResponse) obj;
|
||||||
if (content == null) {
|
if (payload == null) {
|
||||||
if (other.content != null)
|
if (other.payload != null)
|
||||||
return false;
|
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;
|
return false;
|
||||||
if (message == null) {
|
if (message == null) {
|
||||||
if (other.message != null)
|
if (other.message != null)
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.http;
|
package org.jclouds.http;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an error obtained from an HttpResponse.
|
* Represents an error obtained from an HttpResponse.
|
||||||
*
|
*
|
||||||
|
@ -31,15 +33,15 @@ public class HttpResponseException extends RuntimeException {
|
||||||
protected final HttpResponse response;
|
protected final HttpResponse response;
|
||||||
private String content;
|
private String content;
|
||||||
|
|
||||||
public HttpResponseException(String message, HttpCommand command, HttpResponse response,
|
public HttpResponseException(String message, HttpCommand command,
|
||||||
Throwable cause) {
|
@Nullable HttpResponse response, Throwable cause) {
|
||||||
super(message, cause);
|
super(message, cause);
|
||||||
this.command = command;
|
this.command = command;
|
||||||
this.response = response;
|
this.response = response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpResponseException(String message, HttpCommand command, HttpResponse response,
|
public HttpResponseException(String message, HttpCommand command,
|
||||||
String content, Throwable cause) {
|
@Nullable HttpResponse response, String content, Throwable cause) {
|
||||||
super(message, cause);
|
super(message, cause);
|
||||||
this.command = command;
|
this.command = command;
|
||||||
this.response = response;
|
this.response = response;
|
||||||
|
@ -58,14 +60,14 @@ public class HttpResponseException extends RuntimeException {
|
||||||
content, cause);
|
content, cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpResponseException(String message, HttpCommand command, HttpResponse response) {
|
public HttpResponseException(String message, HttpCommand command, @Nullable HttpResponse response) {
|
||||||
super(message);
|
super(message);
|
||||||
this.command = command;
|
this.command = command;
|
||||||
this.response = response;
|
this.response = response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpResponseException(String message, HttpCommand command, HttpResponse response,
|
public HttpResponseException(String message, HttpCommand command,
|
||||||
String content) {
|
@Nullable HttpResponse response, String content) {
|
||||||
super(message);
|
super(message);
|
||||||
this.command = command;
|
this.command = command;
|
||||||
this.response = response;
|
this.response = response;
|
||||||
|
|
|
@ -18,13 +18,17 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.http;
|
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.Preconditions.checkState;
|
||||||
import static com.google.common.base.Throwables.propagate;
|
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.Lists.newArrayList;
|
||||||
import static com.google.common.collect.Sets.newTreeSet;
|
import static com.google.common.collect.Sets.newTreeSet;
|
||||||
import static com.google.common.io.ByteStreams.toByteArray;
|
import static com.google.common.io.ByteStreams.toByteArray;
|
||||||
import static com.google.common.io.Closeables.closeQuietly;
|
import static com.google.common.io.Closeables.closeQuietly;
|
||||||
import static java.util.Collections.singletonList;
|
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 javax.ws.rs.core.HttpHeaders.HOST;
|
||||||
import static org.jclouds.http.Payloads.newUrlEncodedFormPayload;
|
import static org.jclouds.http.Payloads.newUrlEncodedFormPayload;
|
||||||
import static org.jclouds.util.Patterns.CHAR_TO_ENCODED_PATTERN;
|
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.Patterns._7E_PATTERN;
|
||||||
import static org.jclouds.util.Utils.replaceAll;
|
import static org.jclouds.util.Utils.replaceAll;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
|
@ -57,12 +59,15 @@ import javax.annotation.Nullable;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import javax.ws.rs.HttpMethod;
|
import javax.ws.rs.HttpMethod;
|
||||||
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
import javax.ws.rs.core.UriBuilder;
|
import javax.ws.rs.core.UriBuilder;
|
||||||
|
|
||||||
import org.jclouds.Constants;
|
import org.jclouds.Constants;
|
||||||
|
import org.jclouds.encryption.EncryptionService;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
|
|
||||||
import com.google.common.base.Joiner;
|
import com.google.common.base.Joiner;
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.LinkedListMultimap;
|
import com.google.common.collect.LinkedListMultimap;
|
||||||
|
@ -76,6 +81,7 @@ import com.google.inject.Inject;
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
public class HttpUtils {
|
public class HttpUtils {
|
||||||
|
|
||||||
@Inject(optional = true)
|
@Inject(optional = true)
|
||||||
@Named(Constants.PROPERTY_RELAX_HOSTNAME)
|
@Named(Constants.PROPERTY_RELAX_HOSTNAME)
|
||||||
private boolean relaxHostname = false;
|
private boolean relaxHostname = false;
|
||||||
|
@ -90,6 +96,7 @@ public class HttpUtils {
|
||||||
private final int globalMaxConnectionsPerHost;
|
private final int globalMaxConnectionsPerHost;
|
||||||
private final int connectionTimeout;
|
private final int connectionTimeout;
|
||||||
private final int soTimeout;
|
private final int soTimeout;
|
||||||
|
private final EncryptionService encryptionService;
|
||||||
@Inject(optional = true)
|
@Inject(optional = true)
|
||||||
@Named(Constants.PROPERTY_PROXY_HOST)
|
@Named(Constants.PROPERTY_PROXY_HOST)
|
||||||
private String proxyHost;
|
private String proxyHost;
|
||||||
|
@ -104,10 +111,12 @@ public class HttpUtils {
|
||||||
private String proxyPassword;
|
private String proxyPassword;
|
||||||
|
|
||||||
@Inject
|
@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_SO_TIMEOUT) int soTimeout,
|
||||||
@Named(Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT) int globalMaxConnections,
|
@Named(Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT) int globalMaxConnections,
|
||||||
@Named(Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST) int globalMaxConnectionsPerHost) {
|
@Named(Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST) int globalMaxConnectionsPerHost) {
|
||||||
|
this.encryptionService = encryptionService;
|
||||||
this.soTimeout = soTimeout;
|
this.soTimeout = soTimeout;
|
||||||
this.connectionTimeout = connectionTimeout;
|
this.connectionTimeout = connectionTimeout;
|
||||||
this.globalMaxConnections = globalMaxConnections;
|
this.globalMaxConnections = globalMaxConnections;
|
||||||
|
@ -211,37 +220,34 @@ public class HttpUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public static byte[] toByteArrayOrNull(PayloadEnclosing response) {
|
||||||
* Content stream may need to be read. However, we should always close the http stream.
|
if (response.getPayload() != null) {
|
||||||
*/
|
InputStream input = response.getPayload().getInput();
|
||||||
public static void consumeContent(HttpResponse response) {
|
|
||||||
if (response.getContent() != null) {
|
|
||||||
try {
|
try {
|
||||||
toByteArray(response.getContent());
|
return toByteArray(input);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
propagate(e);
|
propagate(e);
|
||||||
} finally {
|
} finally {
|
||||||
closeQuietly(response.getContent());
|
closeQuietly(input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Content stream may need to be read. However, we should always close the http stream.
|
* Content stream may need to be read. However, we should always close the http stream.
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public static byte[] closeClientButKeepContentStream(HttpResponse response) {
|
public static byte[] closeClientButKeepContentStream(PayloadEnclosing response) {
|
||||||
if (response.getContent() != null) {
|
byte[] returnVal = toByteArrayOrNull(response);
|
||||||
try {
|
if (returnVal != null && !response.getPayload().isRepeatable()) {
|
||||||
byte[] data = toByteArray(response.getContent());
|
Payload newPayload = Payloads.newByteArrayPayload(returnVal);
|
||||||
response.setContent(new ByteArrayInputStream(data));
|
newPayload.setContentMD5(response.getPayload().getContentMD5());
|
||||||
return data;
|
newPayload.setContentType(response.getPayload().getContentType());
|
||||||
} catch (IOException e) {
|
response.setPayload(newPayload);
|
||||||
propagate(e);
|
|
||||||
} finally {
|
|
||||||
closeQuietly(response.getContent());
|
|
||||||
}
|
}
|
||||||
}
|
return returnVal;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static URI parseEndPoint(String hostHeader) {
|
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()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("%s %s", prefix, request.getRequestLine().toString());
|
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)
|
if (header.getKey() != null)
|
||||||
logger.debug("%s %s: %s", prefix, header.getKey(), header.getValue());
|
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()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("%s %s", prefix, response.getStatusLine().toString());
|
logger.debug("%s %s", prefix, response.getStatusLine().toString());
|
||||||
for (Entry<String, String> header : response.getHeaders().entries()) {
|
logMessage(logger, response, prefix);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -485,4 +486,80 @@ public class HttpUtils {
|
||||||
}
|
}
|
||||||
return formBuilder.toString();
|
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
|
@Nullable
|
||||||
String getContentType();
|
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;
|
package org.jclouds.http.functions;
|
||||||
|
|
||||||
|
import static org.jclouds.http.HttpUtils.releasePayload;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
import org.jclouds.encryption.internal.Base64;
|
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.rest.InvocationContext;
|
import org.jclouds.rest.InvocationContext;
|
||||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.io.Closeables;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
|
@ -62,10 +62,9 @@ public class ParseContentMD5FromHeaders implements Function<HttpResponse, byte[]
|
||||||
private GeneratedHttpRequest<?> request;
|
private GeneratedHttpRequest<?> request;
|
||||||
|
|
||||||
public byte[] apply(HttpResponse from) {
|
public byte[] apply(HttpResponse from) {
|
||||||
Closeables.closeQuietly(from.getContent());
|
releasePayload(from);
|
||||||
String contentMD5 = from.getFirstHeaderOrNull("Content-MD5");
|
if (from.getPayload() != null) {
|
||||||
if (contentMD5 != null) {
|
return from.getPayload().getContentMD5();
|
||||||
return Base64.decode(contentMD5);
|
|
||||||
}
|
}
|
||||||
throw new NoContentMD5Exception(request, from);
|
throw new NoContentMD5Exception(request, from);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.http.functions;
|
package org.jclouds.http.functions;
|
||||||
|
|
||||||
|
import static org.jclouds.http.HttpUtils.releasePayload;
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
|
|
||||||
|
@ -25,7 +27,6 @@ import org.jclouds.http.HttpException;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.io.Closeables;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses an MD5 checksum from the header {@link HttpHeaders#ETAG}.
|
* 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 class ParseETagHeader implements Function<HttpResponse, String> {
|
||||||
|
|
||||||
public String apply(HttpResponse from) {
|
public String apply(HttpResponse from) {
|
||||||
Closeables.closeQuietly(from.getContent());
|
releasePayload(from);
|
||||||
|
|
||||||
String eTag = from.getFirstHeaderOrNull(HttpHeaders.ETAG);
|
String eTag = from.getFirstHeaderOrNull(HttpHeaders.ETAG);
|
||||||
if (eTag == null) {
|
if (eTag == null) {
|
||||||
// TODO: Cloud Files sends incorrectly cased ETag header... Remove this when fixed.
|
// TODO: Cloud Files sends incorrectly cased ETag header... Remove this when fixed.
|
||||||
|
|
|
@ -18,9 +18,12 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.http.functions;
|
package org.jclouds.http.functions;
|
||||||
|
|
||||||
|
import static org.jclouds.http.HttpUtils.releasePayload;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
|
@ -28,7 +31,6 @@ import org.jclouds.http.HttpResponseException;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.io.Closeables;
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -44,7 +46,8 @@ public abstract class ParseJson<T> implements Function<HttpResponse, T> {
|
||||||
protected Logger logger = Logger.NULL;
|
protected Logger logger = Logger.NULL;
|
||||||
protected final Gson gson;
|
protected final Gson gson;
|
||||||
|
|
||||||
public ParseJson(Gson gson) {
|
@Inject
|
||||||
|
public ParseJson(Gson gson){
|
||||||
this.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>}.
|
* parses the http response body to create a new {@code <T>}.
|
||||||
*/
|
*/
|
||||||
public T apply(HttpResponse from) {
|
public T apply(HttpResponse from) {
|
||||||
InputStream gson = from.getContent();
|
InputStream gson = from.getPayload().getInput();
|
||||||
try {
|
try {
|
||||||
return apply(gson);
|
return apply(gson);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -61,7 +64,7 @@ public abstract class ParseJson<T> implements Function<HttpResponse, T> {
|
||||||
logger.error(e, message.toString());
|
logger.error(e, message.toString());
|
||||||
throw new HttpResponseException(message.toString() + "\n" + from, null, from, e);
|
throw new HttpResponseException(message.toString() + "\n" + from, null, from, e);
|
||||||
} finally {
|
} 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 {
|
public T apply(HttpResponse from) throws HttpException {
|
||||||
return parse(from.getContent());
|
return parse(from.getPayload().getInput());
|
||||||
}
|
}
|
||||||
|
|
||||||
public T parse(InputStream from) throws HttpException {
|
public T parse(InputStream from) throws HttpException {
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
package org.jclouds.http.functions;
|
package org.jclouds.http.functions;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
|
import static org.jclouds.http.HttpUtils.releasePayload;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
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));
|
throw new HttpException(String.format("Unhandled status code - %1$s", from));
|
||||||
if ("text/uri-list".equals(from.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE))) {
|
if ("text/uri-list".equals(from.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE))) {
|
||||||
try {
|
try {
|
||||||
if (from.getContent() == null)
|
if (from.getPayload().getInput() == null)
|
||||||
throw new HttpResponseException("no content", null, from);
|
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());
|
return URI.create(toParse.trim());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new HttpResponseException("couldn't parse uri from content", null, from, e);
|
throw new HttpResponseException("couldn't parse uri from content", null, from, e);
|
||||||
|
} finally {
|
||||||
|
releasePayload(from);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
releasePayload(from);
|
||||||
String location = from.getFirstHeaderOrNull(HttpHeaders.LOCATION);
|
String location = from.getFirstHeaderOrNull(HttpHeaders.LOCATION);
|
||||||
if (location == null)
|
if (location == null)
|
||||||
location = from.getFirstHeaderOrNull("location");
|
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