replaced jersey w/Uris & UriTemplates; removed complexity in url encoding and edge cases like matrix params

This commit is contained in:
Adrian Cole 2012-12-24 14:32:59 -08:00
parent 40d0041898
commit 69a8304617
200 changed files with 1845 additions and 2031 deletions

View File

@ -56,7 +56,6 @@ import org.jclouds.rest.annotations.ParamParser;
import org.jclouds.rest.annotations.QueryParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
@ -74,7 +73,6 @@ import com.google.inject.Provides;
* @author Adrian Cole
*/
@RequestFilters(SignRequest.class)
@SkipEncoding('/')
@Path("/rest/namespace")
public interface AtmosAsyncClient {
/**

View File

@ -18,18 +18,22 @@
*/
package org.jclouds.atmos.filters;
import static com.google.common.base.Throwables.propagate;
import static org.jclouds.Constants.LOGGER_SIGNATURE;
import static org.jclouds.crypto.CryptoStreams.base64;
import static org.jclouds.crypto.CryptoStreams.mac;
import static org.jclouds.http.Uris.uriBuilder;
import java.io.IOException;
import java.net.URI;
import java.security.InvalidKeyException;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import javax.ws.rs.core.UriBuilder;
import org.jclouds.crypto.Crypto;
import org.jclouds.crypto.CryptoStreams;
import org.jclouds.date.TimeStamp;
import org.jclouds.http.HttpException;
import org.jclouds.io.InputSuppliers;
@ -40,6 +44,7 @@ import org.jclouds.rest.annotations.Identity;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap;
/**
* Signs the EMC Atmos Online Storage request.
@ -55,7 +60,6 @@ public class ShareUrl implements Function<String, URI> {
private final byte[] key;
private final Supplier<URI> provider;
private final javax.inject.Provider<Long> timeStampProvider;
private final javax.inject.Provider<UriBuilder> uriBuilders;
private final Crypto crypto;
@Resource
@ -67,12 +71,10 @@ public class ShareUrl implements Function<String, URI> {
@Inject
public ShareUrl(@Identity String uid, @Credential String encodedKey,
@Provider Supplier<URI> provider, @TimeStamp javax.inject.Provider<Long> timeStampProvider,
javax.inject.Provider<UriBuilder> uriBuilders, Crypto crypto) {
@Provider Supplier<URI> provider, @TimeStamp javax.inject.Provider<Long> timeStampProvider, Crypto crypto) {
this.uid = uid;
this.key = CryptoStreams.base64(encodedKey);
this.key = base64(encodedKey);
this.provider = provider;
this.uriBuilders = uriBuilders;
this.timeStampProvider = timeStampProvider;
this.crypto = crypto;
}
@ -80,13 +82,14 @@ public class ShareUrl implements Function<String, URI> {
@Override
public URI apply(String path) throws HttpException {
String requestedResource = new StringBuilder().append("/rest/namespace/").append(path).toString();
long expires = timeStampProvider.get();
String expires = timeStampProvider.get().toString();
String signature = signString(createStringToSign(requestedResource, expires));
return uriBuilders.get().uri(provider.get()).path(requestedResource).queryParam("uid", uid).queryParam("expires",
expires).queryParam("signature", signature).build();
return uriBuilder(provider.get())
.replaceQuery(ImmutableMap.of("uid", uid, "expires", expires, "signature", signature))
.appendPath(requestedResource).build();
}
public String createStringToSign(String requestedResource, long expires) {
public String createStringToSign(String requestedResource, String expires) {
StringBuilder toSign = new StringBuilder();
toSign.append("GET\n");
toSign.append(requestedResource.toLowerCase()).append("\n");
@ -96,13 +99,13 @@ public class ShareUrl implements Function<String, URI> {
}
public String signString(String toSign) {
String signature;
try {
signature = CryptoStreams.base64(CryptoStreams.mac(InputSuppliers.of(toSign), crypto.hmacSHA1(key)));
} catch (Exception e) {
throw new HttpException("error signing request", e);
return base64(mac(InputSuppliers.of(toSign), crypto.hmacSHA1(key)));
} catch (InvalidKeyException e) {
throw propagate(e);
} catch (IOException e) {
throw propagate(e);
}
return signature;
}
}

View File

@ -51,7 +51,6 @@ import org.jclouds.rest.annotations.Headers;
import org.jclouds.rest.annotations.QueryParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.SkipEncoding;
import com.google.common.util.concurrent.ListenableFuture;
@ -66,7 +65,6 @@ import com.google.common.util.concurrent.ListenableFuture;
* @see <a href="http://www.rackspacecloud.com/cf-devguide-20090812.pdf" />
* @author Adrian Cole
*/
@SkipEncoding('/')
@RequestFilters(AuthenticateRequest.class)
@Endpoint(Storage.class)
public interface CloudFilesAsyncClient extends CommonSwiftAsyncClient {

View File

@ -18,12 +18,12 @@
*/
package org.jclouds.cloudfiles.blobstore.functions;
import static org.jclouds.http.Uris.uriBuilder;
import java.net.URI;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import javax.ws.rs.core.UriBuilder;
import org.jclouds.openstack.swift.domain.ObjectInfo;
@ -38,20 +38,18 @@ import com.google.common.cache.LoadingCache;
public class PublicUriForObjectInfo implements Function<ObjectInfo, URI> {
private final LoadingCache<String, URI> cdnContainer;
private final Provider<UriBuilder> uriBuilders;
@Inject
public PublicUriForObjectInfo(LoadingCache<String, URI> cdnContainer, Provider<UriBuilder> uriBuilders) {
public PublicUriForObjectInfo(LoadingCache<String, URI> cdnContainer) {
this.cdnContainer = cdnContainer;
this.uriBuilders = uriBuilders;
}
public URI apply(ObjectInfo from) {
if (from == null)
return null;
try {
return uriBuilders.get().uri(cdnContainer.getUnchecked(from.getContainer())).path(from.getName()).replaceQuery("")
.build();
return uriBuilder(cdnContainer.getUnchecked(from.getContainer()))
.clearQuery().appendPath(from.getName()).build();
} catch (NullPointerException e) {
// nulls not permitted from cache loader
return null;

View File

@ -56,7 +56,6 @@ import org.jclouds.rest.annotations.Payload;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.QueryParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.Unwrap;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404;
@ -76,7 +75,6 @@ import com.google.common.util.concurrent.ListenableFuture;
* @see <a href="http://docs.rackspacecloud.com/servers/api/cs-devguide-latest.pdf" />
* @author Adrian Cole
*/
@SkipEncoding({ '/', '=' })
@RequestFilters({ AuthenticateRequest.class, AddTimestampQuery.class })
@Endpoint(Compute.class)
public interface CloudServersAsyncClient {

View File

@ -20,21 +20,20 @@ package org.jclouds.cloudstack.binders;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.http.Uris.uriBuilder;
import static org.jclouds.http.utils.Queries.queryParser;
import java.net.URI;
import java.util.Map.Entry;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import javax.ws.rs.core.UriBuilder;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.utils.Queries;
import org.jclouds.rest.Binder;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Multimap;
import com.google.common.collect.ImmutableMultimap.Builder;
import com.google.common.collect.Multimap;
/**
*
@ -42,12 +41,6 @@ import com.google.common.collect.ImmutableMultimap.Builder;
*/
@Singleton
public class BindAccountSecurityGroupPairsToIndexedQueryParams implements Binder {
private final Provider<UriBuilder> uriBuilderProvider;
@Inject
public BindAccountSecurityGroupPairsToIndexedQueryParams(Provider<UriBuilder> uriBuilderProvider) {
this.uriBuilderProvider = checkNotNull(uriBuilderProvider, "uriBuilderProvider");
}
@SuppressWarnings("unchecked")
@Override
@ -55,15 +48,14 @@ public class BindAccountSecurityGroupPairsToIndexedQueryParams implements Binder
checkArgument(input instanceof Multimap<?, ?>, "this binder is only valid for Multimaps!");
Multimap<String, String> pairs = (Multimap<String, String>) checkNotNull(input, "account group pairs");
checkArgument(pairs.size() > 0, "you must specify at least one account, group pair");
UriBuilder builder = uriBuilderProvider.get();
builder.uri(request.getEndpoint());
Builder<String, String> map = ImmutableMultimap.<String, String> builder().putAll(
Queries.parseQueryToMap(request.getEndpoint().getQuery()));
Multimap<String, String> existingParams = queryParser().apply(request.getEndpoint().getQuery());
Builder<String, String> map = ImmutableMultimap.<String, String> builder().putAll(existingParams);
int i = 0;
for (Entry<String, String> entry : pairs.entries())
map.put(String.format("usersecuritygrouplist[%d].account", i), entry.getKey()).put(
String.format("usersecuritygrouplist[%d].group", i++), entry.getValue());
builder.replaceQuery(Queries.makeQueryLine(map.build(), null));
return (R) request.toBuilder().endpoint(builder.build()).build();
URI endpoint = uriBuilder(request.getEndpoint()).query(map.build()).build();
return (R) request.toBuilder().endpoint(endpoint).build();
}
}

View File

@ -456,7 +456,6 @@ public class Account extends ForwardingSet<User> {
"templatelimit", "templatetotal", "vmavailable", "vmlimit", "vmrunning", "vmstopped", "vmtotal", "volumeavailable", "volumelimit",
"volumetotal", "user"
})
@SuppressWarnings("unused")
private Account(String id, @Nullable Type type, @Nullable String networkDomain, @Nullable String domain,
@Nullable String domainId, @Nullable String IPsAvailable, @Nullable String IPLimit, long IPs,
boolean cleanupRequired, @Nullable String name, long receivedBytes, long sentBytes,

View File

@ -228,7 +228,6 @@ public class FirewallRule implements Comparable<FirewallRule> {
@ConstructorProperties({
"id", "cidrlist", "startport", "endport", "icmpcode", "icmptype", "ipaddress", "ipaddressid", "protocol", "state"
})
@SuppressWarnings("unused")
private FirewallRule(String id, @Nullable String CIDRs, int startPort, int endPort, @Nullable String icmpCode,
@Nullable String icmpType, @Nullable String ipAddress, @Nullable String ipAddressId,
@Nullable Protocol protocol, @Nullable State state) {

View File

@ -267,7 +267,6 @@ public class LoadBalancerRule {
"id", "account", "algorithm", "description", "domain", "domainid", "name", "privateport", "publicip",
"publicipid", "publicport", "state", "cidrlist", "zoneId"
})
@SuppressWarnings("unused")
private LoadBalancerRule(String id, @Nullable String account, @Nullable Algorithm algorithm,
@Nullable String description, @Nullable String domain, @Nullable String domainId,
@Nullable String name, int privatePort, @Nullable String publicIP,

View File

@ -261,7 +261,6 @@ public class PortForwardingRule implements Comparable<PortForwardingRule> {
"id", "ipaddress", "ipaddressid", "privateport", "protocol", "publicport", "state", "virtualmachinedisplayname",
"virtualmachineid", "virtualmachinename", "cidrlist", "privateendport", "publicendport"
})
@SuppressWarnings("unused")
private PortForwardingRule(String id, @Nullable String IPAddress, @Nullable String IPAddressId, int privatePort,
@Nullable Protocol protocol, int publicPort, @Nullable State state, @Nullable String virtualMachineDisplayName,
@Nullable String virtualMachineId, @Nullable String virtualMachineName, @Nullable String CIDRs,

View File

@ -30,7 +30,6 @@ import org.jclouds.cloudstack.options.ListStoragePoolsOptions;
import org.jclouds.rest.annotations.QueryParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.SkipEncoding;
import com.google.common.util.concurrent.ListenableFuture;
@ -44,7 +43,6 @@ import com.google.common.util.concurrent.ListenableFuture;
*/
@RequestFilters(AuthenticationFilter.class)
@QueryParams(keys = "response", values = "json")
@SkipEncoding({'/'})
public interface GlobalStoragePoolAsyncClient {
@GET

View File

@ -42,7 +42,6 @@ import org.jclouds.rest.annotations.OnlyElement;
import org.jclouds.rest.annotations.QueryParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.Unwrap;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
@ -59,7 +58,6 @@ import com.google.common.util.concurrent.ListenableFuture;
*/
@RequestFilters(AuthenticationFilter.class)
@QueryParams(keys = "response", values = "json")
@SkipEncoding({'/', ','})
public interface ISOAsyncClient {
/**

View File

@ -27,7 +27,6 @@ import javax.ws.rs.core.MediaType;
import org.jclouds.cloudstack.domain.SshKeyPair;
import org.jclouds.cloudstack.filters.AuthenticationFilter;
import org.jclouds.cloudstack.filters.ReEncodeQueryWithDefaultURLEncoder;
import org.jclouds.cloudstack.options.ListSSHKeyPairsOptions;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.OnlyElement;
@ -68,7 +67,6 @@ public interface SSHKeyPairAsyncClient {
@QueryParams(keys = "command", values = "registerSSHKeyPair")
@SelectJson("keypair")
@Consumes(MediaType.APPLICATION_JSON)
@RequestFilters(ReEncodeQueryWithDefaultURLEncoder.class)
ListenableFuture<SshKeyPair> registerSSHKeyPair(@QueryParam("name") String name, @QueryParam("publickey") String publicKey);
/**

View File

@ -46,7 +46,6 @@ import org.jclouds.rest.annotations.OnlyElement;
import org.jclouds.rest.annotations.QueryParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.Unwrap;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
@ -65,7 +64,6 @@ import com.google.common.util.concurrent.ListenableFuture;
*/
@RequestFilters(AuthenticationFilter.class)
@QueryParams(keys = "response", values = "json")
@SkipEncoding(',')
public interface TemplateAsyncClient {
/**

View File

@ -19,42 +19,42 @@
package org.jclouds.cloudstack.filters;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Throwables.propagate;
import static org.jclouds.Constants.LOGGER_SIGNATURE;
import static org.jclouds.crypto.CryptoStreams.base64;
import static org.jclouds.crypto.CryptoStreams.mac;
import static org.jclouds.http.Uris.uriBuilder;
import static org.jclouds.http.utils.Queries.encodeQueryLine;
import static org.jclouds.http.utils.Queries.queryParser;
import static org.jclouds.util.Strings2.toInputStream;
import java.util.Map.Entry;
import java.io.IOException;
import java.security.InvalidKeyException;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;
import javax.ws.rs.core.UriBuilder;
import org.jclouds.Constants;
import org.jclouds.crypto.Crypto;
import org.jclouds.crypto.CryptoStreams;
import org.jclouds.http.HttpException;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpUtils;
import org.jclouds.http.internal.SignatureWire;
import org.jclouds.http.utils.Queries;
import org.jclouds.io.InputSuppliers;
import org.jclouds.logging.Logger;
import org.jclouds.rest.RequestSigner;
import org.jclouds.rest.annotations.Credential;
import org.jclouds.rest.annotations.Identity;
import org.jclouds.util.Strings2;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Multimap;
import com.google.common.collect.TreeMultimap;
/**
*
* @see <a href=
* "http://download.cloud.com/releases/2.2.0/api/user/2.2api_security_details.html"
* />
* @see <a href= "http://download.cloud.com/releases/2.2.0/api/user/2.2api_security_details.html" />
* @author Adrian Cole
*
*/
@ -66,35 +66,29 @@ public class QuerySigner implements AuthenticationFilter, RequestSigner {
private final String secretKey;
private final Crypto crypto;
private final HttpUtils utils;
private final Provider<UriBuilder> builder;
@Resource
@Named(Constants.LOGGER_SIGNATURE)
@Named(LOGGER_SIGNATURE)
private Logger signatureLog = Logger.NULL;
@Inject
public QuerySigner(SignatureWire signatureWire, @Identity String accessKey, @Credential String secretKey,
Crypto crypto, HttpUtils utils, Provider<UriBuilder> builder) {
Crypto crypto, HttpUtils utils) {
this.signatureWire = signatureWire;
this.accessKey = accessKey;
this.secretKey = secretKey;
this.crypto = crypto;
this.utils = utils;
this.builder = builder;
}
public HttpRequest filter(HttpRequest request) throws HttpException {
checkNotNull(request, "request must be present");
Multimap<String, String> decodedParams = Queries.parseQueryToMap(request.getEndpoint().getRawQuery());
Multimap<String, String> decodedParams = queryParser().apply(request.getEndpoint().getRawQuery());
addSigningParams(decodedParams);
String stringToSign = createStringToSign(request, decodedParams);
String signature = sign(stringToSign);
addSignature(decodedParams, signature);
request = request
.toBuilder()
.endpoint(
builder.get().uri(request.getEndpoint())
.replaceQuery(Queries.makeQueryLine(decodedParams, null)).build()).build();
request = request.toBuilder().endpoint(uriBuilder(request.getEndpoint()).query(decodedParams).build()).build();
utils.logRequest(signatureLog, request, "<<");
return request;
}
@ -108,27 +102,24 @@ public class QuerySigner implements AuthenticationFilter, RequestSigner {
public String sign(String stringToSign) {
String signature;
try {
signature = CryptoStreams.base64(CryptoStreams.mac(InputSuppliers.of(stringToSign),
crypto.hmacSHA1(secretKey.getBytes())));
signature = base64(mac(InputSuppliers.of(stringToSign), crypto.hmacSHA1(secretKey.getBytes())));
if (signatureWire.enabled())
signatureWire.input(Strings2.toInputStream(signature));
} catch (Exception e) {
throw new HttpException("error signing request", e);
signatureWire.input(toInputStream(signature));
return signature;
} catch (InvalidKeyException e) {
throw propagate(e);
} catch (IOException e) {
throw propagate(e);
}
return signature;
}
@VisibleForTesting
public String createStringToSign(HttpRequest request, Multimap<String, String> decodedParams) {
utils.logRequest(signatureLog, request, ">>");
// encode each parameter value first,
ImmutableSortedSet.Builder<String> builder = ImmutableSortedSet.naturalOrder();
for (Entry<String, String> entry : decodedParams.entries())
builder.add(entry.getKey() + "=" + Strings2.urlEncode(entry.getValue()));
// like aws, percent encode the canonicalized string without skipping '/' and '?'
String queryLine = encodeQueryLine(TreeMultimap.create(decodedParams), ImmutableList.<Character> of());
// then, lower case the entire query string
String stringToSign = Joiner.on('&').join(builder.build()).toLowerCase();
String stringToSign = queryLine.toLowerCase();
if (signatureWire.enabled())
signatureWire.output(stringToSign);
@ -142,7 +133,7 @@ public class QuerySigner implements AuthenticationFilter, RequestSigner {
}
public String createStringToSign(HttpRequest input) {
Multimap<String, String> decodedParams = Queries.parseQueryToMap(input.getEndpoint().getQuery());
Multimap<String, String> decodedParams = queryParser().apply(input.getEndpoint().getQuery());
addSigningParams(decodedParams);
return createStringToSign(input, decodedParams);
}

View File

@ -1,58 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.cloudstack.filters;
import static com.google.common.collect.Iterables.getOnlyElement;
import javax.ws.rs.core.UriBuilder;
import org.jclouds.http.HttpException;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpRequestFilter;
import org.jclouds.http.utils.Queries;
import com.google.common.collect.Multimap;
import com.google.inject.Inject;
import com.google.inject.Provider;
/**
* By default, jclouds controls encoding based on rules which are different
*
* @author Adrian Cole
*/
public class ReEncodeQueryWithDefaultURLEncoder implements HttpRequestFilter {
private final Provider<UriBuilder> builders;
@Inject
public ReEncodeQueryWithDefaultURLEncoder(Provider<UriBuilder> builders) {
this.builders = builders;
}
@Override
public HttpRequest filter(HttpRequest request) throws HttpException {
UriBuilder builder = builders.get();
builder.uri(request.getEndpoint());
Multimap<String, String> map = Queries.parseQueryToMap(request.getEndpoint().getRawQuery());
builder.replaceQuery("");
for (String key : map.keySet())
builder.queryParam(key, getOnlyElement(map.get(key)));
return request.toBuilder().endpoint(builder.build()).build();
}
}

View File

@ -56,7 +56,7 @@ public class PasswordAuthenticationExpectTest extends BaseCloudStackExpectTest<C
login, loginResponse,
HttpRequest.builder()
.method("GET")
.endpoint("http://localhost:8080/client/api?response=json&command=listAccounts&listAll=true&sessionkey=" + Strings2.urlEncode(sessionKey))
.endpoint("http://localhost:8080/client/api?response=json&command=listAccounts&listAll=true&sessionkey=" + Strings2.urlEncode(sessionKey, '/'))
.addHeader("Accept", "application/json")
.addHeader(HttpHeaders.COOKIE, "JSESSIONID=" + jSessionId)
.build(),

View File

@ -78,7 +78,7 @@ public class CloudStackComputeServiceAdapterExpectTest extends BaseCloudStackCom
.addQueryParam("networkids", "204")
.addQueryParam("keypair", "mykeypair")
.addQueryParam("apiKey", "APIKEY")
.addQueryParam("signature", "hI%2FU4cWXdU6KTZKbJvzPCmOpGmU%3D")
.addQueryParam("signature", "hI/U4cWXdU6KTZKbJvzPCmOpGmU%3D")
.addHeader("Accept", "application/json")
.build();

View File

@ -85,7 +85,7 @@ public class DomainDomainClientExpectTest extends BaseCloudStackExpectTest<Domai
.method("GET")
.endpoint(
URI.create("http://localhost:8080/client/api?response=json&" +
"command=listDomains&listAll=true&id=1&apiKey=identity&signature=M16YxHWKST%2FcIRUHvWhfWovJugU%3D"))
"command=listDomains&listAll=true&id=1&apiKey=identity&signature=M16YxHWKST/cIRUHvWhfWovJugU%3D"))
.addHeader("Accept", "application/json")
.build(),
HttpResponse.builder()
@ -103,7 +103,7 @@ public class DomainDomainClientExpectTest extends BaseCloudStackExpectTest<Domai
.method("GET")
.endpoint(
URI.create("http://localhost:8080/client/api?response=json&" +
"command=listDomains&listAll=true&id=1&apiKey=identity&signature=M16YxHWKST%2FcIRUHvWhfWovJugU%3D"))
"command=listDomains&listAll=true&id=1&apiKey=identity&signature=M16YxHWKST/cIRUHvWhfWovJugU%3D"))
.addHeader("Accept", "application/json")
.build(),
HttpResponse.builder()

View File

@ -131,7 +131,7 @@ public class FirewallClientExpectTest extends BaseCloudStackExpectTest<FirewallC
.method("GET")
.endpoint(
URI.create("http://localhost:8080/client/api?response=json&command=createFirewallRule&" +
"ipaddressid=2&protocol=TCP&apiKey=identity&signature=d0MZ%2FyhQPAaV%2BYQmfZsQtQL2C28%3D"))
"ipaddressid=2&protocol=TCP&apiKey=identity&signature=d0MZ/yhQPAaV%2BYQmfZsQtQL2C28%3D"))
.addHeader("Accept", "application/json")
.build(),
HttpResponse.builder()
@ -150,7 +150,7 @@ public class FirewallClientExpectTest extends BaseCloudStackExpectTest<FirewallC
.method("GET")
.endpoint(
URI.create("http://localhost:8080/client/api?response=json&" +
"command=deleteFirewallRule&id=2015&apiKey=identity&signature=%2FT5FAO2yGPctaPmg7TEtIEFW3EU%3D"))
"command=deleteFirewallRule&id=2015&apiKey=identity&signature=/T5FAO2yGPctaPmg7TEtIEFW3EU%3D"))
.build(),
HttpResponse.builder()
.statusCode(200)
@ -248,7 +248,7 @@ public class FirewallClientExpectTest extends BaseCloudStackExpectTest<FirewallC
.endpoint(
URI.create("http://localhost:8080/client/api?response=json&command=createPortForwardingRule&" +
"ipaddressid=2&publicport=22&protocol=tcp&virtualmachineid=1234&privateport=22&" +
"apiKey=identity&signature=84dtGzQp0G6k3z3Gkc3F%2FHBNS2Y%3D"))
"apiKey=identity&signature=84dtGzQp0G6k3z3Gkc3F/HBNS2Y%3D"))
.addHeader("Accept", "application/json")
.build(),
HttpResponse.builder()

View File

@ -80,7 +80,7 @@ public class GlobalDomainClientExpectTest extends BaseCloudStackExpectTest<Globa
.method("GET")
.endpoint(
URI.create("http://localhost:8080/client/api?response=json&" +
"command=updateDomain&id=10&name=test-2&apiKey=identity&signature=5t1eUf2Eyf%2FaB6qt%2BqIj%2BmcwFIo%3D"))
"command=updateDomain&id=10&name=test-2&apiKey=identity&signature=5t1eUf2Eyf/aB6qt%2BqIj%2BmcwFIo%3D"))
.addHeader("Accept", "application/json")
.build(),
HttpResponse.builder()
@ -99,7 +99,7 @@ public class GlobalDomainClientExpectTest extends BaseCloudStackExpectTest<Globa
.method("GET")
.endpoint(
URI.create("http://localhost:8080/client/api?response=json&" +
"command=updateDomain&id=10&name=test-2&apiKey=identity&signature=5t1eUf2Eyf%2FaB6qt%2BqIj%2BmcwFIo%3D"))
"command=updateDomain&id=10&name=test-2&apiKey=identity&signature=5t1eUf2Eyf/aB6qt%2BqIj%2BmcwFIo%3D"))
.addHeader("Accept", "application/json")
.build(),
HttpResponse.builder()
@ -115,7 +115,7 @@ public class GlobalDomainClientExpectTest extends BaseCloudStackExpectTest<Globa
.method("GET")
.endpoint(
URI.create("http://localhost:8080/client/api?response=json&" +
"command=deleteDomain&cleanup=false&id=1&apiKey=identity&signature=%2F5aLbigg612t9IrZi0JZO7CyiOU%3D"))
"command=deleteDomain&cleanup=false&id=1&apiKey=identity&signature=/5aLbigg612t9IrZi0JZO7CyiOU%3D"))
.build(),
HttpResponse.builder()
.statusCode(200)

