From 42b807168217b214c928d4d240eac8ec152247fb Mon Sep 17 00:00:00 2001 From: Adam Lowe Date: Mon, 14 May 2012 11:38:41 +0100 Subject: [PATCH] openstack-nova: Adding support for @WrapWith on methods --- .../java/org/jclouds/rest/annotations/WrapWith.java | 3 ++- .../rest/binders/BindToJsonPayloadWrappedWith.java | 12 ++++++++++-- .../rest/internal/RestAnnotationProcessor.java | 3 +++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/jclouds/rest/annotations/WrapWith.java b/core/src/main/java/org/jclouds/rest/annotations/WrapWith.java index dafc173496..c517aac4ec 100644 --- a/core/src/main/java/org/jclouds/rest/annotations/WrapWith.java +++ b/core/src/main/java/org/jclouds/rest/annotations/WrapWith.java @@ -18,6 +18,7 @@ */ package org.jclouds.rest.annotations; +import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.PARAMETER; import static java.lang.annotation.RetentionPolicy.RUNTIME; @@ -31,7 +32,7 @@ import java.lang.annotation.Target; * * @author Adrian Cole */ -@Target(PARAMETER) +@Target( { METHOD, PARAMETER }) @Retention(RUNTIME) public @interface WrapWith { diff --git a/core/src/main/java/org/jclouds/rest/binders/BindToJsonPayloadWrappedWith.java b/core/src/main/java/org/jclouds/rest/binders/BindToJsonPayloadWrappedWith.java index a65d14ee52..3909d07961 100644 --- a/core/src/main/java/org/jclouds/rest/binders/BindToJsonPayloadWrappedWith.java +++ b/core/src/main/java/org/jclouds/rest/binders/BindToJsonPayloadWrappedWith.java @@ -20,20 +20,24 @@ package org.jclouds.rest.binders; import static com.google.common.base.Preconditions.checkNotNull; +import java.util.Map; + import javax.inject.Inject; import org.jclouds.http.HttpRequest; import org.jclouds.rest.Binder; +import org.jclouds.rest.MapBinder; +import com.google.common.base.Strings; import com.google.common.collect.ImmutableMap; import com.google.inject.assistedinject.Assisted; /** * Sometimes, cloud apis wrap requests inside an envelope. This addresses this. - * + * * @author Adrian Cole */ -public class BindToJsonPayloadWrappedWith implements Binder { +public class BindToJsonPayloadWrappedWith implements MapBinder { public static interface Factory { BindToJsonPayloadWrappedWith create(String envelope); @@ -53,4 +57,8 @@ public class BindToJsonPayloadWrappedWith implements Binder { return jsonBinder.bindToRequest(request, (Object) ImmutableMap.of(envelope, checkNotNull(payload, "payload"))); } + @Override + public R bindToRequest(R request, Map postParams) { + return this.bindToRequest(request, (Object) postParams); + } } \ No newline at end of file diff --git a/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java b/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java index 7a25e874a5..aa439d4180 100644 --- a/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java +++ b/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java @@ -916,6 +916,9 @@ public class RestAnnotationProcessor { return injector.getInstance(method.getAnnotation(MapBinder.class).value()); } else if (method.isAnnotationPresent(org.jclouds.rest.annotations.Payload.class)) { return injector.getInstance(BindMapToStringPayload.class); + } else if (method.isAnnotationPresent(WrapWith.class)) { + return injector.getInstance(BindToJsonPayloadWrappedWith.Factory.class).create( + method.getAnnotation(WrapWith.class).value()); } return null; }