Adjusting MapBinder to take Map<String,Object> so BindToJsonPayload can bind objects annotated with PayloadParam correctly

This commit is contained in:
Adam Lowe 2012-05-14 12:42:17 +01:00
parent 42b8071682
commit cc016d5dc8
82 changed files with 217 additions and 449 deletions

View File

@ -45,13 +45,13 @@ public class BindBackupScheduleToJsonPayload extends BindToJsonPayload {
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
throw new IllegalStateException("Replace Backup Schedule needs an BackupSchedule object, not a Map");
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object toBind) {
checkArgument(toBind instanceof BackupSchedule, "this binder is only valid for BackupSchedules!");
return super.bindToRequest(request, ImmutableMap.of("backupSchedule", toBind));
return super.bindToRequest(request, (Object) ImmutableMap.of("backupSchedule", toBind));
}
}

View File

@ -94,10 +94,10 @@ public class CreateServerOptions implements MapBinder {
private String publicIp;
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
ServerRequest server = new ServerRequest(checkNotNull(postParams.get("name"), "name parameter not present"),
Integer.parseInt(checkNotNull(postParams.get("imageId"), "imageId parameter not present")), Integer
.parseInt(checkNotNull(postParams.get("flavorId"), "flavorId parameter not present")));
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
ServerRequest server = new ServerRequest(checkNotNull(postParams.get("name"), "name parameter not present").toString(),
Integer.parseInt(checkNotNull(postParams.get("imageId"), "imageId parameter not present").toString()),
Integer.parseInt(checkNotNull(postParams.get("flavorId"), "flavorId parameter not present").toString()));
if (metadata.size() > 0)
server.metadata = metadata;
if (files.size() > 0)
@ -202,7 +202,7 @@ public class CreateServerOptions implements MapBinder {
public static class Builder {
/**
* @see CreateServerOptions#withFile(String,byte [])
* @see CreateServerOptions#withFile(String,byte[])
*/
public static CreateServerOptions withFile(String path, byte[] contents) {
CreateServerOptions options = new CreateServerOptions();

View File

@ -57,8 +57,8 @@ public class CreateSharedIpGroupOptions implements MapBinder {
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
SharedIpGroupRequest createRequest = new SharedIpGroupRequest(checkNotNull(postParams.get("name")), serverId);
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
SharedIpGroupRequest createRequest = new SharedIpGroupRequest(checkNotNull(postParams.get("name")).toString(), serverId);
return jsonBinder.bindToRequest(request, ImmutableMap.of("sharedIpGroup", createRequest));
}

View File

@ -43,7 +43,7 @@ public class RebuildServerOptions implements MapBinder {
Integer imageId;
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
Map<String, Integer> image = Maps.newHashMap();
if (imageId != null)
image.put("imageId", imageId);

View File

@ -55,7 +55,7 @@ public class CreateServerOptionsTest {
private HttpRequest buildRequest(CreateServerOptions options) {
injector.injectMembers(options);
HttpRequest request = new HttpRequest(HttpMethod.POST, URI.create("http://localhost"));
options.bindToRequest(request, ImmutableMap.of("name", "foo", "imageId", "1", "flavorId", "2"));
options.bindToRequest(request, ImmutableMap.<String, Object>of("name", "foo", "imageId", "1", "flavorId", "2"));
return request;
}

View File

@ -53,7 +53,7 @@ public class CreateSharedIpGroupOptionsTest {
private HttpRequest buildRequest(CreateSharedIpGroupOptions options) {
injector.injectMembers(options);
HttpRequest request = new HttpRequest(HttpMethod.POST, URI.create("http://localhost"));
options.bindToRequest(request, ImmutableMap.of("name", "foo"));
options.bindToRequest(request, ImmutableMap.<String,Object>of("name", "foo"));
return request;
}

View File

@ -53,7 +53,7 @@ public class RebuildServerOptionsTest {
private HttpRequest buildRequest(RebuildServerOptions options) {
injector.injectMembers(options);
HttpRequest request = new HttpRequest(HttpMethod.POST, URI.create("http://localhost"));
options.bindToRequest(request, new HashMap<String, String>());
options.bindToRequest(request, new HashMap<String, Object>());
return request;
}

View File

@ -24,6 +24,7 @@ import static com.google.common.base.Preconditions.checkState;
import java.util.Map;
import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.ws.rs.core.MediaType;
@ -35,8 +36,10 @@ import org.jclouds.http.HttpRequest;
import org.jclouds.rest.MapBinder;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
/**
*
@ -53,7 +56,7 @@ public class BindCloneDriveOptionsToPlainTextString implements MapBinder {
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest,
"this binder is only valid for GeneratedHttpRequests!");
@SuppressWarnings("unchecked")
@ -62,10 +65,15 @@ public class BindCloneDriveOptionsToPlainTextString implements MapBinder {
CloneDriveOptions options = findOptionsInArgsOrNull(gRequest);
if (options != null) {
postParams = ImmutableMap.<String, String> builder().putAll(postParams).putAll(options.getOptions()).build();
postParams = ImmutableMap.<String, Object> builder().putAll(postParams).putAll(options.getOptions()).build();
}
request.setPayload(listOfMapsToListOfKeyValuesDelimitedByBlankLines.apply(ImmutableSet.of(postParams)));
request.setPayload(listOfMapsToListOfKeyValuesDelimitedByBlankLines.apply(ImmutableSet.of(Maps.transformValues(postParams, new Function<Object, String>() {
@Override
public String apply(@Nullable Object input) {
return input == null ? null : input.toString();
}
}))));
request.getPayload().getContentMetadata().setContentType(MediaType.TEXT_PLAIN);
return request;
}

View File

@ -47,16 +47,16 @@ public class BindCloneDriveOptionsToPlainTextStringTest {
BindCloneDriveOptionsToPlainTextString.class);
public void testDefault() throws IOException {
assertInputAndArgsCreatesPayload(ImmutableMap.of("name", "newdrive"), ImmutableList.<Object> of(),
assertInputAndArgsCreatesPayload(ImmutableMap.<String, Object>of("name", "newdrive"), ImmutableList.<Object> of(),
"name newdrive");
}
public void testWithSize() throws IOException {
assertInputAndArgsCreatesPayload(ImmutableMap.of("name", "newdrive"),
assertInputAndArgsCreatesPayload(ImmutableMap.<String, Object>of("name", "newdrive"),
ImmutableList.<Object> of(new CloneDriveOptions().size(1024)), "name newdrive\nsize 1024");
}
protected void assertInputAndArgsCreatesPayload(ImmutableMap<String, String> inputMap, List<Object> args,
protected void assertInputAndArgsCreatesPayload(ImmutableMap<String, Object> inputMap, List<Object> args,
String expected) {
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
expect(request.getArgs()).andReturn(args).atLeastOnce();

View File

@ -310,7 +310,7 @@ public interface NovaAsyncClient {
@PayloadParam("serverId") int serverId);
/**
* @see NovaClient#listAddresses
* @see NovaClient#getAddresses
*/
@GET
@Unwrap

View File

@ -100,10 +100,10 @@ public class CreateServerOptions implements MapBinder {
private String adminPass;
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
ServerRequest server = new ServerRequest(checkNotNull(postParams.get("name"), "name parameter not present"),
checkNotNull(postParams.get("imageRef"), "imageRef parameter not present"), checkNotNull(postParams
.get("flavorRef"), "flavorRef parameter not present"));
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
ServerRequest server = new ServerRequest(checkNotNull(postParams.get("name"), "name parameter not present").toString(),
checkNotNull(postParams.get("imageRef"), "imageRef parameter not present").toString(),
checkNotNull(postParams.get("flavorRef"), "flavorRef parameter not present").toString());
if (metadata.size() > 0)
server.metadata = metadata;
if (files.size() > 0)
@ -202,7 +202,7 @@ public class CreateServerOptions implements MapBinder {
public static class Builder {
/**
* @see CreateServerOptions#withFile(String,byte [])
* @see CreateServerOptions#withFile(String,byte[])
*/
public static CreateServerOptions withFile(String path, byte[] contents) {
CreateServerOptions options = new CreateServerOptions();
@ -231,7 +231,7 @@ public class CreateServerOptions implements MapBinder {
}
/**
* @see CreateServerOptions#withGroupName(String)
* @see CreateServerOptions#withSecurityGroup(String)
*/
public static CreateServerOptions withSecurityGroup(String name) {
CreateServerOptions options = new CreateServerOptions();

View File

@ -44,7 +44,7 @@ public class RebuildServerOptions implements MapBinder {
String imageRef;
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
Map<String, String> image = Maps.newHashMap();
if (imageRef != null)
image.put("imageRef", imageRef);

View File

@ -55,7 +55,7 @@ public class CreateServerOptionsTest {
private HttpRequest buildRequest(CreateServerOptions options) {
injector.injectMembers(options);
HttpRequest request = new HttpRequest(HttpMethod.POST, URI.create("http://localhost"));
options.bindToRequest(request, ImmutableMap.of("name", "foo", "imageRef", "1", "flavorRef", "2"));
options.bindToRequest(request, ImmutableMap.<String,Object>of("name", "foo", "imageRef", "1", "flavorRef", "2"));
return request;
}

View File

@ -53,7 +53,7 @@ public class RebuildServerOptionsTest {
private HttpRequest buildRequest(RebuildServerOptions options) {
injector.injectMembers(options);
HttpRequest request = new HttpRequest(HttpMethod.POST, URI.create("http://localhost"));
options.bindToRequest(request, new HashMap<String, String>());
options.bindToRequest(request, new HashMap<String, Object>());
return request;
}

View File

@ -1,39 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.openstack.nova.v1_1.binders;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.json.Json;
import com.google.inject.TypeLiteral;
/**
* @author Adam Lowe
*/
@Singleton
public class BindAggregateMetadataToJsonPayload extends BindObjectToJsonPayload<Map<String,String>> {
@Inject
public BindAggregateMetadataToJsonPayload(Json jsonBinder) {
super(jsonBinder, "metadata", new TypeLiteral<Map<String, String>>(){}, "set_metadata");
}
}

View File

@ -1,39 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.openstack.nova.v1_1.binders;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.json.Json;
import com.google.inject.TypeLiteral;
/**
* @author Adam Lowe
*/
@Singleton
public class BindExtraSpecsToJsonPayload extends BindObjectToJsonPayload<Map<String,String>> {
@Inject
public BindExtraSpecsToJsonPayload(Json jsonBinder) {
super(jsonBinder, "extra_specs", new TypeLiteral<Map<String,String>>(){});
}
}

View File

@ -1,86 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.openstack.nova.v1_1.binders;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Map;
import org.jclouds.http.HttpRequest;
import org.jclouds.json.Json;
import org.jclouds.rest.MapBinder;
import org.jclouds.rest.binders.BindToJsonPayload;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
import com.google.common.collect.Iterables;
import com.google.inject.TypeLiteral;
/**
* @author Adam Lowe
*/
public abstract class BindObjectToJsonPayload<T> extends BindToJsonPayload implements MapBinder {
private final String fieldName;
private final String wrapperName;
private final TypeLiteral<T> type;
/** Bind a specific argument to the json payload
*
* @param fieldName the name of the output json field
* @param fieldType the type of the object to select from the method arguments
* @param wrapperName the name of the json field wrapper (if any)
*/
public BindObjectToJsonPayload(Json jsonBinder, String fieldName, TypeLiteral<T> fieldType, String wrapperName) {
super(jsonBinder);
this.fieldName = fieldName;
this.wrapperName = wrapperName;
this.type = fieldType;
}
public BindObjectToJsonPayload(Json jsonBinder, String fieldName, TypeLiteral<T> fieldType) {
this(jsonBinder, fieldName, fieldType, null);
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object toBind) {
throw new IllegalStateException("BindMapToJsonPayload needs parameters");
}
@SuppressWarnings("unchecked")
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
Builder<String, Object> payload = ImmutableMap.builder();
payload.putAll(postParams);
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest<?>,
"this binder is only valid for GeneratedHttpRequests!");
GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request;
T specs = (T) Iterables.find(gRequest.getArgs(), Predicates.instanceOf(type.getRawType()));
payload.put(fieldName, specs);
if (wrapperName != null) {
return super.bindToRequest(request, ImmutableMap.of(wrapperName, payload.build()));
}
return super.bindToRequest(request, payload.build());
}
}

View File

@ -1,38 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.openstack.nova.v1_1.binders;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.json.Json;
import org.jclouds.openstack.nova.v1_1.domain.QuotaClass;
import com.google.inject.TypeLiteral;
/**
* @author Adam Lowe
*/
@Singleton
public class BindQuotaClassToJsonPayload extends BindObjectToJsonPayload<QuotaClass> {
@Inject
public BindQuotaClassToJsonPayload(Json jsonBinder) {
super(jsonBinder, "quota_class_set", new TypeLiteral<QuotaClass>(){});
}
}

View File

@ -1,38 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.openstack.nova.v1_1.binders;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.json.Json;
import org.jclouds.openstack.nova.v1_1.domain.Quotas;
import com.google.inject.TypeLiteral;
/**
* @author Adam Lowe
*/
@Singleton
public class BindQuotasToJsonPayload extends BindObjectToJsonPayload<Quotas> {
@Inject
public BindQuotasToJsonPayload(Json jsonBinder) {
super(jsonBinder, "quota_set", new TypeLiteral<Quotas>(){});
}
}

View File

@ -56,8 +56,8 @@ public class BindSecurityGroupRuleToJsonPayload extends BindToJsonPayload implem
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
Builder<String, String> payload = ImmutableMap.builder();
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
Builder<String, Object> payload = ImmutableMap.builder();
payload.putAll(postParams);
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest<?>,
"this binder is only valid for GeneratedHttpRequests!");

View File

@ -37,6 +37,7 @@ import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.WrapWith;
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404;
@ -114,7 +115,7 @@ public interface AdminActionsAsyncClient {
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Payload("%7B\"createBackup\":%7B\"name\":\"{name}\",\"backup_type\":\"{backup_type}\",\"rotation\":{rotation}%7D%7D")
@WrapWith("createBackup")
@ExceptionParser(MapHttp4xxCodesToExceptions.class)
@ResponseParser(ParseImageIdFromLocationHeader.class)
ListenableFuture<String> createBackupOfServer(@PathParam("id") String id,
@ -156,9 +157,9 @@ public interface AdminActionsAsyncClient {
@POST
@Produces(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnFalseOnNotFoundOr404.class)
@Payload("%7B\"os-migrateLive\":%7B\"host\":\"{host}\",\"block_migration\":\"{bm}\",\"disk_over_commit\":\"{doc}\"%7D%7D")
@WrapWith("os-migrateLive")
ListenableFuture<Boolean> liveMigrateServer(@PathParam("id") String id,
@PayloadParam("host") String host,
@PayloadParam("bm") boolean blockMigration,
@PayloadParam("doc") boolean diskOverCommit);
@PayloadParam("block_migration") boolean blockMigration,
@PayloadParam("disk_over_commit") boolean diskOverCommit);
}

View File

@ -33,7 +33,6 @@ import javax.ws.rs.core.MediaType;
import org.jclouds.concurrent.Timeout;
import org.jclouds.openstack.filters.AuthenticateRequest;
import org.jclouds.openstack.nova.v1_1.binders.BindExtraSpecsToJsonPayload;
import org.jclouds.openstack.services.Extension;
import org.jclouds.openstack.services.ServiceType;
import org.jclouds.rest.annotations.ExceptionParser;
@ -43,6 +42,7 @@ import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.Unwrap;
import org.jclouds.rest.binders.BindToJsonPayload;
import org.jclouds.rest.functions.ReturnEmptyMapOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
@ -79,8 +79,8 @@ public interface FlavorExtraSpecsAsyncClient {
@Path("/flavors/{flavor_id}/os-extra_specs")
@Produces(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnFalseOnNotFoundOr404.class)
@MapBinder(BindExtraSpecsToJsonPayload.class)
ListenableFuture<Boolean> setAllExtraSpecs(@PathParam("flavor_id") String flavorId, Map<String, String> specs);
@MapBinder(BindToJsonPayload.class)
ListenableFuture<Boolean> setAllExtraSpecs(@PathParam("flavor_id") String flavorId, @PayloadParam("extra_specs") Map<String, String> specs);
/**
* @see FlavorExtraSpecsClient#getExtraSpec(String, String)

View File

@ -33,16 +33,14 @@ import javax.ws.rs.core.MediaType;
import org.jclouds.concurrent.Timeout;
import org.jclouds.openstack.filters.AuthenticateRequest;
import org.jclouds.openstack.nova.v1_1.binders.BindAggregateMetadataToJsonPayload;
import org.jclouds.openstack.nova.v1_1.domain.HostAggregate;
import org.jclouds.openstack.services.Extension;
import org.jclouds.openstack.services.ServiceType;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.Payload;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.WrapWith;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
@ -87,8 +85,9 @@ public interface HostAggregateAsyncClient {
@SelectJson("aggregate")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Payload("%7B\"aggregate\":%7B\"name\":\"{name}\",\"availability_zone\":\"{zone}\"%7D%7D")
ListenableFuture<HostAggregate> createAggregate(@PayloadParam("name") String name, @PayloadParam("zone") String availablityZone);
@WrapWith("aggregate")
ListenableFuture<HostAggregate> createAggregate(@PayloadParam("name") String name,
@PayloadParam("availability_zone") String availablityZone);
/**
* @see HostAggregateClient#updateName
@ -97,7 +96,7 @@ public interface HostAggregateAsyncClient {
@Path("/{id}")
@SelectJson("aggregate")
@Consumes(MediaType.APPLICATION_JSON)
@Payload("%7B\"aggregate\":%7B\"name\":\"{name}\"%7D%7D")
@WrapWith("aggregate")
ListenableFuture<HostAggregate> updateName(@PathParam("id") String id, @PayloadParam("name") String name);
/**
@ -107,8 +106,8 @@ public interface HostAggregateAsyncClient {
@Path("/{id}")
@SelectJson("aggregate")
@Consumes(MediaType.APPLICATION_JSON)
@Payload("%7B\"aggregate\":%7B\"availability_zone\":\"{zone}\"%7D%7D")
ListenableFuture<HostAggregate> updateAvailabilityZone(@PathParam("id") String id, @PayloadParam("zone") String availabilityZone);
@WrapWith("aggregate")
ListenableFuture<HostAggregate> updateAvailabilityZone(@PathParam("id") String id, @PayloadParam("availability_zone") String availabilityZone);
/**
* @see HostAggregateClient#deleteAggregate(String)
@ -127,7 +126,7 @@ public interface HostAggregateAsyncClient {
@SelectJson("aggregate")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Payload("%7B\"add_host\":%7B\"host\":\"{host}\"%7D%7D")
@WrapWith("add_host")
ListenableFuture<HostAggregate> addHost(@PathParam("id") String id, @PayloadParam("host") String host);
@ -139,7 +138,7 @@ public interface HostAggregateAsyncClient {
@SelectJson("aggregate")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Payload("%7B\"remove_host\":%7B\"host\":\"{host}\"%7D%7D")
@WrapWith("remove_host")
ListenableFuture<HostAggregate> removeHost(@PathParam("id") String id, @PayloadParam("host") String host);
/**
@ -150,6 +149,6 @@ public interface HostAggregateAsyncClient {
@SelectJson("aggregate")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@MapBinder(BindAggregateMetadataToJsonPayload.class)
ListenableFuture<HostAggregate> setMetadata(@PathParam("id") String id, Map<String, String> metadata);
@WrapWith("set_metadata")
ListenableFuture<HostAggregate> setMetadata(@PathParam("id") String id, @PayloadParam("metadata") Map<String, String> metadata);
}

View File

@ -30,14 +30,15 @@ import javax.ws.rs.core.MediaType;
import org.jclouds.concurrent.Timeout;
import org.jclouds.openstack.filters.AuthenticateRequest;
import org.jclouds.openstack.nova.v1_1.binders.BindQuotasToJsonPayload;
import org.jclouds.openstack.nova.v1_1.domain.Quotas;
import org.jclouds.openstack.services.Extension;
import org.jclouds.openstack.services.ServiceType;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.binders.BindToJsonPayload;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import com.google.common.util.concurrent.ListenableFuture;
@ -71,8 +72,8 @@ public interface QuotaAsyncClient {
@PUT
@Path("/{tenant_id}")
@Produces(MediaType.APPLICATION_JSON)
@MapBinder(BindQuotasToJsonPayload.class)
ListenableFuture<Boolean> updateQuotasForTenant(@PathParam("tenant_id") String tenantId, Quotas quotas);
@MapBinder(BindToJsonPayload.class)
ListenableFuture<Boolean> updateQuotasForTenant(@PathParam("tenant_id") String tenantId, @PayloadParam("quota_set") Quotas quotas);
/**
* @see QuotaClient#getDefaultQuotasForTenant(String)

View File

@ -30,15 +30,16 @@ import javax.ws.rs.core.MediaType;
import org.jclouds.concurrent.Timeout;
import org.jclouds.openstack.filters.AuthenticateRequest;
import org.jclouds.openstack.nova.v1_1.binders.BindQuotaClassToJsonPayload;
import org.jclouds.openstack.nova.v1_1.domain.QuotaClass;
import org.jclouds.openstack.nova.v1_1.domain.Quotas;
import org.jclouds.openstack.services.Extension;
import org.jclouds.openstack.services.ServiceType;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.WrapWith;
import org.jclouds.rest.binders.BindToJsonPayload;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import com.google.common.util.concurrent.ListenableFuture;
@ -73,7 +74,7 @@ public interface QuotaClassAsyncClient {
@PUT
@Path("/{id}")
@Produces(MediaType.APPLICATION_JSON)
@MapBinder(BindQuotaClassToJsonPayload.class)
ListenableFuture<Boolean> updateQuotaClass(@PathParam("id") String id, QuotaClass quotas);
@MapBinder(BindToJsonPayload.class)
ListenableFuture<Boolean> updateQuotaClass(@PathParam("id") String id, @PayloadParam("quota_class_set") QuotaClass quotas);
}

View File

@ -44,6 +44,7 @@ import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.WrapWith;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
@ -156,8 +157,8 @@ public interface VolumeAsyncClient {
@SelectJson("volumeAttachment")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Payload("%7B\"volumeAttachment\":%7B\"volumeId\":\"{id}\",\"device\":\"{device}\"%7D%7D")
ListenableFuture<VolumeAttachment> attachVolumeToServerAsDevice(@PayloadParam("id") String volumeId,
@WrapWith("volumeAttachment")
ListenableFuture<VolumeAttachment> attachVolumeToServerAsDevice(@PayloadParam("volumeId") String volumeId,
@PathParam("server_id") String serverId, @PayloadParam("device") String device);
/**

View File

@ -20,7 +20,6 @@ package org.jclouds.openstack.nova.v1_1.extensions;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
@ -32,9 +31,7 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.jclouds.concurrent.Timeout;
import org.jclouds.openstack.filters.AuthenticateRequest;
import org.jclouds.openstack.nova.v1_1.binders.BindExtraSpecsToJsonPayload;
import org.jclouds.openstack.nova.v1_1.domain.VolumeType;
import org.jclouds.openstack.nova.v1_1.options.CreateVolumeTypeOptions;
import org.jclouds.openstack.services.Extension;
@ -47,6 +44,8 @@ import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.Unwrap;
import org.jclouds.rest.annotations.WrapWith;
import org.jclouds.rest.binders.BindToJsonPayload;
import org.jclouds.rest.functions.ReturnEmptyMapOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404;
@ -91,7 +90,7 @@ public interface VolumeTypeAsyncClient {
@POST
@SelectJson("volume_type")
@Produces(MediaType.APPLICATION_JSON)
@Payload("%7B\"volume_type\":%7B\"name\":\"{name}\"%7D%7D")
@WrapWith("volume_type")
ListenableFuture<VolumeType> createVolumeType(@PayloadParam("name") String name, CreateVolumeTypeOptions... options);
/**
@ -118,8 +117,8 @@ public interface VolumeTypeAsyncClient {
@Path("/{id}/extra_specs")
@Produces(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnFalseOnNotFoundOr404.class)
@MapBinder(BindExtraSpecsToJsonPayload.class)
ListenableFuture<Boolean> setAllExtraSpecs(@PathParam("id") String id, Map<String, String> specs);
@MapBinder(BindToJsonPayload.class)
ListenableFuture<Boolean> setAllExtraSpecs(@PathParam("id") String id, @PayloadParam("extra_specs") Map<String, String> specs);
/**
* @see VolumeTypeClient#getExtraSpec(String, String)

View File

@ -46,7 +46,7 @@ public class CreateBackupOfServerOptions implements MapBinder {
private Map<String, String> metadata = ImmutableMap.of();
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
Map<String, Object> data = Maps.newHashMap();
data.putAll(postParams);
data.put("metadata", metadata);

View File

@ -166,10 +166,10 @@ public class CreateServerOptions implements MapBinder {
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
ServerRequest server = new ServerRequest(checkNotNull(postParams.get("name"), "name parameter not present"),
checkNotNull(postParams.get("imageRef"), "imageRef parameter not present"), checkNotNull(
postParams.get("flavorRef"), "flavorRef parameter not present"));
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
ServerRequest server = new ServerRequest(checkNotNull(postParams.get("name"), "name parameter not present").toString(),
checkNotNull(postParams.get("imageRef"), "imageRef parameter not present").toString(),
checkNotNull(postParams.get("flavorRef"), "flavorRef parameter not present").toString());
if (metadata.size() > 0)
server.metadata = metadata;
if (personality.size() > 0)

View File

@ -54,7 +54,7 @@ public class CreateVolumeOptions implements MapBinder {
private Map<String, String> metadata = ImmutableMap.of();
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
Map<String, Object> image = Maps.newHashMap();
image.putAll(postParams);
if (name != null)

View File

@ -48,8 +48,8 @@ public class CreateVolumeSnapshotOptions implements MapBinder {
private boolean force = false;
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
Map<String, String> data = Maps.newHashMap(postParams);
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
Map<String, Object> data = Maps.newHashMap(postParams);
if (name != null)
data.put("display_name", name);
if (description != null)

View File

@ -46,7 +46,7 @@ public class CreateVolumeTypeOptions implements MapBinder {
protected Map<String, String> specs = ImmutableMap.of();
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
Map<String, Object> data = Maps.newHashMap();
data.putAll(postParams);
data.put("extra_specs", specs);

View File

@ -44,7 +44,7 @@ public class RebuildServerOptions implements MapBinder {
String imageRef;
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
Map<String, String> image = Maps.newHashMap();
if (imageRef != null)
image.put("imageRef", imageRef);

View File

@ -294,7 +294,7 @@ public class AdminActionsClientExpectTest extends BaseNovaClientExpectTest {
keystoneAuthWithUsernameAndPassword,
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardRequestBuilder(endpoint).method("POST")
.payload(payloadFromStringWithContentType("{\"createBackup\":{\"backup_type\":\"weekly\",\"rotation\":\"3\",\"name\":\"mybackup\",\"metadata\":{\"some\":\"data or other\"}}}", MediaType.APPLICATION_JSON)).build(),
.payload(payloadFromStringWithContentType("{\"createBackup\":{\"backup_type\":\"weekly\",\"rotation\":3,\"name\":\"mybackup\",\"metadata\":{\"some\":\"data or other\"}}}", MediaType.APPLICATION_JSON)).build(),
standardResponseBuilder(202).headers(ImmutableMultimap.of("Location", "http://172.16.89.149:8774/v2/images/1976b3b3-409a-468d-b16c-a9172c341b46")).build()
).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get();
@ -309,7 +309,7 @@ public class AdminActionsClientExpectTest extends BaseNovaClientExpectTest {
keystoneAuthWithUsernameAndPassword,
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardRequestBuilder(endpoint).method("POST")
.payload(payloadFromStringWithContentType("{\"createBackup\":{\"backup_type\":\"weekly\",\"rotation\":\"3\",\"name\":\"mybackup\",\"metadata\":{\"some\":\"data or other\"}}}", MediaType.APPLICATION_JSON)).build(),
.payload(payloadFromStringWithContentType("{\"createBackup\":{\"backup_type\":\"weekly\",\"rotation\":3,\"name\":\"mybackup\",\"metadata\":{\"some\":\"data or other\"}}}", MediaType.APPLICATION_JSON)).build(),
standardResponseBuilder(404).build()
).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get();
@ -322,7 +322,7 @@ public class AdminActionsClientExpectTest extends BaseNovaClientExpectTest {
keystoneAuthWithUsernameAndPassword,
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "GONNAOVERWRITE")
.payload(payloadFromStringWithContentType("{\"os-migrateLive\":{\"host\":\"bighost\",\"block_migration\":\"true\",\"disk_over_commit\":\"false\"}}", MediaType.APPLICATION_JSON)).build(),
.payload(payloadFromStringWithContentType("{\"os-migrateLive\":{\"host\":\"bighost\",\"block_migration\":true,\"disk_over_commit\":false}}", MediaType.APPLICATION_JSON)).build(),
standardResponseBuilder(202).build()
).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get();
@ -335,7 +335,7 @@ public class AdminActionsClientExpectTest extends BaseNovaClientExpectTest {
keystoneAuthWithUsernameAndPassword,
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "GONNAOVERWRITE")
.payload(payloadFromStringWithContentType("{\"os-migrateLive\":{\"host\":\"bighost\",\"block_migration\":\"true\",\"disk_over_commit\":\"false\"}}", MediaType.APPLICATION_JSON)).build(),
.payload(payloadFromStringWithContentType("{\"os-migrateLive\":{\"host\":\"bighost\",\"block_migration\":true,\"disk_over_commit\":false}}", MediaType.APPLICATION_JSON)).build(),
standardResponseBuilder(404).build()
).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get();

View File

@ -111,7 +111,7 @@ public class VolumeClientExpectTest extends BaseNovaClientExpectTest {
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardRequestBuilder(endpoint)
.method("POST")
.payload(payloadFromStringWithContentType("{\"volume\":{\"display_name\":\"jclouds-test-volume\",\"display_description\":\"description of test volume\",\"size\":\"1\"}}", MediaType.APPLICATION_JSON))
.payload(payloadFromStringWithContentType("{\"volume\":{\"display_name\":\"jclouds-test-volume\",\"display_description\":\"description of test volume\",\"size\":1}}", MediaType.APPLICATION_JSON))
.build(),
standardResponseBuilder(200).payload(payloadFromResource("/volume_details.json")).build()
).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
@ -129,7 +129,7 @@ public class VolumeClientExpectTest extends BaseNovaClientExpectTest {
standardRequestBuilder(endpoint)
.endpoint(endpoint)
.method("POST")
.payload(payloadFromStringWithContentType("{\"volume\":{\"display_name\":\"jclouds-test-volume\",\"display_description\":\"description of test volume\",\"size\":\"1\"}}", MediaType.APPLICATION_JSON))
.payload(payloadFromStringWithContentType("{\"volume\":{\"display_name\":\"jclouds-test-volume\",\"display_description\":\"description of test volume\",\"size\":1}}", MediaType.APPLICATION_JSON))
.build(),
standardResponseBuilder(404).payload(payloadFromResource("/volume_details.json")).build()
).getVolumeExtensionForZone("az-1.region-a.geo-1").get();

View File

@ -64,13 +64,13 @@ public class BindCaptureVAppParamsToXmlPayload implements MapBinder {
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest<?>,
"this binder is only valid for GeneratedHttpRequests!");
GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request;
checkState(gRequest.getArgs() != null, "args should be initialized at this point");
String templateName = checkNotNull(postParams.remove("templateName"), "templateName");
String vApp = checkNotNull(postParams.remove("vApp"), "vApp");
String templateName = checkNotNull(postParams.remove("templateName"), "templateName").toString();
String vApp = checkNotNull(postParams.remove("vApp"), "vApp").toString();
CaptureVAppOptions options = findOptionsInArgsOrNull(gRequest);
if (options == null) {

View File

@ -65,13 +65,13 @@ public class BindCatalogItemToXmlPayload implements MapBinder {
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest<?>,
"this binder is only valid for GeneratedHttpRequests!");
GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request;
checkState(gRequest.getArgs() != null, "args should be initialized at this point");
String name = checkNotNull(postParams.get("name"), "name");
URI entity = URI.create(checkNotNull(postParams.get("Entity"), "Entity"));
String name = checkNotNull(postParams.get("name"), "name").toString();
URI entity = URI.create(checkNotNull(postParams.get("Entity"), "Entity").toString());
CatalogItemOptions options = findOptionsInArgsOrNew(gRequest);
try {

View File

@ -65,14 +65,14 @@ public abstract class BindCloneParamsToXmlPayload<O extends CloneOptions> implem
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest<?>,
"this binder is only valid for GeneratedHttpRequests!");
GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request;
checkState(gRequest.getArgs() != null, "args should be initialized at this point");
String name = checkNotNull(postParams.get("name"), "name");
String source = checkNotNull(postParams.get("Source"), "Source");
boolean isSourceDelete = Boolean.parseBoolean(postParams.get("IsSourceDelete"));
String name = checkNotNull(postParams.get("name"), "name").toString();
String source = checkNotNull(postParams.get("Source"), "Source").toString();
boolean isSourceDelete = Boolean.parseBoolean((String) postParams.get("IsSourceDelete"));
O options = findOptionsInArgsOrNew(gRequest);
return stringBinder.bindToRequest(request, generateXml(name, source, isSourceDelete, options));

View File

@ -88,13 +88,13 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest<?>,
"this binder is only valid for GeneratedHttpRequests!");
GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request;
checkState(gRequest.getArgs() != null, "args should be initialized at this point");
String name = checkNotNull(postParams.remove("name"), "name");
URI template = URI.create(checkNotNull(postParams.remove("template"), "template"));
String name = checkNotNull(postParams.remove("name"), "name").toString();
URI template = URI.create(checkNotNull(postParams.remove("template"), "template").toString());
Set<NetworkConfig> networkConfig = null;

View File

@ -57,7 +57,7 @@ public class BindParamsToXmlPayload implements MapBinder {
this.stringBinder = stringBinder;
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
try {
return stringBinder.bindToRequest(request, generateXml(postParams));
} catch (Exception e) {
@ -65,11 +65,11 @@ public class BindParamsToXmlPayload implements MapBinder {
}
}
private String generateXml(Map<String, String> postParams) throws ParserConfigurationException,
private String generateXml(Map<String, Object> postParams) throws ParserConfigurationException,
FactoryConfigurationError, TransformerException {
XMLBuilder rootBuilder = XMLBuilder.create(element);
for (Entry<String, String> entry : postParams.entrySet())
rootBuilder.a(entry.getKey(), entry.getValue());
for (Entry<String, Object> entry : postParams.entrySet())
rootBuilder.a(entry.getKey(), (String) entry.getValue());
rootBuilder.a("xmlns", ns);
Properties outputProperties = new Properties();
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");

View File

@ -67,7 +67,7 @@ public class BindCatalogItemToXmlPayloadTest {
BindCatalogItemToXmlPayload binder = injector.getInstance(BindCatalogItemToXmlPayload.class);
Map<String, String> map = ImmutableMap.of("name", "myname", "Entity", "http://fooentity");
Map<String, Object> map = ImmutableMap.<String, Object>of("name", "myname", "Entity", "http://fooentity");
binder.bindToRequest(request, map);
verify(request);

View File

@ -72,7 +72,7 @@ public class BindCloneVAppParamsToXmlPayloadTest {
BindCloneVAppParamsToXmlPayload binder = injector.getInstance(BindCloneVAppParamsToXmlPayload.class);
Builder<String, String> map = ImmutableMap.builder();
Builder<String, Object> map = ImmutableMap.builder();
map.put("name", "new-linux-server");
map.put("Source", "https://vcenterprise.bluelock.com/api/v1.0/vapp/201");
binder.bindToRequest(request, map.build());
@ -92,7 +92,7 @@ public class BindCloneVAppParamsToXmlPayloadTest {
BindCloneVAppParamsToXmlPayload binder = injector.getInstance(BindCloneVAppParamsToXmlPayload.class);
Builder<String, String> map = ImmutableMap.builder();
Builder<String, Object> map = ImmutableMap.builder();
map.put("name", "new-linux-server");
map.put("Source", "https://vcenterprise.bluelock.com/api/v1.0/vapp/201");
map.put("IsSourceDelete", "true");
@ -111,7 +111,7 @@ public class BindCloneVAppParamsToXmlPayloadTest {
BindCloneVAppParamsToXmlPayload binder = injector.getInstance(BindCloneVAppParamsToXmlPayload.class);
Builder<String, String> map = ImmutableMap.builder();
Builder<String, Object> map = ImmutableMap.builder();
map.put("name", "my-vapp");
map.put("Source", "https://vcenterprise.bluelock.com/api/v1.0/vapp/4181");
binder.bindToRequest(request, map.build());

View File

@ -73,7 +73,7 @@ public class BindCloneVAppTemplateParamsToXmlPayloadTest {
BindCloneVAppTemplateParamsToXmlPayload binder = injector
.getInstance(BindCloneVAppTemplateParamsToXmlPayload.class);
Builder<String, String> map = ImmutableMap.builder();
Builder<String, Object> map = ImmutableMap.builder();
map.put("name", "new-linux-server");
map.put("Source", "https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/201");
binder.bindToRequest(request, map.build());
@ -94,7 +94,7 @@ public class BindCloneVAppTemplateParamsToXmlPayloadTest {
BindCloneVAppTemplateParamsToXmlPayload binder = injector
.getInstance(BindCloneVAppTemplateParamsToXmlPayload.class);
Builder<String, String> map = ImmutableMap.builder();
Builder<String, Object> map = ImmutableMap.builder();
map.put("name", "new-linux-server");
map.put("Source", "https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/201");
map.put("IsSourceDelete", "true");
@ -114,7 +114,7 @@ public class BindCloneVAppTemplateParamsToXmlPayloadTest {
BindCloneVAppTemplateParamsToXmlPayload binder = injector
.getInstance(BindCloneVAppTemplateParamsToXmlPayload.class);
Builder<String, String> map = ImmutableMap.builder();
Builder<String, Object> map = ImmutableMap.builder();
map.put("name", "my-vapptemplate");
map.put("Source", "https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/4181");
binder.bindToRequest(request, map.build());

View File

@ -62,7 +62,7 @@ public class BindDeployVAppParamsToXmlPayloadTest {
BindDeployVAppParamsToXmlPayload binder = injector.getInstance(BindDeployVAppParamsToXmlPayload.class);
Map<String, String> map = Maps.newHashMap();
Map<String, Object> map = Maps.newHashMap();
map.put("powerOn", "true");
binder.bindToRequest(request, map);
verify(request);
@ -78,7 +78,7 @@ public class BindDeployVAppParamsToXmlPayloadTest {
BindDeployVAppParamsToXmlPayload binder = injector.getInstance(BindDeployVAppParamsToXmlPayload.class);
Map<String, String> map = Maps.newHashMap();
Map<String, Object> map = Maps.newHashMap();
binder.bindToRequest(request, map);
verify(request);

View File

@ -126,7 +126,7 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest {
BindInstantiateVAppTemplateParamsToXmlPayload binder = createInjector(templateUri, template).getInstance(
BindInstantiateVAppTemplateParamsToXmlPayload.class);
Map<String, String> map = Maps.newHashMap();
Map<String, Object> map = Maps.newHashMap();
map.put("name", "my-vapp");
map.put("template", templateUri.toASCIIString());
binder.bindToRequest(request, map);
@ -151,7 +151,7 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest {
BindInstantiateVAppTemplateParamsToXmlPayload binder = createInjector(templateUri, template).getInstance(
BindInstantiateVAppTemplateParamsToXmlPayload.class);
Map<String, String> map = Maps.newHashMap();
Map<String, Object> map = Maps.newHashMap();
map.put("name", "my-vapp");
map.put("template", templateUri.toASCIIString());
binder.bindToRequest(request, map);
@ -174,7 +174,7 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest {
BindInstantiateVAppTemplateParamsToXmlPayload binder = createInjector(templateUri, template).getInstance(
BindInstantiateVAppTemplateParamsToXmlPayload.class);
Map<String, String> map = Maps.newHashMap();
Map<String, Object> map = Maps.newHashMap();
map.put("name", "my-vapp");
map.put("template", templateUri.toASCIIString());
binder.bindToRequest(request, map);
@ -200,7 +200,7 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest {
BindInstantiateVAppTemplateParamsToXmlPayload binder = createInjector(templateUri, template).getInstance(
BindInstantiateVAppTemplateParamsToXmlPayload.class);
Map<String, String> map = Maps.newHashMap();
Map<String, Object> map = Maps.newHashMap();
map.put("name", "my-vapp");
map.put("template", "https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/3");
@ -227,7 +227,7 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest {
BindInstantiateVAppTemplateParamsToXmlPayload binder = createInjector(templateUri, template).getInstance(
BindInstantiateVAppTemplateParamsToXmlPayload.class);
Map<String, String> map = Maps.newHashMap();
Map<String, Object> map = Maps.newHashMap();
map.put("name", "my-vapp");
map.put("template", "https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/3");

View File

@ -62,7 +62,7 @@ public class BindUndeployVAppParamsToXmlPayloadTest {
BindUndeployVAppParamsToXmlPayload binder = injector.getInstance(BindUndeployVAppParamsToXmlPayload.class);
Map<String, String> map = Maps.newHashMap();
Map<String, Object> map = Maps.newHashMap();
map.put("saveState", "true");
binder.bindToRequest(request, map);
verify(request);
@ -78,7 +78,7 @@ public class BindUndeployVAppParamsToXmlPayloadTest {
BindUndeployVAppParamsToXmlPayload binder = injector.getInstance(BindUndeployVAppParamsToXmlPayload.class);
Map<String, String> map = Maps.newHashMap();
Map<String, Object> map = Maps.newHashMap();
binder.bindToRequest(request, map);
verify(request);

View File

@ -48,7 +48,7 @@ public class BindCredentialsToJsonPayload extends BindToJsonPayload implements M
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
return super.bindToRequest(request, ImmutableMap.of("credentials", postParams));
}

View File

@ -67,7 +67,7 @@ public class BindAuthToJsonPayload extends BindToJsonPayload implements MapBinde
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest<?>,
"this binder is only valid for GeneratedHttpRequests!");
GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request;
@ -77,7 +77,7 @@ public class BindAuthToJsonPayload extends BindToJsonPayload implements MapBinde
addCredentialsInArgsOrNull(gRequest, builder);
// TODO: is tenantName permanent? or should we switch to tenantId at some point. seems most tools
// still use tenantName
if (Strings.emptyToNull(postParams.get("tenantName")) != null)
if (!Strings.isNullOrEmpty((String) postParams.get("tenantName")))
builder.put("tenantName", postParams.get("tenantName"));
return super.bindToRequest(request, ImmutableMap.of("auth", builder.build()));
}

View File

@ -54,13 +54,13 @@ public class BindAddInternetServiceToXmlPayload implements MapBinder {
private String ns;
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
String name = checkNotNull(postParams.get("name"), "name parameter not present");
String protocol = checkNotNull(postParams.get("protocol"), "protocol parameter not present");
String port = checkNotNull(postParams.get("port"), "port parameter not present");
String enabled = checkNotNull(postParams.get("enabled"), "enabled parameter not present");
String description = postParams.get("description");
String name = checkNotNull(postParams.get("name"), "name parameter not present").toString();
String protocol = checkNotNull(postParams.get("protocol"), "protocol parameter not present").toString();
String port = checkNotNull(postParams.get("port"), "port parameter not present").toString();
String enabled = checkNotNull(postParams.get("enabled"), "enabled parameter not present").toString();
String description = (String) postParams.get("description");
String payload = Strings2.replaceTokens(xmlTemplate,
ImmutableMap.of("name", name, "protocol", protocol, "port", port, "enabled", enabled, "ns", ns));
try {
@ -73,10 +73,10 @@ public class BindAddInternetServiceToXmlPayload implements MapBinder {
return stringBinder.bindToRequest(request, payload);
}
private String getMonitorString(Map<String, String> postParams)
private String getMonitorString(Map<String, Object> postParams)
{
// Sending no <Monitor> element to Terremark will result in default behavior, which is to create a monitor.
String monitor = postParams.get("monitor");
String monitor = (String) postParams.get("monitor");
if (monitor == null || "true".equalsIgnoreCase(monitor)) {
return "";
}

View File

@ -55,12 +55,12 @@ public class BindAddNodeServiceToXmlPayload implements MapBinder {
private String ns;
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
String ipAddress = checkNotNull(postParams.get("ipAddress"), "ipAddress parameter not present");
String name = checkNotNull(postParams.get("name"), "name parameter not present");
String port = checkNotNull(postParams.get("port"), "port parameter not present");
String enabled = checkNotNull(postParams.get("enabled"), "enabled parameter not present");
String description = postParams.get("description");
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
String ipAddress = checkNotNull(postParams.get("ipAddress"), "ipAddress parameter not present").toString();
String name = checkNotNull(postParams.get("name"), "name parameter not present").toString();
String port = checkNotNull(postParams.get("port"), "port parameter not present").toString();
String enabled = checkNotNull(postParams.get("enabled"), "enabled parameter not present").toString();
String description = (String) postParams.get("description");
String payload = Strings2.replaceTokens(xmlTemplate,
ImmutableMap.of("name", name, "ipAddress", ipAddress, "port", port, "enabled", enabled, "ns", ns));

View File

@ -64,13 +64,13 @@ public class BindCloneVAppParamsToXmlPayload implements MapBinder {
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest<?>,
"this binder is only valid for GeneratedHttpRequests!");
GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request;
checkState(gRequest.getArgs() != null, "args should be initialized at this point");
String newName = checkNotNull(postParams.remove("newName"), "newName");
String vApp = checkNotNull(postParams.remove("vApp"), "vApp");
String newName = checkNotNull(postParams.remove("newName"), "newName").toString();
String vApp = checkNotNull(postParams.remove("vApp"), "vApp").toString();
CloneVAppOptions options = findOptionsInArgsOrNull(gRequest);
if (options == null) {

View File

@ -55,9 +55,9 @@ public class BindCreateKeyToXmlPayload implements MapBinder {
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
String name = checkNotNull(postParams.get("name"), "name parameter not present");
String isDefault = checkNotNull(postParams.get("isDefault"), "isDefault parameter not present");
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
String name = checkNotNull(postParams.get("name"), "name parameter not present").toString();
String isDefault = checkNotNull(postParams.get("isDefault"), "isDefault parameter not present").toString();
String payload = Strings2.replaceTokens(xmlTemplate,
ImmutableMap.of("name", name, "isDefault", isDefault, "ns", ns));

View File

@ -83,13 +83,13 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest<?>,
"this binder is only valid for GeneratedHttpRequests!");
GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request;
checkState(gRequest.getArgs() != null, "args should be initialized at this point");
String name = checkNotNull(postParams.remove("name"), "name");
String template = checkNotNull(postParams.remove("template"), "template");
String name = checkNotNull(postParams.remove("name"), "name").toString();
String template = checkNotNull(postParams.remove("template"), "template").toString();
SortedMap<ResourceType, String> virtualHardwareQuantity = Maps.newTreeMap();

View File

@ -55,21 +55,21 @@ public class BindNodeConfigurationToXmlPayload implements MapBinder {
this.stringBinder = stringBinder;
}
protected String generateXml(Map<String, String> postParams) throws ParserConfigurationException,
protected String generateXml(Map<String, Object> postParams) throws ParserConfigurationException,
FactoryConfigurationError, TransformerException {
XMLBuilder rootBuilder = XMLBuilder.create("NodeService").a("xmlns", ns).a("xmlns:xsi",
"http://www.w3.org/2001/XMLSchema-instance").a("xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
rootBuilder.e("Name").t(checkNotNull(postParams.get("name"), "name"));
rootBuilder.e("Enabled").t(checkNotNull(postParams.get("enabled"), "enabled"));
rootBuilder.e("Name").t(checkNotNull(postParams.get("name"), "name").toString());
rootBuilder.e("Enabled").t(checkNotNull(postParams.get("enabled"), "enabled").toString());
if (postParams.containsKey("description") && postParams.get("description") != null)
rootBuilder.e("Description").t(postParams.get("description"));
rootBuilder.e("Description").t((String) postParams.get("description"));
Properties outputProperties = new Properties();
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
return rootBuilder.asString(outputProperties);
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
try {
return stringBinder.bindToRequest(request, generateXml(postParams));
} catch (Exception e) {

View File

@ -78,7 +78,7 @@ public class BindVAppConfigurationToXmlPayload implements MapBinder, Function<Ob
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest<?>,
"this binder is only valid for GeneratedHttpRequests!");
GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request;

View File

@ -41,8 +41,8 @@ public class AddInternetServiceOptions extends BindAddInternetServiceToXmlPayloa
Boolean monitorEnabled = null;
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
ImmutableMap.Builder<String, String> copy = ImmutableMap.builder();
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
ImmutableMap.Builder<String, Object> copy = ImmutableMap.builder();
copy.putAll(postParams);
if (description != null)
copy.put("description", description);

View File

@ -38,8 +38,8 @@ public class AddNodeOptions extends BindAddNodeServiceToXmlPayload {
@VisibleForTesting
String enabled = "true";
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
Map<String, String> copy = Maps.newHashMap();
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
Map<String, Object> copy = Maps.newHashMap();
copy.putAll(postParams);
copy.put("description", description);
copy.put("enabled", enabled);

View File

@ -73,7 +73,7 @@ public class BindAddInternetServiceToXmlPayloadTest {
BindAddInternetServiceToXmlPayload binder = injector
.getInstance(BindAddInternetServiceToXmlPayload.class);
Map<String, String> map = Maps.newHashMap();
Map<String, Object> map = Maps.newHashMap();
map.put("name", "name");
map.put("protocol", "TCP");
map.put("port", "22");
@ -88,7 +88,7 @@ public class BindAddInternetServiceToXmlPayloadTest {
BindAddInternetServiceToXmlPayload binder = injector
.getInstance(BindAddInternetServiceToXmlPayload.class);
Map<String, String> map = Maps.newHashMap();
Map<String, Object> map = Maps.newHashMap();
map.put("name", "name");
map.put("protocol", "TCP");
map.put("port", "22");
@ -106,7 +106,7 @@ public class BindAddInternetServiceToXmlPayloadTest {
BindAddInternetServiceToXmlPayload binder = injector
.getInstance(BindAddInternetServiceToXmlPayload.class);
Map<String, String> map = Maps.newHashMap();
Map<String, Object> map = Maps.newHashMap();
map.put("name", "name");
map.put("protocol", "TCP");
map.put("port", "22");

View File

@ -72,7 +72,7 @@ public class BindAddNodeServiceToXmlPayloadTest {
BindAddNodeServiceToXmlPayload binder = injector
.getInstance(BindAddNodeServiceToXmlPayload.class);
Map<String, String> map = Maps.newHashMap();
Map<String, Object> map = Maps.newHashMap();
map.put("name", "Node for Jim");
map.put("ipAddress", "172.16.20.3");
map.put("port", "80");

View File

@ -72,7 +72,7 @@ public class BindCloneVAppParamsToXmlPayloadTest {
BindCloneVAppParamsToXmlPayload binder = injector.getInstance(BindCloneVAppParamsToXmlPayload.class);
Map<String, String> map = Maps.newHashMap();
Map<String, Object> map = Maps.newHashMap();
map.put("newName", "new-linux-server");
map.put("vApp", "https://vcloud.safesecureweb.com/api/v0.8/vapp/201");
binder.bindToRequest(request, map);
@ -90,7 +90,7 @@ public class BindCloneVAppParamsToXmlPayloadTest {
BindCloneVAppParamsToXmlPayload binder = injector.getInstance(BindCloneVAppParamsToXmlPayload.class);
Map<String, String> map = Maps.newHashMap();
Map<String, Object> map = Maps.newHashMap();
map.put("newName", "my-vapp");
map.put("vApp", "https://vcloud.safesecureweb.com/api/v0.8/vapp/4181");
binder.bindToRequest(request, map);

View File

@ -94,7 +94,7 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest {
BindInstantiateVAppTemplateParamsToXmlPayload binder = injector
.getInstance(BindInstantiateVAppTemplateParamsToXmlPayload.class);
Map<String, String> map = Maps.newHashMap();
Map<String, Object> map = Maps.newHashMap();
map.put("name", "name");
map.put("template", "https://vcloud/vAppTemplate/3");
binder.bindToRequest(request, map);

View File

@ -64,27 +64,27 @@ public class BindNodeConfigurationToXmlPayloadTest {
public void testChangeDescription() throws IOException {
String expectedPayload = "<NodeService xmlns=\"urn:tmrk:vCloudExpressExtensions-1.6\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Name>willie</Name><Enabled>true</Enabled><Description>description</Description></NodeService>";
assertConfigMakesPayload(ImmutableMap.<String, String> of("name", "willie", "enabled", "true", "description",
assertConfigMakesPayload(ImmutableMap.<String, Object> of("name", "willie", "enabled", "true", "description",
"description"), expectedPayload);
}
public void testDisableTraffic() throws IOException {
String expectedPayload = "<NodeService xmlns=\"urn:tmrk:vCloudExpressExtensions-1.6\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Name>willie</Name><Enabled>false</Enabled></NodeService>";
assertConfigMakesPayload(ImmutableMap.<String, String> of("name", "willie", "enabled", "false"), expectedPayload);
assertConfigMakesPayload(ImmutableMap.<String, Object> of("name", "willie", "enabled", "false"), expectedPayload);
}
public void testTwoOptions() throws IOException {
String expectedPayload = "<NodeService xmlns=\"urn:tmrk:vCloudExpressExtensions-1.6\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Name>willie</Name><Enabled>true</Enabled></NodeService>";
assertConfigMakesPayload(ImmutableMap.<String, String> of("name", "willie", "enabled", "true"), expectedPayload);
assertConfigMakesPayload(ImmutableMap.<String, Object> of("name", "willie", "enabled", "true"), expectedPayload);
}
@Test(expectedExceptions = NullPointerException.class)
public void testNoOptions() throws IOException {
String expectedPayload = "<NodeService xmlns=\"urn:tmrk:vCloudExpressExtensions-1.6\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Name>willie</Name><Enabled>false</Enabled></NodeService>";
assertConfigMakesPayload(ImmutableMap.<String, String> of(), expectedPayload);
assertConfigMakesPayload(ImmutableMap.<String, Object> of(), expectedPayload);
}
private void assertConfigMakesPayload(Map<String, String> config, String expectedPayload) {
private void assertConfigMakesPayload(Map<String, Object> config, String expectedPayload) {
BindNodeConfigurationToXmlPayload binder = injector.getInstance(BindNodeConfigurationToXmlPayload.class);
HttpRequest request = createMock(HttpRequest.class);
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();

View File

@ -88,7 +88,7 @@ public class BindVAppConfigurationToXmlPayloadTest {
BindVAppConfigurationToXmlPayload binder = injector.getInstance(BindVAppConfigurationToXmlPayload.class);
Map<String, String> map = Maps.newHashMap();
Map<String, Object> map = Maps.newHashMap();
binder.bindToRequest(request, map);
verify(request);
}
@ -124,7 +124,7 @@ public class BindVAppConfigurationToXmlPayloadTest {
BindVAppConfigurationToXmlPayload binder = injector.getInstance(BindVAppConfigurationToXmlPayload.class);
Map<String, String> map = Maps.newHashMap();
Map<String, Object> map = Maps.newHashMap();
binder.bindToRequest(request, map);
verify(request);
}
@ -153,7 +153,7 @@ public class BindVAppConfigurationToXmlPayloadTest {
BindVAppConfigurationToXmlPayload binder = injector.getInstance(BindVAppConfigurationToXmlPayload.class);
Map<String, String> map = Maps.newHashMap();
Map<String, Object> map = Maps.newHashMap();
binder.bindToRequest(request, map);
verify(request);
}
@ -180,7 +180,7 @@ public class BindVAppConfigurationToXmlPayloadTest {
BindVAppConfigurationToXmlPayload binder = injector.getInstance(BindVAppConfigurationToXmlPayload.class);
Map<String, String> map = Maps.newHashMap();
Map<String, Object> map = Maps.newHashMap();
binder.bindToRequest(request, map);
verify(request);
}
@ -209,7 +209,7 @@ public class BindVAppConfigurationToXmlPayloadTest {
BindVAppConfigurationToXmlPayload binder = injector.getInstance(BindVAppConfigurationToXmlPayload.class);
Map<String, String> map = Maps.newHashMap();
Map<String, Object> map = Maps.newHashMap();
binder.bindToRequest(request, map);
verify(request);
}

View File

@ -39,7 +39,7 @@ import com.google.gson.JsonSerializer;
@SuppressWarnings("unchecked")
public class EnumTypeAdapterThatReturnsFromValue<T extends Enum<T>> implements JsonSerializer<T>, JsonDeserializer<T> {
public JsonElement serialize(T src, Type typeOfSrc, JsonSerializationContext context) {
return new JsonPrimitive(src.name());
return new JsonPrimitive(src.toString());
}
@SuppressWarnings("cast")

View File

@ -35,5 +35,5 @@ public interface MapBinder extends Binder {
*
* @see org.jclouds.rest.annotations.PayloadParam
*/
<R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams);
<R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams);
}

View File

@ -50,7 +50,7 @@ public class BindMapToStringPayload implements MapBinder {
@SuppressWarnings("unchecked")
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
checkNotNull(postParams, "postParams");
GeneratedHttpRequest<?> r = GeneratedHttpRequest.class.cast(checkNotNull(request, "request"));
checkArgument(r.getJavaMethod().isAnnotationPresent(Payload.class),

View File

@ -44,7 +44,7 @@ public class BindToJsonPayload implements MapBinder {
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
return bindToRequest(request, (Object) postParams);
}

View File

@ -25,10 +25,8 @@ 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;
@ -58,7 +56,7 @@ public class BindToJsonPayloadWrappedWith implements MapBinder {
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
return this.bindToRequest(request, (Object) postParams);
}
}

View File

@ -535,7 +535,7 @@ public class RestAnnotationProcessor<T> {
org.jclouds.rest.MapBinder mapBinder = getMapPayloadBinderOrNull(method, args);
if (mapBinder != null) {
Map<String, String> mapParams = buildPostParams(method, args);
Map<String, Object> mapParams = buildPostParams(method, args);
if (method.isAnnotationPresent(PayloadParams.class)) {
PayloadParams params = method.getAnnotation(PayloadParams.class);
addMapPayload(mapParams, params, headers.entries());
@ -681,7 +681,7 @@ public class RestAnnotationProcessor<T> {
}
}
private void addMapPayload(Map<String, String> postParams, PayloadParams mapDefaults,
private void addMapPayload(Map<String, Object> postParams, PayloadParams mapDefaults,
Collection<Entry<String, String>> tokenValues) {
for (int i = 0; i < mapDefaults.keys().length; i++) {
if (mapDefaults.values()[i].equals(PayloadParams.NULL)) {
@ -1313,22 +1313,22 @@ public class RestAnnotationProcessor<T> {
return queryParamValues;
}
//TODO: change to LoadingCache<ClassMethodArgs, Map<String,String> and move this logic to the CacheLoader.
//TODO: change to LoadingCache<ClassMethodArgs, Map<String,Object> and move this logic to the CacheLoader.
//take care to manage size of this cache
private Map<String, String> buildPostParams(Method method, Object... args) throws ExecutionException {
Map<String, String> postParams = newHashMap();
private Map<String, Object> buildPostParams(Method method, Object... args) throws ExecutionException {
Map<String, Object> postParams = newHashMap();
LoadingCache<Integer, Set<Annotation>> indexToPathParam = methodToIndexOfParamToPostParamAnnotations.get(method);
LoadingCache<Integer, Set<Annotation>> indexToParamExtractor = methodToIndexOfParamToParamParserAnnotations.get(method);
for (Entry<Integer, Set<Annotation>> entry : indexToPathParam.asMap().entrySet()) {
for (Annotation key : entry.getValue()) {
Set<Annotation> extractors = indexToParamExtractor.get(entry.getKey());
String paramKey = ((PayloadParam) key).value();
String paramValue;
Object paramValue;
if (extractors != null && extractors.size() > 0) {
ParamParser extractor = (ParamParser) extractors.iterator().next();
paramValue = injector.getInstance(extractor.value()).apply(args[entry.getKey()]);
} else {
paramValue = args[entry.getKey()] != null ? args[entry.getKey()].toString() : null;
paramValue = args[entry.getKey()] != null ? args[entry.getKey()] : null;
}
postParams.put(paramKey, paramValue);

View File

@ -59,7 +59,7 @@ public class BindMapToStringPayloadTest {
.method(HttpMethod.POST).endpoint(URI.create("http://localhost")).build();
GeneratedHttpRequest<TestPayload> newRequest = binder()
.bindToRequest(request, ImmutableMap.of("fooble", "robot"));
.bindToRequest(request, ImmutableMap.<String,Object>of("fooble", "robot"));
assertEquals(newRequest.getRequestLine(), request.getRequestLine());
assertEquals(newRequest.getPayload().getRawContent(), "name robot");
@ -71,7 +71,7 @@ public class BindMapToStringPayloadTest {
GeneratedHttpRequest<TestPayload> request = GeneratedHttpRequest.<TestPayload>requestBuilder()
.declaring(TestPayload.class).javaMethod(noPayload).args(ImmutableList.<Object> of("robot"))
.method(HttpMethod.POST).endpoint(URI.create("http://localhost")).build();
binder().bindToRequest(request, ImmutableMap.of("fooble", "robot"));
binder().bindToRequest(request, ImmutableMap.<String,Object>of("fooble", "robot"));
}
@Test(expectedExceptions = IllegalArgumentException.class)

View File

@ -741,8 +741,8 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
Method method = TestPost.class.getMethod("postWithPath", String.class, MapBinder.class);
HttpRequest request = factory(TestPost.class).createRequest(method, "data", new org.jclouds.rest.MapBinder() {
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
request.setPayload(postParams.get("fooble"));
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
request.setPayload((String) postParams.get("fooble"));
return request;
}

View File

@ -47,14 +47,14 @@ public class CreateServerOptions implements MapBinder {
private String description;
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest<?>,
"this binder is only valid for GeneratedHttpRequests!");
GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request;
checkState(gRequest.getArgs() != null, "args should be initialized at this point");
ImmutableMultimap.Builder<String, String> formParams = ImmutableMultimap.builder();
formParams.putAll(forMap(postParams));
for(String key : postParams.keySet()) formParams.put(key, (String) postParams.get(key));
ServerSpec serverSpec = ServerSpec.class.cast(find(gRequest.getArgs(), instanceOf(ServerSpec.class)));
formParams.put("datacenter", serverSpec.getDatacenter());
formParams.put("platform", serverSpec.getPlatform());

View File

@ -55,7 +55,7 @@ public abstract class BaseBindVMSpecToXmlPayload<T> extends BindToStringPayload
protected abstract T findSpecInArgsOrNull(GeneratedHttpRequest<?> gRequest);
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest<?>,
"this binder is only valid for GeneratedHttpRequests!");
GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request;

View File

@ -65,7 +65,7 @@ public class BindCaptureVAppTemplateToXmlPayload extends BindToStringPayload imp
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest<?>,
"this binder is only valid for GeneratedHttpRequests!");
GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request;

View File

@ -65,14 +65,14 @@ public class BindCloneVMToXmlPayload extends BindToStringPayload implements MapB
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest<?>,
"this binder is only valid for GeneratedHttpRequests!");
GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request;
checkState(gRequest.getArgs() != null, "args should be initialized at this point");
request = super.bindToRequest(request,
generateXml(findVAppURIInArgsOrNull(gRequest), postParams.get("name"), postParams.get("networkTierName")));
generateXml(findVAppURIInArgsOrNull(gRequest), (String) postParams.get("name"), (String) postParams.get("networkTierName")));
request.getPayload().getContentMetadata().setContentType(MediaType.APPLICATION_XML);
return request;
}

View File

@ -64,7 +64,7 @@ public class BindFirewallRuleToXmlPayload extends BindToStringPayload implements
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest<?>,
"this binder is only valid for GeneratedHttpRequests!");
GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request;

View File

@ -44,7 +44,7 @@ import com.google.common.base.Throwables;
public class BindUserOrgAndPasswordAsBasicAuthorizationHeader implements MapBinder {
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
try {
String header = "Basic "
+ CryptoStreams.base64(String.format("%s@%s:%s", checkNotNull(postParams.get("user"), "user"),

View File

@ -45,10 +45,10 @@ public class CreateServerOptions extends RimuHostingJsonBinder {
private List<MetaData> metaData = new ArrayList<MetaData>();
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
String name = checkNotNull(postParams.get("name"));
String imageId = checkNotNull(postParams.get("imageId"));
String planId = checkNotNull(postParams.get("planId"));
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
String name = checkNotNull(postParams.get("name")).toString();
String imageId = checkNotNull(postParams.get("imageId")).toString();
String planId = checkNotNull(postParams.get("planId")).toString();
// There will be cases when the password is null.
String password = this.password;
NewServerData newServerData = new NewServerData(new CreateOptions(name, password, imageId), planId);

View File

@ -27,6 +27,8 @@ import org.jclouds.http.HttpRequest;
import org.jclouds.json.Json;
import org.jclouds.rest.binders.BindToJsonPayload;
import com.google.common.collect.ImmutableMap;
/**
* Generic binder for RimuHosting POSTS/PUTS. In the form of
*
@ -41,14 +43,12 @@ public class RimuHostingJsonBinder extends BindToJsonPayload {
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
return bindToRequest(request, (Object) postParams);
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object toBind) {
Map<String, Object> test = new HashMap<String, Object>();
test.put("request", toBind);
return super.bindToRequest(request, test);
return super.bindToRequest(request, (Object) ImmutableMap.of("request", toBind));
}
}

View File

@ -41,7 +41,7 @@ public class RimuHostingRebootJsonBinder extends RimuHostingJsonBinder {
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
return super.bindToRequest(request, (Object) ImmutableMap.of("running_state", "RESTARTING"));
}
}

View File

@ -45,9 +45,9 @@ public class BindCreateBackupToXmlPayload implements MapBinder {
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
String sliceId = checkNotNull(postParams.get("slice_id"), "slice_id");
String name = checkNotNull(postParams.get("name"), "name");
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
String sliceId = checkNotNull(postParams.get("slice_id"), "slice_id").toString();
String name = checkNotNull(postParams.get("name"), "name").toString();
StringBuilder builder = new StringBuilder();
builder.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><backup>");
builder.append("<slice-id type=\"integer\">").append(sliceId).append("</slice-id>");

View File

@ -44,10 +44,10 @@ public class BindCreateSliceToXmlPayload implements MapBinder {
this.binder = binder;
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
String flavorId = checkNotNull(postParams.get("flavor_id"), "flavor_id");
String imageId = checkNotNull(postParams.get("image_id"), "image_id");
String name = checkNotNull(postParams.get("name"), "name");
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
String flavorId = checkNotNull(postParams.get("flavor_id"), "flavor_id").toString();
String imageId = checkNotNull(postParams.get("image_id"), "image_id").toString();
String name = checkNotNull(postParams.get("name"), "name").toString();
StringBuilder builder = new StringBuilder();
builder.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><slice>");
builder.append("<flavor-id type=\"integer\">").append(flavorId).append("</flavor-id>");