mirror of https://github.com/apache/jclouds.git
Issue 125:payload binder
This commit is contained in:
parent
37fc5505ff
commit
4627a91195
|
@ -59,7 +59,7 @@ import org.jclouds.rest.annotations.BinderParam;
|
|||
import org.jclouds.rest.annotations.Endpoint;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.MapBinder;
|
||||
import org.jclouds.rest.annotations.MapPayloadParam;
|
||||
import org.jclouds.rest.annotations.PayloadParam;
|
||||
import org.jclouds.rest.annotations.QueryParams;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.SkipEncoding;
|
||||
|
@ -162,8 +162,8 @@ public interface CloudServersAsyncClient {
|
|||
@QueryParams(keys = "format", values = "json")
|
||||
@Path("/servers")
|
||||
@MapBinder(CreateServerOptions.class)
|
||||
ListenableFuture<Server> createServer(@MapPayloadParam("name") String name, @MapPayloadParam("imageId") int imageId,
|
||||
@MapPayloadParam("flavorId") int flavorId, CreateServerOptions... options);
|
||||
ListenableFuture<Server> createServer(@PayloadParam("name") String name, @PayloadParam("imageId") int imageId,
|
||||
@PayloadParam("flavorId") int flavorId, CreateServerOptions... options);
|
||||
|
||||
/**
|
||||
* @see CloudServersClient#rebuildServer
|
||||
|
@ -181,8 +181,8 @@ public interface CloudServersAsyncClient {
|
|||
@Path("/servers/{id}/ips/public/{address}")
|
||||
@MapBinder(BindSharedIpGroupToJsonPayload.class)
|
||||
ListenableFuture<Void> shareIp(@PathParam("address") String addressToShare,
|
||||
@PathParam("id") int serverToTosignBindressTo, @MapPayloadParam("sharedIpGroupId") int sharedIpGroup,
|
||||
@MapPayloadParam("configureServer") boolean configureServer);
|
||||
@PathParam("id") int serverToTosignBindressTo, @PayloadParam("sharedIpGroupId") int sharedIpGroup,
|
||||
@PayloadParam("configureServer") boolean configureServer);
|
||||
|
||||
/**
|
||||
* @see CloudServersClient#unshareIp
|
||||
|
@ -270,8 +270,8 @@ public interface CloudServersAsyncClient {
|
|||
@QueryParams(keys = "format", values = "json")
|
||||
@MapBinder(BindCreateImageToJsonPayload.class)
|
||||
@Path("/images")
|
||||
ListenableFuture<Image> createImageFromServer(@MapPayloadParam("imageName") String imageName,
|
||||
@MapPayloadParam("serverId") int serverId);
|
||||
ListenableFuture<Image> createImageFromServer(@PayloadParam("imageName") String imageName,
|
||||
@PayloadParam("serverId") int serverId);
|
||||
|
||||
/**
|
||||
* @see CloudServersClient#listSharedIpGroups
|
||||
|
@ -304,7 +304,7 @@ public interface CloudServersAsyncClient {
|
|||
@QueryParams(keys = "format", values = "json")
|
||||
@Path("/shared_ip_groups")
|
||||
@MapBinder(CreateSharedIpGroupOptions.class)
|
||||
ListenableFuture<SharedIpGroup> createSharedIpGroup(@MapPayloadParam("name") String name,
|
||||
ListenableFuture<SharedIpGroup> createSharedIpGroup(@PayloadParam("name") String name,
|
||||
CreateSharedIpGroupOptions... options);
|
||||
|
||||
/**
|
||||
|
|
|
@ -47,8 +47,8 @@ import org.jclouds.rest.annotations.Endpoint;
|
|||
import org.jclouds.rest.annotations.EndpointParam;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.MapBinder;
|
||||
import org.jclouds.rest.annotations.MapPayloadParam;
|
||||
import org.jclouds.rest.annotations.MapPayloadParams;
|
||||
import org.jclouds.rest.annotations.PayloadParam;
|
||||
import org.jclouds.rest.annotations.PayloadParams;
|
||||
import org.jclouds.rest.annotations.ParamValidators;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.XMLResponseParser;
|
||||
|
@ -154,8 +154,8 @@ public interface VCloudAsyncClient extends CommonVCloudAsyncClient {
|
|||
@XMLResponseParser(VAppHandler.class)
|
||||
@MapBinder(BindInstantiateVAppTemplateParamsToXmlPayload.class)
|
||||
ListenableFuture<? extends VApp> instantiateVAppTemplateInVDC(@EndpointParam URI vdc,
|
||||
@MapPayloadParam("template") URI template,
|
||||
@MapPayloadParam("name") @ParamValidators(DnsNameValidator.class) String appName,
|
||||
@PayloadParam("template") URI template,
|
||||
@PayloadParam("name") @ParamValidators(DnsNameValidator.class) String appName,
|
||||
InstantiateVAppTemplateOptions... options);
|
||||
|
||||
/**
|
||||
|
@ -167,8 +167,8 @@ public interface VCloudAsyncClient extends CommonVCloudAsyncClient {
|
|||
@Consumes(TASK_XML)
|
||||
@XMLResponseParser(TaskHandler.class)
|
||||
@MapBinder(BindCloneVAppParamsToXmlPayload.class)
|
||||
ListenableFuture<? extends Task> cloneVAppInVDC(@EndpointParam URI vdc, @MapPayloadParam("vApp") URI toClone,
|
||||
@MapPayloadParam("newName") @ParamValidators(DnsNameValidator.class) String newName,
|
||||
ListenableFuture<? extends Task> cloneVAppInVDC(@EndpointParam URI vdc, @PayloadParam("vApp") URI toClone,
|
||||
@PayloadParam("newName") @ParamValidators(DnsNameValidator.class) String newName,
|
||||
CloneVAppOptions... options);
|
||||
|
||||
/**
|
||||
|
@ -181,8 +181,8 @@ public interface VCloudAsyncClient extends CommonVCloudAsyncClient {
|
|||
@XMLResponseParser(VAppTemplateHandler.class)
|
||||
@MapBinder(BindCaptureVAppParamsToXmlPayload.class)
|
||||
ListenableFuture<? extends VAppTemplate> captureVAppInVDC(@EndpointParam URI vdc,
|
||||
@MapPayloadParam("vApp") URI toCapture,
|
||||
@MapPayloadParam("templateName") @ParamValidators(DnsNameValidator.class) String templateName,
|
||||
@PayloadParam("vApp") URI toCapture,
|
||||
@PayloadParam("templateName") @ParamValidators(DnsNameValidator.class) String templateName,
|
||||
CaptureVAppOptions... options);
|
||||
|
||||
/**
|
||||
|
@ -246,7 +246,7 @@ public interface VCloudAsyncClient extends CommonVCloudAsyncClient {
|
|||
@Produces(DEPLOYVAPPPARAMS_XML)
|
||||
@Path("/action/deploy")
|
||||
@MapBinder(BindDeployVAppParamsToXmlPayload.class)
|
||||
@MapPayloadParams(keys = "powerOn", values = "true")
|
||||
@PayloadParams(keys = "powerOn", values = "true")
|
||||
@XMLResponseParser(TaskHandler.class)
|
||||
ListenableFuture<? extends Task> deployAndPowerOnVAppOrVm(@EndpointParam URI vAppOrVmId);
|
||||
|
||||
|
@ -269,7 +269,7 @@ public interface VCloudAsyncClient extends CommonVCloudAsyncClient {
|
|||
@Produces(UNDEPLOYVAPPPARAMS_XML)
|
||||
@Path("/action/undeploy")
|
||||
@MapBinder(BindUndeployVAppParamsToXmlPayload.class)
|
||||
@MapPayloadParams(keys = "saveState", values = "true")
|
||||
@PayloadParams(keys = "saveState", values = "true")
|
||||
@XMLResponseParser(TaskHandler.class)
|
||||
ListenableFuture<? extends Task> undeployAndSaveStateOfVAppOrVm(@EndpointParam URI vAppOrVmId);
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ import org.jclouds.predicates.validators.DnsNameValidator;
|
|||
import org.jclouds.rest.annotations.EndpointParam;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.MapBinder;
|
||||
import org.jclouds.rest.annotations.MapPayloadParam;
|
||||
import org.jclouds.rest.annotations.PayloadParam;
|
||||
import org.jclouds.rest.annotations.ParamValidators;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.XMLResponseParser;
|
||||
|
@ -126,8 +126,8 @@ public interface VCloudExpressAsyncClient extends CommonVCloudAsyncClient {
|
|||
@XMLResponseParser(VCloudExpressVAppHandler.class)
|
||||
@MapBinder(BindInstantiateVCloudExpressVAppTemplateParamsToXmlPayload.class)
|
||||
ListenableFuture<? extends VCloudExpressVApp> instantiateVAppTemplateInVDC(@EndpointParam URI vdc,
|
||||
@MapPayloadParam("template") URI template,
|
||||
@MapPayloadParam("name") @ParamValidators(DnsNameValidator.class) String appName,
|
||||
@PayloadParam("template") URI template,
|
||||
@PayloadParam("name") @ParamValidators(DnsNameValidator.class) String appName,
|
||||
InstantiateVAppTemplateOptions... options);
|
||||
|
||||
/**
|
||||
|
@ -139,8 +139,8 @@ public interface VCloudExpressAsyncClient extends CommonVCloudAsyncClient {
|
|||
@Consumes(TASK_XML)
|
||||
@XMLResponseParser(TaskHandler.class)
|
||||
@MapBinder(BindCloneVAppParamsToXmlPayload.class)
|
||||
ListenableFuture<? extends Task> cloneVAppInVDC(@EndpointParam URI vdc, @MapPayloadParam("vApp") URI toClone,
|
||||
@MapPayloadParam("newName") @ParamValidators(DnsNameValidator.class) String newName,
|
||||
ListenableFuture<? extends Task> cloneVAppInVDC(@EndpointParam URI vdc, @PayloadParam("vApp") URI toClone,
|
||||
@PayloadParam("newName") @ParamValidators(DnsNameValidator.class) String newName,
|
||||
CloneVAppOptions... options);
|
||||
|
||||
/**
|
||||
|
|
|
@ -47,7 +47,7 @@ import org.jclouds.predicates.validators.DnsNameValidator;
|
|||
import org.jclouds.rest.annotations.EndpointParam;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.MapBinder;
|
||||
import org.jclouds.rest.annotations.MapPayloadParam;
|
||||
import org.jclouds.rest.annotations.PayloadParam;
|
||||
import org.jclouds.rest.annotations.ParamValidators;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.ResponseParser;
|
||||
|
@ -191,8 +191,8 @@ public interface TerremarkVCloudAsyncClient extends VCloudExpressAsyncClient {
|
|||
@XMLResponseParser(VCloudExpressVAppHandler.class)
|
||||
@MapBinder(TerremarkBindInstantiateVAppTemplateParamsToXmlPayload.class)
|
||||
ListenableFuture<? extends VCloudExpressVApp> instantiateVAppTemplateInVDC(@EndpointParam URI vdc,
|
||||
@MapPayloadParam("template") URI template,
|
||||
@MapPayloadParam("name") @ParamValidators(DnsNameValidator.class) String appName,
|
||||
@PayloadParam("template") URI template,
|
||||
@PayloadParam("name") @ParamValidators(DnsNameValidator.class) String appName,
|
||||
InstantiateVAppTemplateOptions... options);
|
||||
|
||||
/**
|
||||
|
@ -215,8 +215,8 @@ public interface TerremarkVCloudAsyncClient extends VCloudExpressAsyncClient {
|
|||
@XMLResponseParser(InternetServiceHandler.class)
|
||||
@MapBinder(AddInternetServiceOptions.class)
|
||||
ListenableFuture<? extends InternetService> addInternetServiceToExistingIp(@EndpointParam URI publicIpId,
|
||||
@MapPayloadParam("name") String serviceName, @MapPayloadParam("protocol") Protocol protocol,
|
||||
@MapPayloadParam("port") int port, AddInternetServiceOptions... options);
|
||||
@PayloadParam("name") String serviceName, @PayloadParam("protocol") Protocol protocol,
|
||||
@PayloadParam("port") int port, AddInternetServiceOptions... options);
|
||||
|
||||
/**
|
||||
* @see TerremarkVCloudExpressClient#deletePublicIp
|
||||
|
@ -280,8 +280,8 @@ public interface TerremarkVCloudAsyncClient extends VCloudExpressAsyncClient {
|
|||
@XMLResponseParser(NodeHandler.class)
|
||||
@MapBinder(AddNodeOptions.class)
|
||||
ListenableFuture<? extends Node> addNode(@EndpointParam URI internetServiceId,
|
||||
@MapPayloadParam("ipAddress") String ipAddress, @MapPayloadParam("name") String name,
|
||||
@MapPayloadParam("port") int port, AddNodeOptions... options);
|
||||
@PayloadParam("ipAddress") String ipAddress, @PayloadParam("name") String name,
|
||||
@PayloadParam("port") int port, AddNodeOptions... options);
|
||||
|
||||
/**
|
||||
* @see TerremarkVCloudExpressClient#getNodes
|
||||
|
@ -310,8 +310,8 @@ public interface TerremarkVCloudAsyncClient extends VCloudExpressAsyncClient {
|
|||
@Consumes(NODESERVICE_XML)
|
||||
@XMLResponseParser(NodeHandler.class)
|
||||
@MapBinder(BindNodeConfigurationToXmlPayload.class)
|
||||
ListenableFuture<? extends Node> configureNode(@EndpointParam URI nodeId, @MapPayloadParam("name") String name,
|
||||
@MapPayloadParam("enabled") boolean enabled, @Nullable @MapPayloadParam("description") String description);
|
||||
ListenableFuture<? extends Node> configureNode(@EndpointParam URI nodeId, @PayloadParam("name") String name,
|
||||
@PayloadParam("enabled") boolean enabled, @Nullable @PayloadParam("description") String description);
|
||||
|
||||
/**
|
||||
* @see TerremarkVCloudExpressClient#deleteNode
|
||||
|
|
|
@ -34,7 +34,7 @@ public interface MapBinder extends Binder {
|
|||
/**
|
||||
* creates and binds the POST payload to the request using parameters specified.
|
||||
*
|
||||
* @see org.jclouds.rest.annotations.MapPayloadParam
|
||||
* @see org.jclouds.rest.annotations.PayloadParam
|
||||
*/
|
||||
<R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams);
|
||||
}
|
|
@ -35,7 +35,7 @@ import java.lang.annotation.Target;
|
|||
public @interface MapBinder {
|
||||
|
||||
/**
|
||||
* How to bind {@link MapPayloadParam} values, if there is no {@link MapBinder} in the method
|
||||
* How to bind {@link PayloadParam} values, if there is no {@link MapBinder} in the method
|
||||
* definition
|
||||
*/
|
||||
Class<? extends org.jclouds.rest.MapBinder> value();
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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.PARAMETER;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Designates that this parameter will hold the payload for a PUT or POST command.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Target(PARAMETER)
|
||||
@Retention(RUNTIME)
|
||||
public @interface MapPayloadParam {
|
||||
|
||||
/**
|
||||
* The key used in a map passed to the {@link MapBinder} associated with the request.
|
||||
*/
|
||||
String value();
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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;
|
||||
|
||||
import javax.ws.rs.QueryParam;
|
||||
|
||||
/**
|
||||
* Designates that default parameters will be added a map that builds the request entity.
|
||||
*
|
||||
* @see QueryParam
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Target( { TYPE, METHOD })
|
||||
@Retention(RUNTIME)
|
||||
public @interface MapPayloadParams {
|
||||
|
||||
public static final String NULL = "MAP_PAYLOAD_NULL";
|
||||
|
||||
String[] keys();
|
||||
|
||||
String[] values() default NULL;
|
||||
}
|
|
@ -34,7 +34,6 @@ import org.jclouds.rest.MapBinder;
|
|||
* Binds the object to the request as a json object.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @since 4.0
|
||||
*/
|
||||
public class BindToJsonPayload implements MapBinder {
|
||||
|
||||
|
|
|
@ -52,9 +52,9 @@ import java.util.Comparator;
|
|||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.Resource;
|
||||
|
@ -81,6 +81,7 @@ import org.jclouds.http.HttpResponse;
|
|||
import org.jclouds.http.HttpUtils;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.ParseSax.HandlerWithResult;
|
||||
import org.jclouds.http.functions.ParseURIFromListOrLocationHeaderIf20x;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
import org.jclouds.http.functions.ReturnInputStream;
|
||||
|
@ -89,7 +90,6 @@ import org.jclouds.http.functions.ReturnTrueIf2xx;
|
|||
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
|
||||
import org.jclouds.http.functions.UnwrapOnlyNestedJsonValue;
|
||||
import org.jclouds.http.functions.UnwrapOnlyNestedJsonValueInSet;
|
||||
import org.jclouds.http.functions.ParseSax.HandlerWithResult;
|
||||
import org.jclouds.http.options.HttpRequestOptions;
|
||||
import org.jclouds.http.utils.ModifyRequest;
|
||||
import org.jclouds.internal.ClassMethodArgs;
|
||||
|
@ -112,12 +112,12 @@ import org.jclouds.rest.annotations.ExceptionParser;
|
|||
import org.jclouds.rest.annotations.FormParams;
|
||||
import org.jclouds.rest.annotations.Headers;
|
||||
import org.jclouds.rest.annotations.MapBinder;
|
||||
import org.jclouds.rest.annotations.MapPayloadParam;
|
||||
import org.jclouds.rest.annotations.MapPayloadParams;
|
||||
import org.jclouds.rest.annotations.MatrixParams;
|
||||
import org.jclouds.rest.annotations.OverrideRequestFilters;
|
||||
import org.jclouds.rest.annotations.ParamParser;
|
||||
import org.jclouds.rest.annotations.PartParam;
|
||||
import org.jclouds.rest.annotations.PayloadParam;
|
||||
import org.jclouds.rest.annotations.PayloadParams;
|
||||
import org.jclouds.rest.annotations.QueryParams;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.ResponseParser;
|
||||
|
@ -125,6 +125,7 @@ import org.jclouds.rest.annotations.SkipEncoding;
|
|||
import org.jclouds.rest.annotations.Unwrap;
|
||||
import org.jclouds.rest.annotations.VirtualHost;
|
||||
import org.jclouds.rest.annotations.XMLResponseParser;
|
||||
import org.jclouds.rest.binders.BindMapToStringPayload;
|
||||
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
|
||||
import org.jclouds.util.Strings2;
|
||||
|
||||
|
@ -168,13 +169,13 @@ public class RestAnnotationProcessor<T> {
|
|||
static final Map<Method, Map<Integer, Set<Annotation>>> methodToIndexOfParamToFormParamAnnotations = createMethodToIndexOfParamToAnnotation(FormParam.class);
|
||||
static final Map<Method, Map<Integer, Set<Annotation>>> methodToIndexOfParamToQueryParamAnnotations = createMethodToIndexOfParamToAnnotation(QueryParam.class);
|
||||
static final Map<Method, Map<Integer, Set<Annotation>>> methodToIndexOfParamToPathParamAnnotations = createMethodToIndexOfParamToAnnotation(PathParam.class);
|
||||
static final Map<Method, Map<Integer, Set<Annotation>>> methodToIndexOfParamToPostParamAnnotations = createMethodToIndexOfParamToAnnotation(MapPayloadParam.class);
|
||||
static final Map<Method, Map<Integer, Set<Annotation>>> methodToIndexOfParamToPostParamAnnotations = createMethodToIndexOfParamToAnnotation(PayloadParam.class);
|
||||
static final Map<Method, Map<Integer, Set<Annotation>>> methodToIndexOfParamToPartParamAnnotations = createMethodToIndexOfParamToAnnotation(PartParam.class);
|
||||
static final Map<Method, Map<Integer, Set<Annotation>>> methodToIndexOfParamToParamParserAnnotations = createMethodToIndexOfParamToAnnotation(ParamParser.class);
|
||||
static final Map<MethodKey, Method> delegationMap = newHashMap();
|
||||
|
||||
static Map<Method, Map<Integer, Set<Annotation>>> createMethodToIndexOfParamToAnnotation(
|
||||
final Class<? extends Annotation> annotation) {
|
||||
final Class<? extends Annotation> annotation) {
|
||||
return new MapMaker().makeComputingMap(new Function<Method, Map<Integer, Set<Annotation>>>() {
|
||||
public Map<Integer, Set<Annotation>> apply(final Method method) {
|
||||
return new MapMaker().makeComputingMap(new GetAnnotationsForMethodParameterIndex(method, annotation));
|
||||
|
@ -208,7 +209,7 @@ public class RestAnnotationProcessor<T> {
|
|||
}
|
||||
|
||||
private static final Class<? extends HttpRequestOptions[]> optionsVarArgsClass = new HttpRequestOptions[] {}
|
||||
.getClass();
|
||||
.getClass();
|
||||
|
||||
private static final Function<? super Entry<String, String>, ? extends Part> ENTRY_TO_PART = new Function<Entry<String, String>, Part>() {
|
||||
|
||||
|
@ -220,17 +221,17 @@ public class RestAnnotationProcessor<T> {
|
|||
};
|
||||
|
||||
private final Map<Method, Set<Integer>> methodToIndexesOfOptions = new MapMaker()
|
||||
.makeComputingMap(new Function<Method, Set<Integer>>() {
|
||||
public Set<Integer> apply(final Method method) {
|
||||
Set<Integer> toReturn = newHashSet();
|
||||
for (int index = 0; index < method.getParameterTypes().length; index++) {
|
||||
Class<?> type = method.getParameterTypes()[index];
|
||||
if (HttpRequestOptions.class.isAssignableFrom(type) || optionsVarArgsClass.isAssignableFrom(type))
|
||||
toReturn.add(index);
|
||||
}
|
||||
return toReturn;
|
||||
.makeComputingMap(new Function<Method, Set<Integer>>() {
|
||||
public Set<Integer> apply(final Method method) {
|
||||
Set<Integer> toReturn = newHashSet();
|
||||
for (int index = 0; index < method.getParameterTypes().length; index++) {
|
||||
Class<?> type = method.getParameterTypes()[index];
|
||||
if (HttpRequestOptions.class.isAssignableFrom(type) || optionsVarArgsClass.isAssignableFrom(type))
|
||||
toReturn.add(index);
|
||||
}
|
||||
});
|
||||
return toReturn;
|
||||
}
|
||||
});
|
||||
|
||||
private final ParseSax.Factory parserFactory;
|
||||
private final HttpUtils utils;
|
||||
|
@ -249,7 +250,7 @@ public class RestAnnotationProcessor<T> {
|
|||
|
||||
@VisibleForTesting
|
||||
public static Function<HttpResponse, ?> createResponseParser(ParseSax.Factory parserFactory, Injector injector,
|
||||
Method method, HttpRequest request) {
|
||||
Method method, HttpRequest request) {
|
||||
Function<HttpResponse, ?> transformer;
|
||||
Class<? extends HandlerWithResult<?>> handler = getSaxResponseParserClassOrNull(method);
|
||||
if (handler != null) {
|
||||
|
@ -270,7 +271,7 @@ public class RestAnnotationProcessor<T> {
|
|||
|
||||
@VisibleForTesting
|
||||
public static Function<Exception, ?> createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(
|
||||
Injector injector, Method method) {
|
||||
Injector injector, Method method) {
|
||||
ExceptionParser annotation = method.getAnnotation(ExceptionParser.class);
|
||||
if (annotation != null) {
|
||||
return injector.getInstance(annotation.value());
|
||||
|
@ -281,7 +282,7 @@ public class RestAnnotationProcessor<T> {
|
|||
@SuppressWarnings("unchecked")
|
||||
@Inject
|
||||
public RestAnnotationProcessor(Injector injector, ParseSax.Factory parserFactory, HttpUtils utils,
|
||||
TypeLiteral<T> typeLiteral) {
|
||||
TypeLiteral<T> typeLiteral) {
|
||||
this.declaring = (Class<T>) typeLiteral.getRawType();
|
||||
this.injector = injector;
|
||||
this.parserFactory = parserFactory;
|
||||
|
@ -397,7 +398,7 @@ public class RestAnnotationProcessor<T> {
|
|||
public GeneratedHttpRequest<T> createRequest(Method method, Object... args) {
|
||||
inputParamValidator.validateMethodParametersOrThrow(method, args);
|
||||
ClassMethodArgs cma = logger.isTraceEnabled() ? new ClassMethodArgs(method.getDeclaringClass(), method, args)
|
||||
: null;
|
||||
: null;
|
||||
|
||||
URI endpoint = callerEndpoint;
|
||||
try {
|
||||
|
@ -511,8 +512,8 @@ public class RestAnnotationProcessor<T> {
|
|||
org.jclouds.rest.MapBinder mapBinder = getMapPayloadBinderOrNull(method, args);
|
||||
if (mapBinder != null) {
|
||||
Map<String, String> mapParams = buildPostParams(method, args);
|
||||
if (method.isAnnotationPresent(MapPayloadParams.class)) {
|
||||
MapPayloadParams params = method.getAnnotation(MapPayloadParams.class);
|
||||
if (method.isAnnotationPresent(PayloadParams.class)) {
|
||||
PayloadParams params = method.getAnnotation(PayloadParams.class);
|
||||
addMapPayload(mapParams, params, headers.entries());
|
||||
}
|
||||
request = mapBinder.bindToRequest(request, mapParams);
|
||||
|
@ -553,14 +554,14 @@ public class RestAnnotationProcessor<T> {
|
|||
}
|
||||
|
||||
public static URI replaceQuery(Provider<UriBuilder> uriBuilderProvider, URI in, String newQuery,
|
||||
@Nullable Comparator<Entry<String, String>> sorter, char... skips) {
|
||||
@Nullable Comparator<Entry<String, String>> sorter, char... skips) {
|
||||
UriBuilder builder = uriBuilderProvider.get().uri(in);
|
||||
builder.replaceQuery(ModifyRequest.makeQueryLine(ModifyRequest.parseQueryToMap(newQuery), sorter, skips));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private Multimap<String, String> addMatrixParams(Collection<Entry<String, String>> tokenValues, Method method,
|
||||
Object... args) {
|
||||
Object... args) {
|
||||
Multimap<String, String> matrixMap = LinkedListMultimap.create();
|
||||
if (declaring.isAnnotationPresent(MatrixParams.class)) {
|
||||
MatrixParams matrix = declaring.getAnnotation(MatrixParams.class);
|
||||
|
@ -579,7 +580,7 @@ public class RestAnnotationProcessor<T> {
|
|||
}
|
||||
|
||||
private Multimap<String, String> addFormParams(Collection<Entry<String, String>> tokenValues, Method method,
|
||||
Object... args) {
|
||||
Object... args) {
|
||||
Multimap<String, String> formMap = LinkedListMultimap.create();
|
||||
if (declaring.isAnnotationPresent(FormParams.class)) {
|
||||
FormParams form = declaring.getAnnotation(FormParams.class);
|
||||
|
@ -598,7 +599,7 @@ public class RestAnnotationProcessor<T> {
|
|||
}
|
||||
|
||||
private Multimap<String, String> addQueryParams(Collection<Entry<String, String>> tokenValues, Method method,
|
||||
Object... args) {
|
||||
Object... args) {
|
||||
Multimap<String, String> queryMap = LinkedListMultimap.create();
|
||||
if (declaring.isAnnotationPresent(QueryParams.class)) {
|
||||
QueryParams query = declaring.getAnnotation(QueryParams.class);
|
||||
|
@ -617,7 +618,7 @@ public class RestAnnotationProcessor<T> {
|
|||
}
|
||||
|
||||
private void addForm(Multimap<String, String> formParams, FormParams form,
|
||||
Collection<Entry<String, String>> tokenValues) {
|
||||
Collection<Entry<String, String>> tokenValues) {
|
||||
for (int i = 0; i < form.keys().length; i++) {
|
||||
if (form.values()[i].equals(FormParams.NULL)) {
|
||||
formParams.removeAll(form.keys()[i]);
|
||||
|
@ -629,7 +630,7 @@ public class RestAnnotationProcessor<T> {
|
|||
}
|
||||
|
||||
private void addQuery(Multimap<String, String> queryParams, QueryParams query,
|
||||
Collection<Entry<String, String>> tokenValues) {
|
||||
Collection<Entry<String, String>> tokenValues) {
|
||||
for (int i = 0; i < query.keys().length; i++) {
|
||||
if (query.values()[i].equals(QueryParams.NULL)) {
|
||||
queryParams.removeAll(query.keys()[i]);
|
||||
|
@ -641,7 +642,7 @@ public class RestAnnotationProcessor<T> {
|
|||
}
|
||||
|
||||
private void addMatrix(Multimap<String, String> matrixParams, MatrixParams matrix,
|
||||
Collection<Entry<String, String>> tokenValues) {
|
||||
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]);
|
||||
|
@ -652,10 +653,10 @@ public class RestAnnotationProcessor<T> {
|
|||
}
|
||||
}
|
||||
|
||||
private void addMapPayload(Map<String, String> postParams, MapPayloadParams mapDefaults,
|
||||
Collection<Entry<String, String>> tokenValues) {
|
||||
private void addMapPayload(Map<String, String> postParams, PayloadParams mapDefaults,
|
||||
Collection<Entry<String, String>> tokenValues) {
|
||||
for (int i = 0; i < mapDefaults.keys().length; i++) {
|
||||
if (mapDefaults.values()[i].equals(MapPayloadParams.NULL)) {
|
||||
if (mapDefaults.values()[i].equals(PayloadParams.NULL)) {
|
||||
postParams.put(mapDefaults.keys()[i], null);
|
||||
} else {
|
||||
postParams.put(mapDefaults.keys()[i], Strings2.replaceTokens(mapDefaults.values()[i], tokenValues));
|
||||
|
@ -688,7 +689,7 @@ public class RestAnnotationProcessor<T> {
|
|||
@VisibleForTesting
|
||||
public static URI getEndpointInParametersOrNull(Method method, final Object[] args, Injector injector) {
|
||||
Map<Integer, Set<Annotation>> map = indexWithAtLeastOneAnnotation(method,
|
||||
methodToIndexOfParamToEndpointParamAnnotations);
|
||||
methodToIndexOfParamToEndpointParamAnnotations);
|
||||
if (map.size() >= 1 && args.length > 0) {
|
||||
EndpointParam firstAnnotation = (EndpointParam) get(get(map.values(), 0), 0);
|
||||
Function<Object, URI> parser = injector.getInstance(firstAnnotation.parser());
|
||||
|
@ -697,8 +698,8 @@ public class RestAnnotationProcessor<T> {
|
|||
int index = map.keySet().iterator().next();
|
||||
try {
|
||||
URI returnVal = parser.apply(args[index]);
|
||||
checkArgument(returnVal != null, String.format("endpoint for [%s] not configured for %s", args[index],
|
||||
method));
|
||||
checkArgument(returnVal != null,
|
||||
String.format("endpoint for [%s] not configured for %s", args[index], method));
|
||||
return returnVal;
|
||||
} catch (NullPointerException e) {
|
||||
throw new IllegalArgumentException(String.format("argument at index %d on method %s", index, method), e);
|
||||
|
@ -715,12 +716,12 @@ public class RestAnnotationProcessor<T> {
|
|||
});
|
||||
try {
|
||||
URI returnVal = parser.apply(argsToParse);
|
||||
checkArgument(returnVal != null, String.format("endpoint for [%s] not configured for %s", argsToParse,
|
||||
method));
|
||||
checkArgument(returnVal != null,
|
||||
String.format("endpoint for [%s] not configured for %s", argsToParse, method));
|
||||
return returnVal;
|
||||
} catch (NullPointerException e) {
|
||||
throw new IllegalArgumentException(String.format("argument at indexes %s on method %s", map.keySet(),
|
||||
method), e);
|
||||
method), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -756,21 +757,21 @@ public class RestAnnotationProcessor<T> {
|
|||
public static final TypeLiteral<ListenableFuture<HttpResponse>> futureHttpResponseLiteral = new TypeLiteral<ListenableFuture<HttpResponse>>() {
|
||||
};
|
||||
|
||||
@SuppressWarnings( { "unchecked", "rawtypes" })
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public static Key<? extends Function<HttpResponse, ?>> getParserOrThrowException(Method method) {
|
||||
ResponseParser annotation = method.getAnnotation(ResponseParser.class);
|
||||
if (annotation == null) {
|
||||
if (method.getReturnType().equals(void.class)
|
||||
|| TypeLiteral.get(method.getGenericReturnType()).equals(futureVoidLiteral)) {
|
||||
|| TypeLiteral.get(method.getGenericReturnType()).equals(futureVoidLiteral)) {
|
||||
return Key.get(ReleasePayloadAndReturn.class);
|
||||
} else if (method.getReturnType().equals(boolean.class) || method.getReturnType().equals(Boolean.class)
|
||||
|| TypeLiteral.get(method.getGenericReturnType()).equals(futureBooleanLiteral)) {
|
||||
|| TypeLiteral.get(method.getGenericReturnType()).equals(futureBooleanLiteral)) {
|
||||
return Key.get(ReturnTrueIf2xx.class);
|
||||
} else if (method.getReturnType().equals(InputStream.class)
|
||||
|| TypeLiteral.get(method.getGenericReturnType()).equals(futureInputStreamLiteral)) {
|
||||
|| TypeLiteral.get(method.getGenericReturnType()).equals(futureInputStreamLiteral)) {
|
||||
return Key.get(ReturnInputStream.class);
|
||||
} else if (method.getReturnType().equals(HttpResponse.class)
|
||||
|| TypeLiteral.get(method.getGenericReturnType()).equals(futureHttpResponseLiteral)) {
|
||||
|| TypeLiteral.get(method.getGenericReturnType()).equals(futureHttpResponseLiteral)) {
|
||||
return Key.get((Class) IdentityFunction.class);
|
||||
} else if (getAcceptHeadersOrNull(method).contains(MediaType.APPLICATION_JSON)) {
|
||||
Type returnVal;
|
||||
|
@ -796,16 +797,16 @@ public class RestAnnotationProcessor<T> {
|
|||
parserType = Types.newParameterizedType(UnwrapOnlyNestedJsonValueInSet.class, returnVal);
|
||||
else
|
||||
throw new IllegalStateException(String.format(
|
||||
"depth(%d) edgeCollection(%s) not yet supported for @Unwrap", depth, edgeCollection));
|
||||
"depth(%d) edgeCollection(%s) not yet supported for @Unwrap", depth, edgeCollection));
|
||||
} else {
|
||||
parserType = Types.newParameterizedType(ParseJson.class, returnVal);
|
||||
}
|
||||
return (Key<? extends Function<HttpResponse, ?>>) Key.get(parserType);
|
||||
} else if (method.getReturnType().equals(String.class)
|
||||
|| TypeLiteral.get(method.getGenericReturnType()).equals(futureStringLiteral)) {
|
||||
|| TypeLiteral.get(method.getGenericReturnType()).equals(futureStringLiteral)) {
|
||||
return Key.get(ReturnStringIf2xx.class);
|
||||
} else if (method.getReturnType().equals(URI.class)
|
||||
|| TypeLiteral.get(method.getGenericReturnType()).equals(futureURILiteral)) {
|
||||
|| TypeLiteral.get(method.getGenericReturnType()).equals(futureURILiteral)) {
|
||||
return Key.get(ParseURIFromListOrLocationHeaderIf20x.class);
|
||||
} else {
|
||||
throw new IllegalStateException("You must specify a ResponseParser annotation on: " + method.toString());
|
||||
|
@ -837,7 +838,7 @@ public class RestAnnotationProcessor<T> {
|
|||
} else {
|
||||
if (postBinders[0] instanceof org.jclouds.rest.MapBinder) {
|
||||
throw new IllegalArgumentException("we currently do not support multiple varargs postBinders in: "
|
||||
+ method.getName());
|
||||
+ method.getName());
|
||||
}
|
||||
}
|
||||
} else if (arg instanceof org.jclouds.rest.MapBinder) {
|
||||
|
@ -847,9 +848,10 @@ public class RestAnnotationProcessor<T> {
|
|||
}
|
||||
}
|
||||
}
|
||||
MapBinder annotation = method.getAnnotation(MapBinder.class);
|
||||
if (annotation != null) {
|
||||
return injector.getInstance(annotation.value());
|
||||
if (method.isAnnotationPresent(MapBinder.class)) {
|
||||
return injector.getInstance(method.getAnnotation(MapBinder.class).value());
|
||||
} else if (method.isAnnotationPresent(org.jclouds.rest.annotations.Payload.class)) {
|
||||
return injector.getInstance(BindMapToStringPayload.class);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -858,7 +860,7 @@ public class RestAnnotationProcessor<T> {
|
|||
|
||||
public boolean isHttpMethod(Method method) {
|
||||
return method.isAnnotationPresent(Path.class) || getHttpMethods(method) != null
|
||||
|| Sets.newHashSet(method.getParameterTypes()).contains(HttpRequest.class);
|
||||
|| Sets.newHashSet(method.getParameterTypes()).contains(HttpRequest.class);
|
||||
}
|
||||
|
||||
public boolean isConstantDeclaration(Method method) {
|
||||
|
@ -887,8 +889,8 @@ public class RestAnnotationProcessor<T> {
|
|||
Set<String> requests = getHttpMethods(method);
|
||||
if (requests == null || requests.size() != 1) {
|
||||
throw new IllegalStateException(
|
||||
"You must use at least one, but no more than one http method or pathparam annotation on: "
|
||||
+ method.toString());
|
||||
"You must use at least one, but no more than one http method or pathparam annotation on: "
|
||||
+ method.toString());
|
||||
}
|
||||
return requests.iterator().next();
|
||||
}
|
||||
|
@ -902,12 +904,12 @@ public class RestAnnotationProcessor<T> {
|
|||
|
||||
public GeneratedHttpRequest<T> decorateRequest(GeneratedHttpRequest<T> request) {
|
||||
OUTER: for (Entry<Integer, Set<Annotation>> entry : filterValues(
|
||||
methodToIndexOfParamToDecoratorParamAnnotation.get(request.getJavaMethod()),
|
||||
new Predicate<Set<Annotation>>() {
|
||||
public boolean apply(Set<Annotation> input) {
|
||||
return input.size() >= 1;
|
||||
}
|
||||
}).entrySet()) {
|
||||
methodToIndexOfParamToDecoratorParamAnnotation.get(request.getJavaMethod()),
|
||||
new Predicate<Set<Annotation>>() {
|
||||
public boolean apply(Set<Annotation> input) {
|
||||
return input.size() >= 1;
|
||||
}
|
||||
}).entrySet()) {
|
||||
boolean shouldBreak = false;
|
||||
BinderParam payloadAnnotation = (BinderParam) entry.getValue().iterator().next();
|
||||
Binder binder = injector.getInstance(payloadAnnotation.value());
|
||||
|
@ -943,24 +945,24 @@ public class RestAnnotationProcessor<T> {
|
|||
}
|
||||
|
||||
public static Map<Integer, Set<Annotation>> indexWithOnlyOneAnnotation(Method method, String description,
|
||||
Map<Method, Map<Integer, Set<Annotation>>> toRefine) {
|
||||
Map<Method, Map<Integer, Set<Annotation>>> toRefine) {
|
||||
Map<Integer, Set<Annotation>> indexToPayloadAnnotation = indexWithAtLeastOneAnnotation(method, toRefine);
|
||||
if (indexToPayloadAnnotation.size() > 1) {
|
||||
throw new IllegalStateException(String.format(
|
||||
"You must not specify more than one %s annotation on: %s; found %s", description, method.toString(),
|
||||
indexToPayloadAnnotation));
|
||||
"You must not specify more than one %s annotation on: %s; found %s", description, method.toString(),
|
||||
indexToPayloadAnnotation));
|
||||
}
|
||||
return indexToPayloadAnnotation;
|
||||
}
|
||||
|
||||
private static Map<Integer, Set<Annotation>> indexWithAtLeastOneAnnotation(Method method,
|
||||
Map<Method, Map<Integer, Set<Annotation>>> toRefine) {
|
||||
Map<Method, Map<Integer, Set<Annotation>>> toRefine) {
|
||||
Map<Integer, Set<Annotation>> indexToPayloadAnnotation = filterValues(toRefine.get(method),
|
||||
new Predicate<Set<Annotation>>() {
|
||||
public boolean apply(Set<Annotation> input) {
|
||||
return input.size() == 1;
|
||||
}
|
||||
});
|
||||
new Predicate<Set<Annotation>>() {
|
||||
public boolean apply(Set<Annotation> input) {
|
||||
return input.size() == 1;
|
||||
}
|
||||
});
|
||||
return indexToPayloadAnnotation;
|
||||
}
|
||||
|
||||
|
@ -979,7 +981,7 @@ public class RestAnnotationProcessor<T> {
|
|||
} else {
|
||||
if (options[0] instanceof HttpRequestOptions) {
|
||||
throw new IllegalArgumentException("we currently do not support multiple varargs options in: "
|
||||
+ method.getName());
|
||||
+ method.getName());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -991,7 +993,7 @@ public class RestAnnotationProcessor<T> {
|
|||
}
|
||||
|
||||
public Multimap<String, String> buildHeaders(Collection<Entry<String, String>> tokenValues, Method method,
|
||||
final Object... args) {
|
||||
final Object... args) {
|
||||
Multimap<String, String> headers = LinkedHashMultimap.create();
|
||||
addHeaderIfAnnotationPresentOnMethod(headers, method, tokenValues);
|
||||
Map<Integer, Set<Annotation>> indexToHeaderParam = methodToIndexOfParamToHeaderParamAnnotations.get(method);
|
||||
|
@ -1038,7 +1040,7 @@ public class RestAnnotationProcessor<T> {
|
|||
}
|
||||
|
||||
public void addHeaderIfAnnotationPresentOnMethod(Multimap<String, String> headers, Method method,
|
||||
Collection<Entry<String, String>> tokenValues) {
|
||||
Collection<Entry<String, String>> tokenValues) {
|
||||
if (declaring.isAnnotationPresent(Headers.class)) {
|
||||
Headers header = declaring.getAnnotation(Headers.class);
|
||||
addHeader(headers, header, tokenValues);
|
||||
|
@ -1050,7 +1052,7 @@ public class RestAnnotationProcessor<T> {
|
|||
}
|
||||
|
||||
private void addHeader(Multimap<String, String> headers, Headers header,
|
||||
Collection<Entry<String, String>> tokenValues) {
|
||||
Collection<Entry<String, String>> tokenValues) {
|
||||
for (int i = 0; i < header.keys().length; i++) {
|
||||
String value = header.values()[i];
|
||||
value = Strings2.replaceTokens(value, tokenValues);
|
||||
|
@ -1240,7 +1242,7 @@ public class RestAnnotationProcessor<T> {
|
|||
for (Entry<Integer, Set<Annotation>> entry : indexToPathParam.entrySet()) {
|
||||
for (Annotation key : entry.getValue()) {
|
||||
Set<Annotation> extractors = indexToParamExtractor.get(entry.getKey());
|
||||
String paramKey = ((MapPayloadParam) key).value();
|
||||
String paramKey = ((PayloadParam) key).value();
|
||||
String paramValue;
|
||||
if (extractors != null && extractors.size() > 0) {
|
||||
ParamParser extractor = (ParamParser) extractors.iterator().next();
|
||||
|
|
|
@ -42,7 +42,7 @@ import org.jclouds.io.Payload;
|
|||
import org.jclouds.rest.annotations.BinderParam;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.MapBinder;
|
||||
import org.jclouds.rest.annotations.MapPayloadParam;
|
||||
import org.jclouds.rest.annotations.PayloadParam;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.ResponseParser;
|
||||
import org.jclouds.rest.annotations.XMLResponseParser;
|
||||
|
@ -143,7 +143,7 @@ public interface IntegrationTestAsyncClient {
|
|||
@POST
|
||||
@Path("/objects/{id}")
|
||||
@MapBinder(BindToJsonPayload.class)
|
||||
ListenableFuture<String> postJson(@PathParam("id") String id, @MapPayloadParam("key") String toPut);
|
||||
ListenableFuture<String> postJson(@PathParam("id") String id, @PayloadParam("key") String toPut);
|
||||
|
||||
@POST
|
||||
@Path("/objects/{id}/action/{action}")
|
||||
|
|
|
@ -118,12 +118,12 @@ import org.jclouds.rest.annotations.EndpointParam;
|
|||
import org.jclouds.rest.annotations.FormParams;
|
||||
import org.jclouds.rest.annotations.Headers;
|
||||
import org.jclouds.rest.annotations.MapBinder;
|
||||
import org.jclouds.rest.annotations.MapPayloadParam;
|
||||
import org.jclouds.rest.annotations.MapPayloadParams;
|
||||
import org.jclouds.rest.annotations.MatrixParams;
|
||||
import org.jclouds.rest.annotations.OverrideRequestFilters;
|
||||
import org.jclouds.rest.annotations.ParamParser;
|
||||
import org.jclouds.rest.annotations.PartParam;
|
||||
import org.jclouds.rest.annotations.PayloadParam;
|
||||
import org.jclouds.rest.annotations.PayloadParams;
|
||||
import org.jclouds.rest.annotations.QueryParams;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.ResponseParser;
|
||||
|
@ -517,18 +517,25 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
|
||||
@POST
|
||||
@Path("/{foo}")
|
||||
public void postWithPath(@PathParam("foo") @MapPayloadParam("fooble") String path, MapBinder content);
|
||||
public void postWithPath(@PathParam("foo") @PayloadParam("fooble") String path, MapBinder content);
|
||||
|
||||
@POST
|
||||
@Path("/{foo}")
|
||||
@MapBinder(BindToJsonPayload.class)
|
||||
public void postWithMethodBinder(@PathParam("foo") @MapPayloadParam("fooble") String path);
|
||||
public void postWithMethodBinder(@PathParam("foo") @PayloadParam("fooble") String path);
|
||||
|
||||
@POST
|
||||
@Path("/{foo}")
|
||||
@MapPayloadParams(keys = "rat", values = "atat")
|
||||
@PayloadParams(keys = "rat", values = "atat")
|
||||
@MapBinder(BindToJsonPayload.class)
|
||||
public void postWithMethodBinderAndDefaults(@PathParam("foo") @MapPayloadParam("fooble") String path);
|
||||
public void postWithMethodBinderAndDefaults(@PathParam("foo") @PayloadParam("fooble") String path);
|
||||
|
||||
@POST
|
||||
@Path("/{foo}")
|
||||
@PayloadParams(keys = "rat", values = "atat")
|
||||
@org.jclouds.rest.annotations.Payload("name {fooble}")
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
public void testPayload(@PathParam("foo") @PayloadParam("fooble") String path);
|
||||
}
|
||||
|
||||
public void testCreatePostRequest() throws SecurityException, NoSuchMethodException, IOException {
|
||||
|
@ -594,6 +601,15 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
assertPayloadEquals(request, "{\"fooble\":\"data\",\"rat\":\"atat\"}", "application/json", false);
|
||||
}
|
||||
|
||||
public void testCreatePostWithPayload() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TestPost.class.getMethod("testPayload", String.class);
|
||||
HttpRequest request = factory(TestPost.class).createRequest(method, "data");
|
||||
|
||||
assertRequestLineEquals(request, "POST http://localhost:9999/data HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
assertPayloadEquals(request, "name data", "text/plain", false);
|
||||
}
|
||||
|
||||
static interface TestMultipartForm {
|
||||
@POST
|
||||
void withStringPart(@PartParam(name = "fooble") String path);
|
||||
|
@ -714,7 +730,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
@PUT
|
||||
@Path("/{foo}")
|
||||
@MapBinder(BindToJsonPayload.class)
|
||||
void putWithMethodBinder(@PathParam("foo") @MapPayloadParam("fooble") String path);
|
||||
void putWithMethodBinder(@PathParam("foo") @PayloadParam("fooble") String path);
|
||||
|
||||
@PUT
|
||||
@Path("/{foo}")
|
||||
|
@ -725,7 +741,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
|
|||
@Path("/{foo}")
|
||||
@MapBinder(BindToJsonPayload.class)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
Wrapper putWithMethodBinderConsumes(@PathParam("foo") @MapPayloadParam("fooble") String path);
|
||||
Wrapper putWithMethodBinderConsumes(@PathParam("foo") @PayloadParam("fooble") String path);
|
||||
|
||||
@GET
|
||||
@Path("/")
|
||||
|
|
|
@ -26,12 +26,12 @@ import javax.ws.rs.GET;
|
|||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.cloudsigma.binders.BindCloneDriveOptionsToPlainTextString;
|
||||
import org.jclouds.cloudsigma.binders.BindDriveDataToPlainTextString;
|
||||
import org.jclouds.cloudsigma.binders.BindDriveToPlainTextString;
|
||||
import org.jclouds.cloudsigma.binders.BindNameToPayload;
|
||||
import org.jclouds.cloudsigma.binders.BindServerToPlainTextString;
|
||||
import org.jclouds.cloudsigma.domain.Drive;
|
||||
import org.jclouds.cloudsigma.domain.DriveData;
|
||||
|
@ -57,7 +57,8 @@ import org.jclouds.http.filters.BasicAuthentication;
|
|||
import org.jclouds.rest.annotations.BinderParam;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.MapBinder;
|
||||
import org.jclouds.rest.annotations.MapPayloadParam;
|
||||
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.functions.ReturnNullOnNotFoundOr404;
|
||||
|
@ -108,8 +109,8 @@ public interface CloudSigmaAsyncClient {
|
|||
@ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class)
|
||||
@Path("/drives/{uuid}/clone")
|
||||
@MapBinder(BindCloneDriveOptionsToPlainTextString.class)
|
||||
ListenableFuture<DriveInfo> cloneDrive(@PathParam("uuid") String sourceUuid,
|
||||
@MapPayloadParam("name") String newName, CloneDriveOptions... options);
|
||||
ListenableFuture<DriveInfo> cloneDrive(@PathParam("uuid") String sourceUuid, @PayloadParam("name") String newName,
|
||||
CloneDriveOptions... options);
|
||||
|
||||
/**
|
||||
* @see CloudSigmaClient#getProfileInfo
|
||||
|
@ -258,7 +259,9 @@ public interface CloudSigmaAsyncClient {
|
|||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
@ResponseParser(KeyValuesDelimitedByBlankLinesToVLANInfo.class)
|
||||
@Path("/resources/vlan/create")
|
||||
ListenableFuture<VLANInfo> createVLAN(@BinderParam(BindNameToPayload.class) String name);
|
||||
@Payload("name {name}\n")
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
ListenableFuture<VLANInfo> createVLAN(@PayloadParam("name") String name);
|
||||
|
||||
/**
|
||||
* @see CloudSigmaClient#listVLANInfo
|
||||
|
@ -283,8 +286,9 @@ public interface CloudSigmaAsyncClient {
|
|||
@POST
|
||||
@ResponseParser(KeyValuesDelimitedByBlankLinesToVLANInfo.class)
|
||||
@Path("/resources/vlan/{uuid}/set")
|
||||
ListenableFuture<VLANInfo> renameVLAN(@PathParam("uuid") String uuid,
|
||||
@BinderParam(BindNameToPayload.class) String name);
|
||||
@Payload("name {name}\n")
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
ListenableFuture<VLANInfo> renameVLAN(@PathParam("uuid") String uuid, @PayloadParam("name") String name);
|
||||
|
||||
/**
|
||||
* @see CloudSigmaClient#listVLANs
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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.cloudsigma.binders;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.Binder;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
@Singleton
|
||||
public class BindNameToPayload implements Binder {
|
||||
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Object payload) {
|
||||
request.setPayload("name " + checkNotNull(payload, "name") + "\n");
|
||||
request.getPayload().getContentMetadata().setContentType(MediaType.TEXT_PLAIN);
|
||||
return request;
|
||||
}
|
||||
}
|
|
@ -32,7 +32,7 @@ import javax.ws.rs.QueryParam;
|
|||
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.MapBinder;
|
||||
import org.jclouds.rest.annotations.MapPayloadParam;
|
||||
import org.jclouds.rest.annotations.PayloadParam;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.SkipEncoding;
|
||||
import org.jclouds.rest.annotations.XMLResponseParser;
|
||||
|
@ -118,8 +118,8 @@ public interface SlicehostAsyncClient {
|
|||
@Path("/slices.xml")
|
||||
@MapBinder(BindCreateSliceToXmlPayload.class)
|
||||
@XMLResponseParser(SliceHandler.class)
|
||||
ListenableFuture<Slice> createSlice(@MapPayloadParam("name") String name, @MapPayloadParam("image_id") int imageId,
|
||||
@MapPayloadParam("flavor_id") int flavorId);
|
||||
ListenableFuture<Slice> createSlice(@PayloadParam("name") String name, @PayloadParam("image_id") int imageId,
|
||||
@PayloadParam("flavor_id") int flavorId);
|
||||
|
||||
/**
|
||||
* @see SlicehostClient#rebuildSliceFromImage
|
||||
|
|
|
@ -40,7 +40,7 @@ import javax.ws.rs.Produces;
|
|||
import org.jclouds.rest.annotations.EndpointParam;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.MapBinder;
|
||||
import org.jclouds.rest.annotations.MapPayloadParam;
|
||||
import org.jclouds.rest.annotations.PayloadParam;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.XMLResponseParser;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
|
@ -112,8 +112,8 @@ public interface TerremarkECloudAsyncClient extends TerremarkVCloudAsyncClient {
|
|||
@MapBinder(AddInternetServiceOptions.class)
|
||||
@Override
|
||||
ListenableFuture<? extends InternetService> addInternetServiceToExistingIp(@EndpointParam URI existingIpId,
|
||||
@MapPayloadParam("name") String serviceName, @MapPayloadParam("protocol") Protocol protocol,
|
||||
@MapPayloadParam("port") int port, AddInternetServiceOptions... options);
|
||||
@PayloadParam("name") String serviceName, @PayloadParam("protocol") Protocol protocol,
|
||||
@PayloadParam("port") int port, AddInternetServiceOptions... options);
|
||||
|
||||
/**
|
||||
* @see TerremarkVCloudExpressClient#getInternetServicesOnPublicIP
|
||||
|
@ -174,8 +174,8 @@ public interface TerremarkECloudAsyncClient extends TerremarkVCloudAsyncClient {
|
|||
@XMLResponseParser(KeyPairHandler.class)
|
||||
@MapBinder(BindCreateKeyToXmlPayload.class)
|
||||
ListenableFuture<? extends KeyPair> generateKeyPairInOrg(
|
||||
@EndpointParam(parser = OrgURIToKeysListEndpoint.class) URI org, @MapPayloadParam("name") String name,
|
||||
@MapPayloadParam("isDefault") boolean makeDefault);
|
||||
@EndpointParam(parser = OrgURIToKeysListEndpoint.class) URI org, @PayloadParam("name") String name,
|
||||
@PayloadParam("isDefault") boolean makeDefault);
|
||||
|
||||
/**
|
||||
* @see TerremarkECloudClient#getKeyPair
|
||||
|
|
|
@ -36,7 +36,7 @@ import javax.ws.rs.Produces;
|
|||
import org.jclouds.rest.annotations.EndpointParam;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.MapBinder;
|
||||
import org.jclouds.rest.annotations.MapPayloadParam;
|
||||
import org.jclouds.rest.annotations.PayloadParam;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.XMLResponseParser;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
|
@ -76,8 +76,8 @@ public interface TerremarkVCloudExpressAsyncClient extends TerremarkVCloudAsyncC
|
|||
@MapBinder(AddInternetServiceOptions.class)
|
||||
ListenableFuture<? extends InternetService> addInternetServiceToVDC(
|
||||
@EndpointParam(parser = VDCURIToInternetServicesEndpoint.class) URI vDCId,
|
||||
@MapPayloadParam("name") String serviceName, @MapPayloadParam("protocol") Protocol protocol,
|
||||
@MapPayloadParam("port") int port, AddInternetServiceOptions... options);
|
||||
@PayloadParam("name") String serviceName, @PayloadParam("protocol") Protocol protocol,
|
||||
@PayloadParam("port") int port, AddInternetServiceOptions... options);
|
||||
|
||||
/**
|
||||
* @see TerremarkVCloudExpressClient#findKeyPairInOrgNamed
|
||||
|
@ -117,8 +117,8 @@ public interface TerremarkVCloudExpressAsyncClient extends TerremarkVCloudAsyncC
|
|||
@XMLResponseParser(KeyPairHandler.class)
|
||||
@MapBinder(BindCreateKeyToXmlPayload.class)
|
||||
ListenableFuture<? extends KeyPair> generateKeyPairInOrg(
|
||||
@EndpointParam(parser = OrgURIToKeysListEndpoint.class) URI org, @MapPayloadParam("name") String name,
|
||||
@MapPayloadParam("isDefault") boolean makeDefault);
|
||||
@EndpointParam(parser = OrgURIToKeysListEndpoint.class) URI org, @PayloadParam("name") String name,
|
||||
@PayloadParam("isDefault") boolean makeDefault);
|
||||
|
||||
/**
|
||||
* @see TerremarkVCloudExpressClient#getKeyPair
|
||||
|
|
Loading…
Reference in New Issue