mirror of https://github.com/apache/jclouds.git
Merge pull request #1090 from jclouds/no-matrix
removed explicit matrix param support as their use is edge case in rest
This commit is contained in:
commit
847b1c7352
|
@ -145,7 +145,6 @@ public class CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptionsTest {
|
|||
customize.buildFormParameters().entries(),
|
||||
ImmutableMultimap.<String, String> of("InstanceType", size.getProviderId(), "SecurityGroup.1",
|
||||
generatedGroup, "KeyName", systemGeneratedKeyPairName).entries());
|
||||
assertEquals(customize.buildMatrixParameters(), ImmutableMultimap.<String, String> of());
|
||||
assertEquals(customize.buildRequestHeaders(), ImmutableMultimap.<String, String> of());
|
||||
assertEquals(customize.buildStringPayload(), null);
|
||||
|
||||
|
@ -201,7 +200,6 @@ public class CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptionsTest {
|
|||
customize.buildFormParameters().entries(),
|
||||
ImmutableMultimap.<String, String> of("InstanceType", size.getProviderId(), "SecurityGroup.1", "group",
|
||||
"KeyName", systemGeneratedKeyPairName, "UserData", CryptoStreams.base64("hello".getBytes())).entries());
|
||||
assertEquals(customize.buildMatrixParameters(), ImmutableMultimap.<String, String> of());
|
||||
assertEquals(customize.buildRequestHeaders(), ImmutableMultimap.<String, String> of());
|
||||
assertEquals(customize.buildStringPayload(), null);
|
||||
|
||||
|
|
|
@ -31,7 +31,6 @@ import com.google.common.collect.Multimap;
|
|||
*/
|
||||
public class BaseHttpRequestOptions implements HttpRequestOptions {
|
||||
|
||||
protected final Multimap<String, String> matrixParameters = LinkedHashMultimap.create();
|
||||
protected final Multimap<String, String> formParameters = LinkedHashMultimap.create();
|
||||
protected final Multimap<String, String> queryParameters = LinkedHashMultimap.create();
|
||||
protected final Multimap<String, String> headers = LinkedHashMultimap.create();
|
||||
|
@ -42,11 +41,6 @@ public class BaseHttpRequestOptions implements HttpRequestOptions {
|
|||
return payload;
|
||||
}
|
||||
|
||||
protected String getFirstMatrixOrNull(String string) {
|
||||
Collection<String> values = matrixParameters.get(string);
|
||||
return (values != null && values.size() >= 1) ? values.iterator().next() : null;
|
||||
}
|
||||
|
||||
protected String getFirstQueryOrNull(String string) {
|
||||
Collection<String> values = queryParameters.get(string);
|
||||
return (values != null && values.size() >= 1) ? values.iterator().next() : null;
|
||||
|
@ -81,13 +75,6 @@ public class BaseHttpRequestOptions implements HttpRequestOptions {
|
|||
return queryParameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Multimap<String, String> buildMatrixParameters() {
|
||||
return matrixParameters;
|
||||
}
|
||||
|
||||
public String buildPathSuffix() {
|
||||
return pathSuffix;
|
||||
}
|
||||
|
@ -102,7 +89,6 @@ public class BaseHttpRequestOptions implements HttpRequestOptions {
|
|||
int result = 1;
|
||||
result = prime * result + ((formParameters == null) ? 0 : formParameters.hashCode());
|
||||
result = prime * result + ((headers == null) ? 0 : headers.hashCode());
|
||||
result = prime * result + ((matrixParameters == null) ? 0 : matrixParameters.hashCode());
|
||||
result = prime * result + ((pathSuffix == null) ? 0 : pathSuffix.hashCode());
|
||||
result = prime * result + ((payload == null) ? 0 : payload.hashCode());
|
||||
result = prime * result + ((queryParameters == null) ? 0 : queryParameters.hashCode());
|
||||
|
@ -128,11 +114,6 @@ public class BaseHttpRequestOptions implements HttpRequestOptions {
|
|||
return false;
|
||||
} else if (!headers.equals(other.headers))
|
||||
return false;
|
||||
if (matrixParameters == null) {
|
||||
if (other.matrixParameters != null)
|
||||
return false;
|
||||
} else if (!matrixParameters.equals(other.matrixParameters))
|
||||
return false;
|
||||
if (pathSuffix == null) {
|
||||
if (other.pathSuffix != null)
|
||||
return false;
|
||||
|
@ -153,9 +134,8 @@ public class BaseHttpRequestOptions implements HttpRequestOptions {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[formParameters=" + formParameters + ", headers=" + headers + ", matrixParameters="
|
||||
+ matrixParameters + ", pathSuffix=" + pathSuffix + ", payload=" + payload
|
||||
+ ", queryParameters=" + queryParameters + "]";
|
||||
return "[formParameters=" + formParameters + ", headers=" + headers + ", pathSuffix=" + pathSuffix + ", payload="
|
||||
+ payload + ", queryParameters=" + queryParameters + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -298,9 +298,8 @@ public class GetOptions extends BaseHttpRequestOptions {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[matrixParameters=" + matrixParameters + ", formParameters=" + formParameters + ", queryParameters="
|
||||
+ queryParameters + ", headers=" + headers + ", payload=" + payload + ", pathSuffix=" + pathSuffix
|
||||
+ ", ranges=" + ranges + "]";
|
||||
return "[formParameters=" + formParameters + ", queryParameters=" + queryParameters + ", headers=" + headers
|
||||
+ ", payload=" + payload + ", pathSuffix=" + pathSuffix + ", ranges=" + ranges + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -49,13 +49,6 @@ public interface HttpRequestOptions {
|
|||
*/
|
||||
Multimap<String, String> buildFormParameters();
|
||||
|
||||
/**
|
||||
* Builds matrix parameters representing options.
|
||||
*
|
||||
* @return multimap that may contain matrix parameters.
|
||||
*/
|
||||
Multimap<String, String> buildMatrixParameters();
|
||||
|
||||
String buildStringPayload();
|
||||
|
||||
String buildPathSuffix();
|
||||
|
|
|
@ -1,43 +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.rest.annotations;
|
||||
|
||||
import static java.lang.annotation.ElementType.METHOD;
|
||||
import static java.lang.annotation.ElementType.TYPE;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Designates that a matrix param will be added to the request.
|
||||
*
|
||||
* @see MatrixParam
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Target( { TYPE, METHOD })
|
||||
@Retention(RUNTIME)
|
||||
public @interface MatrixParams {
|
||||
|
||||
public static final String NULL = "MATRIX_NULL";
|
||||
|
||||
String[] keys();
|
||||
|
||||
String[] values() default NULL;
|
||||
}
|
|
@ -58,7 +58,6 @@ import javax.ws.rs.Consumes;
|
|||
import javax.ws.rs.FormParam;
|
||||
import javax.ws.rs.HeaderParam;
|
||||
import javax.ws.rs.HttpMethod;
|
||||
import javax.ws.rs.MatrixParam;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
|
@ -112,7 +111,6 @@ import org.jclouds.rest.annotations.FormParams;
|
|||
import org.jclouds.rest.annotations.Headers;
|
||||
import org.jclouds.rest.annotations.JAXBResponseParser;
|
||||
import org.jclouds.rest.annotations.MapBinder;
|
||||
import org.jclouds.rest.annotations.MatrixParams;
|
||||
import org.jclouds.rest.annotations.OnlyElement;
|
||||
import org.jclouds.rest.annotations.OverrideRequestFilters;
|
||||
import org.jclouds.rest.annotations.ParamParser;
|
||||
|
@ -183,7 +181,6 @@ public class RestAnnotationProcessor<T> {
|
|||
static final LoadingCache<Method, LoadingCache<Integer, Set<Annotation>>> methodToIndexOfParamToHeaderParamAnnotations = createMethodToIndexOfParamToAnnotation(HeaderParam.class);
|
||||
static final LoadingCache<Method, LoadingCache<Integer, Set<Annotation>>> methodToIndexOfParamToEndpointAnnotations = createMethodToIndexOfParamToAnnotation(Endpoint.class);
|
||||
static final LoadingCache<Method, LoadingCache<Integer, Set<Annotation>>> methodToIndexOfParamToEndpointParamAnnotations = createMethodToIndexOfParamToAnnotation(EndpointParam.class);
|
||||
static final LoadingCache<Method, LoadingCache<Integer, Set<Annotation>>> methodToIndexOfParamToMatrixParamAnnotations = createMethodToIndexOfParamToAnnotation(MatrixParam.class);
|
||||
static final LoadingCache<Method, LoadingCache<Integer, Set<Annotation>>> methodToIndexOfParamToFormParamAnnotations = createMethodToIndexOfParamToAnnotation(FormParam.class);
|
||||
static final LoadingCache<Method, LoadingCache<Integer, Set<Annotation>>> methodToIndexOfParamToQueryParamAnnotations = createMethodToIndexOfParamToAnnotation(QueryParam.class);
|
||||
static final LoadingCache<Method, LoadingCache<Integer, Set<Annotation>>> methodToIndexOfParamToPathParamAnnotations = createMethodToIndexOfParamToAnnotation(PathParam.class);
|
||||
|
@ -430,7 +427,6 @@ public class RestAnnotationProcessor<T> {
|
|||
|
||||
Multimap<String, String> formParams = addFormParams(tokenValues.entries(), method, args);
|
||||
Multimap<String, String> queryParams = addQueryParams(tokenValues.entries(), method, args);
|
||||
Multimap<String, String> matrixParams = addMatrixParams(tokenValues.entries(), method, args);
|
||||
Multimap<String, String> headers = buildHeaders(tokenValues.entries(), method, args);
|
||||
if (r != null)
|
||||
headers.putAll(r.getHeaders());
|
||||
|
@ -448,9 +444,6 @@ public class RestAnnotationProcessor<T> {
|
|||
for (Entry<String, String> header : options.buildRequestHeaders().entries()) {
|
||||
headers.put(header.getKey(), Strings2.replaceTokens(header.getValue(), tokenValues.entries()));
|
||||
}
|
||||
for (Entry<String, String> matrix : options.buildMatrixParameters().entries()) {
|
||||
matrixParams.put(matrix.getKey(), Strings2.replaceTokens(matrix.getValue(), tokenValues.entries()));
|
||||
}
|
||||
for (Entry<String, String> query : options.buildQueryParameters().entries()) {
|
||||
queryParams.put(query.getKey(), Strings2.replaceTokens(query.getValue(), tokenValues.entries()));
|
||||
}
|
||||
|
@ -467,11 +460,6 @@ public class RestAnnotationProcessor<T> {
|
|||
payload = Payloads.newStringPayload(stringPayload);
|
||||
}
|
||||
|
||||
if (matrixParams.size() > 0) {
|
||||
for (String key : matrixParams.keySet())
|
||||
builder.matrixParam(key, Lists.newArrayList(matrixParams.get(key)).toArray());
|
||||
}
|
||||
|
||||
if (queryParams.size() > 0) {
|
||||
builder.replaceQuery(Queries.makeQueryLine(queryParams, null, skips));
|
||||
}
|
||||
|
@ -588,25 +576,6 @@ public class RestAnnotationProcessor<T> {
|
|||
return builder.build();
|
||||
}
|
||||
|
||||
private Multimap<String, String> addMatrixParams(Collection<Entry<String, String>> tokenValues, Method method,
|
||||
Object... args) {
|
||||
Multimap<String, String> matrixMap = LinkedListMultimap.create();
|
||||
if (declaring.isAnnotationPresent(MatrixParams.class)) {
|
||||
MatrixParams matrix = declaring.getAnnotation(MatrixParams.class);
|
||||
addMatrix(matrixMap, matrix, tokenValues);
|
||||
}
|
||||
|
||||
if (method.isAnnotationPresent(MatrixParams.class)) {
|
||||
MatrixParams matrix = method.getAnnotation(MatrixParams.class);
|
||||
addMatrix(matrixMap, matrix, tokenValues);
|
||||
}
|
||||
|
||||
for (Entry<String, String> matrix : getMatrixParamKeyValues(method, args).entries()) {
|
||||
matrixMap.put(matrix.getKey(), Strings2.replaceTokens(matrix.getValue(), tokenValues));
|
||||
}
|
||||
return matrixMap;
|
||||
}
|
||||
|
||||
private Multimap<String, String> addFormParams(Collection<Entry<String, String>> tokenValues, Method method,
|
||||
Object... args) {
|
||||
Multimap<String, String> formMap = LinkedListMultimap.create();
|
||||
|
@ -669,18 +638,6 @@ public class RestAnnotationProcessor<T> {
|
|||
}
|
||||
}
|
||||
|
||||
private void addMatrix(Multimap<String, String> matrixParams, MatrixParams matrix,
|
||||
Collection<Entry<String, String>> tokenValues) {
|
||||
for (int i = 0; i < matrix.keys().length; i++) {
|
||||
if (matrix.values()[i].equals(MatrixParams.NULL)) {
|
||||
matrixParams.removeAll(matrix.keys()[i]);
|
||||
matrixParams.put(matrix.keys()[i], null);
|
||||
} else {
|
||||
matrixParams.put(matrix.keys()[i], Strings2.replaceTokens(matrix.values()[i], tokenValues));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addMapPayload(Map<String, Object> postParams, PayloadParams mapDefaults,
|
||||
Collection<Entry<String, String>> tokenValues) {
|
||||
for (int i = 0; i < mapDefaults.keys().length; i++) {
|
||||
|
@ -1250,33 +1207,6 @@ public class RestAnnotationProcessor<T> {
|
|||
return encoded;
|
||||
}
|
||||
|
||||
//TODO: change to LoadingCache<ClassMethodArgs, Multimap<String,String> and move this logic to the CacheLoader.
|
||||
private Multimap<String, String> getMatrixParamKeyValues(Method method, Object... args) {
|
||||
Multimap<String, String> matrixParamValues = LinkedHashMultimap.create();
|
||||
LoadingCache<Integer, Set<Annotation>> indexToMatrixParam = methodToIndexOfParamToMatrixParamAnnotations
|
||||
.getUnchecked(method);
|
||||
|
||||
LoadingCache<Integer, Set<Annotation>> indexToParamExtractor = methodToIndexOfParamToParamParserAnnotations
|
||||
.getUnchecked(method);
|
||||
for (Entry<Integer, Set<Annotation>> entry : indexToMatrixParam.asMap().entrySet()) {
|
||||
for (Annotation key : entry.getValue()) {
|
||||
Set<Annotation> extractors = indexToParamExtractor.getUnchecked(entry.getKey());
|
||||
String paramKey = ((MatrixParam) key).value();
|
||||
Optional<?> paramValue = getParamValue(method, args, extractors, entry, paramKey);
|
||||
if (paramValue.isPresent())
|
||||
matrixParamValues.put(paramKey, paramValue.get().toString());
|
||||
}
|
||||
}
|
||||
|
||||
if (method.isAnnotationPresent(MatrixParam.class) && method.isAnnotationPresent(ParamParser.class)) {
|
||||
String paramKey = method.getAnnotation(MatrixParam.class).value();
|
||||
String paramValue = injector.getInstance(method.getAnnotation(ParamParser.class).value()).apply(args);
|
||||
matrixParamValues.put(paramKey, paramValue);
|
||||
|
||||
}
|
||||
return matrixParamValues;
|
||||
}
|
||||
|
||||
//TODO: change to LoadingCache<ClassMethodArgs, Multimap<String,String> and move this logic to the CacheLoader.
|
||||
//take care to manage size of this cache
|
||||
private Multimap<String, String> getFormParamKeyValues(Method method, Object... args) {
|
||||
|
|
|
@ -25,7 +25,6 @@ import static org.jclouds.rest.internal.RestAnnotationProcessor.methodToIndexOfP
|
|||
import static org.jclouds.rest.internal.RestAnnotationProcessor.methodToIndexOfParamToEndpointParamAnnotations;
|
||||
import static org.jclouds.rest.internal.RestAnnotationProcessor.methodToIndexOfParamToFormParamAnnotations;
|
||||
import static org.jclouds.rest.internal.RestAnnotationProcessor.methodToIndexOfParamToHeaderParamAnnotations;
|
||||
import static org.jclouds.rest.internal.RestAnnotationProcessor.methodToIndexOfParamToMatrixParamAnnotations;
|
||||
import static org.jclouds.rest.internal.RestAnnotationProcessor.methodToIndexOfParamToParamParserAnnotations;
|
||||
import static org.jclouds.rest.internal.RestAnnotationProcessor.methodToIndexOfParamToPartParamAnnotations;
|
||||
import static org.jclouds.rest.internal.RestAnnotationProcessor.methodToIndexOfParamToPathParamAnnotations;
|
||||
|
@ -84,7 +83,6 @@ public class SeedAnnotationCache extends CacheLoader<Class<?>, Boolean> {
|
|||
methodToIndexOfParamToBinderParamAnnotation.get(method).get(index);
|
||||
methodToIndexOfParamToWrapWithAnnotation.get(method).get(index);
|
||||
methodToIndexOfParamToHeaderParamAnnotations.get(method).get(index);
|
||||
methodToIndexOfParamToMatrixParamAnnotations.get(method).get(index);
|
||||
methodToIndexOfParamToFormParamAnnotations.get(method).get(index);
|
||||
methodToIndexOfParamToQueryParamAnnotations.get(method).get(index);
|
||||
methodToIndexOfParamToEndpointAnnotations.get(method).get(index);
|
||||
|
|
|
@ -59,7 +59,6 @@ import javax.ws.rs.FormParam;
|
|||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.HeaderParam;
|
||||
import javax.ws.rs.HttpMethod;
|
||||
import javax.ws.rs.MatrixParam;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Path;
|
||||
|
@ -115,7 +114,6 @@ import org.jclouds.rest.annotations.FormParams;
|
|||
import org.jclouds.rest.annotations.Headers;
|
||||
import org.jclouds.rest.annotations.JAXBResponseParser;
|
||||
import org.jclouds.rest.annotations.MapBinder;
|
||||
import org.jclouds.rest.annotations.MatrixParams;
|
||||
import org.jclouds.rest.annotations.OnlyElement;
|
||||
import org.jclouds.rest.annotations.OverrideRequestFilters;
|
||||
import org.jclouds.rest.annotations.ParamParser;
|
||||
|
@ -1511,11 +1509,6 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
public void oneFormParamExtractor(@FormParam("one") @ParamParser(FirstCharacter.class) String one) {
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/")
|
||||
public void oneMatrixParamExtractor(@MatrixParam("one") @ParamParser(FirstCharacter.class) String one) {
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/{path}")
|
||||
@PathParam("path")
|
||||
|
@ -1551,25 +1544,6 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
assertNonPayloadHeadersEqual(request, "");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatrixParamExtractor() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TestPath.class.getMethod("oneMatrixParamExtractor", String.class);
|
||||
HttpRequest request = factory(TestPath.class).createRequest(method, new Object[] { "localhost" });
|
||||
assertRequestLineEquals(request, "GET http://localhost:9999/;one=l HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNiceNPEMatrixParam() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TestPath.class.getMethod("oneMatrixParamExtractor", String.class);
|
||||
try {
|
||||
factory(TestPath.class).createRequest(method, (String) null);
|
||||
} catch (NullPointerException e) {
|
||||
assertEquals(e.getMessage(), "param{one} for method TestPath.oneMatrixParamExtractor");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormParamExtractor() throws SecurityException, NoSuchMethodException, IOException {
|
||||
|
@ -1786,104 +1760,6 @@ public class RestAnnotationProcessorTest extends BaseRestApiTest {
|
|||
assertEquals(query, "x-amz-copy-source=/eggs/robot");
|
||||
}
|
||||
|
||||
public class TestReplaceMatrixOptions extends BaseHttpRequestOptions {
|
||||
public TestReplaceMatrixOptions() {
|
||||
this.matrixParameters.put("x-amz-copy-source", "/{bucket}");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatrixInOptions() throws SecurityException, NoSuchMethodException {
|
||||
Method oneMatrix = TestMatrixReplace.class.getMethod("matrixInOptions", String.class,
|
||||
TestReplaceMatrixOptions.class);
|
||||
String path = factory(TestMatrixReplace.class)
|
||||
.createRequest(oneMatrix, new Object[] { "robot", new TestReplaceMatrixOptions() }).getEndpoint().getPath();
|
||||
assertEquals(path, "/;x-amz-copy-source=/robot");
|
||||
}
|
||||
|
||||
@Path("/")
|
||||
public class TestMatrixReplace {
|
||||
|
||||
@GET
|
||||
@Path("/")
|
||||
public void matrixInOptions(@PathParam("bucket") String path, TestReplaceMatrixOptions options) {
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/")
|
||||
@MatrixParams(keys = "x-amz-copy-source", values = "/{bucket}")
|
||||
public void oneMatrix(@PathParam("bucket") String path) {
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/")
|
||||
@MatrixParams(keys = { "slash", "hyphen" }, values = { "/{bucket}", "-{bucket}" })
|
||||
public void twoMatrix(@PathParam("bucket") String path) {
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/")
|
||||
@MatrixParams(keys = "x-amz-copy-source", values = "/{bucket}/{key}")
|
||||
public void twoMatrixs(@PathParam("bucket") String path, @PathParam("key") String path2) {
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/")
|
||||
@MatrixParams(keys = "x-amz-copy-source", values = "/{bucket}/{key}")
|
||||
public void twoMatrixsOutOfOrder(@PathParam("key") String path, @PathParam("bucket") String path2) {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildTwoMatrix() throws SecurityException, NoSuchMethodException {
|
||||
Method oneMatrix = TestMatrixReplace.class.getMethod("twoMatrix", String.class);
|
||||
String path = factory(TestMatrixReplace.class).createRequest(oneMatrix, new Object[] { "robot" }).getEndpoint()
|
||||
.getPath();
|
||||
assertEquals(path, "/;slash=/robot;hyphen=-robot");
|
||||
}
|
||||
|
||||
@MatrixParams(keys = "x-amz-copy-source", values = "/{bucket}")
|
||||
@Path("/")
|
||||
public class TestClassMatrix {
|
||||
@GET
|
||||
@Path("/")
|
||||
public void oneMatrix(@PathParam("bucket") String path) {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildOneClassMatrix() throws SecurityException, NoSuchMethodException {
|
||||
Method oneMatrix = TestClassMatrix.class.getMethod("oneMatrix", String.class);
|
||||
String path = factory(TestClassMatrix.class).createRequest(oneMatrix, new Object[] { "robot" }).getEndpoint()
|
||||
.getPath();
|
||||
assertEquals(path, "/;x-amz-copy-source=/robot");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildOneMatrix() throws SecurityException, NoSuchMethodException {
|
||||
Method oneMatrix = TestMatrixReplace.class.getMethod("oneMatrix", String.class);
|
||||
String path = factory(TestMatrixReplace.class).createRequest(oneMatrix, new Object[] { "robot" }).getEndpoint()
|
||||
.getPath();
|
||||
assertEquals(path, "/;x-amz-copy-source=/robot");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildTwoMatrixs() throws SecurityException, NoSuchMethodException {
|
||||
Method twoMatrixs = TestMatrixReplace.class.getMethod("twoMatrixs", String.class, String.class);
|
||||
String path = factory(TestMatrixReplace.class).createRequest(twoMatrixs, new Object[] { "robot", "eggs" })
|
||||
.getEndpoint().getPath();
|
||||
assertEquals(path, "/;x-amz-copy-source=/robot/eggs");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildTwoMatrixsOutOfOrder() throws SecurityException, NoSuchMethodException {
|
||||
Method twoMatrixsOutOfOrder = TestMatrixReplace.class.getMethod("twoMatrixsOutOfOrder", String.class,
|
||||
String.class);
|
||||
String path = factory(TestMatrixReplace.class)
|
||||
.createRequest(twoMatrixsOutOfOrder, new Object[] { "robot", "eggs" }).getEndpoint().getPath();
|
||||
assertEquals(path, "/;x-amz-copy-source=/eggs/robot");
|
||||
}
|
||||
|
||||
public interface TestTransformers {
|
||||
@GET
|
||||
int noTransformer();
|
||||
|
|
|
@ -107,7 +107,7 @@ public class BindToPath implements Binder {
|
|||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
static <R extends HttpRequest> R bindToPath(final R request, final String endpoint) {
|
||||
// Preserve current query and matrix parameters
|
||||
// Preserve current query parameters
|
||||
String newEndpoint = endpoint + getParameterString(request);
|
||||
|
||||
// Replace the URI with the edit link in the DTO
|
||||
|
@ -126,20 +126,13 @@ public class BindToPath implements Binder {
|
|||
String endpoint = request.getEndpoint().toString();
|
||||
|
||||
int query = endpoint.indexOf('?');
|
||||
int matrix = endpoint.indexOf(';');
|
||||
|
||||
if (query == -1 && matrix == -1) {
|
||||
if (query == -1) {
|
||||
// No parameters
|
||||
return "";
|
||||
} else if (query != -1 && matrix != -1) {
|
||||
// Both parameter types
|
||||
return endpoint.substring(query < matrix ? query : matrix);
|
||||
} else if (query != -1) {
|
||||
} else {
|
||||
// Only request parameters
|
||||
return endpoint.substring(query);
|
||||
} else {
|
||||
// Only matrix parameters
|
||||
return endpoint.substring(matrix);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -127,18 +127,6 @@ public class BindToPathTest {
|
|||
assertEquals(newRequest.getRequestLine(), "GET http://linkuri?param=value HTTP/1.1");
|
||||
}
|
||||
|
||||
public void testBindWithQueryAndMatrixParameters() throws SecurityException, NoSuchMethodException {
|
||||
TestDto dto = new TestDto();
|
||||
Method withEndpointLink = TestEndpointLink.class.getMethod("withEndpointLink", TestDto.class);
|
||||
GeneratedHttpRequest request = GeneratedHttpRequest.builder().declaring(TestEndpointLink.class)
|
||||
.javaMethod(withEndpointLink).args(ImmutableList.<Object> of(dto)).method(HttpMethod.GET)
|
||||
.endpoint(URI.create("http://localhost?param=value;matrix=value2")).build();
|
||||
|
||||
BindToPath binder = new BindToPath();
|
||||
GeneratedHttpRequest newRequest = binder.bindToRequest(request, dto);
|
||||
assertEquals(newRequest.getRequestLine(), "GET http://linkuri?param=value;matrix=value2 HTTP/1.1");
|
||||
}
|
||||
|
||||
static interface TestEndpointLink {
|
||||
@GET
|
||||
void withEndpointLink(@EndpointLink("edit") TestDto dto);
|
||||
|
|
|
@ -4,7 +4,7 @@ import org.jclouds.http.options.BaseHttpRequestOptions;
|
|||
|
||||
/**
|
||||
* Optional get CDMI object options Note: We use BaseHttpRequestOptions.pathSuffix to include the
|
||||
* CDMI query parameters rather than queryParam or MatrixParam because the CDMI specification is not
|
||||
* CDMI query parameters rather than queryParam because the CDMI specification is not
|
||||
* following the standard usage. This is the summary of the CDMI specification: To read one or more
|
||||
* requested fields from an existing CDMI container object, one of the following requests shall be
|
||||
* performed: GET <root URI>/<ContainerName>/<TheContainerName>/?<fieldname>;<fieldname>;... GET
|
||||
|
|
|
@ -129,7 +129,6 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT
|
|||
customize.buildFormParameters().entries(),
|
||||
ImmutableMultimap.<String, String> of("InstanceType", size.getProviderId(), "SecurityGroup.1",
|
||||
generatedGroup, "KeyName", systemGeneratedKeyPairName).entries());
|
||||
assertEquals(customize.buildMatrixParameters(), ImmutableMultimap.<String, String> of());
|
||||
assertEquals(customize.buildRequestHeaders(), ImmutableMultimap.<String, String> of());
|
||||
assertEquals(customize.buildStringPayload(), null);
|
||||
|
||||
|
@ -195,7 +194,6 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT
|
|||
ImmutableMultimap.<String, String> of("InstanceType", size.getProviderId(), "SecurityGroup.1",
|
||||
generatedGroup, "KeyName", systemGeneratedKeyPairName, "Placement.GroupName", generatedGroup)
|
||||
.entries());
|
||||
assertEquals(customize.buildMatrixParameters(), ImmutableMultimap.<String, String> of());
|
||||
assertEquals(customize.buildRequestHeaders(), ImmutableMultimap.<String, String> of());
|
||||
assertEquals(customize.buildStringPayload(), null);
|
||||
|
||||
|
@ -261,7 +259,6 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT
|
|||
ImmutableMultimap.<String, String> of("InstanceType", size.getProviderId(), "SecurityGroup.1",
|
||||
generatedGroup, "KeyName", systemGeneratedKeyPairName, "Placement.GroupName", generatedGroup)
|
||||
.entries());
|
||||
assertEquals(customize.buildMatrixParameters(), ImmutableMultimap.<String, String> of());
|
||||
assertEquals(customize.buildRequestHeaders(), ImmutableMultimap.<String, String> of());
|
||||
assertEquals(customize.buildStringPayload(), null);
|
||||
|
||||
|
@ -321,7 +318,6 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT
|
|||
customize.buildFormParameters().entries(),
|
||||
ImmutableMultimap.<String, String> of("InstanceType", size.getProviderId(), "SubnetId", "1", "KeyName",
|
||||
systemGeneratedKeyPairName).entries());
|
||||
assertEquals(customize.buildMatrixParameters(), ImmutableMultimap.<String, String> of());
|
||||
assertEquals(customize.buildRequestHeaders(), ImmutableMultimap.<String, String> of());
|
||||
assertEquals(customize.buildStringPayload(), null);
|
||||
|
||||
|
@ -384,7 +380,6 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT
|
|||
customize.buildFormParameters().entries(),
|
||||
ImmutableMultimap.<String, String> of("InstanceType", size.getProviderId(), "SecurityGroup.1", "group",
|
||||
"KeyName", systemGeneratedKeyPairName, "UserData", CryptoStreams.base64("hello".getBytes())).entries());
|
||||
assertEquals(customize.buildMatrixParameters(), ImmutableMultimap.<String, String> of());
|
||||
assertEquals(customize.buildRequestHeaders(), ImmutableMultimap.<String, String> of());
|
||||
assertEquals(customize.buildStringPayload(), null);
|
||||
|
||||
|
|
|
@ -33,7 +33,6 @@ import javax.ws.rs.core.MediaType;
|
|||
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.MapBinder;
|
||||
import org.jclouds.rest.annotations.MatrixParams;
|
||||
import org.jclouds.rest.annotations.PayloadParam;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.ResponseParser;
|
||||
|
@ -83,9 +82,8 @@ public interface RimuHostingAsyncClient {
|
|||
* @see RimuHostingClient#getServerList
|
||||
*/
|
||||
@GET
|
||||
@Path("/orders")
|
||||
@Path("/orders;include_inactive=N")
|
||||
@ResponseParser(ParseServersFromJsonResponse.class)
|
||||
@MatrixParams(keys = "include_inactive", values = "N")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ParseRimuHostingException.class)
|
||||
ListenableFuture<Set<Server>> getServerList();
|
||||
|
@ -94,8 +92,7 @@ public interface RimuHostingAsyncClient {
|
|||
* @see RimuHostingClient#getPricingPlanList
|
||||
*/
|
||||
@GET
|
||||
@Path("/pricing-plans")
|
||||
@MatrixParams(keys = "server-type", values = "VPS")
|
||||
@Path("/pricing-plans;server-type=VPS")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ParseRimuHostingException.class)
|
||||
@ResponseParser(ParsePricingPlansFromJsonResponse.class)
|
||||
|
|
Loading…
Reference in New Issue