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 @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"); throw new IllegalStateException("Replace Backup Schedule needs an BackupSchedule object, not a Map");
} }
@Override @Override
public <R extends HttpRequest> R bindToRequest(R request, Object toBind) { public <R extends HttpRequest> R bindToRequest(R request, Object toBind) {
checkArgument(toBind instanceof BackupSchedule, "this binder is only valid for BackupSchedules!"); 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; private String publicIp;
@Override @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) {
ServerRequest server = new ServerRequest(checkNotNull(postParams.get("name"), "name parameter not present"), ServerRequest server = new ServerRequest(checkNotNull(postParams.get("name"), "name parameter not present").toString(),
Integer.parseInt(checkNotNull(postParams.get("imageId"), "imageId parameter not present")), Integer Integer.parseInt(checkNotNull(postParams.get("imageId"), "imageId parameter not present").toString()),
.parseInt(checkNotNull(postParams.get("flavorId"), "flavorId parameter not present"))); Integer.parseInt(checkNotNull(postParams.get("flavorId"), "flavorId parameter not present").toString()));
if (metadata.size() > 0) if (metadata.size() > 0)
server.metadata = metadata; server.metadata = metadata;
if (files.size() > 0) if (files.size() > 0)

View File

@ -57,8 +57,8 @@ public class CreateSharedIpGroupOptions implements MapBinder {
} }
@Override @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) {
SharedIpGroupRequest createRequest = new SharedIpGroupRequest(checkNotNull(postParams.get("name")), serverId); SharedIpGroupRequest createRequest = new SharedIpGroupRequest(checkNotNull(postParams.get("name")).toString(), serverId);
return jsonBinder.bindToRequest(request, ImmutableMap.of("sharedIpGroup", createRequest)); return jsonBinder.bindToRequest(request, ImmutableMap.of("sharedIpGroup", createRequest));
} }

View File

