Merge pull request #1355 from jclouds/consider-form-param

consider @FormParam on @Delegate calls
This commit is contained in:
Adrian Cole 2013-02-24 23:36:15 -08:00
commit 1c17f59073
2 changed files with 25 additions and 2 deletions

View File

@ -220,8 +220,13 @@ public class RestAnnotationProcessor implements Function<Invocation, HttpRequest
if (caller != null)
tokenValues.putAll(addPathAndGetTokens(caller, uriBuilder));
tokenValues.putAll(addPathAndGetTokens(invocation, uriBuilder));
Multimap<String, Object> formParams = addFormParams(tokenValues, invocation);
Multimap<String, Object> formParams;
if (caller != null) {
formParams = addFormParams(tokenValues, caller);
formParams.putAll(addFormParams(tokenValues, invocation));
} else {
formParams = addFormParams(tokenValues, invocation);
}
Multimap<String, Object> queryParams = addQueryParams(tokenValues, invocation);
Multimap<String, String> headers = buildHeaders(tokenValues, invocation);

View File

@ -21,6 +21,7 @@ package org.jclouds.rest.annotationparsing;
import static org.jclouds.providers.AnonymousProviderMetadata.forClientMappedToAsyncClientOnEndpoint;
import static org.testng.Assert.assertTrue;
import javax.ws.rs.FormParam;
import javax.ws.rs.HEAD;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
@ -52,6 +53,8 @@ import com.google.inject.Module;
public class DelegateAnnotationExpectTest extends BaseRestClientExpectTest<DelegateAnnotationExpectTest.DelegatingApi> {
static interface DelegatingApi {
@Delegate
DiskApi getDiskApiForProjectForm(@FormParam("project") String projectName);
@Delegate
@Path("/projects/{project}")
@ -59,6 +62,8 @@ public class DelegateAnnotationExpectTest extends BaseRestClientExpectTest<Deleg
}
static interface DelegatingAsyncApi {
@Delegate
DiskAsyncApi getDiskApiForProjectForm(@FormParam("project") String projectName);
@Delegate
@Path("/projects/{project}")
@ -66,12 +71,17 @@ public class DelegateAnnotationExpectTest extends BaseRestClientExpectTest<Deleg
}
static interface DiskApi {
void form();
void syncAll();
boolean exists(@PathParam("disk") String diskName);
}
static interface DiskAsyncApi {
@POST
ListenableFuture<Void> form();
@POST
@Payload("<Sync>{project}</Sync>")
ListenableFuture<Void> syncAll();
@ -82,6 +92,14 @@ public class DelegateAnnotationExpectTest extends BaseRestClientExpectTest<Deleg
public ListenableFuture<Boolean> exists(@PathParam("disk") String diskName);
}
public void testDelegatingCallTakesIntoConsiderationAndCalleeFormParam() {
DelegatingApi client = requestSendsResponse(HttpRequest.builder().method("POST").endpoint("http://mock")
.addFormParam("project", "prod").build(), HttpResponse.builder().statusCode(200).build());
client.getDiskApiForProjectForm("prod").form();
}
public void testDelegatingCallTakesIntoConsiderationAndCalleePayloadParam() {
DelegatingApi client = requestSendsResponse(