Issue 125:payload binder

This commit is contained in:
Adrian Cole 2011-02-14 15:17:19 +01:00
parent 37fc5505ff
commit 4627a91195
17 changed files with 160 additions and 270 deletions

View File

@ -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);
/**

View File

@ -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);

View File

@ -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);
/**

View File

@ -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

View File

@ -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);
}

View File

@ -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();

View File

@ -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();
}

View File

@ -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;
}

View File

@ -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 {

View File

@ -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,7 +169,7 @@ 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();
@ -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);
@ -652,10 +653,10 @@ public class RestAnnotationProcessor<T> {
}
}
private void addMapPayload(Map<String, String> postParams, MapPayloadParams mapDefaults,
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));
@ -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,8 +716,8 @@ 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(),
@ -756,7 +757,7 @@ 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) {
@ -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;
}
@ -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();

View File

@ -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}")

View File

@ -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("/")

View File

@ -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

View File

@ -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;
}
}

View File

@ -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

View File

@ -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

View File

@ -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