View File

@ -101,7 +101,7 @@ public class GlobalHostClientExpectTest extends BaseCloudStackExpectTest<GlobalH
public void testAddHostWhenResponseIs2xx() {
HttpRequest request = HttpRequest.builder()
.method("GET")
.endpoint("http://localhost:8080/client/api?response=json&command=addHost&zoneid=1&hypervisor=XenServer&url=http%3A%2F%2Fexample.com&username=fred&password=sekrit&hosttags=&allocationstate=Enabled&clusterid=1&clustername=Xen%20Clust%201&podid=1&apiKey=identity&signature=ExGaljKKQIlVbWk5hd0BnnjmBzs%3D")
.endpoint("http://localhost:8080/client/api?response=json&command=addHost&zoneid=1&hypervisor=XenServer&url=http%3A//example.com&username=fred&password=sekrit&hosttags=&allocationstate=Enabled&clusterid=1&clustername=Xen%20Clust%201&podid=1&apiKey=identity&signature=ExGaljKKQIlVbWk5hd0BnnjmBzs%3D")
.addHeader("Accept", "application/json").build();
HttpResponse response = HttpResponse.builder()
.payload(payloadFromResource("/addhostresponse.json"))
@ -121,7 +121,7 @@ public class GlobalHostClientExpectTest extends BaseCloudStackExpectTest<GlobalH
public void testUpdateHostWhenResponseIs2xx() {
HttpRequest request = HttpRequest.builder()
.method("GET")
.endpoint("http://localhost:8080/client/api?response=json&command=updateHost&id=1&allocationstate=Enabled&hosttags=&oscategoryid=5&apiKey=identity&signature=qTxNq9yQG8S108giqS%2FROFzgev8%3D")
.endpoint("http://localhost:8080/client/api?response=json&command=updateHost&id=1&allocationstate=Enabled&hosttags=&oscategoryid=5&apiKey=identity&signature=qTxNq9yQG8S108giqS/ROFzgev8%3D")
.addHeader("Accept", "application/json").build();
HttpResponse response = HttpResponse.builder()
.payload(payloadFromResource("/updatehostresponse.json"))
@ -165,7 +165,7 @@ public class GlobalHostClientExpectTest extends BaseCloudStackExpectTest<GlobalH
public void testPrepareHostForMaintenanceWhenResponseIs2xx() {
HttpRequest request = HttpRequest.builder()
.method("GET")
.endpoint("http://localhost:8080/client/api?response=json&command=prepareHostForMaintenance&id=1&apiKey=identity&signature=9tDwdox%2FxAKmZr9kVrR6Ttnxf3U%3D")
.endpoint("http://localhost:8080/client/api?response=json&command=prepareHostForMaintenance&id=1&apiKey=identity&signature=9tDwdox/xAKmZr9kVrR6Ttnxf3U%3D")
.addHeader("Accept", "application/json").build();
HttpResponse response = HttpResponse.builder()
.payload(payloadFromResource("/preparehostformaintenanceresponse.json"))
@ -207,7 +207,7 @@ public class GlobalHostClientExpectTest extends BaseCloudStackExpectTest<GlobalH
public void testAddSecondaryStorageWhenResponseIs2xx() {
HttpRequest request = HttpRequest.builder()
.method("GET")
.endpoint("http://localhost:8080/client/api?response=json&command=addSecondaryStorage&url=nfs%3A%2F%2F10.26.26.165%2Fmnt%2Fnfs%2Fcs_sec&zoneid=1&apiKey=identity&signature=MccRKx1yPP43ImiO70WlhVDlAIA%3D")
.endpoint("http://localhost:8080/client/api?response=json&command=addSecondaryStorage&url=nfs%3A//10.26.26.165/mnt/nfs/cs_sec&zoneid=1&apiKey=identity&signature=MccRKx1yPP43ImiO70WlhVDlAIA%3D")
.addHeader("Accept", "application/json").build();
HttpResponse response = HttpResponse.builder()
.payload(payloadFromResource("/addsecondarystorageresponse.json"))
@ -258,7 +258,7 @@ public class GlobalHostClientExpectTest extends BaseCloudStackExpectTest<GlobalH
public void testAddClusterWhenResponseIs2xx() {
HttpRequest request = HttpRequest.builder()
.method("GET")
.endpoint("http://localhost:8080/client/api?response=json&command=addCluster&zoneid=1&clustertype=CloudManaged&clustername=Xen%20Clust%201&hypervisor=XenServer&allocationstate=Enabled&podid=1&url=http%3A%2F%2Fexample.com%2Fcluster&username=fred&password=sekrit&apiKey=identity&signature=2uIQ5qF0bVycXK111wxvogWp1Yw%3D")
.endpoint("http://localhost:8080/client/api?response=json&command=addCluster&zoneid=1&clustertype=CloudManaged&clustername=Xen%20Clust%201&hypervisor=XenServer&allocationstate=Enabled&podid=1&url=http%3A//example.com/cluster&username=fred&password=sekrit&apiKey=identity&signature=2uIQ5qF0bVycXK111wxvogWp1Yw%3D")
.addHeader("Accept", "application/json").build();
HttpResponse response = HttpResponse.builder()
.payload(payloadFromResource("/addclusterresponse.json"))
@ -275,7 +275,7 @@ public class GlobalHostClientExpectTest extends BaseCloudStackExpectTest<GlobalH
public void testUpdateClusterWhenResponseIs2xx() {
HttpRequest request = HttpRequest.builder()
.method("GET")
.endpoint("http://localhost:8080/client/api?response=json&command=updateCluster&id=1&allocationstate=Enabled&clustername=Xen%20Clust%201&clustertype=CloudManaged&hypervisor=XenServer&managedstate=Managed&apiKey=identity&signature=%2FwbuYKwInciSXWkUf05lEfJZShQ%3D")
.endpoint("http://localhost:8080/client/api?response=json&command=updateCluster&id=1&allocationstate=Enabled&clustername=Xen%20Clust%201&clustertype=CloudManaged&hypervisor=XenServer&managedstate=Managed&apiKey=identity&signature=/wbuYKwInciSXWkUf05lEfJZShQ%3D")
.addHeader("Accept", "application/json").build();
HttpResponse response = HttpResponse.builder()
.payload(payloadFromResource("/updateclusterresponse.json"))
@ -292,7 +292,7 @@ public class GlobalHostClientExpectTest extends BaseCloudStackExpectTest<GlobalH
public void testUpdateClusterPasswordWhenResponseIs2xx() {
HttpRequest request = HttpRequest.builder()
.method("GET")
.endpoint("http://localhost:8080/client/api?response=json&command=updateHostPassword&clusterid=1&password=sekrit&username=fred&apiKey=identity&signature=xwc83%2BoYK0cuAiFQAlg%2F7%2F1IVHE%3D")
.endpoint("http://localhost:8080/client/api?response=json&command=updateHostPassword&clusterid=1&password=sekrit&username=fred&apiKey=identity&signature=xwc83%2BoYK0cuAiFQAlg/7/1IVHE%3D")
.addHeader("Accept", "application/json").build();
HttpResponse response = HttpResponse.builder()
.statusCode(200).build();

View File

@ -144,7 +144,7 @@ public class GlobalPodClientExpectTest extends BaseCloudStackExpectTest<GlobalPo
HttpRequest.builder()
.method("GET")
.endpoint(
URI.create("http://localhost:8080/client/api?response=json&command=updatePod&id=7&netmask=255.255.255.128&name=richard-updatepod&startip=172.21.0.129&endip=172.21.0.250&gateway=172.21.0.254&allocationstate=Disabled&apiKey=identity&signature=QpdbRyyF%2FxJ78ioJWhPKXEWhthY%3D"))
URI.create("http://localhost:8080/client/api?response=json&command=updatePod&id=7&netmask=255.255.255.128&name=richard-updatepod&startip=172.21.0.129&endip=172.21.0.250&gateway=172.21.0.254&allocationstate=Disabled&apiKey=identity&signature=QpdbRyyF/xJ78ioJWhPKXEWhthY%3D"))
.headers(
ImmutableMultimap.<String, String>builder()
.put("Accept", "application/json")

View File

@ -50,7 +50,7 @@ public class GlobalZoneClientExpectTest extends BaseCloudStackExpectTest<GlobalZ
.endpoint(
URI.create("http://localhost:8080/client/api?response=json&command=createZone&" +
"name=test-zone&dns1=8.8.8.8&networktype=Basic&internaldns1=10.10.10.10&" +
"apiKey=identity&signature=hWNmM2%2BTsfb5DelQa%2FGJLN5DVWE%3D"))
"apiKey=identity&signature=hWNmM2%2BTsfb5DelQa/GJLN5DVWE%3D"))
.headers(
ImmutableMultimap.<String, String>builder()
.put("Accept", "application/json")

View File

@ -26,10 +26,8 @@ import org.jclouds.cloudstack.internal.BaseCloudStackAsyncClientTest;
import org.jclouds.cloudstack.options.AccountInDomainOptions;
import org.jclouds.cloudstack.options.DeleteISOOptions;
import org.jclouds.cloudstack.options.ExtractISOOptions;
import org.jclouds.cloudstack.options.RegisterISOOptions;
import org.jclouds.cloudstack.options.UpdateISOOptions;
import org.jclouds.cloudstack.options.UpdateISOPermissionsOptions;
import org.jclouds.functions.IdentityFunction;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
import org.jclouds.http.functions.ReleasePayloadAndReturn;
@ -38,7 +36,6 @@ import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test;
import com.google.common.base.Functions;
import com.google.common.collect.ImmutableSet;
import com.google.inject.TypeLiteral;
/**
@ -47,8 +44,7 @@ import com.google.inject.TypeLiteral;
* @see ISOAsyncClient
* @author Richard Downer
*/
// NOTE:without testName, this will not call @Before* and fail w/NPE during
// surefire
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
@Test(groups = "unit", testName = "ISOAsyncClientTest")
public class ISOAsyncClientTest extends BaseCloudStackAsyncClientTest<ISOAsyncClient> {

View File

@ -81,7 +81,7 @@ public class ISOClientExpectTest extends BaseCloudStackExpectTest<ISOClient> {
.addQueryParam("command", "listIsos")
.addQueryParam("listAll", "true")
.addQueryParam("apiKey", "identity")
.addQueryParam("signature", "qUUF6hCDc57Bc%2FnHriS9umbZBKA%3D")
.addQueryParam("signature", "qUUF6hCDc57Bc/nHriS9umbZBKA%3D")
.addHeader("Accept", "application/json")
.build();
@ -121,7 +121,7 @@ public class ISOClientExpectTest extends BaseCloudStackExpectTest<ISOClient> {
.addQueryParam("name", "bob%27s%20iso")
.addQueryParam("zoneid", "7")
.addQueryParam("apiKey", "identity")
.addQueryParam("signature", "4S5ustbaBErEnpymWLSj1rEJ%2Fnk%3D")
.addQueryParam("signature", "4S5ustbaBErEnpymWLSj1rEJ/nk%3D")
.addHeader("Accept", "application/json")
.build();

View File

@ -117,7 +117,7 @@ public class SSHKeyPairAsyncClientTest extends BaseCloudStackAsyncClientTest<SSH
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
assertEquals(httpRequest.getFilters().size(), 2);
assertEquals(httpRequest.getFilters().size(), 1);
assertEquals(httpRequest.getFilters().get(0).getClass(), QuerySigner.class);
}

View File

@ -21,6 +21,7 @@ package org.jclouds.cloudstack.features;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import org.jclouds.cloudstack.CloudStackContext;
@ -29,11 +30,11 @@ import org.jclouds.cloudstack.internal.BaseCloudStackExpectTest;
import org.jclouds.crypto.SshKeys;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.util.Strings2;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableSet;
import com.sun.jersey.api.uri.UriComponent;
/**
* Test the CloudStack SSHKeyPairClient
@ -115,7 +116,7 @@ public class SSHKeyPairClientExpectTest extends BaseCloudStackExpectTest<SSHKeyP
}
@Test
public void testRegisterSSHKeyPairWhenResponseIs2xx() {
public void testRegisterSSHKeyPairWhenResponseIs2xx() throws UnsupportedEncodingException {
String publicKey = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCc903twxU2zcQnIJdXv61RwZNZW94uId9qz08fgsBJsCOnHNIC4+L9kDOA2IHV9cUfEDBm1Be5TbpadWwSbS/05E+FARH2/MCO932UgcKUq5PGymS0249fLCBPci5zoLiG5vIym+1ij1hL/nHvkK99NIwe7io+Lmp9OcF3PTsm3Rgh5T09cRHGX9horp0VoAVa9vKJx6C1/IEHVnG8p0YPPa1lmemvx5kNBEiyoNQNYa34EiFkcJfP6rqNgvY8h/j4nE9SXoUCC/g6frhMFMOL0tzYqvz0Lczqm1Oh4RnSn3O9X4R934p28qqAobe337hmlLUdb6H5zuf+NwCh0HdZ";
String privateKey = "-----BEGIN RSA PRIVATE KEY-----\n" +
@ -158,7 +159,7 @@ public class SSHKeyPairClientExpectTest extends BaseCloudStackExpectTest<SSHKeyP
.method("GET")
.endpoint(
URI.create("http://localhost:8080/client/api?response=json&command=registerSSHKeyPair&" +
"name=jclouds-keypair&publickey=" + UriComponent.encode(publicKey, UriComponent.Type.QUERY_PARAM) +
"name=jclouds-keypair&publickey=" + Strings2.urlEncode(publicKey, '/') +
"&apiKey=identity&signature=g/6BXLnnvOMlKQBp1yM7GKlvfus%3D"))
.headers(
ImmutableMultimap.<String, String>builder()

View File

@ -130,7 +130,7 @@ public class SecurityGroupAsyncClientTest extends BaseCloudStackAsyncClientTest<
assertRequestLineEquals(
httpRequest,
"GET http://localhost:8080/client/api?response=json&command=authorizeSecurityGroupIngress&securitygroupid=2&startport=22&protocol=tcp&endport=22&cidrlist=1.1.1.1%2F24%2C1.2.2.2%2F16 HTTP/1.1");
"GET http://localhost:8080/client/api?response=json&command=authorizeSecurityGroupIngress&securitygroupid=2&startport=22&protocol=tcp&endport=22&cidrlist=1.1.1.1/24,1.2.2.2/16 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
@ -169,7 +169,7 @@ public class SecurityGroupAsyncClientTest extends BaseCloudStackAsyncClientTest<
assertRequestLineEquals(
httpRequest,
"GET http://localhost:8080/client/api?response=json&command=authorizeSecurityGroupIngress&protocol=ICMP&securitygroupid=2&icmptype=22&icmpcode=22&cidrlist=1.1.1.1%2F24%2C1.2.2.2%2F16 HTTP/1.1");
"GET http://localhost:8080/client/api?response=json&command=authorizeSecurityGroupIngress&protocol=ICMP&securitygroupid=2&icmptype=22&icmpcode=22&cidrlist=1.1.1.1/24,1.2.2.2/16 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);

View File

@ -23,7 +23,6 @@ import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.net.URI;
import java.net.URLEncoder;
import org.jclouds.cloudstack.CloudStackContext;
import org.jclouds.cloudstack.domain.Account;
@ -43,7 +42,6 @@ import com.google.common.collect.ImmutableMultimap;
@Test(groups = "live", singleThreaded = true, testName = "SessionClientExpectTest")
public class SessionClientExpectTest extends BaseCloudStackExpectTest<SessionClient> {
@SuppressWarnings("deprecation")
public void testLoginWhenResponseIs2xxIncludesJSessionId() throws IOException {
String domain = "Partners/jCloud";
String user = "jcloud";
@ -54,7 +52,7 @@ public class SessionClientExpectTest extends BaseCloudStackExpectTest<SessionCli
.method("GET")
.endpoint(
URI.create("http://localhost:8080/client/api?response=json&command=login&" +
"username=" + user + "&password=" + md5password + "&domain=" + URLEncoder.encode(domain)))
"username=" + user + "&password=" + md5password + "&domain=" + domain))
.addHeader("Accept", "application/json")
.build();

View File

@ -189,7 +189,7 @@ public class SnapshotAsyncClientTest extends BaseCloudStackAsyncClientTest<Snaps
HttpRequest httpRequest = processor.createRequest(method, ids);
assertRequestLineEquals(httpRequest,
"GET http://localhost:8080/client/api?response=json&command=deleteSnapshotPolicies&ids=3%2C5%2C7 HTTP/1.1");
"GET http://localhost:8080/client/api?response=json&command=deleteSnapshotPolicies&ids=3,5,7 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);

View File

@ -93,7 +93,7 @@ public class TemplateAsyncClientTest extends BaseCloudStackAsyncClientTest<Templ
Method method = TemplateAsyncClient.class.getMethod("registerTemplate", TemplateMetadata.class, String.class, String.class, String.class, String.class, RegisterTemplateOptions[].class);
HttpRequest httpRequest = processor.createRequest(method, TemplateMetadata.builder().name("thename").osTypeId("10").displayText("description").build(), Template.Format.QCOW2, "xen", "http://example.com/", 20);
assertRequestLineEquals(httpRequest, "GET http://localhost:8080/client/api?response=json&command=registerTemplate&hypervisor=xen&format=QCOW2&url=http%3A%2F%2Fexample.com%2F&zoneid=20&name=thename&ostypeid=10&displaytext=description HTTP/1.1");
assertRequestLineEquals(httpRequest, "GET http://localhost:8080/client/api?response=json&command=registerTemplate&hypervisor=xen&format=QCOW2&url=http%3A//example.com/&zoneid=20&name=thename&ostypeid=10&displaytext=description HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
@ -109,7 +109,7 @@ public class TemplateAsyncClientTest extends BaseCloudStackAsyncClientTest<Templ
HttpRequest httpRequest = processor.createRequest(method, TemplateMetadata.builder().name("thename").osTypeId("10").displayText("description").build(), Template.Format.QCOW2, "xen", "http://example.com/", 20,
RegisterTemplateOptions.Builder.accountInDomain("mydomain", "3").bits(32).checksum("ABC").isExtractable(true).isFeatured(true).isPublic(true).passwordEnabled(true).requiresHVM(true));
assertRequestLineEquals(httpRequest, "GET http://localhost:8080/client/api?response=json&command=registerTemplate&hypervisor=xen&format=QCOW2&url=http%3A%2F%2Fexample.com%2F&zoneid=20&account=mydomain&domainid=3&bits=32&checksum=ABC&isextractable=true&isfeatured=true&ispublic=true&passwordenabled=true&requireshvm=true&name=thename&ostypeid=10&displaytext=description HTTP/1.1");
assertRequestLineEquals(httpRequest, "GET http://localhost:8080/client/api?response=json&command=registerTemplate&hypervisor=xen&format=QCOW2&url=http%3A//example.com/&zoneid=20&account=mydomain&domainid=3&bits=32&checksum=ABC&isextractable=true&isfeatured=true&ispublic=true&passwordenabled=true&requireshvm=true&name=thename&ostypeid=10&displaytext=description HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
@ -332,7 +332,7 @@ public class TemplateAsyncClientTest extends BaseCloudStackAsyncClientTest<Templ
Method method = TemplateAsyncClient.class.getMethod("extractTemplate", String.class, ExtractMode.class, String.class, ExtractTemplateOptions[].class);
HttpRequest httpRequest = processor.createRequest(method, 3, ExtractMode.HTTP_DOWNLOAD, 5, ExtractTemplateOptions.Builder.url("http://example.com/"));
assertRequestLineEquals(httpRequest, "GET http://localhost:8080/client/api?response=json&command=extractTemplate&id=3&zoneid=5&mode=HTTP_DOWNLOAD&url=http%3A%2F%2Fexample.com%2F HTTP/1.1");
assertRequestLineEquals(httpRequest, "GET http://localhost:8080/client/api?response=json&command=extractTemplate&id=3&zoneid=5&mode=HTTP_DOWNLOAD&url=http%3A//example.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);

View File

@ -1,66 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.cloudstack.filters;
import static org.testng.Assert.assertEquals;
import java.net.URLEncoder;
import javax.ws.rs.core.UriBuilder;
import org.jclouds.http.HttpRequest;
import org.jclouds.util.Strings2;
import org.testng.annotations.Test;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.sun.jersey.api.uri.UriBuilderImpl;
import com.sun.jersey.api.uri.UriComponent;
/**
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "ReEncodeQueryWithJavaNetURLEncoder")
public class ReEncodeQueryWithJavaNetURLEncoderTest {
@Test
public void testReUrlEncode() {
String input = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCc903twxU2zcQnIJdXv61RwZNZW94uId9qz08fgsBJsCOnHNIC4+L9k" +
"DOA2IHV9cUfEDBm1Be5TbpadWwSbS/05E+FARH2/MCO932UgcKUq5PGymS0249fLCBPci5zoLiG5vIym+1ij1hL/nHvkK99NIwe7io+Lmp" +
"9OcF3PTsm3Rgh5T09cRHGX9horp0VoAVa9vKJx6C1/IEHVnG8p0YPPa1lmemvx5kNBEiyoNQNYa34EiFkcJfP6rqNgvY8h/j4nE9SXoUCC" +
"/g6frhMFMOL0tzYqvz0Lczqm1Oh4RnSn3O9X4R934p28qqAobe337hmlLUdb6H5zuf+NwCh0HdZ";
String defaultJcloudsEncodedRequest = "http://localhost?foo=" + Strings2.urlEncode(input);
@SuppressWarnings("deprecation")
String defaultEncodedRequest = "http://localhost?foo=" + URLEncoder.encode(input);
assert !defaultJcloudsEncodedRequest.equals(defaultEncodedRequest);
HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://localhost?foo=" + Strings2.urlEncode(input)).build();
request = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(UriBuilder.class).to(UriBuilderImpl.class);
}
}).getInstance(ReEncodeQueryWithDefaultURLEncoder.class).filter(request);
assertEquals(request.getEndpoint().toASCIIString(), "http://localhost?foo=" +
UriComponent.encode(input, UriComponent.Type.QUERY_PARAM));
}
}

View File

@ -41,7 +41,7 @@ public abstract class BaseCloudStackComputeServiceContextExpectTest<T> extends B
.addQueryParam("listAll", "true")
.addQueryParam("templatefilter", "executable")
.addQueryParam("apiKey", "APIKEY")
.addQueryParam("signature", "Xk6lF%2Fv3SbhrxTKqaC2IWoBPKHo%3D")
.addQueryParam("signature", "Xk6lF/v3SbhrxTKqaC2IWoBPKHo%3D")
.addHeader("Accept", "application/json")
.build();
@ -56,7 +56,7 @@ public abstract class BaseCloudStackComputeServiceContextExpectTest<T> extends B
.addQueryParam("command", "listOsTypes")
.addQueryParam("listAll", "true")
.addQueryParam("apiKey", "APIKEY")
.addQueryParam("signature", "8BsE8MsOAhUzo1Q4Y3UD%2Fe96u84%3D")
.addQueryParam("signature", "8BsE8MsOAhUzo1Q4Y3UD/e96u84%3D")
.addHeader("Accept", "application/json")
.build();
@ -70,7 +70,7 @@ public abstract class BaseCloudStackComputeServiceContextExpectTest<T> extends B
.addQueryParam("command", "listOsCategories")
.addQueryParam("listAll", "true")
.addQueryParam("apiKey", "APIKEY")
.addQueryParam("signature", "OojW4ssh%2FRQ3CubAzXue4svlofM%3D")
.addQueryParam("signature", "OojW4ssh/RQ3CubAzXue4svlofM%3D")
// .addHeader("Accept", "application/json") //TODO: why are we not passing this?
.build();
@ -84,7 +84,7 @@ public abstract class BaseCloudStackComputeServiceContextExpectTest<T> extends B
.addQueryParam("command", "listZones")
.addQueryParam("listAll", "true")
.addQueryParam("apiKey", "APIKEY")
.addQueryParam("signature", "GTUgn%2FLHDioJRq48kurOdCAYueo%3D")
.addQueryParam("signature", "GTUgn/LHDioJRq48kurOdCAYueo%3D")
.addHeader("Accept", "application/json")
.build();
@ -128,7 +128,7 @@ public abstract class BaseCloudStackComputeServiceContextExpectTest<T> extends B
.addQueryParam("account", "jclouds") // account and domain came from above
.addQueryParam("domainid", "457")
.addQueryParam("apiKey", "APIKEY")
.addQueryParam("signature", "FDiGGBiG%2FsVj0k6DmZIgMNU8SqI%3D")
.addQueryParam("signature", "FDiGGBiG/sVj0k6DmZIgMNU8SqI%3D")
.addHeader("Accept", "application/json")
.build();
@ -157,7 +157,7 @@ public abstract class BaseCloudStackComputeServiceContextExpectTest<T> extends B
.addQueryParam("listAll", "true")
.addQueryParam("command", "listCapabilities")
.addQueryParam("apiKey", "APIKEY")
.addQueryParam("signature", "vVdhtet%2FzG59FXgkYkAzEQQ4q1o%3D")
.addQueryParam("signature", "vVdhtet/zG59FXgkYkAzEQQ4q1o%3D")
.addHeader("Accept", "application/json")
.build();

View File

@ -72,7 +72,7 @@ public class CloudWatchAsyncApiTest extends BaseAsyncApiTest<CloudWatchAsyncApi>
assertNonPayloadHeadersEqual(request, "Host: monitoring.us-east-1.amazonaws.com\n");
assertPayloadEquals(
request,
"Action=GetMetricStatistics&Statistics.member.1=Average&Period=60&Namespace=AWS%2FEC2&MetricName=CPUUtilization&StartTime=1970-01-01T02%3A46%3A40Z&EndTime=1970-01-01T02%3A46%3A40Z&Dimensions.member.1.Name=InstanceId&Dimensions.member.1.Value=i-12312313",
"Action=GetMetricStatistics&Statistics.member.1=Average&Period=60&Namespace=AWS/EC2&MetricName=CPUUtilization&StartTime=1970-01-01T02%3A46%3A40Z&EndTime=1970-01-01T02%3A46%3A40Z&Dimensions.member.1.Name=InstanceId&Dimensions.member.1.Value=i-12312313",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ParseSax.class);

View File

@ -56,7 +56,7 @@ public class MetricApiExpectTest extends BaseCloudWatchApiExpectTest {
.payload(
payloadFromStringWithContentType(
"Action=ListMetrics" +
"&Signature=KSh9oQydCR0HMAV6QPYwDzqwQIpxs8I%2Fig7brYgHVZU%3D" +
"&Signature=KSh9oQydCR0HMAV6QPYwDzqwQIpxs8I/ig7brYgHVZU%3D" +
"&SignatureMethod=HmacSHA256" +
"&SignatureVersion=2" +
"&Timestamp=2009-11-08T15%3A54%3A08.897Z" +
@ -100,7 +100,7 @@ public class MetricApiExpectTest extends BaseCloudWatchApiExpectTest {
payloadFromStringWithContentType(
"Action=ListMetrics" +
"&NextToken=MARKER" +
"&Signature=RpBdQydXD1jQhEUnXoqT60NEuCP%2FZgdvO6Hf3uf%2Fwy0%3D" +
"&Signature=RpBdQydXD1jQhEUnXoqT60NEuCP/ZgdvO6Hf3uf/wy0%3D" +
"&SignatureMethod=HmacSHA256" +
"&SignatureVersion=2" +
"&Timestamp=2009-11-08T15%3A54%3A08.897Z" +
@ -132,8 +132,8 @@ public class MetricApiExpectTest extends BaseCloudWatchApiExpectTest {
"&Dimensions.member.1.Value=SOMEINSTANCEID" +
"&MetricName=CPUUtilization" +
"&Namespace=SOMENEXTTOKEN" +
"&NextToken=AWS%2FEC2" +
"&Signature=G05HKEx9FJpGZBk02OVYwt3u4g%2FilAY9nU5hJI9LDXA%3D" +
"&NextToken=AWS/EC2" +
"&Signature=G05HKEx9FJpGZBk02OVYwt3u4g/ilAY9nU5hJI9LDXA%3D" +
"&SignatureMethod=HmacSHA256" +
"&SignatureVersion=2" +
"&Timestamp=2009-11-08T15%3A54%3A08.897Z" +
@ -178,9 +178,9 @@ public class MetricApiExpectTest extends BaseCloudWatchApiExpectTest {
"Action=GetMetricStatistics" +
"&EndTime=1970-01-01T02%3A46%3A40Z" +
"&MetricName=CPUUtilization" +
"&Namespace=AWS%2FEC2" +
"&Namespace=AWS/EC2" +
"&Period=60" +
"&Signature=rmg8%2Ba7w4ycy%2FKfO8rnuj6rDL0jNE96m8GKfjh3SWcw%3D" +
"&Signature=rmg8%2Ba7w4ycy/KfO8rnuj6rDL0jNE96m8GKfjh3SWcw%3D" +
"&SignatureMethod=HmacSHA256" +
"&SignatureVersion=2" +
"&StartTime=1970-01-01T02%3A46%3A40Z" +
@ -235,9 +235,9 @@ public class MetricApiExpectTest extends BaseCloudWatchApiExpectTest {
"&Dimensions.member.2.Value=t1.micro" +
"&EndTime=1970-01-01T02%3A46%3A40Z" +
"&MetricName=CPUUtilization" +
"&Namespace=AWS%2FEC2" +
"&Namespace=AWS/EC2" +
"&Period=60" +
"&Signature=e0WyI%2FNm4hN2%2BMEm1mjRUzsvgvMCdFXbVJWi4ORpwic%3D" +
"&Signature=e0WyI/Nm4hN2%2BMEm1mjRUzsvgvMCdFXbVJWi4ORpwic%3D" +
"&SignatureMethod=HmacSHA256" +
"&SignatureVersion=2" +
"&StartTime=1970-01-01T02%3A46%3A40Z" +

View File

@ -19,9 +19,7 @@
package org.jclouds.deltacloud.handlers;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import javax.ws.rs.core.UriBuilder;
import org.jclouds.http.HttpCommand;
import org.jclouds.http.HttpResponse;
@ -37,9 +35,8 @@ import org.jclouds.http.handlers.RedirectionRetryHandler;
public class DeltacloudRedirectionRetryHandler extends RedirectionRetryHandler {
@Inject
public DeltacloudRedirectionRetryHandler(Provider<UriBuilder> uriBuilderProvider,
BackoffLimitedRetryHandler backoffHandler) {
super(uriBuilderProvider, backoffHandler);
public DeltacloudRedirectionRetryHandler(BackoffLimitedRetryHandler backoffHandler) {
super(backoffHandler);
}
@Override

View File

@ -57,7 +57,7 @@ public class GetImageWhenStatusAvailablePredicateWithResultExpectTest extends Ba
.endpoint("https://ec2.us-east-1.amazonaws.com/")
.addHeader("Host", "ec2.us-east-1.amazonaws.com")
.payload(payloadFromStringWithContentType(
"Action=DescribeImages&ImageId.1=ami-0&Signature=k9douTXFWkAZecPiZfBLUm3LIS3bTLanMV%2F%2BWrB1jFA%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2012-04-16T15%3A54%3A08.897Z&Version=2010-06-15&AWSAccessKeyId=identity",
"Action=DescribeImages&ImageId.1=ami-0&Signature=k9douTXFWkAZecPiZfBLUm3LIS3bTLanMV/%2BWrB1jFA%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2012-04-16T15%3A54%3A08.897Z&Version=2010-06-15&AWSAccessKeyId=identity",
"application/x-www-form-urlencoded")).build();
protected HttpRequest describeImagesRequest1 = HttpRequest.builder()

View File

@ -102,7 +102,7 @@ public class TagApiExpectTest extends BaseEC2ApiExpectTest<EC2Api> {
payloadFromStringWithContentType(
"Action=CreateTags" +
"&ResourceId.1=i-43532" +
"&Signature=jwCQr50j%2BvGkav4t0BN0G8RmNJ7VaFK6%2F7N%2FHKUmHL8%3D" +
"&Signature=jwCQr50j%2BvGkav4t0BN0G8RmNJ7VaFK6/7N/HKUmHL8%3D" +
"&SignatureMethod=HmacSHA256" +
"&SignatureVersion=2" +
"&Tag.1.Key=tag" +
@ -180,7 +180,7 @@ public class TagApiExpectTest extends BaseEC2ApiExpectTest<EC2Api> {
"&Filter.1.Value.1=instance" +
"&Filter.2.Name=key" +
"&Filter.2.Value.1=stack" +
"&Signature=doNEEZHEzXV%2FSD2eSZ6PpB1PADcsAF99lXGvsh3MbS4%3D" +
"&Signature=doNEEZHEzXV/SD2eSZ6PpB1PADcsAF99lXGvsh3MbS4%3D" +
"&SignatureMethod=HmacSHA256" +
"&SignatureVersion=2" +
"&Timestamp=2012-04-16T15%3A54%3A08.897Z" +
@ -223,7 +223,7 @@ public class TagApiExpectTest extends BaseEC2ApiExpectTest<EC2Api> {
payloadFromStringWithContentType(
"Action=DeleteTags" +
"&ResourceId.1=i-43532" +
"&Signature=ytM605menR00re60wXMgBDpozrQCi0lVupf755%2FMpck%3D" +
"&Signature=ytM605menR00re60wXMgBDpozrQCi0lVupf755/Mpck%3D" +
"&SignatureMethod=HmacSHA256" +
"&SignatureVersion=2" +
"&Tag.1.Key=tag" +
@ -261,7 +261,7 @@ public class TagApiExpectTest extends BaseEC2ApiExpectTest<EC2Api> {
payloadFromStringWithContentType(
"Action=DeleteTags" +
"&ResourceId.1=i-43532" +
"&Signature=vRvgPegVDDjIEKudZ5Tpck0GQrVts%2F%2F1jzk4W5RgI9k%3D" +
"&Signature=vRvgPegVDDjIEKudZ5Tpck0GQrVts//1jzk4W5RgI9k%3D" +
"&SignatureMethod=HmacSHA256" +
"&SignatureVersion=2" +
"&Tag.1.Key=tag" +

View File

@ -48,7 +48,7 @@ public class WindowsApiExpectTest extends BaseEC2ApiExpectTest<EC2Api> {
payloadFromStringWithContentType(
"Action=GetPasswordData" +
"&InstanceId=i-2574e22a" +
"&Signature=vX1Tskc4VuBUWPqsJ%2BzcjEj6%2F2iMCKzqjWnKFXRkDdA%3D" +
"&Signature=vX1Tskc4VuBUWPqsJ%2BzcjEj6/2iMCKzqjWnKFXRkDdA%3D" +
"&SignatureMethod=HmacSHA256" +
"&SignatureVersion=2" +
"&Timestamp=2012-04-16T15%3A54%3A08.897Z" +

View File

@ -99,7 +99,7 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
filter.filter(request);
assertPayloadEquals(
request,
"Action=DescribeImages&Signature=qE4vexSFJqS0UWK%2BccV3s%2BP9woL3M5HI5bTBoM7s%2FLY%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&Version=2010-06-15&AWSAccessKeyId=identity",
"Action=DescribeImages&Signature=qE4vexSFJqS0UWK%2BccV3s%2BP9woL3M5HI5bTBoM7s/LY%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&Version=2010-06-15&AWSAccessKeyId=identity",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
@ -190,7 +190,7 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(
request,
"Action=RegisterImage&RootDeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.0.DeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.0.Ebs.SnapshotId=snapshotId&Name=imageName",
"Action=RegisterImage&RootDeviceName=/dev/sda1&BlockDeviceMapping.0.DeviceName=/dev/sda1&BlockDeviceMapping.0.Ebs.SnapshotId=snapshotId&Name=imageName",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, ImageIdHandler.class);
@ -210,7 +210,7 @@ public class AMIAsyncClientTest extends BaseEC2AsyncClientTest<AMIAsyncClient> {
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(
request,
"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",
"Action=RegisterImage&RootDeviceName=/dev/sda1&BlockDeviceMapping.0.DeviceName=/dev/sda1&BlockDeviceMapping.0.Ebs.SnapshotId=snapshotId&Name=imageName&Description=description&BlockDeviceMapping.1.Ebs.DeleteOnTermination=false&BlockDeviceMapping.1.DeviceName=/dev/device&BlockDeviceMapping.1.Ebs.SnapshotId=snapshot&BlockDeviceMapping.2.Ebs.DeleteOnTermination=false&BlockDeviceMapping.2.DeviceName=/dev/newdevice&BlockDeviceMapping.2.VirtualName=newblock&BlockDeviceMapping.2.Ebs.VolumeSize=100",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ParseSax.class);

View File

@ -111,7 +111,7 @@ public class ElasticBlockStoreAsyncClientTest extends BaseEC2AsyncClientTest<Ela
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(request,
"Action=AttachVolume&InstanceId=instanceId&VolumeId=id&Device=%2Fdevice",
"Action=AttachVolume&InstanceId=instanceId&VolumeId=id&Device=/device",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ParseSax.class);
@ -147,7 +147,7 @@ public class ElasticBlockStoreAsyncClientTest extends BaseEC2AsyncClientTest<Ela
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(request,
"Action=DetachVolume&Force=true&VolumeId=id&InstanceId=instanceId&Device=%2Fdevice",
"Action=DetachVolume&Force=true&VolumeId=id&InstanceId=instanceId&Device=/device",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);

View File

@ -475,12 +475,12 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(
request,
"Action=ModifyInstanceAttribute&InstanceId=1&BlockDeviceMapping.1.Ebs.VolumeId=vol-test1&BlockDeviceMapping.1.DeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.1.Ebs.DeleteOnTermination=true",
"Action=ModifyInstanceAttribute&InstanceId=1&BlockDeviceMapping.1.Ebs.VolumeId=vol-test1&BlockDeviceMapping.1.DeviceName=/dev/sda1&BlockDeviceMapping.1.Ebs.DeleteOnTermination=true",
"application/x-www-form-urlencoded", false);
filter.filter(request);// ensure encoding worked properly
assertPayloadEquals(
request,
"Action=ModifyInstanceAttribute&BlockDeviceMapping.1.DeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.1.Ebs.DeleteOnTermination=true&BlockDeviceMapping.1.Ebs.VolumeId=vol-test1&InstanceId=1&Signature=RwY8lVPHSQxQkd5efUKccHdSTkN4OxMIMFiYAe3rrUE%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&Version=2010-06-15&AWSAccessKeyId=identity",
"Action=ModifyInstanceAttribute&BlockDeviceMapping.1.DeviceName=/dev/sda1&BlockDeviceMapping.1.Ebs.DeleteOnTermination=true&BlockDeviceMapping.1.Ebs.VolumeId=vol-test1&InstanceId=1&Signature=RwY8lVPHSQxQkd5efUKccHdSTkN4OxMIMFiYAe3rrUE%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&Version=2010-06-15&AWSAccessKeyId=identity",
"application/x-www-form-urlencoded", false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);

View File

@ -143,13 +143,13 @@ public class SecurityGroupAsyncClientTest extends BaseEC2AsyncClientTest<Securit
try {
assertPayloadEquals(
request,
"Action=AuthorizeSecurityGroupIngress&CidrIp=0.0.0.0%2F0&IpProtocol=tcp&GroupName=group&FromPort=6000&ToPort=7000",
"Action=AuthorizeSecurityGroupIngress&CidrIp=0.0.0.0/0&IpProtocol=tcp&GroupName=group&FromPort=6000&ToPort=7000",
"application/x-www-form-urlencoded", false);
} catch (AssertionError e) {
// mvn 3.0 osx 10.6.5 somehow sorts differently
assertPayloadEquals(
request,
"Action=AuthorizeSecurityGroupIngress&CidrIp=0.0.0.0%2F0&IpProtocol=tcp&GroupName=group&ToPort=7000&FromPort=6000",
"Action=AuthorizeSecurityGroupIngress&CidrIp=0.0.0.0/0&IpProtocol=tcp&GroupName=group&ToPort=7000&FromPort=6000",
"application/x-www-form-urlencoded", false);
}
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
@ -189,13 +189,13 @@ public class SecurityGroupAsyncClientTest extends BaseEC2AsyncClientTest<Securit
try {
assertPayloadEquals(
request,
"Action=RevokeSecurityGroupIngress&CidrIp=0.0.0.0%2F0&IpProtocol=tcp&GroupName=group&FromPort=6000&ToPort=7000",
"Action=RevokeSecurityGroupIngress&CidrIp=0.0.0.0/0&IpProtocol=tcp&GroupName=group&FromPort=6000&ToPort=7000",
"application/x-www-form-urlencoded", false);
} catch (AssertionError e) {
// mvn 3.0 osx 10.6.5 somehow sorts differently
assertPayloadEquals(
request,
"Action=RevokeSecurityGroupIngress&CidrIp=0.0.0.0%2F0&IpProtocol=tcp&GroupName=group&ToPort=7000&FromPort=6000",
"Action=RevokeSecurityGroupIngress&CidrIp=0.0.0.0/0&IpProtocol=tcp&GroupName=group&ToPort=7000&FromPort=6000",
"application/x-www-form-urlencoded", false);
}
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);

View File

@ -53,7 +53,7 @@ public class WindowsAsyncClientTest extends BaseEC2AsyncClientTest<WindowsAsyncC
"my-bucket",
"{\"expiration\": \"2008-08-30T08:49:09Z\",\"conditions\": [{\"bucket\": \"my-bucket\"},[\"starts-with\", \"$key\", \"my-new-image\"]]}");
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
String payload = "Action=BundleInstance&Storage.S3.Prefix=winami&InstanceId=i-e468cd8d&Storage.S3.Bucket=my-bucket&Storage.S3.UploadPolicy=eyJleHBpcmF0aW9uIjogIjIwMDgtMDgtMzBUMDg6NDk6MDlaIiwiY29uZGl0aW9ucyI6IFt7ImJ1Y2tldCI6ICJteS1idWNrZXQifSxbInN0YXJ0cy13aXRoIiwgIiRrZXkiLCAibXktbmV3LWltYWdlIl1dfQ%3D%3D&Storage.S3.UploadPolicySignature=ih%2FiohGe0A7y4QVRbKaq6BZShzUsmBEJEa9AdFbxM6Y%3D";
String payload = "Action=BundleInstance&Storage.S3.Prefix=winami&InstanceId=i-e468cd8d&Storage.S3.Bucket=my-bucket&Storage.S3.UploadPolicy=eyJleHBpcmF0aW9uIjogIjIwMDgtMDgtMzBUMDg6NDk6MDlaIiwiY29uZGl0aW9ucyI6IFt7ImJ1Y2tldCI6ICJteS1idWNrZXQifSxbInN0YXJ0cy13aXRoIiwgIiRrZXkiLCAibXktbmV3LWltYWdlIl1dfQ%3D%3D&Storage.S3.UploadPolicySignature=ih/iohGe0A7y4QVRbKaq6BZShzUsmBEJEa9AdFbxM6Y%3D";
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(request, payload, "application/x-www-form-urlencoded", false);
@ -77,7 +77,7 @@ public class WindowsAsyncClientTest extends BaseEC2AsyncClientTest<WindowsAsyncC
"{\"expiration\": \"2008-08-30T08:49:09Z\",\"conditions\": [{\"bucket\": \"my-bucket\"},[\"starts-with\", \"$key\", \"my-new-image\"]]}",
BundleInstanceS3StorageOptions.Builder.bucketOwnedBy("10QMXFEV71ZS32XQFTR2"));
assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
String payload = "Action=BundleInstance&Storage.S3.Prefix=winami&InstanceId=i-e468cd8d&Storage.S3.Bucket=my-bucket&Storage.S3.AWSAccessKeyId=10QMXFEV71ZS32XQFTR2&Storage.S3.UploadPolicy=eyJleHBpcmF0aW9uIjogIjIwMDgtMDgtMzBUMDg6NDk6MDlaIiwiY29uZGl0aW9ucyI6IFt7ImJ1Y2tldCI6ICJteS1idWNrZXQifSxbInN0YXJ0cy13aXRoIiwgIiRrZXkiLCAibXktbmV3LWltYWdlIl1dfQ%3D%3D&Storage.S3.UploadPolicySignature=ih%2FiohGe0A7y4QVRbKaq6BZShzUsmBEJEa9AdFbxM6Y%3D";
String payload = "Action=BundleInstance&Storage.S3.Prefix=winami&InstanceId=i-e468cd8d&Storage.S3.Bucket=my-bucket&Storage.S3.AWSAccessKeyId=10QMXFEV71ZS32XQFTR2&Storage.S3.UploadPolicy=eyJleHBpcmF0aW9uIjogIjIwMDgtMDgtMzBUMDg6NDk6MDlaIiwiY29uZGl0aW9ucyI6IFt7ImJ1Y2tldCI6ICJteS1idWNrZXQifSxbInN0YXJ0cy13aXRoIiwgIiRrZXkiLCAibXktbmV3LWltYWdlIl1dfQ%3D%3D&Storage.S3.UploadPolicySignature=ih/iohGe0A7y4QVRbKaq6BZShzUsmBEJEa9AdFbxM6Y%3D";
assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
assertPayloadEquals(request, payload, "application/x-www-form-urlencoded", false);

View File

@ -48,7 +48,7 @@ public abstract class BaseEucalyptusExpectTest<T> extends BaseRestClientExpectTe
.endpoint("http://partnercloud.eucalyptus.com:8773/services/Eucalyptus/")
.addHeader("Host", "partnercloud.eucalyptus.com:8773")
.payload(payloadFromStringWithContentType(
"Action=DescribeRegions&Signature=tp9WpT8503JdxIXYu6Eu2Dmu%2Bd%2FpqviST7N7Fvr%2FyQo%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2012-04-16T15%3A54%3A08.897Z&Version=2010-06-15&AWSAccessKeyId=identity",
"Action=DescribeRegions&Signature=tp9WpT8503JdxIXYu6Eu2Dmu%2Bd/pqviST7N7Fvr/yQo%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2012-04-16T15%3A54%3A08.897Z&Version=2010-06-15&AWSAccessKeyId=identity",
MediaType.APPLICATION_FORM_URLENCODED)).build();
protected HttpResponse describeRegionsResponse = HttpResponse.builder().statusCode(200)
@ -60,7 +60,7 @@ public abstract class BaseEucalyptusExpectTest<T> extends BaseRestClientExpectTe
.endpoint("http://eucalyptus.partner.eucalyptus.com:8773/services/Eucalyptus/")
.addHeader("Host", "eucalyptus.partner.eucalyptus.com:8773")
.payload(payloadFromStringWithContentType(
"Action=DescribeAvailabilityZones&Signature=i4OkMed1sqQV7hlF%2Fl1KdbQwmwJ4Fh4o9W32eVGayPk%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2012-04-16T15%3A54%3A08.897Z&Version=2010-06-15&AWSAccessKeyId=identity",
"Action=DescribeAvailabilityZones&Signature=i4OkMed1sqQV7hlF/l1KdbQwmwJ4Fh4o9W32eVGayPk%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2012-04-16T15%3A54%3A08.897Z&Version=2010-06-15&AWSAccessKeyId=identity",
MediaType.APPLICATION_FORM_URLENCODED)).build();
protected HttpResponse describeAZResponse = HttpResponse.builder().statusCode(200)

View File

@ -50,7 +50,6 @@ import org.jclouds.rest.annotations.Payload;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.QueryParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.Unwrap;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404;
@ -69,7 +68,6 @@ import com.google.common.util.concurrent.ListenableFuture;
* @see NovaClient
* @see <a href="http://wiki.openstack.org/OpenStackAPI_1-1" />
*/
@SkipEncoding({'/', '='})
@RequestFilters({AuthenticateRequest.class, AddTimestampQuery.class})
@Endpoint(ServerManagement.class)
public interface NovaAsyncClient {

View File

@ -18,7 +18,7 @@
*/
package org.jclouds.openstack.keystone.v2_0.domain;
import static org.jclouds.http.utils.Queries.parseQueryToMap;
import static org.jclouds.http.utils.Queries.queryParser;
import java.util.Collection;
import java.util.Iterator;
@ -78,7 +78,7 @@ public class PaginatedCollection<T> extends IterableWithMarker<T> {
}).transform(new Function<Link, Optional<Object>>() {
@Override
public Optional<Object> apply(Link link) {
Collection<String> markers = parseQueryToMap(link.getHref().getRawQuery()).get("marker");
Collection<String> markers = queryParser().apply(link.getHref().getRawQuery()).get("marker");
return Optional.<Object> fromNullable(markers == null ? null : Iterables.get(markers, 0));
}
}).first().or(Optional.absent());

View File

@ -30,7 +30,6 @@ import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import com.google.common.util.concurrent.ListenableFuture;
@ -45,7 +44,6 @@ import com.google.common.util.concurrent.ListenableFuture;
* />
* @author Adam Lowe
*/
@SkipEncoding( { '/', '=' })
public interface ServiceAsyncApi {
/**

View File

@ -38,7 +38,6 @@ import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.Transform;
import org.jclouds.rest.functions.ReturnEmptyPagedIterableOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
@ -56,7 +55,6 @@ import com.google.common.util.concurrent.ListenableFuture;
* @author Adam Lowe
*/
@org.jclouds.rest.annotations.Endpoint(Identity.class)
@SkipEncoding( { '/', '=' })
public interface TenantAsyncApi {
/**

View File

@ -35,7 +35,6 @@ import org.jclouds.openstack.v2_0.services.Identity;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
@ -52,7 +51,6 @@ import com.google.common.util.concurrent.ListenableFuture;
* />
* @author Adam Lowe
*/
@SkipEncoding({ '/', '=' })
@org.jclouds.rest.annotations.Endpoint(Identity.class)
public interface TokenAsyncApi {

View File

@ -41,7 +41,6 @@ import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.Transform;
import org.jclouds.rest.functions.ReturnEmptyPagedIterableOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
@ -60,7 +59,6 @@ import com.google.common.util.concurrent.ListenableFuture;
* @author Adam Lowe
*/
@org.jclouds.rest.annotations.Endpoint(Identity.class)
@SkipEncoding({ '/', '=' })
public interface UserAsyncApi {
/**

View File

@ -31,7 +31,6 @@ import org.jclouds.openstack.v2_0.domain.Extension;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
@ -47,7 +46,6 @@ import com.google.common.util.concurrent.ListenableFuture;
* />
* @author Adrian Cole
*/
@SkipEncoding({ '/', '=' })
@RequestFilters(AuthenticateRequest.class)
public interface ExtensionAsyncApi {

View File

@ -18,12 +18,11 @@
*/
package org.jclouds.openstack.v2_0.functions;
import static org.jclouds.http.Uris.uriBuilder;
import java.net.URI;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import javax.ws.rs.core.UriBuilder;
import org.jclouds.openstack.v2_0.domain.Extension;
@ -31,20 +30,14 @@ import com.google.common.base.Function;
@Singleton
public class ExtensionToNameSpace implements Function<Extension, URI> {
private final Provider<UriBuilder> uriBuilders;
@Inject
public ExtensionToNameSpace(Provider<UriBuilder> uriBuilders) {
this.uriBuilders = uriBuilders;
}
@Override
public URI apply(Extension input) {
return uriBuilders.get().uri(input.getNamespace()).scheme("http").build();
return uriBuilder(input.getNamespace()).scheme("http").build();
}
public String toString() {
return "extensionToURI()";
return "changeSchemeToHttp()";
}
}

View File

@ -4,28 +4,16 @@ import static org.testng.Assert.assertEquals;
import java.net.URI;
import javax.inject.Provider;
import javax.ws.rs.core.UriBuilder;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.openstack.v2_0.domain.Extension;
import org.testng.annotations.Test;
import com.sun.jersey.api.uri.UriBuilderImpl;
/**
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "ExtensionToNameSpaceTest")
public class ExtensionToNameSpaceTest {
private final ExtensionToNameSpace fn = new ExtensionToNameSpace(new Provider<UriBuilder>() {
@Override
public UriBuilder get() {
return new UriBuilderImpl();
}
});
private final ExtensionToNameSpace fn = new ExtensionToNameSpace();
public void testReturnsNamespace() {
URI ns = URI.create("http://docs.openstack.org/ext/keypairs/api/v1.1");

View File

@ -42,7 +42,7 @@ public class NovaEC2AMIClientExpectTest extends BaseNovaEC2RestClientExpectTest
HttpRequest.builder().method("POST")
.endpoint("http://localhost:8773/services/Cloud/")
.addHeader("Host", "localhost:8773")
.payload(payloadFromStringWithContentType("Action=DescribeImages&Signature=Z3q3jSutwlfgvbcINT0Ed3AjrjxM4WMvQloXu%2F1kd40%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2012-04-16T15%3A54%3A08.897Z&Version=2009-04-04&AWSAccessKeyId=identity", "application/x-www-form-urlencoded")).build(),
.payload(payloadFromStringWithContentType("Action=DescribeImages&Signature=Z3q3jSutwlfgvbcINT0Ed3AjrjxM4WMvQloXu/1kd40%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2012-04-16T15%3A54%3A08.897Z&Version=2009-04-04&AWSAccessKeyId=identity", "application/x-www-form-urlencoded")).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/nova_ec2_images_with_ramdisk.xml")).build()
).getAMIServices();

View File

@ -0,0 +1,49 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.openstack.nova.v2_0.binders;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.http.HttpRequest;
import org.jclouds.json.Json;
import org.jclouds.rest.binders.BindToJsonPayload;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSortedMap;
/**
*
* @author Adrian Cole
*/
@Singleton
public class BindKeyPairToJsonPayload extends BindToJsonPayload {
@Inject
public BindKeyPairToJsonPayload(Json jsonBinder) {
super(jsonBinder);
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
return bindToRequest(request, (Object) ImmutableMap.of("keypair", ImmutableSortedMap.copyOf(postParams)));
}
}

View File

@ -37,7 +37,6 @@ import org.jclouds.rest.annotations.Payload;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.functions.ReturnEmptyFluentIterableOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
@ -59,7 +58,6 @@ import com.google.common.util.concurrent.ListenableFuture;
*/
@Beta
@Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.FLOATING_IPS)
@SkipEncoding( { '/', '=' })
@RequestFilters(AuthenticateRequest.class)
public interface FloatingIPAsyncApi {

View File

@ -43,7 +43,6 @@ import org.jclouds.rest.annotations.Payload;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.functions.ReturnEmptyFluentIterableOnNotFoundOr404;
import com.google.common.annotations.Beta;
@ -62,7 +61,6 @@ import com.google.common.util.concurrent.ListenableFuture;
*/
@Beta
@Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.HOSTS)
@SkipEncoding({'/', '='})
@RequestFilters(AuthenticateRequest.class)
@Path("/os-hosts")
@Consumes(MediaType.APPLICATION_JSON)

View File

@ -28,18 +28,19 @@ import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest;
import org.jclouds.openstack.nova.v2_0.binders.BindKeyPairToJsonPayload;
import org.jclouds.openstack.nova.v2_0.domain.KeyPair;
import org.jclouds.openstack.nova.v2_0.functions.internal.ParseKeyPairs;
import org.jclouds.openstack.v2_0.ServiceType;
import org.jclouds.openstack.v2_0.features.ExtensionAsyncApi;
import org.jclouds.openstack.v2_0.services.Extension;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.Payload;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.functions.ReturnEmptyFluentIterableOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404;
@ -62,7 +63,6 @@ import com.google.common.util.concurrent.ListenableFuture;
*/
@Beta
@Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.KEYPAIRS)
@SkipEncoding({ '/', '=' })
@RequestFilters(AuthenticateRequest.class)
public interface KeyPairAsyncApi {
@ -86,9 +86,9 @@ public interface KeyPairAsyncApi {
@SelectJson("keypair")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Payload("%7B\"keypair\":%7B\"name\":\"{name}\",\"public_key\":\"{publicKey}\"%7D%7D")
@MapBinder(BindKeyPairToJsonPayload.class)
ListenableFuture<? extends KeyPair> createWithPublicKey(@PayloadParam("name") String name,
@PayloadParam("publicKey") String publicKey);
@PayloadParam("public_key") String publicKey);
@DELETE
@Path("/os-keypairs/{name}")

View File

@ -40,7 +40,6 @@ import org.jclouds.rest.annotations.Payload;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.functions.ReturnEmptyFluentIterableOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
@ -62,7 +61,6 @@ import com.google.common.util.concurrent.ListenableFuture;
*/
@Beta
@Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.SECURITY_GROUPS)
@SkipEncoding( { '/', '=' })
@RequestFilters(AuthenticateRequest.class)
public interface SecurityGroupAsyncApi {

View File

@ -36,7 +36,6 @@ import org.jclouds.rest.annotations.Payload;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.WrapWith;
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404;
@ -52,7 +51,6 @@ import com.google.common.util.concurrent.ListenableFuture;
*/
@Beta
@Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.ADMIN_ACTIONS)
@SkipEncoding( { '/', '=' })
@RequestFilters(AuthenticateRequest.class)
@Path("/servers/{id}/action")
public interface ServerAdminAsyncApi {

View File

@ -31,7 +31,6 @@ import org.jclouds.openstack.v2_0.services.Extension;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import com.google.common.annotations.Beta;
@ -47,7 +46,6 @@ import com.google.common.util.concurrent.ListenableFuture;
*/
@Beta
@Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.CREATESERVEREXT)
@SkipEncoding({'/', '='})
@RequestFilters(AuthenticateRequest.class)
public interface ServerWithSecurityGroupsAsyncApi {

View File

@ -31,7 +31,6 @@ import org.jclouds.openstack.v2_0.services.Extension;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.functions.ReturnEmptyFluentIterableOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
@ -51,7 +50,6 @@ import com.google.common.util.concurrent.ListenableFuture;
*/
@Beta
@Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.SIMPLE_TENANT_USAGE)
@SkipEncoding({'/', '='})
@RequestFilters(AuthenticateRequest.class)
public interface SimpleTenantUsageAsyncApi {

View File

@ -31,7 +31,6 @@ import org.jclouds.openstack.v2_0.services.Extension;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.functions.ReturnEmptyFluentIterableOnNotFoundOr404;
import com.google.common.annotations.Beta;
@ -46,7 +45,6 @@ import com.google.common.util.concurrent.ListenableFuture;
*/
@Beta
@Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.VIRTUAL_INTERFACES)
@SkipEncoding({'/', '='})
@RequestFilters(AuthenticateRequest.class)
public interface VirtualInterfaceAsyncApi {
/**

View File

@ -40,7 +40,6 @@ import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.WrapWith;
import org.jclouds.rest.functions.ReturnEmptyFluentIterableOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404;
@ -59,7 +58,6 @@ import com.google.common.util.concurrent.ListenableFuture;
*/
@Beta
@Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.VOLUMES)
@SkipEncoding({'/', '='})
@RequestFilters(AuthenticateRequest.class)
public interface VolumeAsyncApi {
/**

View File

@ -35,7 +35,6 @@ import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.WrapWith;
import org.jclouds.rest.functions.ReturnEmptyFluentIterableOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404;
@ -53,7 +52,6 @@ import com.google.common.util.concurrent.ListenableFuture;
*/
@Beta
@Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.VOLUMES)
@SkipEncoding({'/', '='})
@RequestFilters(AuthenticateRequest.class)
public interface VolumeAttachmentAsyncApi {
/**
@ -103,4 +101,4 @@ public interface VolumeAttachmentAsyncApi {
ListenableFuture<Boolean> detachVolumeFromServer(
@PathParam("id") String volumeId,
@PathParam("server_id") String serverId);
}
}

View File

@ -41,7 +41,6 @@ import org.jclouds.rest.annotations.Payload;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.Unwrap;
import org.jclouds.rest.annotations.WrapWith;
import org.jclouds.rest.binders.BindToJsonPayload;
@ -62,7 +61,6 @@ import com.google.common.util.concurrent.ListenableFuture;
*/
@Beta
@Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.VOLUME_TYPES)
@SkipEncoding({'/', '='})
@RequestFilters(AuthenticateRequest.class)
@Path("/os-volume-types")
@Consumes(MediaType.APPLICATION_JSON)

View File

@ -37,7 +37,6 @@ import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.Transform;
import org.jclouds.rest.functions.ReturnEmptyPagedIterableOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
@ -55,7 +54,6 @@ import com.google.common.util.concurrent.ListenableFuture;
* @author Jeremy Daggett TODO: Need a ListFlavorOptions class minDisk=minDiskInGB&
* minRam=minRamInMB& marker=markerID&limit=int
*/
@SkipEncoding({ '/', '=' })
@RequestFilters(AuthenticateRequest.class)
public interface FlavorAsyncApi {

View File

@ -47,7 +47,6 @@ import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.Transform;
import org.jclouds.rest.binders.BindToJsonPayload;
import org.jclouds.rest.functions.ReturnEmptyMapOnNotFoundOr404;
@ -64,7 +63,6 @@ import com.google.common.util.concurrent.ListenableFuture;
* @see ImageApi
* @author Jeremy Daggett
*/
@SkipEncoding({ '/', '=' })
@RequestFilters(AuthenticateRequest.class)
public interface ImageAsyncApi {

View File

@ -54,7 +54,6 @@ import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.Transform;
import org.jclouds.rest.annotations.Unwrap;
import org.jclouds.rest.binders.BindToJsonPayload;
@ -78,7 +77,6 @@ import org.jclouds.openstack.nova.v2_0.functions.internal.*;
* />
* @author Adrian Cole
*/
@SkipEncoding({ '/', '=' })
@RequestFilters(AuthenticateRequest.class)
public interface ServerAsyncApi {

View File

@ -40,7 +40,6 @@ import org.jclouds.rackspace.cloudloadbalancers.functions.ParseLoadBalancers;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.Transform;
import org.jclouds.rest.annotations.WrapWith;
import org.jclouds.rest.functions.ReturnEmptyPagedIterableOnNotFoundOr404;
@ -56,7 +55,6 @@ import com.google.common.util.concurrent.ListenableFuture;
* @see LoadBalancerApi
* @author Everett Toews
*/
@SkipEncoding('/')
@RequestFilters(AuthenticateRequest.class)
public interface LoadBalancerAsyncApi {

View File

@ -44,7 +44,6 @@ import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.Transform;
import org.jclouds.rest.annotations.WrapWith;
import org.jclouds.rest.functions.ReturnEmptyPagedIterableOnNotFoundOr404;
@ -60,7 +59,6 @@ import com.google.common.util.concurrent.ListenableFuture;
* @see NodeAsyncApi
* @author Everett Toews
*/
@SkipEncoding('/')
@RequestFilters(AuthenticateRequest.class)
public interface NodeAsyncApi {

View File

@ -52,7 +52,6 @@ import org.jclouds.rest.annotations.ParamValidators;
import org.jclouds.rest.annotations.QueryParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.VirtualHost;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
@ -106,7 +105,6 @@ import com.google.inject.Provides;
* @see S3Client
* @see <a href="http://docs.amazonwebservices.com/AmazonS3/2006-03-01/RESTAPI.html" />
*/
@SkipEncoding('/')
@RequestFilters(RequestAuthorizeSignature.class)
@BlobScope(CONTAINER)
public interface S3AsyncClient {

View File

@ -21,7 +21,7 @@ package org.jclouds.s3.filters;
import static com.google.common.collect.Iterables.get;
import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AUTH_TAG;
import static org.jclouds.aws.reference.AWSConstants.PROPERTY_HEADER_TAG;
import static org.jclouds.http.utils.Queries.parseQueryToMap;
import static org.jclouds.http.utils.Queries.queryParser;
import static org.jclouds.s3.reference.S3Constants.PROPERTY_S3_SERVICE_PATH;
import static org.jclouds.s3.reference.S3Constants.PROPERTY_S3_VIRTUAL_HOST_BUCKETS;
import static org.jclouds.util.Strings2.toInputStream;
@ -238,7 +238,7 @@ public class RequestAuthorizeSignature implements HttpRequestFilter, RequestSign
// ...however, there are a few exceptions that must be included in the
// signed URI.
if (request.getEndpoint().getQuery() != null) {
Multimap<String, String> params = parseQueryToMap(request.getEndpoint().getQuery());
Multimap<String, String> params = queryParser().apply(request.getEndpoint().getQuery());
char separator = '?';
for (String paramName : Ordering.natural().sortedCopy(params.keySet())) {
// Skip any parameters that aren't part of the canonical signed string

View File

@ -19,13 +19,14 @@
package org.jclouds.s3.handlers;
import static org.jclouds.http.HttpUtils.closeClientButKeepContentStream;
import static org.jclouds.http.Uris.uriBuilder;
import java.net.URI;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.UriBuilder;
import org.jclouds.aws.domain.AWSError;
import org.jclouds.aws.util.AWSUtils;
@ -44,9 +45,8 @@ public class S3RedirectionRetryHandler extends RedirectionRetryHandler {
private final AWSUtils utils;
@Inject
public S3RedirectionRetryHandler(Provider<UriBuilder> uriBuilderProvider,
BackoffLimitedRetryHandler backoffHandler, AWSUtils utils) {
super(uriBuilderProvider, backoffHandler);
public S3RedirectionRetryHandler(BackoffLimitedRetryHandler backoffHandler, AWSUtils utils) {
super(backoffHandler);
this.utils = utils;
}
@ -69,9 +69,8 @@ public class S3RedirectionRetryHandler extends RedirectionRetryHandler {
// http://developer.amazonwebservices.com/connect/thread.jspa?messageID=72287&#72287
return backoffHandler.shouldRetryRequest(command, response);
} else {
UriBuilder builder = uriBuilderProvider.get().uri(command.getCurrentRequest().getEndpoint());
builder.host(host);
command.setCurrentRequest(command.getCurrentRequest().toBuilder().endpoint(builder.build()).build());
URI newHost = uriBuilder(command.getCurrentRequest().getEndpoint()).host(host).build();
command.setCurrentRequest(command.getCurrentRequest().toBuilder().endpoint(newHost).build());
}
return true;
} else {

View File

@ -18,11 +18,10 @@
*/
package org.jclouds.s3.xml;
import static org.jclouds.http.Uris.uriBuilder;
import static org.jclouds.util.SaxUtils.currentOrNull;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.ws.rs.core.UriBuilder;
import org.jclouds.crypto.CryptoStreams;
import org.jclouds.date.DateService;
@ -56,7 +55,6 @@ public class ListBucketHandler extends ParseSax.HandlerWithResult<ListBucketResp
private ObjectMetadataBuilder builder = new ObjectMetadataBuilder();
private final Provider<UriBuilder> uriBuilders;
private final DateService dateParser;
private String bucketName;
@ -67,9 +65,8 @@ public class ListBucketHandler extends ParseSax.HandlerWithResult<ListBucketResp
private boolean isTruncated;
@Inject
public ListBucketHandler(DateService dateParser, Provider<UriBuilder> uriBuilders) {
public ListBucketHandler(DateService dateParser) {
this.dateParser = dateParser;
this.uriBuilders = uriBuilders;
}
public ListBucketResponse getResult() {
@ -96,7 +93,7 @@ public class ListBucketHandler extends ParseSax.HandlerWithResult<ListBucketResp
} else if (qName.equals("Key")) { // content stuff
currentKey = currentOrNull(currentText);
builder.key(currentKey);
builder.uri(uriBuilders.get().uri(getRequest().getEndpoint()).path(currentKey).replaceQuery("").build());
builder.uri(uriBuilder(getRequest().getEndpoint()).clearQuery().appendPath(currentKey).build());
} else if (qName.equals("LastModified")) {
builder.lastModified(dateParser.iso8601DateParse(currentOrNull(currentText)));
} else if (qName.equals("ETag")) {

View File

@ -23,9 +23,6 @@ import static org.testng.Assert.assertEquals;
import java.net.URI;
import java.util.Map;
import javax.inject.Provider;
import javax.ws.rs.core.UriBuilder;
import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull;
import org.testng.annotations.Test;
@ -34,7 +31,6 @@ import com.google.common.base.Optional;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableMap;
import com.sun.jersey.api.uri.UriBuilderImpl;
/**
* Tests behavior of {@code AssignCorrectHostnameForBucket}
@ -45,14 +41,6 @@ import com.sun.jersey.api.uri.UriBuilderImpl;
// surefire
@Test(groups = "unit", testName = "AssignCorrectHostnameForBucketTest")
public class AssignCorrectHostnameForBucketTest {
Provider<UriBuilder> uriBuilderProvider = new Provider<UriBuilder>() {
@Override
public UriBuilder get() {
return new UriBuilderImpl();
}
};
public void testWhenNoBucketRegionMappingInCache() {

View File

@ -28,8 +28,6 @@ import java.util.concurrent.CompletionService;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorCompletionService;
import javax.ws.rs.core.UriBuilder;
import org.jclouds.PerformanceTest;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.http.HttpException;
@ -50,7 +48,6 @@ import org.xml.sax.SAXException;
import com.google.common.collect.Iterables;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.sun.jersey.api.uri.UriBuilderImpl;
/**
* Tests parsing of S3 responses
@ -65,12 +62,7 @@ public class S3ParserTest extends PerformanceTest {
@BeforeTest
protected void setUpInjector() {
injector = Guice.createInjector(new SaxParserModule() {
public void configure() {
super.configure();
bind(UriBuilder.class).to(UriBuilderImpl.class);
}
});
injector = Guice.createInjector(new SaxParserModule());
factory = injector.getInstance(ParseSax.Factory.class);
assert factory != null;
}

View File

@ -103,7 +103,7 @@ public class MessageApiExpectTest extends BaseSQSApiExpectTest {
.addFormParam("SendMessageBatchRequestEntry.1.MessageBody", "payload1")
.addFormParam("SendMessageBatchRequestEntry.2.Id", "foo2")
.addFormParam("SendMessageBatchRequestEntry.2.MessageBody", "payload2")
.addFormParam("Signature", "f9v8e%2FrPXTI3zhBYMhg7U8yCfvPqHjAV8bFjhGL6%2BXc%3D")
.addFormParam("Signature", "f9v8e/rPXTI3zhBYMhg7U8yCfvPqHjAV8bFjhGL6%2BXc%3D")
.addFormParam("SignatureMethod", "HmacSHA256")
.addFormParam("SignatureVersion", "2")
.addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z")
@ -135,7 +135,7 @@ public class MessageApiExpectTest extends BaseSQSApiExpectTest {
.addFormParam("SendMessageBatchRequestEntry.2.DelaySeconds", "10")
.addFormParam("SendMessageBatchRequestEntry.2.Id", "foo2")
.addFormParam("SendMessageBatchRequestEntry.2.MessageBody", "payload2")
.addFormParam("Signature", "COjjEaJ76EwziEFtkT2FuSRSbrCIu%2FhlJf1Zmu7cYoU%3D")
.addFormParam("Signature", "COjjEaJ76EwziEFtkT2FuSRSbrCIu/hlJf1Zmu7cYoU%3D")
.addFormParam("SignatureMethod", "HmacSHA256")
.addFormParam("SignatureVersion", "2")
.addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z")
@ -168,7 +168,7 @@ public class MessageApiExpectTest extends BaseSQSApiExpectTest {
.addFormParam("SendMessageBatchRequestEntry.2.DelaySeconds", "10")
.addFormParam("SendMessageBatchRequestEntry.2.Id", "2")
.addFormParam("SendMessageBatchRequestEntry.2.MessageBody", "payload2")
.addFormParam("Signature", "8AVNvSVXPSnoXjJAc6h1rysMBBZPnSycbnmD2%2FqpdV8%3D")
.addFormParam("Signature", "8AVNvSVXPSnoXjJAc6h1rysMBBZPnSycbnmD2/qpdV8%3D")
.addFormParam("SignatureMethod", "HmacSHA256")
.addFormParam("SignatureVersion", "2")
.addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z")
@ -231,7 +231,7 @@ public class MessageApiExpectTest extends BaseSQSApiExpectTest {
.addFormParam("SendMessageBatchRequestEntry.2.DelaySeconds", "10")
.addFormParam("SendMessageBatchRequestEntry.2.Id", "2")
.addFormParam("SendMessageBatchRequestEntry.2.MessageBody", "payload2")
.addFormParam("Signature", "nbA4UnKDAuQCiCcvQHH%2F1UjMMeo2s3d94A27Q3t9SlI%3D")
.addFormParam("Signature", "nbA4UnKDAuQCiCcvQHH/1UjMMeo2s3d94A27Q3t9SlI%3D")
.addFormParam("SignatureMethod", "HmacSHA256")
.addFormParam("SignatureVersion", "2")
.addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z")
@ -281,7 +281,7 @@ public class MessageApiExpectTest extends BaseSQSApiExpectTest {
.addHeader("Host", "sqs.us-east-1.amazonaws.com")
.addFormParam("Action", "ReceiveMessage")
.addFormParam("MaxNumberOfMessages", "10")
.addFormParam("Signature", "pZ9B4%2BTBvQA4n0joP4t8ue5x0xmKMd9prpVLVoT%2F7qU%3D")
.addFormParam("Signature", "pZ9B4%2BTBvQA4n0joP4t8ue5x0xmKMd9prpVLVoT/7qU%3D")
.addFormParam("SignatureMethod", "HmacSHA256")
.addFormParam("SignatureVersion", "2")
.addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z")
@ -305,7 +305,7 @@ public class MessageApiExpectTest extends BaseSQSApiExpectTest {
.addHeader("Host", "sqs.us-east-1.amazonaws.com")
.addFormParam("Action", "DeleteMessage")
.addFormParam("ReceiptHandle", "eXJYhj5rDr9cAe")
.addFormParam("Signature", "9%2FkuCc2i78gMsmul%2BRsOPcdQ1OLUKrItqgGIRRBJb8M%3D")
.addFormParam("Signature", "9/kuCc2i78gMsmul%2BRsOPcdQ1OLUKrItqgGIRRBJb8M%3D")
.addFormParam("SignatureMethod", "HmacSHA256")
.addFormParam("SignatureVersion", "2")
.addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z")
@ -335,7 +335,7 @@ public class MessageApiExpectTest extends BaseSQSApiExpectTest {
.addFormParam("DeleteMessageBatchRequestEntry.1.ReceiptHandle", "eXJYhj5rDr9cAe")
.addFormParam("DeleteMessageBatchRequestEntry.2.Id", "2")
.addFormParam("DeleteMessageBatchRequestEntry.2.ReceiptHandle", "fffeeerrr")
.addFormParam("Signature", "S4xIobjm3LOkJvibeI2X54nxKJw9r1a5zj%2FdvHlfDMY%3D")
.addFormParam("Signature", "S4xIobjm3LOkJvibeI2X54nxKJw9r1a5zj/dvHlfDMY%3D")
.addFormParam("SignatureMethod", "HmacSHA256")
.addFormParam("SignatureVersion", "2")
.addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z")
@ -487,7 +487,7 @@ public class MessageApiExpectTest extends BaseSQSApiExpectTest {
.addFormParam("ChangeMessageVisibilityBatchRequestEntry.2.Id", "foo2")
.addFormParam("ChangeMessageVisibilityBatchRequestEntry.2.ReceiptHandle", "bbbbbbbbb")
.addFormParam("ChangeMessageVisibilityBatchRequestEntry.2.VisibilityTimeout", "10")
.addFormParam("Signature", "y%2FgaaxoE5wrG2P7NIAyfDo7DTgRx2PLJUi9%2FzNnWQ6A%3D")
.addFormParam("Signature", "y/gaaxoE5wrG2P7NIAyfDo7DTgRx2PLJUi9/zNnWQ6A%3D")
.addFormParam("SignatureMethod", "HmacSHA256")
.addFormParam("SignatureVersion", "2")
.addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z")

View File

@ -36,8 +36,8 @@ public class PermissionApiExpectTest extends BaseSQSApiExpectTest {
.endpoint("https://sqs.us-east-1.amazonaws.com/993194456877/adrian-sqs11/")
.addHeader("Host", "sqs.us-east-1.amazonaws.com")
.addFormParam("Action", "AddPermission")
.addFormParam("ActionName.1", "ReceiveMessage")
.addFormParam("AWSAccountId.1", "125074342641")
.addFormParam("ActionName.1", "ReceiveMessage")
.addFormParam("Label", "testLabel")
.addFormParam("Signature", "J9sV4q1rJ7dWYJDQp9JxsfEKNXQhpQBYIwBYi1IeXV0%3D")
.addFormParam("SignatureMethod", "HmacSHA256")

View File

@ -71,7 +71,7 @@ public class QueueApiExpectTest extends BaseSQSApiExpectTest {
.addFormParam("Action", "GetQueueUrl")
.addFormParam("QueueName", "queueName")
.addFormParam("QueueOwnerAWSAccountId", "120908098979")
.addFormParam("Signature", "O0E%2B3jh2vN6bKqmb4%2FXPTHUmPO1iat9o8YnIFH463g8%3D")
.addFormParam("Signature", "O0E%2B3jh2vN6bKqmb4/XPTHUmPO1iat9o8YnIFH463g8%3D")
.addFormParam("SignatureMethod", "HmacSHA256")
.addFormParam("SignatureVersion", "2")
.addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z")
@ -213,7 +213,7 @@ public class QueueApiExpectTest extends BaseSQSApiExpectTest {
.addFormParam("Action", "SetQueueAttributes")
.addFormParam("Attribute.Name", "MaximumMessageSize")
.addFormParam("Attribute.Value", "1")
.addFormParam("Signature", "ktBkQ3c%2FrwGcBSec0fkckfo73xmcoTuub5fxudM1qh0%3D")
.addFormParam("Signature", "ktBkQ3c/rwGcBSec0fkckfo73xmcoTuub5fxudM1qh0%3D")
.addFormParam("SignatureMethod", "HmacSHA256")
.addFormParam("SignatureVersion", "2")
.addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z")

View File

@ -66,7 +66,6 @@ import org.jclouds.rest.annotations.ParamParser;
import org.jclouds.rest.annotations.QueryParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import com.google.common.annotations.Beta;
@ -80,7 +79,6 @@ import com.google.inject.Provides;
* @see <a href="http://www.rackspacecloud.com/cf-devguide-20090812.pdf" />
* @author Adrian Cole
*/
@SkipEncoding('/')
@RequestFilters(AuthenticateRequest.class)
@Endpoint(Storage.class)
public interface CommonSwiftAsyncClient {

View File

@ -21,14 +21,12 @@ package org.jclouds.openstack.swift;
import org.jclouds.openstack.filters.AuthenticateRequest;
import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SkipEncoding;
/**
* Functionality that's in Swift, and not in CloudFiles.
*
* @author Adrian Cole
*/
@SkipEncoding('/')
@RequestFilters(AuthenticateRequest.class)
@Endpoint(Storage.class)
public interface SwiftAsyncClient extends CommonSwiftAsyncClient {

View File

@ -21,14 +21,12 @@ package org.jclouds.openstack.swift;
import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest;
import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SkipEncoding;
/**
* Functionality that's in Swift, and not in CloudFiles.
*
* @author Adrian Cole
*/
@SkipEncoding('/')
@RequestFilters(AuthenticateRequest.class)
@Endpoint(Storage.class)
public interface SwiftKeystoneAsyncClient extends CommonSwiftAsyncClient {

View File

@ -22,7 +22,6 @@ import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest;
import org.jclouds.openstack.swift.Storage;
import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SkipEncoding;
/**
* Only purpose is to override the auth filter with one that works in keystone
@ -30,7 +29,6 @@ import org.jclouds.rest.annotations.SkipEncoding;
* @author Adrian Cole
* @see TemporaryUrlKeyApi
*/
@SkipEncoding('/')
@RequestFilters(AuthenticateRequest.class)
@Endpoint(Storage.class)
public interface KeystoneTemporaryUrlKeyAsyncApi extends TemporaryUrlKeyAsyncApi {

View File

@ -26,7 +26,6 @@ import org.jclouds.openstack.swift.reference.SwiftHeaders;
import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.SkipEncoding;
import javax.ws.rs.Consumes;
import javax.ws.rs.HEAD;
@ -39,7 +38,6 @@ import javax.ws.rs.core.MediaType;
* @author Andrei Savu
* @see TemporaryUrlKeyApi
*/
@SkipEncoding('/')
@RequestFilters(AuthenticateRequest.class)
@Endpoint(Storage.class)
public interface TemporaryUrlKeyAsyncApi {

View File

@ -20,6 +20,7 @@ package org.jclouds.openstack.swift.functions;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
import static org.jclouds.http.Uris.uriBuilder;
import java.io.IOException;
import java.io.InputStream;
@ -27,8 +28,6 @@ import java.lang.reflect.Type;
import java.util.SortedSet;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.ws.rs.core.UriBuilder;
import org.jclouds.blobstore.domain.PageSet;
import org.jclouds.blobstore.domain.internal.PageSetImpl;
@ -54,16 +53,14 @@ import com.google.inject.TypeLiteral;
*/
public class ParseObjectInfoListFromJsonResponse extends ParseJson<PageSet<ObjectInfo>> implements
InvocationContext<ParseObjectInfoListFromJsonResponse> {
private final Provider<UriBuilder> uriBuilders;
private GeneratedHttpRequest request;
private String container;
@Inject
public ParseObjectInfoListFromJsonResponse(Json json, Provider<UriBuilder> uriBuilders) {
public ParseObjectInfoListFromJsonResponse(Json json) {
super(json, new TypeLiteral<PageSet<ObjectInfo>>() {
});
this.uriBuilders = uriBuilders;
}
public PageSet<ObjectInfo> apply(InputStream stream) {
@ -82,9 +79,9 @@ public class ParseObjectInfoListFromJsonResponse extends ParseJson<PageSet<Objec
SortedSet<ObjectInfo> returnVal = Sets.newTreeSet(Iterables.transform(list,
new Function<ObjectInfoImpl, ObjectInfo>() {
public ObjectInfo apply(ObjectInfoImpl from) {
return from.toBuilder().container(container).uri(
uriBuilders.get().uri(request.getEndpoint()).path(from.getName()).replaceQuery("")
.build()).build();
return from.toBuilder().container(container)
.uri(uriBuilder(request.getEndpoint()).clearQuery().appendPath(from.getName()).build())
.build();
}
}));
boolean truncated = options.getMaxResults() == returnVal.size();

View File

@ -22,8 +22,6 @@ import static org.testng.Assert.assertEquals;
import java.net.URI;
import javax.ws.rs.core.UriBuilder;
import org.jclouds.Constants;
import org.jclouds.blobstore.reference.BlobStoreConstants;
import org.jclouds.http.HttpResponse;
@ -35,7 +33,6 @@ import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.name.Names;
import com.sun.jersey.api.uri.UriBuilderImpl;
/**
* Tests behavior of {@code ParseContainerListFromJsonResponse}
@ -51,7 +48,6 @@ public class ParseAuthenticationResponseFromHeadersTest {
protected void configure() {
bindConstant().annotatedWith(Names.named(BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX)).to("sdf");
bindConstant().annotatedWith(Names.named(Constants.PROPERTY_API_VERSION)).to("1");
bind(UriBuilder.class).to(UriBuilderImpl.class);
}
});

View File

@ -27,8 +27,6 @@ import java.io.InputStream;
import java.net.URI;
import java.util.Set;
import javax.ws.rs.core.UriBuilder;
import org.jclouds.crypto.CryptoStreams;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.json.config.GsonModule;
@ -45,7 +43,6 @@ import com.google.common.collect.ImmutableSet;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.sun.jersey.api.uri.UriBuilderImpl;
/**
* Tests behavior of {@code ParseObjectInfoListFromJsonResponse}
@ -60,7 +57,6 @@ public class ParseObjectInfoListFromJsonResponseTest {
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
bind(UriBuilder.class).to(UriBuilderImpl.class);
}
}, new GsonModule());

View File

@ -18,13 +18,8 @@
*/
package org.jclouds.vcloud.binders;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.net.URI;
import java.util.Properties;
import org.jclouds.rest.internal.GeneratedHttpRequest;
@ -33,7 +28,6 @@ import org.jclouds.vcloud.VCloudApiMetadata;
import org.jclouds.vcloud.options.CloneVAppOptions;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
import com.google.inject.AbstractModule;
@ -59,36 +53,30 @@ public class BindCloneVAppParamsToXmlPayloadTest {
}
});
public void testWithDescriptionDeployOn() throws IOException {
public void testWithDescriptionDeployOn() throws Exception {
String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/copyVApp.xml"));
CloneVAppOptions options = new CloneVAppOptions().deploy().powerOn().description(
"The description of the new vApp");
GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class);
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
expect(request.getArgs()).andReturn(ImmutableList.<Object> of(options)).atLeastOnce();
request.setPayload(expected);
replay(request);
GeneratedHttpRequest request = GeneratedHttpRequest.builder().method("POST").endpoint("http://localhost/key")
.declaring(String.class).javaMethod(String.class.getDeclaredMethod("toString")).arg(options).build();
BindCloneVAppParamsToXmlPayload binder = injector.getInstance(BindCloneVAppParamsToXmlPayload.class);
Builder<String, Object> map = ImmutableMap.builder();
map.put("name", "new-linux-server");
map.put("Source", "https://vcenterprise.bluelock.com/api/v1.0/vapp/201");
binder.bindToRequest(request, map.build());
verify(request);
assertEquals(binder.bindToRequest(request, map.build()).getPayload().getRawContent(), expected);
}
public void testWithDescriptionDeployOnSourceDelete() throws IOException {
public void testWithDescriptionDeployOnSourceDelete() throws Exception {
String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/moveVApp.xml"));
CloneVAppOptions options = new CloneVAppOptions().deploy().powerOn().description(
"The description of the new vApp");
GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class);
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
expect(request.getArgs()).andReturn(ImmutableList.<Object> of(options)).atLeastOnce();
request.setPayload(expected);
replay(request);
GeneratedHttpRequest request = GeneratedHttpRequest.builder().method("POST").endpoint("http://localhost/key")
.declaring(String.class).javaMethod(String.class.getDeclaredMethod("toString")).arg(options).build();
BindCloneVAppParamsToXmlPayload binder = injector.getInstance(BindCloneVAppParamsToXmlPayload.class);
@ -96,25 +84,21 @@ public class BindCloneVAppParamsToXmlPayloadTest {
map.put("name", "new-linux-server");
map.put("Source", "https://vcenterprise.bluelock.com/api/v1.0/vapp/201");
map.put("IsSourceDelete", "true");
binder.bindToRequest(request, map.build());
verify(request);
assertEquals(binder.bindToRequest(request, map.build()).getPayload().getRawContent(), expected);
}
public void testDefault() throws IOException {
public void testDefault() throws Exception {
String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/copyVApp-default.xml"));
GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class);
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
expect(request.getArgs()).andReturn(ImmutableList.<Object> of()).atLeastOnce();
request.setPayload(expected);
replay(request);
GeneratedHttpRequest request = GeneratedHttpRequest.builder().method("POST").endpoint("http://localhost/key")
.declaring(String.class).javaMethod(String.class.getDeclaredMethod("toString")).build();
BindCloneVAppParamsToXmlPayload binder = injector.getInstance(BindCloneVAppParamsToXmlPayload.class);
Builder<String, Object> map = ImmutableMap.builder();
map.put("name", "my-vapp");
map.put("Source", "https://vcenterprise.bluelock.com/api/v1.0/vapp/4181");
binder.bindToRequest(request, map.build());
verify(request);
assertEquals(binder.bindToRequest(request, map.build()).getPayload().getRawContent(), expected);
}
}

View File

@ -31,7 +31,6 @@ import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.ParamValidators;
import org.jclouds.rest.annotations.QueryParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.s3.Bucket;
import org.jclouds.s3.S3AsyncClient;
import org.jclouds.s3.S3Client;
@ -45,7 +44,6 @@ import com.google.common.util.concurrent.ListenableFuture;
*
* @author Adrian Cole
*/
@SkipEncoding('/')
@RequestFilters(RequestAuthorizeSignature.class)
@BlobScope(CONTAINER)
public interface WalrusAsyncClient extends S3AsyncClient {

View File

@ -37,7 +37,6 @@ import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.Headers;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.binders.BindToJsonPayload;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
@ -50,7 +49,6 @@ import com.google.common.util.concurrent.ListenableFuture;
* @see KeyApi
* @see <a href="TODO!">api doc</a>
*/
@SkipEncoding({ '/', '=' })
@Headers(keys = "X-Api-Version", values = "{jclouds.api-version}")
@RequestFilters(BasicAuthentication.class)
public interface KeyAsyncApi {

View File

@ -27,15 +27,9 @@ import java.util.Date;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import javax.inject.Provider;
import javax.inject.Inject;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.UriBuilder;
import com.google.common.base.Preconditions;
import com.google.common.base.Supplier;
import com.google.common.base.Throwables;
import com.google.common.collect.Multimaps;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.domain.Blob.Factory;
@ -47,6 +41,7 @@ import org.jclouds.crypto.CryptoStreams;
import org.jclouds.date.DateService;
import org.jclouds.domain.Location;
import org.jclouds.http.HttpUtils;
import static org.jclouds.http.Uris.*;
import org.jclouds.io.ContentMetadataCodec;
import org.jclouds.io.MutableContentMetadata;
import org.jclouds.io.Payload;
@ -54,6 +49,11 @@ import org.jclouds.io.Payloads;
import org.jclouds.io.payloads.ByteArrayPayload;
import org.jclouds.io.payloads.DelegatingPayload;
import com.google.common.base.Supplier;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Multimaps;
public class TransientStorageStrategy implements LocalStorageStrategy {
private final ConcurrentMap<String, ConcurrentMap<String, Blob>> containerToBlobs = new ConcurrentHashMap<String, ConcurrentMap<String, Blob>>();
private final ConcurrentMap<String, Location> containerToLocation = new ConcurrentHashMap<String, Location>();
@ -62,19 +62,15 @@ public class TransientStorageStrategy implements LocalStorageStrategy {
private final Factory blobFactory;
private final Crypto crypto;
private final ContentMetadataCodec contentMetadataCodec;
private final Provider<UriBuilder> uriBuilders;
@Inject
TransientStorageStrategy(final Supplier<Location> defaultLocation,
DateService dateService, Factory blobFactory, Crypto crypto,
ContentMetadataCodec contentMetadataCodec,
Provider<UriBuilder> uriBuilders) {
TransientStorageStrategy(Supplier<Location> defaultLocation, DateService dateService, Factory blobFactory,
Crypto crypto, ContentMetadataCodec contentMetadataCodec) {
this.defaultLocation = defaultLocation;
this.dateService = dateService;
this.blobFactory = blobFactory;
this.crypto = crypto;
this.contentMetadataCodec = contentMetadataCodec;
this.uriBuilders = uriBuilders;
}
@Override
@ -185,7 +181,7 @@ public class TransientStorageStrategy implements LocalStorageStrategy {
blob.setPayload(payload);
blob.getMetadata().setContainer(containerName);
blob.getMetadata().setUri(
uriBuilders.get().scheme("mem").host(containerName).path(in.getMetadata().getName()).build());
uriBuilder(new StringBuilder("mem://").append(containerName)).path(in.getMetadata().getName()).build());
blob.getMetadata().setLastModified(new Date());
String eTag = CryptoStreams.hex(payload.getContentMetadata().getContentMD5());
blob.getMetadata().setETag(eTag);

View File

@ -363,51 +363,6 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
}
}
// @Test(groups = { "integration", "live" })
// public void testGetTail() throws InterruptedException, ExecutionException,
// TimeoutException,
// IOException {
// String container = getContainerName();
// try {
//
// String name = "apples";
//
// addObjectAndValidateContent(container, name);
// Blob blob = context.getBlobStore().getBlob(container, name,
// tail(5)).get(30,
// TimeUnit.SECONDS);
// assertEquals(BlobStoreUtils.getContentAsStringAndClose(blob), TEST_STRING
// .substring(TEST_STRING.length() - 5));
// assertEquals(blob.getContentLength(), 5);
// assertEquals(blob.getMetadata().getSize(), TEST_STRING.length());
// } finally {
// returnContainer(container);
// }
// }
// @Test(groups = { "integration", "live" })
// public void testGetStartAt() throws InterruptedException,
// ExecutionException,
// TimeoutException,
// IOException {
// String container = getContainerName();
// try {
// String name = "apples";
//
// addObjectAndValidateContent(container, name);
// Blob blob = context.getBlobStore().getBlob(container, name,
// startAt(5)).get(30,
// TimeUnit.SECONDS);
// assertEquals(BlobStoreUtils.getContentAsStringAndClose(blob),
// TEST_STRING.substring(5,
// TEST_STRING.length()));
// assertEquals(blob.getContentLength(), TEST_STRING.length() - 5);
// assertEquals(blob.getMetadata().getSize(), TEST_STRING.length());
// } finally {
// returnContainer(container);
// }
// }
private String addObjectAndValidateContent(String sourcecontainer, String sourceKey) throws InterruptedException {
String eTag = addBlobToContainer(sourcecontainer, sourceKey);
validateContent(sourcecontainer, sourceKey);
@ -646,4 +601,4 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
assertEquals(metadata.getContentMetadata().getContentMD5(), CryptoStreams.md5(InputSuppliers.of(TEST_STRING)));
}
}
}

View File

@ -20,6 +20,7 @@ package org.jclouds.aws.filters;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.Ordering.natural;
import static org.jclouds.aws.reference.FormParameters.ACTION;
import static org.jclouds.aws.reference.FormParameters.AWS_ACCESS_KEY_ID;
import static org.jclouds.aws.reference.FormParameters.SIGNATURE;
@ -27,11 +28,14 @@ import static org.jclouds.aws.reference.FormParameters.SIGNATURE_METHOD;
import static org.jclouds.aws.reference.FormParameters.SIGNATURE_VERSION;
import static org.jclouds.aws.reference.FormParameters.TIMESTAMP;
import static org.jclouds.aws.reference.FormParameters.VERSION;
import static org.jclouds.crypto.CryptoStreams.base64;
import static org.jclouds.crypto.CryptoStreams.mac;
import static org.jclouds.http.utils.Queries.encodeQueryLine;
import static org.jclouds.http.utils.Queries.queryParser;
import static org.jclouds.util.Strings2.toInputStream;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import javax.annotation.Resource;
import javax.inject.Inject;
@ -42,31 +46,29 @@ import javax.ws.rs.core.HttpHeaders;
import org.jclouds.Constants;
import org.jclouds.crypto.Crypto;
import org.jclouds.crypto.CryptoStreams;
import org.jclouds.date.TimeStamp;
import org.jclouds.http.HttpException;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpRequestFilter;
import org.jclouds.http.HttpUtils;
import org.jclouds.http.internal.SignatureWire;
import org.jclouds.http.utils.Queries;
import org.jclouds.io.InputSuppliers;
import org.jclouds.logging.Logger;
import org.jclouds.rest.RequestSigner;
import org.jclouds.rest.annotations.ApiVersion;
import org.jclouds.rest.annotations.Credential;
import org.jclouds.rest.annotations.Identity;
import org.jclouds.util.Strings2;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Multimap;
import com.google.common.collect.TreeMultimap;
/**
*
* @see <a href=
* "http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/Form-Common-Parameters.html"
* "http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/Query-Common-Parameters.html"
* />
* @author Adrian Cole
*
@ -74,8 +76,9 @@ import com.google.common.collect.Multimap;
@Singleton
public class FormSigner implements HttpRequestFilter, RequestSigner {
public static String[] mandatoryParametersForSignature = new String[] { ACTION, SIGNATURE_METHOD, SIGNATURE_VERSION,
VERSION };
public static final Set<String> mandatoryParametersForSignature = ImmutableSet.of(ACTION, SIGNATURE_METHOD,
SIGNATURE_VERSION, VERSION);
private final SignatureWire signatureWire;
private final String apiVersion;
private final String accessKey;
@ -103,8 +106,7 @@ public class FormSigner implements HttpRequestFilter, RequestSigner {
public HttpRequest filter(HttpRequest request) throws HttpException {
checkNotNull(request.getFirstHeaderOrNull(HttpHeaders.HOST), "request is not ready to sign; host not present");
Multimap<String, String> decodedParams = Queries.parseQueryToMap(request.getPayload().getRawContent()
.toString());
Multimap<String, String> decodedParams = queryParser().apply(request.getPayload().getRawContent().toString());
decodedParams.replaceValues(VERSION, ImmutableSet.of(apiVersion));
addSigningParams(decodedParams);
validateParams(decodedParams);
@ -115,36 +117,39 @@ public class FormSigner implements HttpRequestFilter, RequestSigner {
utils.logRequest(signatureLog, request, "<<");
return request;
}
String[] sortForSigning(String queryLine) {
String[] parts = queryLine.split("&");
// 1. Sort the UTF-8 query string components by parameter name with natural byte ordering.
Arrays.sort(parts, new Comparator<String>() {
public int compare(String o1, String o2) {
if (o1.startsWith("AWSAccessKeyId"))
return -1;
return o1.compareTo(o2);
}
});
return parts;
}
HttpRequest setPayload(HttpRequest request, Multimap<String, String> decodedParams) {
request.setPayload(Queries.makeQueryLine(decodedParams, new Comparator<Map.Entry<String, String>>() {
public int compare(Entry<String, String> o1, Entry<String, String> o2) {
if (o1.getKey().startsWith("Action") || o2.getKey().startsWith("AWSAccessKeyId"))
return -1;
if (o1.getKey().startsWith("AWSAccessKeyId") || o2.getKey().startsWith("Action"))
return 1;
return o1.getKey().compareTo(o2.getKey());
}
}));
String queryLine = buildQueryLine(decodedParams);
request.setPayload(queryLine);
request.getPayload().getContentMetadata().setContentType("application/x-www-form-urlencoded");
return request;
}
private static final Comparator<String> actionFirstAccessKeyLast = new Comparator<String>() {
static final int LEFT_IS_GREATER = 1;
static final int RIGHT_IS_GREATER = -1;
@Override
public int compare(String left, String right) {
if (left == right) {
return 0;
}
if ("Action".equals(right) || "AWSAccessKeyId".equals(left)) {
return LEFT_IS_GREATER;
}
if ("Action".equals(left) || "AWSAccessKeyId".equals(right)) {
return RIGHT_IS_GREATER;
}
return natural().compare(left, right);
}
};
private static String buildQueryLine(Multimap<String, String> decodedParams) {
Multimap<String, String> sortedParams = TreeMultimap.create(actionFirstAccessKeyLast, natural());
sortedParams.putAll(decodedParams);
return encodeQueryLine(sortedParams);
}
@VisibleForTesting
void validateParams(Multimap<String, String> params) {
for (String parameter : mandatoryParametersForSignature) {
@ -161,10 +166,9 @@ public class FormSigner implements HttpRequestFilter, RequestSigner {
public String sign(String stringToSign) {
String signature;
try {
signature = CryptoStreams.base64(CryptoStreams.mac(InputSuppliers.of(stringToSign), crypto
.hmacSHA256(secretKey.getBytes())));
signature = base64(mac(InputSuppliers.of(stringToSign), crypto.hmacSHA256(secretKey.getBytes())));
if (signatureWire.enabled())
signatureWire.input(Strings2.toInputStream(signature));
signatureWire.input(toInputStream(signature));
} catch (Exception e) {
throw new HttpException("error signing request", e);
}
@ -190,16 +194,10 @@ public class FormSigner implements HttpRequestFilter, RequestSigner {
@VisibleForTesting
String buildCanonicalizedString(Multimap<String, String> decodedParams) {
return Queries.makeQueryLine(decodedParams, sortAWSFirst);
// note that aws wants to percent encode the canonicalized string without skipping '/' and '?'
return encodeQueryLine(TreeMultimap.create(decodedParams), ImmutableList.<Character> of());
}
public static final Comparator<Map.Entry<String, String>> sortAWSFirst = new Comparator<Map.Entry<String, String>>() {
public int compare(Map.Entry<String, String> o1, Map.Entry<String, String> o2) {
if (o1.getKey().startsWith("AWSAccessKeyId"))
return -1;
return o1.getKey().compareTo(o2.getKey());
}
};
@VisibleForTesting
void addSigningParams(Multimap<String, String> params) {
@ -211,7 +209,7 @@ public class FormSigner implements HttpRequestFilter, RequestSigner {
}
public String createStringToSign(HttpRequest input) {
return createStringToSign(input, Queries.parseQueryToMap(input.getPayload().getRawContent().toString()));
return createStringToSign(input, queryParser().apply(input.getPayload().getRawContent().toString()));
}
}

View File

@ -77,7 +77,7 @@ public class FormSignerTest {
.addHeader(HttpHeaders.HOST, "localhost")
.payload("Action=DescribeImages&ImageId.1=ami-2bb65342").build())
.getPayload().getRawContent(),
"Action=DescribeImages&ImageId.1=ami-2bb65342&Signature=ugnt4m2eHE7Ka%2FvXTr9EhKZq7bhxOfvW0y4pAEqF97w%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&Version=apiVersion&AWSAccessKeyId=identity");
"Action=DescribeImages&ImageId.1=ami-2bb65342&Signature=ugnt4m2eHE7Ka/vXTr9EhKZq7bhxOfvW0y4pAEqF97w%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&Version=apiVersion&AWSAccessKeyId=identity");
}
@Test
@ -90,4 +90,4 @@ public class FormSignerTest {
"AWSAccessKeyId=foo&Action=DescribeImages&Expires=2008-02-10T12%3A00%3A00Z&ImageId.1=ami-2bb65342&SignatureMethod=HmacSHA256&SignatureVersion=2&Version=2010-06-15");
}
}
}

View File

@ -20,6 +20,7 @@ package org.jclouds.openstack.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.http.HttpUtils.releasePayload;
import static org.jclouds.http.Uris.uriBuilder;
import static org.jclouds.openstack.reference.AuthHeaders.AUTH_TOKEN;
import static org.jclouds.openstack.reference.AuthHeaders.URL_SUFFIX;
@ -27,9 +28,6 @@ import java.net.URI;
import java.util.Map.Entry;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.ws.rs.core.UriBuilder;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
@ -53,14 +51,8 @@ public class ParseAuthenticationResponseFromHeaders implements Function<HttpResp
@Resource
protected Logger logger = Logger.NULL;
private final Provider<UriBuilder> uriBuilderProvider;
private String hostToReplace;
@Inject
public ParseAuthenticationResponseFromHeaders(Provider<UriBuilder> uriBuilderProvider) {
this.uriBuilderProvider = uriBuilderProvider;
}
/**
* parses the http response headers to create a new {@link AuthenticationResponse} object.
*/
@ -84,7 +76,7 @@ public class ParseAuthenticationResponseFromHeaders implements Function<HttpResp
URI toReturn = URI.create(headerValue);
if (!"127.0.0.1".equals(toReturn.getHost()))
return toReturn;
return uriBuilderProvider.get().uri(toReturn).host(hostToReplace).build();
return uriBuilder(toReturn).host(hostToReplace).build();
}
@Override
@ -98,4 +90,4 @@ public class ParseAuthenticationResponseFromHeaders implements Function<HttpResp
this.hostToReplace = hostToReplace;
return this;
}
}
}

View File

@ -18,13 +18,8 @@
*/
package org.jclouds.trmk.vcloud_0_8.binders;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.net.URI;
import java.util.Map;
import java.util.Properties;
@ -34,7 +29,6 @@ import org.jclouds.trmk.vcloud_0_8.options.CloneVAppOptions;
import org.jclouds.util.Strings2;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Maps;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
@ -59,41 +53,34 @@ public class BindCloneVAppParamsToXmlPayloadTest {
}
});
public void testWithDescriptionDeployOn() throws IOException {
public void testWithDescriptionDeployOn() throws Exception {
String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/cloneVApp.xml"));
CloneVAppOptions options = new CloneVAppOptions().deploy().powerOn().withDescription(
"The description of the new vApp");
GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class);
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
expect(request.getArgs()).andReturn(ImmutableList.<Object> of(options)).atLeastOnce();
request.setPayload(expected);
replay(request);
GeneratedHttpRequest request = GeneratedHttpRequest.builder().method("POST").endpoint("http://localhost/key")
.declaring(String.class).javaMethod(String.class.getDeclaredMethod("toString")).arg(options).build();
BindCloneVAppParamsToXmlPayload binder = injector.getInstance(BindCloneVAppParamsToXmlPayload.class);
Map<String, Object> map = Maps.newHashMap();
map.put("newName", "new-linux-server");
map.put("vApp", "https://vcloud.safesecureweb.com/api/v0.8/vapp/201");
binder.bindToRequest(request, map);
verify(request);
assertEquals(binder.bindToRequest(request, map).getPayload().getRawContent(), expected);
}
public void testDefault() throws IOException {
public void testDefault() throws Exception {
String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/cloneVApp-default.xml"));
GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class);
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
expect(request.getArgs()).andReturn(ImmutableList.<Object> of()).atLeastOnce();
request.setPayload(expected);
replay(request);
GeneratedHttpRequest request = GeneratedHttpRequest.builder().method("POST").endpoint("http://localhost/key")
.declaring(String.class).javaMethod(String.class.getDeclaredMethod("toString")).build();
BindCloneVAppParamsToXmlPayload binder = injector.getInstance(BindCloneVAppParamsToXmlPayload.class);
Map<String, Object> map = Maps.newHashMap();
map.put("newName", "my-vapp");
map.put("vApp", "https://vcloud.safesecureweb.com/api/v0.8/vapp/4181");
binder.bindToRequest(request, map);
verify(request);
assertEquals(binder.bindToRequest(request, map).getPayload().getRawContent(), expected);
}
}

View File

@ -53,9 +53,9 @@
<version>1.46</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>1.12</version>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>

Some files were not shown because too many files have changed in this diff Show More