mirror of https://github.com/apache/jclouds.git
Adding fix to Project.get fallback. Returns 400 or 404.
This commit is contained in:
parent
19245ec18b
commit
1772ea896b
|
@ -16,14 +16,27 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.googlecomputeengine;
|
package org.jclouds.googlecomputeengine;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static com.google.common.base.Predicates.in;
|
||||||
|
import static com.google.common.base.Throwables.propagate;
|
||||||
|
import static com.google.common.primitives.Ints.asList;
|
||||||
import static org.jclouds.Fallbacks.valOnNotFoundOr404;
|
import static org.jclouds.Fallbacks.valOnNotFoundOr404;
|
||||||
|
import static org.jclouds.http.HttpUtils.returnValueOnCodeOrNull;
|
||||||
|
|
||||||
import org.jclouds.Fallback;
|
import org.jclouds.Fallback;
|
||||||
import org.jclouds.googlecomputeengine.domain.ListPage;
|
import org.jclouds.googlecomputeengine.domain.ListPage;
|
||||||
|
|
||||||
public final class GoogleComputeEngineFallbacks {
|
public final class GoogleComputeEngineFallbacks {
|
||||||
|
public static class NullOn400or404 implements Fallback<Object> {
|
||||||
|
@Override public Object createOrPropagate(Throwable t) throws Exception {
|
||||||
|
Boolean returnVal = returnValueOnCodeOrNull(checkNotNull(t, "throwable"), false, in(asList(400, 404)));
|
||||||
|
if (returnVal != null)
|
||||||
|
return null;
|
||||||
|
throw propagate(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
public static final class EmptyListPageOnNotFoundOr404 implements Fallback<Object> {
|
public static final class EmptyListPageOnNotFoundOr404 implements Fallback<Object> {
|
||||||
public ListPage<Object> createOrPropagate(Throwable t) throws Exception {
|
@Override public ListPage<Object> createOrPropagate(Throwable t) throws Exception {
|
||||||
return valOnNotFoundOr404(ListPage.create(null, null, null), t);
|
return valOnNotFoundOr404(ListPage.create(null, null, null), t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,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.Fallbacks.NullOnNotFoundOr404;
|
import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.NullOn400or404;
|
||||||
import org.jclouds.googlecomputeengine.binders.MetadataBinder;
|
import org.jclouds.googlecomputeengine.binders.MetadataBinder;
|
||||||
import org.jclouds.googlecomputeengine.domain.Operation;
|
import org.jclouds.googlecomputeengine.domain.Operation;
|
||||||
import org.jclouds.googlecomputeengine.domain.Project;
|
import org.jclouds.googlecomputeengine.domain.Project;
|
||||||
|
@ -59,7 +59,7 @@ public interface ProjectApi {
|
||||||
@GET
|
@GET
|
||||||
@OAuthScopes(COMPUTE_READONLY_SCOPE)
|
@OAuthScopes(COMPUTE_READONLY_SCOPE)
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Fallback(NullOnNotFoundOr404.class)
|
@Fallback(NullOn400or404.class)
|
||||||
@Path("/projects/{project}")
|
@Path("/projects/{project}")
|
||||||
Project get(@PathParam("project") String projectName);
|
Project get(@PathParam("project") String projectName);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue