attempting to operate against or retrieve pieces of a resource that doesn't exist should result in a ResourceNotFoundException, not null

This commit is contained in:
Adrian Cole 2012-06-08 11:05:52 -07:00
parent 70fa2b6c6d
commit 1fdfe5761f
4 changed files with 8 additions and 9 deletions

View File

@ -83,7 +83,6 @@ public interface NATAsyncClient {
@QueryParams(keys = { "command", "listAll" }, values = { "listIpForwardingRules", "true" }) @QueryParams(keys = { "command", "listAll" }, values = { "listIpForwardingRules", "true" })
@SelectJson("ipforwardingrule") @SelectJson("ipforwardingrule")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Set<IPForwardingRule>> getIPForwardingRulesForIPAddress(@QueryParam("ipaddressid") String id); ListenableFuture<Set<IPForwardingRule>> getIPForwardingRulesForIPAddress(@QueryParam("ipaddressid") String id);
/** /**
@ -93,7 +92,6 @@ public interface NATAsyncClient {
@QueryParams(keys = { "command", "listAll" }, values = { "listIpForwardingRules", "true" }) @QueryParams(keys = { "command", "listAll" }, values = { "listIpForwardingRules", "true" })
@SelectJson("ipforwardingrule") @SelectJson("ipforwardingrule")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Set<IPForwardingRule>> getIPForwardingRulesForVirtualMachine(@QueryParam("virtualmachineid") String id); ListenableFuture<Set<IPForwardingRule>> getIPForwardingRulesForVirtualMachine(@QueryParam("virtualmachineid") String id);
/** /**
@ -133,7 +131,6 @@ public interface NATAsyncClient {
@QueryParams(keys = "command", values = "disableStaticNat") @QueryParams(keys = "command", values = "disableStaticNat")
@SelectJson("jobid") @SelectJson("jobid")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<String> disableStaticNATOnPublicIP(@QueryParam("ipaddressid") String IPAddressId); ListenableFuture<String> disableStaticNATOnPublicIP(@QueryParam("ipaddressid") String IPAddressId);
} }

View File

@ -31,7 +31,7 @@ import org.jclouds.concurrent.Timeout;
* Provides synchronous access to CloudStack IPForwardingRule features. * Provides synchronous access to CloudStack IPForwardingRule features.
* <p/> * <p/>
* *
* @see IPForwardingRuleAsyncClient * @see NATAsyncClient
* @see <a * @see <a
* href="http://download.cloud.com/releases/2.2.0/api_2.2.12/TOC_User.html" * href="http://download.cloud.com/releases/2.2.0/api_2.2.12/TOC_User.html"
* /> * />

View File

@ -1,14 +1,17 @@
package org.jclouds.cloudstack.functions; package org.jclouds.cloudstack.functions;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.cache.CacheLoader;
import com.google.common.collect.ImmutableSet;
import java.util.Set; import java.util.Set;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.cloudstack.CloudStackClient; import org.jclouds.cloudstack.CloudStackClient;
import org.jclouds.cloudstack.domain.IPForwardingRule; import org.jclouds.cloudstack.domain.IPForwardingRule;
import com.google.common.cache.CacheLoader;
@Singleton @Singleton
public class GetIPForwardingRulesByVirtualMachine extends CacheLoader<String, Set<IPForwardingRule>> { public class GetIPForwardingRulesByVirtualMachine extends CacheLoader<String, Set<IPForwardingRule>> {
private final CloudStackClient client; private final CloudStackClient client;
@ -24,7 +27,6 @@ public class GetIPForwardingRulesByVirtualMachine extends CacheLoader<String, Se
*/ */
@Override @Override
public Set<IPForwardingRule> load(String input) { public Set<IPForwardingRule> load(String input) {
Set<IPForwardingRule> rules = client.getNATClient().getIPForwardingRulesForVirtualMachine(input); return client.getNATClient().getIPForwardingRulesForVirtualMachine(input);
return rules != null ? rules : ImmutableSet.<IPForwardingRule>of();
} }
} }

View File

@ -164,7 +164,7 @@ public class NATAsyncClientTest extends BaseCloudStackAsyncClientTest<NATAsyncCl
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class); assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
checkFilters(httpRequest); checkFilters(httpRequest);