@ -43,7 +43,7 @@ public class RebuildServerOptions implements MapBinder {
Integer imageId; Integer imageId;
@Override @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(); Map<String, Integer> image = Maps.newHashMap();
if (imageId != null) if (imageId != null)
image.put("imageId", imageId); image.put("imageId", imageId);

View File

@ -55,7 +55,7 @@ public class CreateServerOptionsTest {
private HttpRequest buildRequest(CreateServerOptions options) { private HttpRequest buildRequest(CreateServerOptions options) {
injector.injectMembers(options); injector.injectMembers(options);
HttpRequest request = new HttpRequest(HttpMethod.POST, URI.create("http://localhost")); 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; return request;
} }

View File

@ -53,7 +53,7 @@ public class CreateSharedIpGroupOptionsTest {
private HttpRequest buildRequest(CreateSharedIpGroupOptions options) { private HttpRequest buildRequest(CreateSharedIpGroupOptions options) {
injector.injectMembers(options); injector.injectMembers(options);
HttpRequest request = new HttpRequest(HttpMethod.POST, URI.create("http://localhost")); 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; return request;
} }

View File

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

View File

@ -24,6 +24,7 @@ import static com.google.common.base.Preconditions.checkState;
import java.util.Map; import java.util.Map;
import javax.annotation.Nullable;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
@ -35,8 +36,10 @@ import org.jclouds.http.HttpRequest;
import org.jclouds.rest.MapBinder; import org.jclouds.rest.MapBinder;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
/** /**
* *
@ -53,7 +56,7 @@ public class BindCloneDriveOptionsToPlainTextString implements MapBinder {
} }
@Override @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, checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest,
"this binder is only valid for GeneratedHttpRequests!"); "this binder is only valid for GeneratedHttpRequests!");
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -62,10 +65,15 @@ public class BindCloneDriveOptionsToPlainTextString implements MapBinder {
CloneDriveOptions options = findOptionsInArgsOrNull(gRequest); CloneDriveOptions options = findOptionsInArgsOrNull(gRequest);
if (options != null) { 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); request.getPayload().getContentMetadata().setContentType(MediaType.TEXT_PLAIN);
return request; return request;
} }

View File

@ -47,16 +47,16 @@ public class BindCloneDriveOptionsToPlainTextStringTest {
BindCloneDriveOptionsToPlainTextString.class); BindCloneDriveOptionsToPlainTextString.class);
public void testDefault() throws IOException { 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"); "name newdrive");
} }
public void testWithSize() throws IOException { 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"); 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) { String expected) {
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class); GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
expect(request.getArgs()).andReturn(args).atLeastOnce(); expect(request.getArgs()).andReturn(args).atLeastOnce();

View File

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

View File

@ -100,10 +100,10 @@ public class CreateServerOptions implements MapBinder {
private String adminPass; private String adminPass;
@Override @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) {
ServerRequest server = new ServerRequest(checkNotNull(postParams.get("name"), "name parameter not present"), ServerRequest server = new ServerRequest(checkNotNull(postParams.get("name"), "name parameter not present").toString(),
checkNotNull(postParams.get("imageRef"), "imageRef parameter not present"), checkNotNull(postParams checkNotNull(postParams.get("imageRef"), "imageRef parameter not present").toString(),
.get("flavorRef"), "flavorRef parameter not present")); checkNotNull(postParams.get("flavorRef"), "flavorRef parameter not present").toString());
if (metadata.size() > 0) if (metadata.size() > 0)
server.metadata = metadata; server.metadata = metadata;
if (files.size() > 0) if (files.size() > 0)
@ -231,7 +231,7 @@ public class CreateServerOptions implements MapBinder {
} }
/** /**
* @see CreateServerOptions#withGroupName(String) * @see CreateServerOptions#withSecurityGroup(String)
*/ */
public static CreateServerOptions withSecurityGroup(String name) { public static CreateServerOptions withSecurityGroup(String name) {
CreateServerOptions options = new CreateServerOptions(); CreateServerOptions options = new CreateServerOptions();

View File

@ -44,7 +44,7 @@ public class RebuildServerOptions implements MapBinder {
String imageRef; String imageRef;
@Override @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(); Map<String, String> image = Maps.newHashMap();
if (imageRef != null) if (imageRef != null)
image.put("imageRef", imageRef); image.put("imageRef", imageRef);

View File

@ -55,7 +55,7 @@ public class CreateServerOptionsTest {
private HttpRequest buildRequest(CreateServerOptions options) { private HttpRequest buildRequest(CreateServerOptions options) {
injector.injectMembers(options); injector.injectMembers(options);
HttpRequest request = new HttpRequest(HttpMethod.POST, URI.create("http://localhost")); 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; return request;
} }

View File

@ -53,7 +53,7 @@ public class RebuildServerOptionsTest {
private HttpRequest buildRequest(RebuildServerOptions options) { private HttpRequest buildRequest(RebuildServerOptions options) {
injector.injectMembers(options); injector.injectMembers(options);
HttpRequest request = new HttpRequest(HttpMethod.POST, URI.create("http://localhost")); 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; 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 @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) {
Builder<String, String> payload = ImmutableMap.builder(); Builder<String, Object> payload = ImmutableMap.builder();
payload.putAll(postParams); payload.putAll(postParams);
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest<?>, checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest<?>,
"this binder is only valid for GeneratedHttpRequests!"); "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.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser; import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.SkipEncoding; import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.WrapWith;
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404; import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404;
@ -114,7 +115,7 @@ public interface AdminActionsAsyncClient {
@POST @POST
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@Produces(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) @ExceptionParser(MapHttp4xxCodesToExceptions.class)
@ResponseParser(ParseImageIdFromLocationHeader.class) @ResponseParser(ParseImageIdFromLocationHeader.class)
ListenableFuture<String> createBackupOfServer(@PathParam("id") String id, ListenableFuture<String> createBackupOfServer(@PathParam("id") String id,
@ -156,9 +157,9 @@ public interface AdminActionsAsyncClient {
@POST @POST
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnFalseOnNotFoundOr404.class) @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, ListenableFuture<Boolean> liveMigrateServer(@PathParam("id") String id,
@PayloadParam("host") String host, @PayloadParam("host") String host,
@PayloadParam("bm") boolean blockMigration, @PayloadParam("block_migration") boolean blockMigration,
@PayloadParam("doc") boolean diskOverCommit); @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.concurrent.Timeout;
import org.jclouds.openstack.filters.AuthenticateRequest; 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.Extension;
import org.jclouds.openstack.services.ServiceType; import org.jclouds.openstack.services.ServiceType;
import org.jclouds.rest.annotations.ExceptionParser; 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.RequestFilters;
import org.jclouds.rest.annotations.SelectJson; import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.Unwrap; import org.jclouds.rest.annotations.Unwrap;
import org.jclouds.rest.binders.BindToJsonPayload;
import org.jclouds.rest.functions.ReturnEmptyMapOnNotFoundOr404; import org.jclouds.rest.functions.ReturnEmptyMapOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404; import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
@ -79,8 +79,8 @@ public interface FlavorExtraSpecsAsyncClient {
@Path("/flavors/{flavor_id}/os-extra_specs") @Path("/flavors/{flavor_id}/os-extra_specs")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnFalseOnNotFoundOr404.class) @ExceptionParser(ReturnFalseOnNotFoundOr404.class)
@MapBinder(BindExtraSpecsToJsonPayload.class) @MapBinder(BindToJsonPayload.class)
ListenableFuture<Boolean> setAllExtraSpecs(@PathParam("flavor_id") String flavorId, Map<String, String> specs); ListenableFuture<Boolean> setAllExtraSpecs(@PathParam("flavor_id") String flavorId, @PayloadParam("extra_specs") Map<String, String> specs);
/** /**
* @see FlavorExtraSpecsClient#getExtraSpec(String, String) * @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.concurrent.Timeout;
import org.jclouds.openstack.filters.AuthenticateRequest; 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.nova.v1_1.domain.HostAggregate;
import org.jclouds.openstack.services.Extension; import org.jclouds.openstack.services.Extension;
import org.jclouds.openstack.services.ServiceType; import org.jclouds.openstack.services.ServiceType;
import org.jclouds.rest.annotations.ExceptionParser; 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.PayloadParam;
import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson; import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.WrapWith;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404; import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
@ -87,8 +85,9 @@ public interface HostAggregateAsyncClient {
@SelectJson("aggregate") @SelectJson("aggregate")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Payload("%7B\"aggregate\":%7B\"name\":\"{name}\",\"availability_zone\":\"{zone}\"%7D%7D") @WrapWith("aggregate")
ListenableFuture<HostAggregate> createAggregate(@PayloadParam("name") String name, @PayloadParam("zone") String availablityZone); ListenableFuture<HostAggregate> createAggregate(@PayloadParam("name") String name,
@PayloadParam("availability_zone") String availablityZone);
/** /**
* @see HostAggregateClient#updateName * @see HostAggregateClient#updateName
@ -97,7 +96,7 @@ public interface HostAggregateAsyncClient {
@Path("/{id}") @Path("/{id}")
@SelectJson("aggregate") @SelectJson("aggregate")
@Consumes(MediaType.APPLICATION_JSON) @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); ListenableFuture<HostAggregate> updateName(@PathParam("id") String id, @PayloadParam("name") String name);
/** /**
@ -107,8 +106,8 @@ public interface HostAggregateAsyncClient {
@Path("/{id}") @Path("/{id}")
@SelectJson("aggregate") @SelectJson("aggregate")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@Payload("%7B\"aggregate\":%7B\"availability_zone\":\"{zone}\"%7D%7D") @WrapWith("aggregate")
ListenableFuture<HostAggregate> updateAvailabilityZone(@PathParam("id") String id, @PayloadParam("zone") String availabilityZone); ListenableFuture<HostAggregate> updateAvailabilityZone(@PathParam("id") String id, @PayloadParam("availability_zone") String availabilityZone);
/** /**
* @see HostAggregateClient#deleteAggregate(String) * @see HostAggregateClient#deleteAggregate(String)
@ -127,7 +126,7 @@ public interface HostAggregateAsyncClient {
@SelectJson("aggregate") @SelectJson("aggregate")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@Produces(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); ListenableFuture<HostAggregate> addHost(@PathParam("id") String id, @PayloadParam("host") String host);
@ -139,7 +138,7 @@ public interface HostAggregateAsyncClient {
@SelectJson("aggregate") @SelectJson("aggregate")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@Produces(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); ListenableFuture<HostAggregate> removeHost(@PathParam("id") String id, @PayloadParam("host") String host);
/** /**
@ -150,6 +149,6 @@ public interface HostAggregateAsyncClient {
@SelectJson("aggregate") @SelectJson("aggregate")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@MapBinder(BindAggregateMetadataToJsonPayload.class) @WrapWith("set_metadata")
ListenableFuture<HostAggregate> setMetadata(@PathParam("id") String id, Map<String, String> 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.concurrent.Timeout;
import org.jclouds.openstack.filters.AuthenticateRequest; 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.nova.v1_1.domain.Quotas;
import org.jclouds.openstack.services.Extension; import org.jclouds.openstack.services.Extension;
import org.jclouds.openstack.services.ServiceType; import org.jclouds.openstack.services.ServiceType;
import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.MapBinder; import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson; import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.binders.BindToJsonPayload;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
@ -71,8 +72,8 @@ public interface QuotaAsyncClient {
@PUT @PUT
@Path("/{tenant_id}") @Path("/{tenant_id}")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@MapBinder(BindQuotasToJsonPayload.class) @MapBinder(BindToJsonPayload.class)
ListenableFuture<Boolean> updateQuotasForTenant(@PathParam("tenant_id") String tenantId, Quotas quotas); ListenableFuture<Boolean> updateQuotasForTenant(@PathParam("tenant_id") String tenantId, @PayloadParam("quota_set") Quotas quotas);
/** /**
* @see QuotaClient#getDefaultQuotasForTenant(String) * @see QuotaClient#getDefaultQuotasForTenant(String)

View File

@ -30,15 +30,16 @@ import javax.ws.rs.core.MediaType;
import org.jclouds.concurrent.Timeout; import org.jclouds.concurrent.Timeout;
import org.jclouds.openstack.filters.AuthenticateRequest; 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.QuotaClass;
import org.jclouds.openstack.nova.v1_1.domain.Quotas;
import org.jclouds.openstack.services.Extension; import org.jclouds.openstack.services.Extension;
import org.jclouds.openstack.services.ServiceType; import org.jclouds.openstack.services.ServiceType;
import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.MapBinder; import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson; 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 org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
@ -73,7 +74,7 @@ public interface QuotaClassAsyncClient {
@PUT @PUT
@Path("/{id}") @Path("/{id}")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@MapBinder(BindQuotaClassToJsonPayload.class) @MapBinder(BindToJsonPayload.class)
ListenableFuture<Boolean> updateQuotaClass(@PathParam("id") String id, QuotaClass quotas); 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.RequestFilters;
import org.jclouds.rest.annotations.SelectJson; import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.SkipEncoding; import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.WrapWith;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404; import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
@ -156,8 +157,8 @@ public interface VolumeAsyncClient {
@SelectJson("volumeAttachment") @SelectJson("volumeAttachment")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@Payload("%7B\"volumeAttachment\":%7B\"volumeId\":\"{id}\",\"device\":\"{device}\"%7D%7D") @WrapWith("volumeAttachment")
ListenableFuture<VolumeAttachment> attachVolumeToServerAsDevice(@PayloadParam("id") String volumeId, ListenableFuture<VolumeAttachment> attachVolumeToServerAsDevice(@PayloadParam("volumeId") String volumeId,
@PathParam("server_id") String serverId, @PayloadParam("device") String device); @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.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.TimeUnit;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE; import javax.ws.rs.DELETE;
@ -32,9 +31,7 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import org.jclouds.concurrent.Timeout;
import org.jclouds.openstack.filters.AuthenticateRequest; 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.domain.VolumeType;
import org.jclouds.openstack.nova.v1_1.options.CreateVolumeTypeOptions; import org.jclouds.openstack.nova.v1_1.options.CreateVolumeTypeOptions;
import org.jclouds.openstack.services.Extension; 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.SelectJson;
import org.jclouds.rest.annotations.SkipEncoding; import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.Unwrap; 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.ReturnEmptyMapOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404; import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404;
@ -91,7 +90,7 @@ public interface VolumeTypeAsyncClient {
@POST @POST
@SelectJson("volume_type") @SelectJson("volume_type")
@Produces(MediaType.APPLICATION_JSON) @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); ListenableFuture<VolumeType> createVolumeType(@PayloadParam("name") String name, CreateVolumeTypeOptions... options);
/** /**
@ -118,8 +117,8 @@ public interface VolumeTypeAsyncClient {
@Path("/{id}/extra_specs") @Path("/{id}/extra_specs")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnFalseOnNotFoundOr404.class) @ExceptionParser(ReturnFalseOnNotFoundOr404.class)
@MapBinder(BindExtraSpecsToJsonPayload.class) @MapBinder(BindToJsonPayload.class)
ListenableFuture<Boolean> setAllExtraSpecs(@PathParam("id") String id, Map<String, String> specs); ListenableFuture<Boolean> setAllExtraSpecs(@PathParam("id") String id, @PayloadParam("extra_specs") Map<String, String> specs);
/** /**
* @see VolumeTypeClient#getExtraSpec(String, String) * @see VolumeTypeClient#getExtraSpec(String, String)

View File

@ -46,7 +46,7 @@ public class CreateBackupOfServerOptions implements MapBinder {
private Map<String, String> metadata = ImmutableMap.of(); private Map<String, String> metadata = ImmutableMap.of();
@Override @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(); Map<String, Object> data = Maps.newHashMap();
data.putAll(postParams); data.putAll(postParams);
data.put("metadata", metadata); data.put("metadata", metadata);

View File

@ -166,10 +166,10 @@ public class CreateServerOptions implements MapBinder {
} }
@Override @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) {
ServerRequest server = new ServerRequest(checkNotNull(postParams.get("name"), "name parameter not present"), ServerRequest server = new ServerRequest(checkNotNull(postParams.get("name"), "name parameter not present").toString(),
checkNotNull(postParams.get("imageRef"), "imageRef parameter not present"), checkNotNull( checkNotNull(postParams.get("imageRef"), "imageRef parameter not present").toString(),
postParams.get("flavorRef"), "flavorRef parameter not present")); checkNotNull(postParams.get("flavorRef"), "flavorRef parameter not present").toString());
if (metadata.size() > 0) if (metadata.size() > 0)
server.metadata = metadata; server.metadata = metadata;
if (personality.size() > 0) if (personality.size() > 0)

View File

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

View File

@ -48,8 +48,8 @@ public class CreateVolumeSnapshotOptions implements MapBinder {
private boolean force = false; private boolean force = false;
@Override @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> data = Maps.newHashMap(postParams); Map<String, Object> data = Maps.newHashMap(postParams);
if (name != null) if (name != null)
data.put("display_name", name); data.put("display_name", name);
if (description != null) if (description != null)

View File

@ -46,7 +46,7 @@ public class CreateVolumeTypeOptions implements MapBinder {
protected Map<String, String> specs = ImmutableMap.of(); protected Map<String, String> specs = ImmutableMap.of();
@Override @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(); Map<String, Object> data = Maps.newHashMap();
data.putAll(postParams); data.putAll(postParams);
data.put("extra_specs", specs); data.put("extra_specs", specs);

View File

@ -44,7 +44,7 @@ public class RebuildServerOptions implements MapBinder {
String imageRef; String imageRef;
@Override @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(); Map<String, String> image = Maps.newHashMap();
if (imageRef != null) if (imageRef != null)
image.put("imageRef", imageRef); image.put("imageRef", imageRef);

View File

@ -294,7 +294,7 @@ public class AdminActionsClientExpectTest extends BaseNovaClientExpectTest {
keystoneAuthWithUsernameAndPassword, keystoneAuthWithUsernameAndPassword,
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardRequestBuilder(endpoint).method("POST") 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() 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(); ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get();
@ -309,7 +309,7 @@ public class AdminActionsClientExpectTest extends BaseNovaClientExpectTest {
keystoneAuthWithUsernameAndPassword, keystoneAuthWithUsernameAndPassword,
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardRequestBuilder(endpoint).method("POST") 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() standardResponseBuilder(404).build()
).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get();
@ -322,7 +322,7 @@ public class AdminActionsClientExpectTest extends BaseNovaClientExpectTest {
keystoneAuthWithUsernameAndPassword, keystoneAuthWithUsernameAndPassword,
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "GONNAOVERWRITE") 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() standardResponseBuilder(202).build()
).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get();
@ -335,7 +335,7 @@ public class AdminActionsClientExpectTest extends BaseNovaClientExpectTest {
keystoneAuthWithUsernameAndPassword, keystoneAuthWithUsernameAndPassword,
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardActionRequestBuilderVoidResponse(endpoint, "GONNAOVERWRITE") 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() standardResponseBuilder(404).build()
).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get(); ).getAdminActionsExtensionForZone("az-1.region-a.geo-1").get();

View File

@ -111,7 +111,7 @@ public class VolumeClientExpectTest extends BaseNovaClientExpectTest {
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
standardRequestBuilder(endpoint) standardRequestBuilder(endpoint)
.method("POST") .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(), .build(),
standardResponseBuilder(200).payload(payloadFromResource("/volume_details.json")).build() standardResponseBuilder(200).payload(payloadFromResource("/volume_details.json")).build()
).getVolumeExtensionForZone("az-1.region-a.geo-1").get(); ).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
@ -129,7 +129,7 @@ public class VolumeClientExpectTest extends BaseNovaClientExpectTest {
standardRequestBuilder(endpoint) standardRequestBuilder(endpoint)
.endpoint(endpoint) .endpoint(endpoint)
.method("POST") .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(), .build(),
standardResponseBuilder(404).payload(payloadFromResource("/volume_details.json")).build() standardResponseBuilder(404).payload(payloadFromResource("/volume_details.json")).build()
).getVolumeExtensionForZone("az-1.region-a.geo-1").get(); ).getVolumeExtensionForZone("az-1.region-a.geo-1").get();

View File

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

View File

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

View File

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

View File

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

View File

@ -57,7 +57,7 @@ public class BindParamsToXmlPayload implements MapBinder {
this.stringBinder = stringBinder; this.stringBinder = stringBinder;
} }
@Override @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 { try {
return stringBinder.bindToRequest(request, generateXml(postParams)); return stringBinder.bindToRequest(request, generateXml(postParams));
} catch (Exception e) { } 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 { FactoryConfigurationError, TransformerException {
XMLBuilder rootBuilder = XMLBuilder.create(element); XMLBuilder rootBuilder = XMLBuilder.create(element);
for (Entry<String, String> entry : postParams.entrySet()) for (Entry<String, Object> entry : postParams.entrySet())
rootBuilder.a(entry.getKey(), entry.getValue()); rootBuilder.a(entry.getKey(), (String) entry.getValue());
rootBuilder.a("xmlns", ns); rootBuilder.a("xmlns", ns);
Properties outputProperties = new Properties(); Properties outputProperties = new Properties();
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes"); 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); 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); binder.bindToRequest(request, map);
verify(request); verify(request);

View File

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

View File

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

View File

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

View File

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

View File

@ -48,7 +48,7 @@ public class BindCredentialsToJsonPayload extends BindToJsonPayload implements M
} }
@Override @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)); return super.bindToRequest(request, ImmutableMap.of("credentials", postParams));
} }

View File

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

View File

@ -54,13 +54,13 @@ public class BindAddInternetServiceToXmlPayload implements MapBinder {
private String ns; private String ns;
@Override @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 name = checkNotNull(postParams.get("name"), "name parameter not present").toString();
String protocol = checkNotNull(postParams.get("protocol"), "protocol parameter not present"); String protocol = checkNotNull(postParams.get("protocol"), "protocol parameter not present").toString();
String port = checkNotNull(postParams.get("port"), "port parameter not present"); String port = checkNotNull(postParams.get("port"), "port parameter not present").toString();
String enabled = checkNotNull(postParams.get("enabled"), "enabled parameter not present"); String enabled = checkNotNull(postParams.get("enabled"), "enabled parameter not present").toString();
String description = postParams.get("description"); String description = (String) postParams.get("description");
String payload = Strings2.replaceTokens(xmlTemplate, String payload = Strings2.replaceTokens(xmlTemplate,
ImmutableMap.of("name", name, "protocol", protocol, "port", port, "enabled", enabled, "ns", ns)); ImmutableMap.of("name", name, "protocol", protocol, "port", port, "enabled", enabled, "ns", ns));
try { try {
@ -73,10 +73,10 @@ public class BindAddInternetServiceToXmlPayload implements MapBinder {
return stringBinder.bindToRequest(request, payload); 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. // 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)) { if (monitor == null || "true".equalsIgnoreCase(monitor)) {
return ""; return "";
} }

View File

@ -55,12 +55,12 @@ public class BindAddNodeServiceToXmlPayload implements MapBinder {
private String ns; private String ns;
@Override @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 ipAddress = checkNotNull(postParams.get("ipAddress"), "ipAddress parameter not present"); String ipAddress = checkNotNull(postParams.get("ipAddress"), "ipAddress parameter not present").toString();
String name = checkNotNull(postParams.get("name"), "name parameter not present"); String name = checkNotNull(postParams.get("name"), "name parameter not present").toString();
String port = checkNotNull(postParams.get("port"), "port parameter not present"); String port = checkNotNull(postParams.get("port"), "port parameter not present").toString();
String enabled = checkNotNull(postParams.get("enabled"), "enabled parameter not present"); String enabled = checkNotNull(postParams.get("enabled"), "enabled parameter not present").toString();
String description = postParams.get("description"); String description = (String) postParams.get("description");
String payload = Strings2.replaceTokens(xmlTemplate, String payload = Strings2.replaceTokens(xmlTemplate,
ImmutableMap.of("name", name, "ipAddress", ipAddress, "port", port, "enabled", enabled, "ns", ns)); ImmutableMap.of("name", name, "ipAddress", ipAddress, "port", port, "enabled", enabled, "ns", ns));

View File

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

View File

@ -55,9 +55,9 @@ public class BindCreateKeyToXmlPayload implements MapBinder {
} }
@Override @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 name = checkNotNull(postParams.get("name"), "name parameter not present").toString();
String isDefault = checkNotNull(postParams.get("isDefault"), "isDefault parameter not present"); String isDefault = checkNotNull(postParams.get("isDefault"), "isDefault parameter not present").toString();
String payload = Strings2.replaceTokens(xmlTemplate, String payload = Strings2.replaceTokens(xmlTemplate,
ImmutableMap.of("name", name, "isDefault", isDefault, "ns", ns)); ImmutableMap.of("name", name, "isDefault", isDefault, "ns", ns));

View File

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

View File

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

View File

@ -78,7 +78,7 @@ public class BindVAppConfigurationToXmlPayload implements MapBinder, Function<Ob
} }
@Override @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<?>, checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest<?>,
"this binder is only valid for GeneratedHttpRequests!"); "this binder is only valid for GeneratedHttpRequests!");
GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request; GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request;

View File

@ -41,8 +41,8 @@ public class AddInternetServiceOptions extends BindAddInternetServiceToXmlPayloa
Boolean monitorEnabled = null; Boolean monitorEnabled = null;
@Override @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) {
ImmutableMap.Builder<String, String> copy = ImmutableMap.builder(); ImmutableMap.Builder<String, Object> copy = ImmutableMap.builder();
copy.putAll(postParams); copy.putAll(postParams);
if (description != null) if (description != null)
copy.put("description", description); copy.put("description", description);

View File

@ -38,8 +38,8 @@ public class AddNodeOptions extends BindAddNodeServiceToXmlPayload {
@VisibleForTesting @VisibleForTesting
String enabled = "true"; String enabled = "true";
@Override @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> copy = Maps.newHashMap(); Map<String, Object> copy = Maps.newHashMap();
copy.putAll(postParams); copy.putAll(postParams);
copy.put("description", description); copy.put("description", description);
copy.put("enabled", enabled); copy.put("enabled", enabled);

View File

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

View File

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

View File

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

View File

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

View File

@ -64,27 +64,27 @@ public class BindNodeConfigurationToXmlPayloadTest {
public void testChangeDescription() throws IOException { 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>"; 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); "description"), expectedPayload);
} }
public void testDisableTraffic() throws IOException { 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>"; 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 { 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>"; 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) @Test(expectedExceptions = NullPointerException.class)
public void testNoOptions() throws IOException { 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>"; 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); BindNodeConfigurationToXmlPayload binder = injector.getInstance(BindNodeConfigurationToXmlPayload.class);
HttpRequest request = createMock(HttpRequest.class); HttpRequest request = createMock(HttpRequest.class);
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes(); 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); BindVAppConfigurationToXmlPayload binder = injector.getInstance(BindVAppConfigurationToXmlPayload.class);
Map<String, String> map = Maps.newHashMap(); Map<String, Object> map = Maps.newHashMap();
binder.bindToRequest(request, map); binder.bindToRequest(request, map);
verify(request); verify(request);
} }
@ -124,7 +124,7 @@ public class BindVAppConfigurationToXmlPayloadTest {
BindVAppConfigurationToXmlPayload binder = injector.getInstance(BindVAppConfigurationToXmlPayload.class); BindVAppConfigurationToXmlPayload binder = injector.getInstance(BindVAppConfigurationToXmlPayload.class);
Map<String, String> map = Maps.newHashMap(); Map<String, Object> map = Maps.newHashMap();
binder.bindToRequest(request, map); binder.bindToRequest(request, map);
verify(request); verify(request);
} }
@ -153,7 +153,7 @@ public class BindVAppConfigurationToXmlPayloadTest {
BindVAppConfigurationToXmlPayload binder = injector.getInstance(BindVAppConfigurationToXmlPayload.class); BindVAppConfigurationToXmlPayload binder = injector.getInstance(BindVAppConfigurationToXmlPayload.class);
Map<String, String> map = Maps.newHashMap(); Map<String, Object> map = Maps.newHashMap();
binder.bindToRequest(request, map); binder.bindToRequest(request, map);
verify(request); verify(request);
} }
@ -180,7 +180,7 @@ public class BindVAppConfigurationToXmlPayloadTest {
BindVAppConfigurationToXmlPayload binder = injector.getInstance(BindVAppConfigurationToXmlPayload.class); BindVAppConfigurationToXmlPayload binder = injector.getInstance(BindVAppConfigurationToXmlPayload.class);
Map<String, String> map = Maps.newHashMap(); Map<String, Object> map = Maps.newHashMap();
binder.bindToRequest(request, map); binder.bindToRequest(request, map);
verify(request); verify(request);
} }
@ -209,7 +209,7 @@ public class BindVAppConfigurationToXmlPayloadTest {
BindVAppConfigurationToXmlPayload binder = injector.getInstance(BindVAppConfigurationToXmlPayload.class); BindVAppConfigurationToXmlPayload binder = injector.getInstance(BindVAppConfigurationToXmlPayload.class);
Map<String, String> map = Maps.newHashMap(); Map<String, Object> map = Maps.newHashMap();
binder.bindToRequest(request, map); binder.bindToRequest(request, map);
verify(request); verify(request);
} }

View File

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

View File

@ -35,5 +35,5 @@ public interface MapBinder extends Binder {
* *
* @see org.jclouds.rest.annotations.PayloadParam * @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") @SuppressWarnings("unchecked")
@Override @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"); checkNotNull(postParams, "postParams");
GeneratedHttpRequest<?> r = GeneratedHttpRequest.class.cast(checkNotNull(request, "request")); GeneratedHttpRequest<?> r = GeneratedHttpRequest.class.cast(checkNotNull(request, "request"));
checkArgument(r.getJavaMethod().isAnnotationPresent(Payload.class), checkArgument(r.getJavaMethod().isAnnotationPresent(Payload.class),

View File

@ -44,7 +44,7 @@ public class BindToJsonPayload implements MapBinder {
} }
@Override @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); return bindToRequest(request, (Object) postParams);
} }

View File

@ -25,10 +25,8 @@ import java.util.Map;
import javax.inject.Inject; import javax.inject.Inject;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.rest.Binder;
import org.jclouds.rest.MapBinder; import org.jclouds.rest.MapBinder;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.inject.assistedinject.Assisted; import com.google.inject.assistedinject.Assisted;
@ -58,7 +56,7 @@ public class BindToJsonPayloadWrappedWith implements MapBinder {
} }
@Override @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); return this.bindToRequest(request, (Object) postParams);
} }
} }

View File

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

View File

@ -59,7 +59,7 @@ public class BindMapToStringPayloadTest {
.method(HttpMethod.POST).endpoint(URI.create("http://localhost")).build(); .method(HttpMethod.POST).endpoint(URI.create("http://localhost")).build();
GeneratedHttpRequest<TestPayload> newRequest = binder() 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.getRequestLine(), request.getRequestLine());
assertEquals(newRequest.getPayload().getRawContent(), "name robot"); assertEquals(newRequest.getPayload().getRawContent(), "name robot");
@ -71,7 +71,7 @@ public class BindMapToStringPayloadTest {
GeneratedHttpRequest<TestPayload> request = GeneratedHttpRequest.<TestPayload>requestBuilder() GeneratedHttpRequest<TestPayload> request = GeneratedHttpRequest.<TestPayload>requestBuilder()
.declaring(TestPayload.class).javaMethod(noPayload).args(ImmutableList.<Object> of("robot")) .declaring(TestPayload.class).javaMethod(noPayload).args(ImmutableList.<Object> of("robot"))
.method(HttpMethod.POST).endpoint(URI.create("http://localhost")).build(); .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) @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); Method method = TestPost.class.getMethod("postWithPath", String.class, MapBinder.class);
HttpRequest request = factory(TestPost.class).createRequest(method, "data", new org.jclouds.rest.MapBinder() { HttpRequest request = factory(TestPost.class).createRequest(method, "data", new org.jclouds.rest.MapBinder() {
@Override @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) {
request.setPayload(postParams.get("fooble")); request.setPayload((String) postParams.get("fooble"));
return request; return request;
} }

View File

@ -47,14 +47,14 @@ public class CreateServerOptions implements MapBinder {
private String description; private String description;
@Override @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<?>, checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest<?>,
"this binder is only valid for GeneratedHttpRequests!"); "this binder is only valid for GeneratedHttpRequests!");
GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request; GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request;
checkState(gRequest.getArgs() != null, "args should be initialized at this point"); checkState(gRequest.getArgs() != null, "args should be initialized at this point");
ImmutableMultimap.Builder<String, String> formParams = ImmutableMultimap.builder(); 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))); ServerSpec serverSpec = ServerSpec.class.cast(find(gRequest.getArgs(), instanceOf(ServerSpec.class)));
formParams.put("datacenter", serverSpec.getDatacenter()); formParams.put("datacenter", serverSpec.getDatacenter());
formParams.put("platform", serverSpec.getPlatform()); formParams.put("platform", serverSpec.getPlatform());

View File

@ -55,7 +55,7 @@ public abstract class BaseBindVMSpecToXmlPayload<T> extends BindToStringPayload
protected abstract T findSpecInArgsOrNull(GeneratedHttpRequest<?> gRequest); protected abstract T findSpecInArgsOrNull(GeneratedHttpRequest<?> gRequest);
@Override @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<?>, checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest<?>,
"this binder is only valid for GeneratedHttpRequests!"); "this binder is only valid for GeneratedHttpRequests!");
GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request; GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request;

View File

@ -65,7 +65,7 @@ public class BindCaptureVAppTemplateToXmlPayload extends BindToStringPayload imp
} }
@Override @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<?>, checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest<?>,
"this binder is only valid for GeneratedHttpRequests!"); "this binder is only valid for GeneratedHttpRequests!");
GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request; GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request;

View File

@ -65,14 +65,14 @@ public class BindCloneVMToXmlPayload extends BindToStringPayload implements MapB
} }
@Override @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<?>, checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest<?>,
"this binder is only valid for GeneratedHttpRequests!"); "this binder is only valid for GeneratedHttpRequests!");
GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request; GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request;
checkState(gRequest.getArgs() != null, "args should be initialized at this point"); checkState(gRequest.getArgs() != null, "args should be initialized at this point");
request = super.bindToRequest(request, 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); request.getPayload().getContentMetadata().setContentType(MediaType.APPLICATION_XML);
return request; return request;
} }

View File

@ -64,7 +64,7 @@ public class BindFirewallRuleToXmlPayload extends BindToStringPayload implements
} }
@Override @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<?>, checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest<?>,
"this binder is only valid for GeneratedHttpRequests!"); "this binder is only valid for GeneratedHttpRequests!");
GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request; GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request;

View File

@ -44,7 +44,7 @@ import com.google.common.base.Throwables;
public class BindUserOrgAndPasswordAsBasicAuthorizationHeader implements MapBinder { public class BindUserOrgAndPasswordAsBasicAuthorizationHeader implements MapBinder {
@Override @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 { try {
String header = "Basic " String header = "Basic "
+ CryptoStreams.base64(String.format("%s@%s:%s", checkNotNull(postParams.get("user"), "user"), + 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>(); private List<MetaData> metaData = new ArrayList<MetaData>();
@Override @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")); String name = checkNotNull(postParams.get("name")).toString();
String imageId = checkNotNull(postParams.get("imageId")); String imageId = checkNotNull(postParams.get("imageId")).toString();
String planId = checkNotNull(postParams.get("planId")); String planId = checkNotNull(postParams.get("planId")).toString();
// There will be cases when the password is null. // There will be cases when the password is null.
String password = this.password; String password = this.password;
NewServerData newServerData = new NewServerData(new CreateOptions(name, password, imageId), planId); 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.json.Json;
import org.jclouds.rest.binders.BindToJsonPayload; import org.jclouds.rest.binders.BindToJsonPayload;
import com.google.common.collect.ImmutableMap;
/** /**
* Generic binder for RimuHosting POSTS/PUTS. In the form of * Generic binder for RimuHosting POSTS/PUTS. In the form of
* *
@ -41,14 +43,12 @@ public class RimuHostingJsonBinder extends BindToJsonPayload {
} }
@Override @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); return bindToRequest(request, (Object) postParams);
} }
@Override @Override
public <R extends HttpRequest> R bindToRequest(R request, Object toBind) { public <R extends HttpRequest> R bindToRequest(R request, Object toBind) {
Map<String, Object> test = new HashMap<String, Object>(); return super.bindToRequest(request, (Object) ImmutableMap.of("request", toBind));
test.put("request", toBind);
return super.bindToRequest(request, test);
} }
} }

View File

@ -41,7 +41,7 @@ public class RimuHostingRebootJsonBinder extends RimuHostingJsonBinder {
} }
@Override @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")); return super.bindToRequest(request, (Object) ImmutableMap.of("running_state", "RESTARTING"));
} }
} }

View File

@ -45,9 +45,9 @@ public class BindCreateBackupToXmlPayload implements MapBinder {
} }
@Override @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 sliceId = checkNotNull(postParams.get("slice_id"), "slice_id"); String sliceId = checkNotNull(postParams.get("slice_id"), "slice_id").toString();
String name = checkNotNull(postParams.get("name"), "name"); String name = checkNotNull(postParams.get("name"), "name").toString();
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><backup>"); builder.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><backup>");
builder.append("<slice-id type=\"integer\">").append(sliceId).append("</slice-id>"); 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; this.binder = binder;
} }
@Override @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 flavorId = checkNotNull(postParams.get("flavor_id"), "flavor_id"); String flavorId = checkNotNull(postParams.get("flavor_id"), "flavor_id").toString();
String imageId = checkNotNull(postParams.get("image_id"), "image_id"); String imageId = checkNotNull(postParams.get("image_id"), "image_id").toString();
String name = checkNotNull(postParams.get("name"), "name"); String name = checkNotNull(postParams.get("name"), "name").toString();
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><slice>"); builder.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><slice>");
builder.append("<flavor-id type=\"integer\">").append(flavorId).append("</flavor-id>"); builder.append("<flavor-id type=\"integer\">").append(flavorId).append("</flavor-id>");