support null; add AuthorizationException

git-svn-id: http://jclouds.googlecode.com/svn/trunk@2717 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2010-01-22 00:30:07 +00:00
parent 56116204df
commit a17da70588
88 changed files with 580 additions and 443 deletions

View File

@ -20,7 +20,8 @@ package org.jclouds.atmosonline.saas.blobstore;
import static com.google.common.util.concurrent.Futures.compose; import static com.google.common.util.concurrent.Futures.compose;
import static org.jclouds.blobstore.options.ListContainerOptions.Builder.recursive; import static org.jclouds.blobstore.options.ListContainerOptions.Builder.recursive;
import static org.jclouds.concurrent.internal.ConcurrentUtils.makeListenable; import static org.jclouds.concurrent.ConcurrentUtils.convertExceptionToValue;
import static org.jclouds.concurrent.ConcurrentUtils.makeListenable;
import java.net.URI; import java.net.URI;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
@ -39,6 +40,7 @@ import org.jclouds.atmosonline.saas.blobstore.internal.BaseAtmosBlobStore;
import org.jclouds.atmosonline.saas.domain.AtmosObject; import org.jclouds.atmosonline.saas.domain.AtmosObject;
import org.jclouds.atmosonline.saas.options.ListOptions; import org.jclouds.atmosonline.saas.options.ListOptions;
import org.jclouds.blobstore.AsyncBlobStore; import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.KeyNotFoundException;
import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.domain.BlobMetadata; import org.jclouds.blobstore.domain.BlobMetadata;
import org.jclouds.blobstore.domain.ListContainerResponse; import org.jclouds.blobstore.domain.ListContainerResponse;
@ -81,8 +83,8 @@ public class AtmosAsyncBlobStore extends BaseAtmosBlobStore implements AsyncBlob
* This implementation uses the AtmosStorage HEAD Object command to return the result * This implementation uses the AtmosStorage HEAD Object command to return the result
*/ */
public ListenableFuture<BlobMetadata> blobMetadata(String container, String key) { public ListenableFuture<BlobMetadata> blobMetadata(String container, String key) {
return compose(async.headFile(container + "/" + key), return compose(convertExceptionToValue(async.headFile(container + "/" + key),
new Function<AtmosObject, BlobMetadata>() { KeyNotFoundException.class, null), new Function<AtmosObject, BlobMetadata>() {
@Override @Override
public BlobMetadata apply(AtmosObject from) { public BlobMetadata apply(AtmosObject from) {
return object2BlobMd.apply(from); return object2BlobMd.apply(from);
@ -155,7 +157,8 @@ public class AtmosAsyncBlobStore extends BaseAtmosBlobStore implements AsyncBlob
org.jclouds.blobstore.options.GetOptions... optionsList) { org.jclouds.blobstore.options.GetOptions... optionsList) {
GetOptions httpOptions = blob2ObjectGetOptions.apply(optionsList); GetOptions httpOptions = blob2ObjectGetOptions.apply(optionsList);
ListenableFuture<AtmosObject> returnVal = async.readFile(container + "/" + key, httpOptions); ListenableFuture<AtmosObject> returnVal = async.readFile(container + "/" + key, httpOptions);
return compose(returnVal, object2Blob, service); return compose(convertExceptionToValue(returnVal, KeyNotFoundException.class, null),
object2Blob, service);
} }
public ListenableFuture<? extends ListResponse<? extends StorageMetadata>> list() { public ListenableFuture<? extends ListResponse<? extends StorageMetadata>> list() {

View File

@ -19,6 +19,7 @@
package org.jclouds.atmosonline.saas.blobstore; package org.jclouds.atmosonline.saas.blobstore;
import static org.jclouds.blobstore.options.ListContainerOptions.Builder.recursive; import static org.jclouds.blobstore.options.ListContainerOptions.Builder.recursive;
import static org.jclouds.blobstore.util.BlobStoreUtils.returnNullOnKeyNotFoundOrPropagate;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
@ -71,7 +72,11 @@ public class AtmosBlobStore extends BaseAtmosBlobStore implements BlobStore {
* This implementation uses the AtmosStorage HEAD Object command to return the result * This implementation uses the AtmosStorage HEAD Object command to return the result
*/ */
public BlobMetadata blobMetadata(String container, String key) { public BlobMetadata blobMetadata(String container, String key) {
try {
return object2BlobMd.apply(sync.headFile(container + "/" + key)); return object2BlobMd.apply(sync.headFile(container + "/" + key));
} catch (Exception e) {
return returnNullOnKeyNotFoundOrPropagate(e);
}
} }
public void clearContainer(final String container) { public void clearContainer(final String container) {
@ -115,13 +120,21 @@ public class AtmosBlobStore extends BaseAtmosBlobStore implements BlobStore {
} }
public boolean directoryExists(String container, String directory) { public boolean directoryExists(String container, String directory) {
try {
return sync.pathExists(container + "/" + directory); return sync.pathExists(container + "/" + directory);
} catch (Exception e) {
return (Boolean)returnNullOnKeyNotFoundOrPropagate(e);
}
} }
public Blob getBlob(String container, String key, public Blob getBlob(String container, String key,
org.jclouds.blobstore.options.GetOptions... optionsList) { org.jclouds.blobstore.options.GetOptions... optionsList) {
GetOptions httpOptions = blob2ObjectGetOptions.apply(optionsList); GetOptions httpOptions = blob2ObjectGetOptions.apply(optionsList);
try {
return object2Blob.apply(sync.readFile(container + "/" + key, httpOptions)); return object2Blob.apply(sync.readFile(container + "/" + key, httpOptions));
} catch (Exception e) {
return returnNullOnKeyNotFoundOrPropagate(e);
}
} }
public ListResponse<? extends StorageMetadata> list() { public ListResponse<? extends StorageMetadata> list() {

View File

@ -44,11 +44,13 @@ public class BlobMetadataToObject implements Function<BlobMetadata, AtmosObject>
this.blob2SysMd = blob2SysMd; this.blob2SysMd = blob2SysMd;
} }
public AtmosObject apply(BlobMetadata base) { public AtmosObject apply(BlobMetadata from) {
if (from == null)
return null;
UserMetadata userMd = new UserMetadata(); UserMetadata userMd = new UserMetadata();
if (base.getUserMetadata() != null) if (from.getUserMetadata() != null)
userMd.getMetadata().putAll(base.getUserMetadata()); userMd.getMetadata().putAll(from.getUserMetadata());
return factory.create(blob2ContentMd.apply(base), blob2SysMd.apply(base), userMd); return factory.create(blob2ContentMd.apply(from), blob2SysMd.apply(from), userMd);
} }
} }

View File

@ -39,6 +39,8 @@ public class BlobToObject implements Function<Blob, AtmosObject> {
} }
public AtmosObject apply(Blob from) { public AtmosObject apply(Blob from) {
if (from == null)
return null;
AtmosObject object = blobMd2Object.apply(from.getMetadata()); AtmosObject object = blobMd2Object.apply(from.getMetadata());
object.setPayload(from.getPayload()); object.setPayload(from.getPayload());
object.setAllHeaders(from.getAllHeaders()); object.setAllHeaders(from.getAllHeaders());

View File

@ -42,6 +42,8 @@ public class ObjectToBlob implements Function<AtmosObject, Blob> {
} }
public Blob apply(AtmosObject from) { public Blob apply(AtmosObject from) {
if (from == null)
return null;
Blob blob = blobFactory.create(object2BlobMd.apply(from)); Blob blob = blobFactory.create(object2BlobMd.apply(from));
if (from.getContentMetadata().getContentLength() != null) if (from.getContentMetadata().getContentLength() != null)
blob.setContentLength(from.getContentMetadata().getContentLength()); blob.setContentLength(from.getContentMetadata().getContentLength());

View File

@ -55,6 +55,8 @@ public class ObjectToBlobMetadata implements Function<AtmosObject, MutableBlobMe
} }
public MutableBlobMetadata apply(AtmosObject from) { public MutableBlobMetadata apply(AtmosObject from) {
if (from == null)
return null;
MutableBlobMetadata to = new MutableBlobMetadataImpl(); MutableBlobMetadata to = new MutableBlobMetadataImpl();
to.setId(from.getSystemMetadata().getObjectID()); to.setId(from.getSystemMetadata().getObjectID());
to.setLastModified(from.getSystemMetadata().getLastUserDataModification()); to.setLastModified(from.getSystemMetadata().getLastUserDataModification());

View File

@ -18,6 +18,8 @@
*/ */
package org.jclouds.atmosonline.saas.functions; package org.jclouds.atmosonline.saas.functions;
import static org.jclouds.util.Utils.propagateOrNull;
import java.net.URI; import java.net.URI;
import org.jclouds.blobstore.KeyAlreadyExistsException; import org.jclouds.blobstore.KeyAlreadyExistsException;
@ -38,7 +40,7 @@ public class ReturnEndpointIfAlreadyExists implements Function<Exception, URI>,
if (from instanceof KeyAlreadyExistsException) { if (from instanceof KeyAlreadyExistsException) {
return endpoint; return endpoint;
} }
return null; return URI.class.cast(propagateOrNull(from));
} }
public void setContext(GeneratedHttpRequest<?> request) { public void setContext(GeneratedHttpRequest<?> request) {

View File

@ -45,7 +45,7 @@ import org.jclouds.blobstore.functions.ThrowKeyNotFoundOn404;
import org.jclouds.date.TimeStamp; import org.jclouds.date.TimeStamp;
import org.jclouds.encryption.internal.Base64; import org.jclouds.encryption.internal.Base64;
import org.jclouds.http.functions.ParseURIFromListOrLocationHeaderIf20x; import org.jclouds.http.functions.ParseURIFromListOrLocationHeaderIf20x;
import org.jclouds.http.functions.ReturnVoidIf2xx; import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.http.options.GetOptions; import org.jclouds.http.options.GetOptions;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.logging.Logger.LoggerFactory;
@ -199,7 +199,7 @@ public class AtmosStorageClientTest extends RestClientTest<AtmosStorageAsyncClie
+ ": */*\nContent-Length: 5\nContent-Type: text/plain\n"); + ": */*\nContent-Length: 5\nContent-Type: text/plain\n");
assertPayloadEquals(httpMethod, "hello"); assertPayloadEquals(httpMethod, "hello");
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ThrowKeyNotFoundOn404.class); assertExceptionParserClassEquals(method, ThrowKeyNotFoundOn404.class);
@ -252,7 +252,7 @@ public class AtmosStorageClientTest extends RestClientTest<AtmosStorageAsyncClie
assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT + ": */*\n"); assertHeadersEqual(httpMethod, HttpHeaders.ACCEPT + ": */*\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class); assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);

View File

@ -40,7 +40,6 @@ import org.jclouds.atmosonline.saas.domain.DirectoryEntry;
import org.jclouds.atmosonline.saas.domain.SystemMetadata; import org.jclouds.atmosonline.saas.domain.SystemMetadata;
import org.jclouds.atmosonline.saas.domain.UserMetadata; import org.jclouds.atmosonline.saas.domain.UserMetadata;
import org.jclouds.atmosonline.saas.options.ListOptions; import org.jclouds.atmosonline.saas.options.ListOptions;
import org.jclouds.blobstore.KeyNotFoundException;
import org.jclouds.blobstore.attr.ConsistencyModel; import org.jclouds.blobstore.attr.ConsistencyModel;
import org.jclouds.blobstore.attr.ConsistencyModels; import org.jclouds.blobstore.attr.ConsistencyModels;
import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.Blob;
@ -48,11 +47,9 @@ import org.jclouds.blobstore.domain.BlobMetadata;
import org.jclouds.blobstore.functions.HttpGetOptionsListToGetOptions; import org.jclouds.blobstore.functions.HttpGetOptionsListToGetOptions;
import org.jclouds.blobstore.integration.internal.StubAsyncBlobStore; import org.jclouds.blobstore.integration.internal.StubAsyncBlobStore;
import org.jclouds.http.options.GetOptions; import org.jclouds.http.options.GetOptions;
import org.jclouds.rest.ResourceNotFoundException;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
import com.google.common.collect.Iterables;
import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
@ -204,16 +201,10 @@ public class StubAtmosStorageAsyncClient implements AtmosStorageAsyncClient {
String container = path.substring(0, path.indexOf('/')); String container = path.substring(0, path.indexOf('/'));
String blobName = path.substring(path.indexOf('/') + 1); String blobName = path.substring(path.indexOf('/') + 1);
try { try {
blobStore.blobMetadata(container, blobName).get(); return immediateFuture(blobStore.blobMetadata(container, blobName).get() != null);
return immediateFuture(true);
} catch (KeyNotFoundException e) {
return immediateFuture(false);
} catch (InterruptedException e) { } catch (InterruptedException e) {
return immediateFuture(false); return immediateFailedFuture(e);
} catch (ExecutionException e) { } catch (ExecutionException e) {
if (Iterables.size(Iterables.filter(Throwables.getCausalChain(e),
ResourceNotFoundException.class)) >= 1)
return immediateFuture(false);
return immediateFailedFuture(e); return immediateFailedFuture(e);
} }
} }

View File

@ -18,7 +18,7 @@
*/ */
package org.jclouds.aws.ec2.functions; package org.jclouds.aws.ec2.functions;
import java.lang.reflect.Constructor; import static org.jclouds.util.Utils.propagateOrNull;
import javax.inject.Singleton; import javax.inject.Singleton;
@ -29,24 +29,12 @@ import com.google.common.base.Function;
@Singleton @Singleton
public class ReturnVoidOnGroupNotFound implements Function<Exception, Void> { public class ReturnVoidOnGroupNotFound implements Function<Exception, Void> {
static final Void v;
static {
Constructor<Void> cv;
try {
cv = Void.class.getDeclaredConstructor();
cv.setAccessible(true);
v = cv.newInstance();
} catch (Exception e) {
throw new Error("Error setting up class", e);
}
}
public Void apply(Exception from) { public Void apply(Exception from) {
if (from instanceof AWSResponseException) { if (from instanceof AWSResponseException) {
if (((AWSResponseException) from).getError().getCode().equals("InvalidGroup.NotFound")) if (((AWSResponseException) from).getError().getCode().equals("InvalidGroup.NotFound"))
return v;
}
return null; return null;
} }
return Void.class.cast(propagateOrNull(from));
}
} }

View File

@ -18,7 +18,7 @@
*/ */
package org.jclouds.aws.ec2.functions; package org.jclouds.aws.ec2.functions;
import java.lang.reflect.Constructor; import static org.jclouds.util.Utils.propagateOrNull;
import javax.inject.Singleton; import javax.inject.Singleton;
@ -29,26 +29,14 @@ import com.google.common.base.Function;
@Singleton @Singleton
public class ReturnVoidOnVolumeAvailable implements Function<Exception, Void> { public class ReturnVoidOnVolumeAvailable implements Function<Exception, Void> {
static final Void v;
static {
Constructor<Void> cv;
try {
cv = Void.class.getDeclaredConstructor();
cv.setAccessible(true);
v = cv.newInstance();
} catch (Exception e) {
throw new Error("Error setting up class", e);
}
}
public Void apply(Exception from) { public Void apply(Exception from) {
if (from instanceof AWSResponseException) { if (from instanceof AWSResponseException) {
AWSResponseException e = (AWSResponseException) from; AWSResponseException e = (AWSResponseException) from;
if (e.getError().getCode().equals("IncorrectState") if (e.getError().getCode().equals("IncorrectState")
&& e.getError().getCode().contains("available")) && e.getError().getCode().contains("available"))
return v;
}
return null; return null;
} }
return Void.class.cast(propagateOrNull(from));
}
} }

View File

@ -20,7 +20,8 @@ package org.jclouds.aws.s3.blobstore;
import static com.google.common.util.concurrent.Futures.compose; import static com.google.common.util.concurrent.Futures.compose;
import static org.jclouds.blobstore.options.ListContainerOptions.Builder.recursive; import static org.jclouds.blobstore.options.ListContainerOptions.Builder.recursive;
import static org.jclouds.concurrent.internal.ConcurrentUtils.makeListenable; import static org.jclouds.concurrent.ConcurrentUtils.convertExceptionToValue;
import static org.jclouds.concurrent.ConcurrentUtils.makeListenable;
import java.util.SortedSet; import java.util.SortedSet;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
@ -87,8 +88,8 @@ public class S3AsyncBlobStore extends BaseS3BlobStore implements AsyncBlobStore
* This implementation uses the S3 HEAD Object command to return the result * This implementation uses the S3 HEAD Object command to return the result
*/ */
public ListenableFuture<BlobMetadata> blobMetadata(String container, String key) { public ListenableFuture<BlobMetadata> blobMetadata(String container, String key) {
return compose(makeListenable(async.headObject(container, key), service), return compose(convertExceptionToValue(async.headObject(container, key),
new Function<ObjectMetadata, BlobMetadata>() { KeyNotFoundException.class, null), new Function<ObjectMetadata, BlobMetadata>() {
@Override @Override
public BlobMetadata apply(ObjectMetadata from) { public BlobMetadata apply(ObjectMetadata from) {
@ -158,7 +159,8 @@ public class S3AsyncBlobStore extends BaseS3BlobStore implements AsyncBlobStore
public ListenableFuture<Blob> getBlob(String container, String key, public ListenableFuture<Blob> getBlob(String container, String key,
org.jclouds.blobstore.options.GetOptions... optionsList) { org.jclouds.blobstore.options.GetOptions... optionsList) {
GetOptions httpOptions = blob2ObjectGetOptions.apply(optionsList); GetOptions httpOptions = blob2ObjectGetOptions.apply(optionsList);
return compose(async.getObject(container, key, httpOptions), object2Blob, service); return compose(convertExceptionToValue(async.getObject(container, key, httpOptions),
KeyNotFoundException.class, null), object2Blob, service);
} }
public ListenableFuture<? extends ListResponse<? extends StorageMetadata>> list() { public ListenableFuture<? extends ListResponse<? extends StorageMetadata>> list() {

View File

@ -19,6 +19,7 @@
package org.jclouds.aws.s3.blobstore; package org.jclouds.aws.s3.blobstore;
import static org.jclouds.blobstore.options.ListContainerOptions.Builder.recursive; import static org.jclouds.blobstore.options.ListContainerOptions.Builder.recursive;
import static org.jclouds.blobstore.util.BlobStoreUtils.returnNullOnKeyNotFoundOrPropagate;
import java.util.SortedSet; import java.util.SortedSet;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
@ -80,7 +81,11 @@ public class S3BlobStore extends BaseS3BlobStore implements BlobStore {
* This implementation uses the S3 HEAD Object command to return the result * This implementation uses the S3 HEAD Object command to return the result
*/ */
public BlobMetadata blobMetadata(String container, String key) { public BlobMetadata blobMetadata(String container, String key) {
try {
return object2BlobMd.apply(sync.headObject(container, key)); return object2BlobMd.apply(sync.headObject(container, key));
} catch (Exception e) {
return returnNullOnKeyNotFoundOrPropagate(e);
}
} }
public void clearContainer(String container) { public void clearContainer(String container) {
@ -116,7 +121,11 @@ public class S3BlobStore extends BaseS3BlobStore implements BlobStore {
public Blob getBlob(String container, String key, public Blob getBlob(String container, String key,
org.jclouds.blobstore.options.GetOptions... optionsList) { org.jclouds.blobstore.options.GetOptions... optionsList) {
GetOptions httpOptions = blob2ObjectGetOptions.apply(optionsList); GetOptions httpOptions = blob2ObjectGetOptions.apply(optionsList);
try {
return object2Blob.apply(sync.getObject(container, key, httpOptions)); return object2Blob.apply(sync.getObject(container, key, httpOptions));
} catch (Exception e) {
return returnNullOnKeyNotFoundOrPropagate(e);
}
} }
public ListResponse<? extends StorageMetadata> list() { public ListResponse<? extends StorageMetadata> list() {

View File

@ -41,6 +41,8 @@ public class BlobToObject implements Function<Blob, S3Object> {
} }
public S3Object apply(Blob from) { public S3Object apply(Blob from) {
if (from == null)
return null;
S3Object object = objectProvider.create(blob2ObjectMd.apply(from.getMetadata())); S3Object object = objectProvider.create(blob2ObjectMd.apply(from.getMetadata()));
if (from.getContentLength() != null) if (from.getContentLength() != null)
object.setContentLength(from.getContentLength()); object.setContentLength(from.getContentLength());

View File

@ -31,17 +31,19 @@ import com.google.common.base.Function;
*/ */
@Singleton @Singleton
public class BlobToObjectMetadata implements Function<BlobMetadata, MutableObjectMetadata> { public class BlobToObjectMetadata implements Function<BlobMetadata, MutableObjectMetadata> {
public MutableObjectMetadata apply(BlobMetadata base) { public MutableObjectMetadata apply(BlobMetadata from) {
if (from == null)
return null;
MutableObjectMetadata to = new MutableObjectMetadataImpl(); MutableObjectMetadata to = new MutableObjectMetadataImpl();
to.setContentType(base.getContentType()); to.setContentType(from.getContentType());
to.setETag(base.getETag()); to.setETag(from.getETag());
to.setContentMD5(base.getContentMD5()); to.setContentMD5(from.getContentMD5());
to.setKey(base.getName()); to.setKey(from.getName());
to.setLastModified(base.getLastModified()); to.setLastModified(from.getLastModified());
if (base.getSize() != null) if (from.getSize() != null)
to.setSize(base.getSize()); to.setSize(from.getSize());
if (base.getUserMetadata() != null) if (from.getUserMetadata() != null)
to.setUserMetadata(base.getUserMetadata()); to.setUserMetadata(from.getUserMetadata());
return to; return to;
} }

View File

@ -42,6 +42,8 @@ public class ObjectToBlob implements Function<S3Object, Blob> {
} }
public Blob apply(S3Object from) { public Blob apply(S3Object from) {
if (from == null)
return null;
Blob blob = blobFactory.create(object2BlobMd.apply(from.getMetadata())); Blob blob = blobFactory.create(object2BlobMd.apply(from.getMetadata()));
if (from.getContentLength() != null) if (from.getContentLength() != null)
blob.setContentLength(from.getContentLength()); blob.setContentLength(from.getContentLength());

View File

@ -42,6 +42,8 @@ public class ObjectToBlobMetadata implements Function<ObjectMetadata, MutableBlo
} }
public MutableBlobMetadata apply(ObjectMetadata from) { public MutableBlobMetadata apply(ObjectMetadata from) {
if (from == null)
return null;
MutableBlobMetadata to = new MutableBlobMetadataImpl(); MutableBlobMetadata to = new MutableBlobMetadataImpl();
to.setContentMD5(from.getContentMD5()); to.setContentMD5(from.getContentMD5());
if (from.getContentType() != null) if (from.getContentType() != null)

View File

@ -18,6 +18,8 @@
*/ */
package org.jclouds.aws.s3.functions; package org.jclouds.aws.s3.functions;
import static org.jclouds.util.Utils.propagateOrNull;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.aws.AWSResponseException; import org.jclouds.aws.AWSResponseException;
@ -38,7 +40,6 @@ public class ReturnTrueIfBucketAlreadyOwnedByYou implements Function<Exception,
return true; return true;
} }
} }
return null; return Boolean.class.cast(propagateOrNull(from));
} }
} }

View File

@ -18,6 +18,8 @@
*/ */
package org.jclouds.aws.s3.functions; package org.jclouds.aws.s3.functions;
import static org.jclouds.util.Utils.propagateOrNull;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.aws.AWSResponseException; import org.jclouds.aws.AWSResponseException;
@ -37,7 +39,6 @@ public class ReturnTrueOn404FalseIfNotEmpty implements Function<Exception, Boole
return false; return false;
} }
} }
return null; return Boolean.class.cast(propagateOrNull(from));
} }
} }

View File

@ -44,7 +44,7 @@ import org.jclouds.aws.filters.FormSigner;
import org.jclouds.aws.reference.AWSConstants; import org.jclouds.aws.reference.AWSConstants;
import org.jclouds.date.TimeStamp; import org.jclouds.date.TimeStamp;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ReturnVoidIf2xx; import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.logging.Logger.LoggerFactory;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
@ -165,7 +165,7 @@ public class AMIAsyncClientTest extends RestClientTest<AMIAsyncClient> {
"Content-Length: 57\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.amazonaws.com\n"); "Content-Length: 57\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.amazonaws.com\n");
assertPayloadEquals(httpMethod, "Version=2009-11-30&Action=DeregisterImage&ImageId=imageId"); assertPayloadEquals(httpMethod, "Version=2009-11-30&Action=DeregisterImage&ImageId=imageId");
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
@ -339,7 +339,7 @@ public class AMIAsyncClientTest extends RestClientTest<AMIAsyncClient> {
httpMethod, httpMethod,
"Action=ModifyImageAttribute&Attribute=launchPermission&ImageId=imageId&OperationType=add&Signature=pWWwIIdcLSw0vrWFpRsCnHk93X3qYWVfcl%2FaXRhoFd8%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&UserGroup.1=all&UserId.1=bob&UserId.2=sue&Version=2009-11-30&AWSAccessKeyId=user"); "Action=ModifyImageAttribute&Attribute=launchPermission&ImageId=imageId&OperationType=add&Signature=pWWwIIdcLSw0vrWFpRsCnHk93X3qYWVfcl%2FaXRhoFd8%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&UserGroup.1=all&UserId.1=bob&UserId.2=sue&Version=2009-11-30&AWSAccessKeyId=user");
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
@ -359,7 +359,7 @@ public class AMIAsyncClientTest extends RestClientTest<AMIAsyncClient> {
assertPayloadEquals( assertPayloadEquals(
httpMethod, httpMethod,
"Version=2009-11-30&Action=ModifyImageAttribute&OperationType=remove&Attribute=launchPermission&ImageId=imageId&UserGroup.1=all&UserId.1=bob&UserId.2=sue"); "Version=2009-11-30&Action=ModifyImageAttribute&OperationType=remove&Attribute=launchPermission&ImageId=imageId&UserGroup.1=all&UserId.1=bob&UserId.2=sue");
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
@ -378,7 +378,7 @@ public class AMIAsyncClientTest extends RestClientTest<AMIAsyncClient> {
"Content-Length: 88\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.amazonaws.com\n"); "Content-Length: 88\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(httpMethod,
"Version=2009-11-30&Action=ResetImageAttribute&Attribute=launchPermission&ImageId=imageId"); "Version=2009-11-30&Action=ResetImageAttribute&Attribute=launchPermission&ImageId=imageId");
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
@ -399,7 +399,7 @@ public class AMIAsyncClientTest extends RestClientTest<AMIAsyncClient> {
httpMethod, httpMethod,
"Version=2009-11-30&Action=ModifyImageAttribute&OperationType=add&Attribute=productCodes&ImageId=imageId&ProductCode.1=code1&ProductCode.2=code2"); "Version=2009-11-30&Action=ModifyImageAttribute&OperationType=add&Attribute=productCodes&ImageId=imageId&ProductCode.1=code1&ProductCode.2=code2");
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
@ -420,7 +420,7 @@ public class AMIAsyncClientTest extends RestClientTest<AMIAsyncClient> {
httpMethod, httpMethod,
"Version=2009-11-30&Action=ModifyImageAttribute&OperationType=remove&Attribute=productCodes&ImageId=imageId&ProductCode.1=code1&ProductCode.2=code2"); "Version=2009-11-30&Action=ModifyImageAttribute&OperationType=remove&Attribute=productCodes&ImageId=imageId&ProductCode.1=code1&ProductCode.2=code2");
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);

View File

@ -47,7 +47,7 @@ import org.jclouds.aws.filters.FormSigner;
import org.jclouds.aws.reference.AWSConstants; import org.jclouds.aws.reference.AWSConstants;
import org.jclouds.date.TimeStamp; import org.jclouds.date.TimeStamp;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ReturnVoidIf2xx; import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.logging.Logger.LoggerFactory;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
@ -121,7 +121,7 @@ public class ElasticBlockStoreAsyncClientTest extends RestClientTest<ElasticBloc
"Content-Length: 50\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.amazonaws.com\n"); "Content-Length: 50\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.amazonaws.com\n");
assertPayloadEquals(httpMethod, "Version=2009-11-30&Action=DeleteVolume&VolumeId=id"); assertPayloadEquals(httpMethod, "Version=2009-11-30&Action=DeleteVolume&VolumeId=id");
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
@ -198,7 +198,7 @@ public class ElasticBlockStoreAsyncClientTest extends RestClientTest<ElasticBloc
assertPayloadEquals(httpMethod, assertPayloadEquals(httpMethod,
"Version=2009-11-30&Action=DetachVolume&Force=false&VolumeId=id"); "Version=2009-11-30&Action=DetachVolume&Force=false&VolumeId=id");
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnVoidOnVolumeAvailable.class); assertExceptionParserClassEquals(method, ReturnVoidOnVolumeAvailable.class);
@ -221,7 +221,7 @@ public class ElasticBlockStoreAsyncClientTest extends RestClientTest<ElasticBloc
httpMethod, httpMethod,
"Version=2009-11-30&Action=DetachVolume&Force=true&VolumeId=id&InstanceId=instanceId&Device=%2Fdevice"); "Version=2009-11-30&Action=DetachVolume&Force=true&VolumeId=id&InstanceId=instanceId&Device=%2Fdevice");
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnVoidOnVolumeAvailable.class); assertExceptionParserClassEquals(method, ReturnVoidOnVolumeAvailable.class);
@ -346,7 +346,7 @@ public class ElasticBlockStoreAsyncClientTest extends RestClientTest<ElasticBloc
httpMethod, httpMethod,
"Version=2009-11-30&Action=ModifySnapshotAttribute&OperationType=add&Attribute=createVolumePermission&SnapshotId=snapshotId&UserGroup.1=all&UserId.1=bob&UserId.2=sue"); "Version=2009-11-30&Action=ModifySnapshotAttribute&OperationType=add&Attribute=createVolumePermission&SnapshotId=snapshotId&UserGroup.1=all&UserId.1=bob&UserId.2=sue");
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
@ -368,7 +368,7 @@ public class ElasticBlockStoreAsyncClientTest extends RestClientTest<ElasticBloc
assertPayloadEquals( assertPayloadEquals(
httpMethod, httpMethod,
"Version=2009-11-30&Action=ModifySnapshotAttribute&OperationType=remove&Attribute=createVolumePermission&SnapshotId=snapshotId&UserGroup.1=all&UserId.1=bob&UserId.2=sue"); "Version=2009-11-30&Action=ModifySnapshotAttribute&OperationType=remove&Attribute=createVolumePermission&SnapshotId=snapshotId&UserGroup.1=all&UserId.1=bob&UserId.2=sue");
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
@ -388,7 +388,7 @@ public class ElasticBlockStoreAsyncClientTest extends RestClientTest<ElasticBloc
assertPayloadEquals( assertPayloadEquals(
httpMethod, httpMethod,
"Version=2009-11-30&Action=ResetSnapshotAttribute&Attribute=createVolumePermission&SnapshotId=snapshotId"); "Version=2009-11-30&Action=ResetSnapshotAttribute&Attribute=createVolumePermission&SnapshotId=snapshotId");
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);

View File

@ -37,7 +37,7 @@ import org.jclouds.aws.filters.FormSigner;
import org.jclouds.aws.reference.AWSConstants; import org.jclouds.aws.reference.AWSConstants;
import org.jclouds.date.TimeStamp; import org.jclouds.date.TimeStamp;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ReturnVoidIf2xx; import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.logging.Logger.LoggerFactory;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
@ -73,7 +73,7 @@ public class ElasticIPAddressAsyncClientTest extends RestClientTest<ElasticIPAdd
assertPayloadEquals(httpMethod, assertPayloadEquals(httpMethod,
"Version=2009-11-30&Action=DisassociateAddress&PublicIp=127.0.0.1"); "Version=2009-11-30&Action=DisassociateAddress&PublicIp=127.0.0.1");
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
@ -92,7 +92,7 @@ public class ElasticIPAddressAsyncClientTest extends RestClientTest<ElasticIPAdd
assertPayloadEquals(httpMethod, assertPayloadEquals(httpMethod,
"Version=2009-11-30&Action=AssociateAddress&InstanceId=me&PublicIp=127.0.0.1"); "Version=2009-11-30&Action=AssociateAddress&InstanceId=me&PublicIp=127.0.0.1");
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
@ -110,7 +110,7 @@ public class ElasticIPAddressAsyncClientTest extends RestClientTest<ElasticIPAdd
"Content-Length: 59\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.amazonaws.com\n"); "Content-Length: 59\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.amazonaws.com\n");
assertPayloadEquals(httpMethod, "Version=2009-11-30&Action=ReleaseAddress&PublicIp=127.0.0.1"); assertPayloadEquals(httpMethod, "Version=2009-11-30&Action=ReleaseAddress&PublicIp=127.0.0.1");
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);

View File

@ -47,7 +47,7 @@ import org.jclouds.aws.filters.FormSigner;
import org.jclouds.aws.reference.AWSConstants; import org.jclouds.aws.reference.AWSConstants;
import org.jclouds.date.TimeStamp; import org.jclouds.date.TimeStamp;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ReturnVoidIf2xx; import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.logging.Logger.LoggerFactory;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
@ -203,7 +203,7 @@ public class InstanceAsyncClientTest extends RestClientTest<InstanceAsyncClient>
assertPayloadEquals(httpMethod, assertPayloadEquals(httpMethod,
"Version=2009-11-30&Action=RebootInstances&InstanceId.1=1&InstanceId.2=2"); "Version=2009-11-30&Action=RebootInstances&InstanceId.1=1&InstanceId.2=2");
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
@ -409,7 +409,7 @@ public class InstanceAsyncClientTest extends RestClientTest<InstanceAsyncClient>
httpMethod, httpMethod,
"Action=ModifyInstanceAttribute&Attribute=userData&InstanceId=1&Signature=LyanxPcmESLrkIIFu9RX2yGN1rSQmyF489LYcoszbFE%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&Value=dGVzdA%3D%3D&Version=2009-11-30&AWSAccessKeyId=user"); "Action=ModifyInstanceAttribute&Attribute=userData&InstanceId=1&Signature=LyanxPcmESLrkIIFu9RX2yGN1rSQmyF489LYcoszbFE%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&Value=dGVzdA%3D%3D&Version=2009-11-30&AWSAccessKeyId=user");
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
@ -428,7 +428,7 @@ public class InstanceAsyncClientTest extends RestClientTest<InstanceAsyncClient>
"Content-Length: 91\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.amazonaws.com\n"); "Content-Length: 91\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(httpMethod,
"Version=2009-11-30&Action=ModifyInstanceAttribute&Attribute=ramdisk&Value=test&InstanceId=1"); "Version=2009-11-30&Action=ModifyInstanceAttribute&Attribute=ramdisk&Value=test&InstanceId=1");
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
@ -447,7 +447,7 @@ public class InstanceAsyncClientTest extends RestClientTest<InstanceAsyncClient>
"Content-Length: 90\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.amazonaws.com\n"); "Content-Length: 90\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.amazonaws.com\n");
assertPayloadEquals(httpMethod, assertPayloadEquals(httpMethod,
"Version=2009-11-30&Action=ModifyInstanceAttribute&Attribute=kernel&Value=test&InstanceId=1"); "Version=2009-11-30&Action=ModifyInstanceAttribute&Attribute=kernel&Value=test&InstanceId=1");
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
@ -469,7 +469,7 @@ public class InstanceAsyncClientTest extends RestClientTest<InstanceAsyncClient>
httpMethod, httpMethod,
"Version=2009-11-30&Action=ModifyInstanceAttribute&Attribute=disableApiTermination&Value=true&InstanceId=1"); "Version=2009-11-30&Action=ModifyInstanceAttribute&Attribute=disableApiTermination&Value=true&InstanceId=1");
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
@ -490,7 +490,7 @@ public class InstanceAsyncClientTest extends RestClientTest<InstanceAsyncClient>
httpMethod, httpMethod,
"Version=2009-11-30&Action=ModifyInstanceAttribute&Attribute=instanceType&Value=c1.medium&InstanceId=1"); "Version=2009-11-30&Action=ModifyInstanceAttribute&Attribute=instanceType&Value=c1.medium&InstanceId=1");
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
@ -512,7 +512,7 @@ public class InstanceAsyncClientTest extends RestClientTest<InstanceAsyncClient>
httpMethod, httpMethod,
"Version=2009-11-30&Action=ModifyInstanceAttribute&Attribute=instanceInitiatedShutdownBehavior&Value=terminate&InstanceId=1"); "Version=2009-11-30&Action=ModifyInstanceAttribute&Attribute=instanceInitiatedShutdownBehavior&Value=terminate&InstanceId=1");
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
@ -538,7 +538,7 @@ public class InstanceAsyncClientTest extends RestClientTest<InstanceAsyncClient>
httpMethod, httpMethod,
"Action=ModifyInstanceAttribute&Attribute=blockDeviceMapping&InstanceId=1&Signature=KNCKfLATSmpXGuIBpXOx3lBmHv9tyu17Cxrfi%2FTzQHE%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&Value=test&Version=2009-11-30&AWSAccessKeyId=user"); "Action=ModifyInstanceAttribute&Attribute=blockDeviceMapping&InstanceId=1&Signature=KNCKfLATSmpXGuIBpXOx3lBmHv9tyu17Cxrfi%2FTzQHE%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&Value=test&Version=2009-11-30&AWSAccessKeyId=user");
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);

View File

@ -35,7 +35,7 @@ import org.jclouds.aws.filters.FormSigner;
import org.jclouds.aws.reference.AWSConstants; import org.jclouds.aws.reference.AWSConstants;
import org.jclouds.date.TimeStamp; import org.jclouds.date.TimeStamp;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ReturnVoidIf2xx; import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.logging.Logger.LoggerFactory;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
@ -69,7 +69,7 @@ public class KeyPairAsyncClientTest extends RestClientTest<KeyPairAsyncClient> {
"Content-Length: 53\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.amazonaws.com\n"); "Content-Length: 53\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.amazonaws.com\n");
assertPayloadEquals(httpMethod, "Version=2009-11-30&Action=DeleteKeyPair&KeyName=mykey"); assertPayloadEquals(httpMethod, "Version=2009-11-30&Action=DeleteKeyPair&KeyName=mykey");
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);

View File

@ -38,7 +38,7 @@ import org.jclouds.aws.filters.FormSigner;
import org.jclouds.aws.reference.AWSConstants; import org.jclouds.aws.reference.AWSConstants;
import org.jclouds.date.TimeStamp; import org.jclouds.date.TimeStamp;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ReturnVoidIf2xx; import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.logging.Logger.LoggerFactory;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
@ -74,7 +74,7 @@ public class SecurityGroupAsyncClientTest extends RestClientTest<SecurityGroupAs
assertPayloadEquals(httpMethod, assertPayloadEquals(httpMethod,
"Version=2009-11-30&Action=DeleteSecurityGroup&GroupName=name"); "Version=2009-11-30&Action=DeleteSecurityGroup&GroupName=name");
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnVoidOnGroupNotFound.class); assertExceptionParserClassEquals(method, ReturnVoidOnGroupNotFound.class);
@ -94,7 +94,7 @@ public class SecurityGroupAsyncClientTest extends RestClientTest<SecurityGroupAs
assertPayloadEquals(httpMethod, assertPayloadEquals(httpMethod,
"Version=2009-11-30&Action=CreateSecurityGroup&GroupDescription=description&GroupName=name"); "Version=2009-11-30&Action=CreateSecurityGroup&GroupDescription=description&GroupName=name");
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
@ -155,7 +155,7 @@ public class SecurityGroupAsyncClientTest extends RestClientTest<SecurityGroupAs
httpMethod, httpMethod,
"Version=2009-11-30&Action=AuthorizeSecurityGroupIngress&GroupName=group&SourceSecurityGroupOwnerId=sourceUser&SourceSecurityGroupName=sourceGroup"); "Version=2009-11-30&Action=AuthorizeSecurityGroupIngress&GroupName=group&SourceSecurityGroupOwnerId=sourceUser&SourceSecurityGroupName=sourceGroup");
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
@ -177,7 +177,7 @@ public class SecurityGroupAsyncClientTest extends RestClientTest<SecurityGroupAs
httpMethod, httpMethod,
"Version=2009-11-30&Action=AuthorizeSecurityGroupIngress&CidrIp=0.0.0.0%2F0&IpProtocol=tcp&GroupName=group&FromPort=6000&ToPort=7000"); "Version=2009-11-30&Action=AuthorizeSecurityGroupIngress&CidrIp=0.0.0.0%2F0&IpProtocol=tcp&GroupName=group&FromPort=6000&ToPort=7000");
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
@ -199,7 +199,7 @@ public class SecurityGroupAsyncClientTest extends RestClientTest<SecurityGroupAs
httpMethod, httpMethod,
"Version=2009-11-30&Action=RevokeSecurityGroupIngress&GroupName=group&SourceSecurityGroupOwnerId=sourceUser&SourceSecurityGroupName=sourceGroup"); "Version=2009-11-30&Action=RevokeSecurityGroupIngress&GroupName=group&SourceSecurityGroupOwnerId=sourceUser&SourceSecurityGroupName=sourceGroup");
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
@ -221,7 +221,7 @@ public class SecurityGroupAsyncClientTest extends RestClientTest<SecurityGroupAs
httpMethod, httpMethod,
"Version=2009-11-30&Action=RevokeSecurityGroupIngress&CidrIp=0.0.0.0%2F0&IpProtocol=tcp&GroupName=group&FromPort=6000&ToPort=7000"); "Version=2009-11-30&Action=RevokeSecurityGroupIngress&CidrIp=0.0.0.0%2F0&IpProtocol=tcp&GroupName=group&FromPort=6000&ToPort=7000");
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);

View File

@ -64,7 +64,7 @@ import org.jclouds.http.functions.ParseETagHeader;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ReturnFalseOn404; import org.jclouds.http.functions.ReturnFalseOn404;
import org.jclouds.http.functions.ReturnTrueIf2xx; import org.jclouds.http.functions.ReturnTrueIf2xx;
import org.jclouds.http.functions.ReturnVoidIf2xx; import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.http.options.GetOptions; import org.jclouds.http.options.GetOptions;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.logging.Logger.LoggerFactory;
@ -133,7 +133,7 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
httpMethod, httpMethod,
"<RequestPaymentConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Payer>BucketOwner</Payer></RequestPaymentConfiguration>"); "<RequestPaymentConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Payer>BucketOwner</Payer></RequestPaymentConfiguration>");
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
@ -153,7 +153,7 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
httpMethod, httpMethod,
"<RequestPaymentConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Payer>Requester</Payer></RequestPaymentConfiguration>"); "<RequestPaymentConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Payer>Requester</Payer></RequestPaymentConfiguration>");
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
@ -237,7 +237,7 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
assertHeadersEqual(httpMethod, "Host: bucket.stub\n"); assertHeadersEqual(httpMethod, "Host: bucket.stub\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class); assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
@ -458,7 +458,7 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
assertPayloadEquals(httpMethod, assertPayloadEquals(httpMethod,
"<BucketLoggingStatus xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"/>"); "<BucketLoggingStatus xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"/>");
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
@ -479,7 +479,7 @@ public class S3AsyncClientTest extends RestClientTest<S3AsyncClient> {
assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream( assertPayloadEquals(httpMethod, Utils.toStringAndClose(getClass().getResourceAsStream(
"/s3/bucket_logging.xml"))); "/s3/bucket_logging.xml")));
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);

View File

@ -18,13 +18,8 @@
*/ */
package org.jclouds.aws.s3.functions; package org.jclouds.aws.s3.functions;
import static org.easymock.EasyMock.expect;
import static org.easymock.classextension.EasyMock.createMock;
import static org.easymock.classextension.EasyMock.replay;
import org.jclouds.aws.AWSResponseException; import org.jclouds.aws.AWSResponseException;
import org.jclouds.aws.domain.AWSError; import org.jclouds.aws.domain.AWSError;
import org.jclouds.aws.s3.functions.ReturnTrueIfBucketAlreadyOwnedByYou;
import org.testng.annotations.Test; import org.testng.annotations.Test;
/** /**
@ -39,19 +34,15 @@ public class ReturnTrueIfBucketAlreadyOwnedByYouTest {
assert new ReturnTrueIfBucketAlreadyOwnedByYou().apply(e); assert new ReturnTrueIfBucketAlreadyOwnedByYou().apply(e);
} }
@Test @Test(expectedExceptions = AWSResponseException.class)
void testBlahIsNotOk() throws Exception { void testBlahIsNotOk() throws Exception {
Exception e = getErrorWithCode("blah"); Exception e = getErrorWithCode("blah");
assert new ReturnTrueIfBucketAlreadyOwnedByYou().apply(e) == null; new ReturnTrueIfBucketAlreadyOwnedByYou().apply(e);
} }
private Exception getErrorWithCode(String code) { private Exception getErrorWithCode(String code) {
AWSResponseException inner = createMock(AWSResponseException.class); AWSError error = new AWSError();
AWSError error = createMock(AWSError.class); error.setCode(code);
expect(inner.getError()).andReturn(error); return new AWSResponseException(null, null, null, error);
expect(error.getCode()).andReturn(code);
replay(inner);
replay(error);
return inner;
} }
} }

View File

@ -64,7 +64,7 @@ import org.jclouds.blobstore.domain.MutableBlobMetadata;
import org.jclouds.blobstore.functions.HttpGetOptionsListToGetOptions; import org.jclouds.blobstore.functions.HttpGetOptionsListToGetOptions;
import org.jclouds.blobstore.integration.internal.StubAsyncBlobStore; import org.jclouds.blobstore.integration.internal.StubAsyncBlobStore;
import org.jclouds.blobstore.options.ListContainerOptions; import org.jclouds.blobstore.options.ListContainerOptions;
import org.jclouds.concurrent.internal.ConcurrentUtils; import org.jclouds.concurrent.ConcurrentUtils;
import org.jclouds.date.DateService; import org.jclouds.date.DateService;
import org.jclouds.http.options.GetOptions; import org.jclouds.http.options.GetOptions;

View File

@ -122,7 +122,7 @@ public class JCloudsS3Service extends S3Service {
throw new UnsupportedOperationException("Bucket ACL is not yet supported"); throw new UnsupportedOperationException("Bucket ACL is not yet supported");
try { try {
if (connection.putBucketInRegion(Region.fromValue(location), bucketName)) { if (connection.putBucketInRegion(Region.DEFAULT, bucketName)) {
// Bucket created. // Bucket created.
} }
} catch (Exception e) { } catch (Exception e) {

View File

@ -20,7 +20,8 @@ package org.jclouds.azure.storage.blob.blobstore;
import static com.google.common.util.concurrent.Futures.compose; import static com.google.common.util.concurrent.Futures.compose;
import static org.jclouds.blobstore.options.ListContainerOptions.Builder.recursive; import static org.jclouds.blobstore.options.ListContainerOptions.Builder.recursive;
import static org.jclouds.concurrent.internal.ConcurrentUtils.makeListenable; import static org.jclouds.concurrent.ConcurrentUtils.convertExceptionToValue;
import static org.jclouds.concurrent.ConcurrentUtils.makeListenable;
import static org.jclouds.azure.storage.options.ListOptions.Builder.*; import static org.jclouds.azure.storage.options.ListOptions.Builder.*;
import java.util.Set; import java.util.Set;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
@ -87,8 +88,8 @@ public class AzureAsyncBlobStore extends BaseAzureBlobStore implements AsyncBlob
* This implementation uses the AzureBlob HEAD Object command to return the result * This implementation uses the AzureBlob HEAD Object command to return the result
*/ */
public ListenableFuture<BlobMetadata> blobMetadata(String container, String key) { public ListenableFuture<BlobMetadata> blobMetadata(String container, String key) {
return compose(async.getBlobProperties(container, key), return compose(convertExceptionToValue(async.getBlobProperties(container, key),
new Function<BlobProperties, BlobMetadata>() { KeyNotFoundException.class, null), new Function<BlobProperties, BlobMetadata>() {
@Override @Override
public BlobMetadata apply(BlobProperties from) { public BlobMetadata apply(BlobProperties from) {
@ -129,7 +130,8 @@ public class AzureAsyncBlobStore extends BaseAzureBlobStore implements AsyncBlob
org.jclouds.blobstore.options.GetOptions... optionsList) { org.jclouds.blobstore.options.GetOptions... optionsList) {
GetOptions azureOptions = blob2ObjectGetOptions.apply(optionsList); GetOptions azureOptions = blob2ObjectGetOptions.apply(optionsList);
ListenableFuture<AzureBlob> returnVal = async.getBlob(container, key, azureOptions); ListenableFuture<AzureBlob> returnVal = async.getBlob(container, key, azureOptions);
return compose(returnVal, object2Blob, service); return compose(convertExceptionToValue(returnVal, KeyNotFoundException.class, null),
object2Blob, service);
} }
public ListenableFuture<? extends org.jclouds.blobstore.domain.ListResponse<? extends StorageMetadata>> list() { public ListenableFuture<? extends org.jclouds.blobstore.domain.ListResponse<? extends StorageMetadata>> list() {

View File

@ -20,6 +20,7 @@ package org.jclouds.azure.storage.blob.blobstore;
import static org.jclouds.azure.storage.options.ListOptions.Builder.includeMetadata; import static org.jclouds.azure.storage.options.ListOptions.Builder.includeMetadata;
import static org.jclouds.blobstore.options.ListContainerOptions.Builder.recursive; import static org.jclouds.blobstore.options.ListContainerOptions.Builder.recursive;
import static org.jclouds.blobstore.util.BlobStoreUtils.returnNullOnKeyNotFoundOrPropagate;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
@ -80,7 +81,11 @@ public class AzureBlobStore extends BaseAzureBlobStore implements BlobStore {
* This implementation uses the AzureBlob HEAD Object command to return the result * This implementation uses the AzureBlob HEAD Object command to return the result
*/ */
public BlobMetadata blobMetadata(String container, String key) { public BlobMetadata blobMetadata(String container, String key) {
try {
return object2BlobMd.apply(sync.getBlobProperties(container, key)); return object2BlobMd.apply(sync.getBlobProperties(container, key));
} catch (Exception e) {
return returnNullOnKeyNotFoundOrPropagate(e);
}
} }
public void clearContainer(final String container) { public void clearContainer(final String container) {
@ -118,7 +123,11 @@ public class AzureBlobStore extends BaseAzureBlobStore implements BlobStore {
public Blob getBlob(String container, String key, public Blob getBlob(String container, String key,
org.jclouds.blobstore.options.GetOptions... optionsList) { org.jclouds.blobstore.options.GetOptions... optionsList) {
GetOptions azureOptions = blob2ObjectGetOptions.apply(optionsList); GetOptions azureOptions = blob2ObjectGetOptions.apply(optionsList);
try {
return object2Blob.apply(sync.getBlob(container, key, azureOptions)); return object2Blob.apply(sync.getBlob(container, key, azureOptions));
} catch (Exception e) {
return returnNullOnKeyNotFoundOrPropagate(e);
}
} }
public ListResponse<? extends StorageMetadata> list() { public ListResponse<? extends StorageMetadata> list() {
@ -134,7 +143,8 @@ public class AzureBlobStore extends BaseAzureBlobStore implements BlobStore {
public ListContainerResponse<? extends StorageMetadata> list(String container, public ListContainerResponse<? extends StorageMetadata> list(String container,
ListContainerOptions... optionsList) { ListContainerOptions... optionsList) {
ListBlobsOptions azureOptions = container2ContainerListOptions.apply(optionsList); ListBlobsOptions azureOptions = container2ContainerListOptions.apply(optionsList);
return container2ResourceList.apply(sync.listBlobs(container, azureOptions.includeMetadata())); return container2ResourceList
.apply(sync.listBlobs(container, azureOptions.includeMetadata()));
} }
public String putBlob(String container, Blob blob) { public String putBlob(String container, Blob blob) {

View File

@ -42,6 +42,8 @@ public class AzureBlobToBlob implements Function<AzureBlob, Blob> {
} }
public Blob apply(AzureBlob from) { public Blob apply(AzureBlob from) {
if (from == null)
return null;
Blob blob = blobFactory.create(blobPr2BlobMd.apply(from.getProperties())); Blob blob = blobFactory.create(blobPr2BlobMd.apply(from.getProperties()));
if (from.getContentLength() != null) if (from.getContentLength() != null)
blob.setContentLength(from.getContentLength()); blob.setContentLength(from.getContentLength());

View File

@ -31,17 +31,19 @@ import com.google.common.base.Function;
*/ */
@Singleton @Singleton
public class BlobMetadataToBlobProperties implements Function<BlobMetadata, MutableBlobProperties> { public class BlobMetadataToBlobProperties implements Function<BlobMetadata, MutableBlobProperties> {
public MutableBlobProperties apply(BlobMetadata base) { public MutableBlobProperties apply(BlobMetadata from) {
if (from == null)
return null;
MutableBlobProperties to = new MutableBlobPropertiesImpl(); MutableBlobProperties to = new MutableBlobPropertiesImpl();
to.setContentType(base.getContentType()); to.setContentType(from.getContentType());
to.setETag(base.getETag()); to.setETag(from.getETag());
to.setContentMD5(base.getContentMD5()); to.setContentMD5(from.getContentMD5());
to.setName(base.getName()); to.setName(from.getName());
to.setLastModified(base.getLastModified()); to.setLastModified(from.getLastModified());
if (base.getSize() != null) if (from.getSize() != null)
to.setContentLength(base.getSize()); to.setContentLength(from.getSize());
if (base.getUserMetadata() != null) if (from.getUserMetadata() != null)
to.setMetadata(base.getUserMetadata()); to.setMetadata(from.getUserMetadata());
return to; return to;
} }

View File

@ -42,6 +42,8 @@ public class BlobPropertiesToBlobMetadata implements Function<BlobProperties, Mu
} }
public MutableBlobMetadata apply(BlobProperties from) { public MutableBlobMetadata apply(BlobProperties from) {
if (from == null)
return null;
MutableBlobMetadata to = new MutableBlobMetadataImpl(); MutableBlobMetadata to = new MutableBlobMetadataImpl();
if (from.getContentMD5() != null) if (from.getContentMD5() != null)
to.setContentMD5(from.getContentMD5()); to.setContentMD5(from.getContentMD5());

View File

@ -41,6 +41,8 @@ public class BlobToAzureBlob implements Function<Blob, AzureBlob> {
} }
public AzureBlob apply(Blob from) { public AzureBlob apply(Blob from) {
if (from == null)
return null;
AzureBlob object = objectProvider.create(blob2ObjectMd.apply(from.getMetadata())); AzureBlob object = objectProvider.create(blob2ObjectMd.apply(from.getMetadata()));
if (from.getContentLength() != null) if (from.getContentLength() != null)
object.setContentLength(from.getContentLength()); object.setContentLength(from.getContentLength());

View File

@ -18,6 +18,8 @@
*/ */
package org.jclouds.azure.storage.blob.functions; package org.jclouds.azure.storage.blob.functions;
import static org.jclouds.util.Utils.propagateOrNull;
import org.jclouds.azure.storage.AzureStorageResponseException; import org.jclouds.azure.storage.AzureStorageResponseException;
import com.google.common.base.Function; import com.google.common.base.Function;
@ -35,7 +37,7 @@ public class ReturnTrueIfContainerAlreadyExists implements Function<Exception, B
return true; return true;
} }
} }
return null; return Boolean.class.cast(propagateOrNull(from));
} }
} }

View File

@ -49,11 +49,11 @@ import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ReturnTrueIf2xx; import org.jclouds.http.functions.ReturnTrueIf2xx;
import org.jclouds.http.functions.ReturnTrueOn404; import org.jclouds.http.functions.ReturnTrueOn404;
import org.jclouds.http.functions.ReturnVoidIf2xx; import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.logging.Logger.LoggerFactory;
import org.jclouds.rest.config.RestModule; import org.jclouds.rest.config.RestModule;
import org.jclouds.rest.functions.ThrowResourceNotFoundOn404; import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.util.Jsr330; import org.jclouds.util.Jsr330;
@ -93,7 +93,7 @@ public class AzureBlobAsyncClientTest {
// TODO check generic type of response parser // TODO check generic type of response parser
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
ThrowResourceNotFoundOn404.class); MapHttp4xxCodesToExceptions.class);
} }
public void testListContainersOptions() throws SecurityException, NoSuchMethodException { public void testListContainersOptions() throws SecurityException, NoSuchMethodException {
@ -116,7 +116,7 @@ public class AzureBlobAsyncClientTest {
// TODO check generic type of response parser // TODO check generic type of response parser
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
ThrowResourceNotFoundOn404.class); MapHttp4xxCodesToExceptions.class);
} }
public void testCreateContainer() throws SecurityException, NoSuchMethodException { public void testCreateContainer() throws SecurityException, NoSuchMethodException {
@ -154,7 +154,7 @@ public class AzureBlobAsyncClientTest {
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
.singletonList("2009-09-19")); .singletonList("2009-09-19"));
assertEquals(processor.createResponseParser(method, httpMethod).getClass(), assertEquals(processor.createResponseParser(method, httpMethod).getClass(),
ReturnVoidIf2xx.class); CloseContentAndReturn.class);
// TODO check generic type of response parser // TODO check generic type of response parser
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
@ -222,7 +222,7 @@ public class AzureBlobAsyncClientTest {
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
.singletonList("2009-09-19")); .singletonList("2009-09-19"));
assertEquals(processor.createResponseParser(method, httpMethod).getClass(), assertEquals(processor.createResponseParser(method, httpMethod).getClass(),
ReturnVoidIf2xx.class); CloseContentAndReturn.class);
// TODO check generic type of response parser // TODO check generic type of response parser
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
@ -271,7 +271,7 @@ public class AzureBlobAsyncClientTest {
// TODO check generic type of response parser // TODO check generic type of response parser
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
ThrowResourceNotFoundOn404.class); MapHttp4xxCodesToExceptions.class);
} }
public void testListRootBlobs() throws SecurityException, NoSuchMethodException { public void testListRootBlobs() throws SecurityException, NoSuchMethodException {
@ -291,7 +291,7 @@ public class AzureBlobAsyncClientTest {
// TODO check generic type of response parser // TODO check generic type of response parser
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
ThrowResourceNotFoundOn404.class); MapHttp4xxCodesToExceptions.class);
} }
public void testContainerProperties() throws SecurityException, NoSuchMethodException { public void testContainerProperties() throws SecurityException, NoSuchMethodException {
@ -310,7 +310,7 @@ public class AzureBlobAsyncClientTest {
ParseContainerPropertiesFromHeaders.class); ParseContainerPropertiesFromHeaders.class);
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
ThrowResourceNotFoundOn404.class); MapHttp4xxCodesToExceptions.class);
} }
public void testSetResourceMetadata() throws SecurityException, NoSuchMethodException { public void testSetResourceMetadata() throws SecurityException, NoSuchMethodException {
@ -331,10 +331,10 @@ public class AzureBlobAsyncClientTest {
assertEquals(httpMethod.getHeaders().get("x-ms-meta-key"), Collections.singletonList("value")); assertEquals(httpMethod.getHeaders().get("x-ms-meta-key"), Collections.singletonList("value"));
assertEquals(processor.createResponseParser(method, httpMethod).getClass(), assertEquals(processor.createResponseParser(method, httpMethod).getClass(),
ReturnVoidIf2xx.class); CloseContentAndReturn.class);
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
ThrowResourceNotFoundOn404.class); MapHttp4xxCodesToExceptions.class);
} }
public void testSetBlobMetadata() throws SecurityException, NoSuchMethodException { public void testSetBlobMetadata() throws SecurityException, NoSuchMethodException {
@ -354,10 +354,10 @@ public class AzureBlobAsyncClientTest {
assertEquals(httpMethod.getHeaders().get("x-ms-meta-key"), Collections.singletonList("value")); assertEquals(httpMethod.getHeaders().get("x-ms-meta-key"), Collections.singletonList("value"));
assertEquals(processor.createResponseParser(method, httpMethod).getClass(), assertEquals(processor.createResponseParser(method, httpMethod).getClass(),
ReturnVoidIf2xx.class); CloseContentAndReturn.class);
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
ThrowResourceNotFoundOn404.class); MapHttp4xxCodesToExceptions.class);
} }
@BeforeClass @BeforeClass

View File

@ -41,11 +41,11 @@ import org.jclouds.date.TimeStamp;
import org.jclouds.encryption.internal.Base64; import org.jclouds.encryption.internal.Base64;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ReturnTrueIf2xx; import org.jclouds.http.functions.ReturnTrueIf2xx;
import org.jclouds.http.functions.ReturnVoidIf2xx; import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.logging.Logger.LoggerFactory;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.functions.ThrowResourceNotFoundOn404; import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.util.Jsr330; import org.jclouds.util.Jsr330;
@ -85,7 +85,7 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
// TODO check generic type of response parser // TODO check generic type of response parser
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
ThrowResourceNotFoundOn404.class); MapHttp4xxCodesToExceptions.class);
} }
public void testListQueuesOptions() throws SecurityException, NoSuchMethodException { public void testListQueuesOptions() throws SecurityException, NoSuchMethodException {
@ -107,7 +107,7 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
// TODO check generic type of response parser // TODO check generic type of response parser
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
ThrowResourceNotFoundOn404.class); MapHttp4xxCodesToExceptions.class);
} }
public void testCreateQueue() throws SecurityException, NoSuchMethodException { public void testCreateQueue() throws SecurityException, NoSuchMethodException {
@ -129,7 +129,7 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
// TODO check generic type of response parser // TODO check generic type of response parser
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
ThrowResourceNotFoundOn404.class); MapHttp4xxCodesToExceptions.class);
} }
public void testCreateQueueOptions() throws SecurityException, NoSuchMethodException { public void testCreateQueueOptions() throws SecurityException, NoSuchMethodException {
@ -152,7 +152,7 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
// TODO check generic type of response parser // TODO check generic type of response parser
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
ThrowResourceNotFoundOn404.class); MapHttp4xxCodesToExceptions.class);
} }
public void testDeleteQueue() throws SecurityException, NoSuchMethodException { public void testDeleteQueue() throws SecurityException, NoSuchMethodException {
@ -168,11 +168,11 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections assertEquals(httpMethod.getHeaders().get("x-ms-version"), Collections
.singletonList("2009-09-19")); .singletonList("2009-09-19"));
assertEquals(processor.createResponseParser(method, httpMethod).getClass(), assertEquals(processor.createResponseParser(method, httpMethod).getClass(),
ReturnVoidIf2xx.class); CloseContentAndReturn.class);
// TODO check generic type of response parser // TODO check generic type of response parser
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
ThrowResourceNotFoundOn404.class); MapHttp4xxCodesToExceptions.class);
} }
public void testPutMessage() throws SecurityException, NoSuchMethodException, IOException { public void testPutMessage() throws SecurityException, NoSuchMethodException, IOException {
@ -187,7 +187,7 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
assertPayloadEquals(httpMethod, assertPayloadEquals(httpMethod,
"<QueueMessage><MessageText>message</MessageText></QueueMessage>"); "<QueueMessage><MessageText>message</MessageText></QueueMessage>");
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
@ -207,7 +207,7 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
assertPayloadEquals(httpMethod, assertPayloadEquals(httpMethod,
"<QueueMessage><MessageText>message</MessageText></QueueMessage>"); "<QueueMessage><MessageText>message</MessageText></QueueMessage>");
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
@ -223,7 +223,7 @@ public class AzureQueueAsyncClientTest extends RestClientTest<AzureQueueAsyncCli
assertHeadersEqual(httpMethod, "x-ms-version: 2009-09-19\n"); assertHeadersEqual(httpMethod, "x-ms-version: 2009-09-19\n");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);

View File

@ -18,7 +18,8 @@
*/ */
package org.jclouds.blobstore.functions; package org.jclouds.blobstore.functions;
import java.lang.reflect.Constructor; import static org.jclouds.util.Utils.propagateOrNull;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.inject.Named; import javax.inject.Named;
@ -36,17 +37,7 @@ import com.google.common.base.Throwables;
import com.google.inject.Inject; import com.google.inject.Inject;
public class ClearAndDeleteIfNotEmpty implements Function<Exception, Void>, InvocationContext { public class ClearAndDeleteIfNotEmpty implements Function<Exception, Void>, InvocationContext {
static final Void v;
static {
Constructor<Void> cv;
try {
cv = Void.class.getDeclaredConstructor();
cv.setAccessible(true);
v = cv.newInstance();
} catch (Exception e) {
throw new Error("Error setting up class", e);
}
}
/** /**
* maximum duration of an blob Request * maximum duration of an blob Request
*/ */
@ -69,13 +60,13 @@ public class ClearAndDeleteIfNotEmpty implements Function<Exception, Void>, Invo
if (from instanceof HttpResponseException) { if (from instanceof HttpResponseException) {
HttpResponseException responseException = (HttpResponseException) from; HttpResponseException responseException = (HttpResponseException) from;
if (responseException.getResponse().getStatusCode() == 404) { if (responseException.getResponse().getStatusCode() == 404) {
return v; return null;
} else if (responseException.getResponse().getStatusCode() == 409) { } else if (responseException.getResponse().getStatusCode() == 409) {
clear.execute(request.getArgs()[0].toString()); clear.execute(request.getArgs()[0].toString());
try { try {
connection.deleteContainer(request.getArgs()[0].toString()).get( connection.deleteContainer(request.getArgs()[0].toString()).get(
requestTimeoutMilliseconds, TimeUnit.MILLISECONDS); requestTimeoutMilliseconds, TimeUnit.MILLISECONDS);
return v; return null;
} catch (Exception e) { } catch (Exception e) {
Throwables.propagateIfPossible(e, BlobRuntimeException.class); Throwables.propagateIfPossible(e, BlobRuntimeException.class);
throw new BlobRuntimeException("Error deleting container: " throw new BlobRuntimeException("Error deleting container: "
@ -83,7 +74,7 @@ public class ClearAndDeleteIfNotEmpty implements Function<Exception, Void>, Invo
} }
} }
} }
return null; return Void.class.cast(propagateOrNull(from));
} }
public void setContext(GeneratedHttpRequest<?> request) { public void setContext(GeneratedHttpRequest<?> request) {

View File

@ -19,8 +19,7 @@
package org.jclouds.blobstore.functions; package org.jclouds.blobstore.functions;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.util.Utils.propagateOrNull;
import java.lang.reflect.Constructor;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
@ -34,18 +33,6 @@ import com.google.common.base.Function;
@Singleton @Singleton
public class ReturnVoidOnNotFoundOr404 implements Function<Exception, Void> { public class ReturnVoidOnNotFoundOr404 implements Function<Exception, Void> {
static final Void v;
static {
Constructor<Void> cv;
try {
cv = Void.class.getDeclaredConstructor();
cv.setAccessible(true);
v = cv.newInstance();
} catch (Exception e) {
throw new Error("Error setting up class", e);
}
}
private final ReturnTrueOn404 rto404; private final ReturnTrueOn404 rto404;
@Inject @Inject
@ -55,11 +42,12 @@ public class ReturnVoidOnNotFoundOr404 implements Function<Exception, Void> {
public Void apply(Exception from) { public Void apply(Exception from) {
if (from instanceof KeyNotFoundException || from instanceof ContainerNotFoundException) { if (from instanceof KeyNotFoundException || from instanceof ContainerNotFoundException) {
return v; return null;
} else { } else {
return rto404.apply(from) ? v : null; Boolean value = rto404.apply(from);
if (value != null && value)
return null;
} }
return Void.class.cast(propagateOrNull(from));
} }
} }

View File

@ -18,6 +18,8 @@
*/ */
package org.jclouds.blobstore.functions; package org.jclouds.blobstore.functions;
import static org.jclouds.util.Utils.propagateOrNull;
import org.jclouds.blobstore.ContainerNotFoundException; import org.jclouds.blobstore.ContainerNotFoundException;
import org.jclouds.http.HttpResponseException; import org.jclouds.http.HttpResponseException;
@ -40,7 +42,7 @@ public class ThrowContainerNotFoundOn404 implements Function<Exception, Object>
throw new ContainerNotFoundException(from); throw new ContainerNotFoundException(from);
} }
} }
return null; return propagateOrNull(from);
} }
} }

View File

@ -18,6 +18,8 @@
*/ */
package org.jclouds.blobstore.functions; package org.jclouds.blobstore.functions;
import static org.jclouds.util.Utils.propagateOrNull;
import org.jclouds.blobstore.KeyNotFoundException; import org.jclouds.blobstore.KeyNotFoundException;
import org.jclouds.http.HttpResponseException; import org.jclouds.http.HttpResponseException;
@ -40,7 +42,7 @@ public class ThrowKeyNotFoundOn404 implements Function<Exception, Object> {
throw new KeyNotFoundException(from); throw new KeyNotFoundException(from);
} }
} }
return null; return propagateOrNull(from);
} }
} }

View File

@ -42,7 +42,6 @@ import org.jclouds.blobstore.strategy.ContainsValueInListStrategy;
import org.jclouds.blobstore.strategy.CountListStrategy; import org.jclouds.blobstore.strategy.CountListStrategy;
import org.jclouds.blobstore.strategy.GetBlobsInListStrategy; import org.jclouds.blobstore.strategy.GetBlobsInListStrategy;
import org.jclouds.blobstore.strategy.ListBlobMetadataStrategy; import org.jclouds.blobstore.strategy.ListBlobMetadataStrategy;
import org.jclouds.rest.ResourceNotFoundException;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
@ -205,9 +204,6 @@ public abstract class BaseBlobMap<V> {
return connection.blobMetadata(containerName, realKey).get(requestTimeoutMilliseconds, return connection.blobMetadata(containerName, realKey).get(requestTimeoutMilliseconds,
TimeUnit.MILLISECONDS) != null; TimeUnit.MILLISECONDS) != null;
} catch (Exception e) { } catch (Exception e) {
if (Iterables.size(Iterables.filter(Throwables.getCausalChain(e),
ResourceNotFoundException.class)) >= 1)
return false;
Throwables.propagateIfPossible(e, BlobRuntimeException.class); Throwables.propagateIfPossible(e, BlobRuntimeException.class);
throw new BlobRuntimeException(String.format("Error searching for %1$s:%2$s", throw new BlobRuntimeException(String.format("Error searching for %1$s:%2$s",
containerName, realKey), e); containerName, realKey), e);

View File

@ -40,7 +40,6 @@ import org.jclouds.blobstore.strategy.ListBlobMetadataStrategy;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
import com.google.common.collect.Collections2; import com.google.common.collect.Collections2;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
@ -116,12 +115,10 @@ public class BlobMapImpl extends BaseBlobMap<Blob> implements BlobMap {
public Blob get(Object key) { public Blob get(Object key) {
String realKey = prefixer.apply(key.toString()); String realKey = prefixer.apply(key.toString());
try { try {
return stripPrefix(connection.getBlob(containerName, realKey).get( Blob blob = connection.getBlob(containerName, realKey).get(requestTimeoutMilliseconds,
requestTimeoutMilliseconds, TimeUnit.MILLISECONDS)); TimeUnit.MILLISECONDS);
return blob != null ? stripPrefix(blob) : null;
} catch (Exception e) { } catch (Exception e) {
if (Iterables.size(Iterables.filter(Throwables.getCausalChain(e),
KeyNotFoundException.class)) >= 1)
return null;
Throwables.propagateIfPossible(e, BlobRuntimeException.class); Throwables.propagateIfPossible(e, BlobRuntimeException.class);
throw new BlobRuntimeException(String.format("Error geting blob %s:%s", containerName, throw new BlobRuntimeException(String.format("Error geting blob %s:%s", containerName,
realKey), e); realKey), e);
@ -180,8 +177,8 @@ public class BlobMapImpl extends BaseBlobMap<Blob> implements BlobMap {
TimeUnit.MILLISECONDS); TimeUnit.MILLISECONDS);
} catch (Exception e) { } catch (Exception e) {
Throwables.propagateIfPossible(e, BlobRuntimeException.class); Throwables.propagateIfPossible(e, BlobRuntimeException.class);
throw new BlobRuntimeException(String.format("Error removing blob %s:%s", throw new BlobRuntimeException(String.format("Error removing blob %s:%s", containerName,
containerName, realKey), e); realKey), e);
} }
return old; return old;
} }

View File

@ -49,7 +49,6 @@ import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
import com.google.common.collect.Collections2; import com.google.common.collect.Collections2;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
@ -82,12 +81,10 @@ public class InputStreamMapImpl extends BaseBlobMap<InputStream> implements Inpu
public InputStream get(Object o) { public InputStream get(Object o) {
String realKey = prefixer.apply(o.toString()); String realKey = prefixer.apply(o.toString());
try { try {
return connection.getBlob(containerName, realKey).get(requestTimeoutMilliseconds, Blob blob = connection.getBlob(containerName, realKey).get(requestTimeoutMilliseconds,
TimeUnit.MILLISECONDS).getContent(); TimeUnit.MILLISECONDS);
return blob != null ? blob.getContent() : null;
} catch (Exception e) { } catch (Exception e) {
if (Iterables.size(Iterables.filter(Throwables.getCausalChain(e),
KeyNotFoundException.class)) >= 1)
return null;
Throwables.propagateIfPossible(e, BlobRuntimeException.class); Throwables.propagateIfPossible(e, BlobRuntimeException.class);
throw new BlobRuntimeException(String.format("Error geting blob %s:%s", containerName, throw new BlobRuntimeException(String.format("Error geting blob %s:%s", containerName,
realKey), e); realKey), e);
@ -107,8 +104,8 @@ public class InputStreamMapImpl extends BaseBlobMap<InputStream> implements Inpu
TimeUnit.MILLISECONDS); TimeUnit.MILLISECONDS);
} catch (Exception e) { } catch (Exception e) {
Throwables.propagateIfPossible(e, BlobRuntimeException.class); Throwables.propagateIfPossible(e, BlobRuntimeException.class);
throw new BlobRuntimeException(String.format("Error removing blob %s:%s", throw new BlobRuntimeException(String.format("Error removing blob %s:%s", containerName,
containerName, realKey), e); realKey), e);
} }
return old; return old;
} }
@ -295,8 +292,8 @@ public class InputStreamMapImpl extends BaseBlobMap<InputStream> implements Inpu
return returnVal; return returnVal;
} catch (Exception e) { } catch (Exception e) {
Throwables.propagateIfPossible(e, BlobRuntimeException.class); Throwables.propagateIfPossible(e, BlobRuntimeException.class);
throw new BlobRuntimeException(String.format("Error adding blob %s:%s", throw new BlobRuntimeException(String.format("Error adding blob %s:%s", containerName,
containerName, object), e); object), e);
} }
} }

View File

@ -30,7 +30,6 @@ import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.blobstore.AsyncBlobStore; import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.KeyNotFoundException;
import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.domain.BlobMetadata; import org.jclouds.blobstore.domain.BlobMetadata;
import org.jclouds.blobstore.internal.BlobRuntimeException; import org.jclouds.blobstore.internal.BlobRuntimeException;
@ -41,7 +40,6 @@ import org.jclouds.blobstore.strategy.ListBlobMetadataStrategy;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
@ -84,7 +82,8 @@ public class GetAllBlobsInListAndRetryOnFailure implements GetBlobsInListStrateg
for (BlobMetadata md : getAllBlobMetadata.execute(container, options)) { for (BlobMetadata md : getAllBlobMetadata.execute(container, options)) {
futureObjects.put(md.getName(), connection.getBlob(container, md.getName())); futureObjects.put(md.getName(), connection.getBlob(container, md.getName()));
} }
for (Entry<String, ListenableFuture<? extends Blob>> futureObjectEntry : futureObjects.entrySet()) { for (Entry<String, ListenableFuture<? extends Blob>> futureObjectEntry : futureObjects
.entrySet()) {
try { try {
ifNotFoundRetryOtherwiseAddToSet(container, futureObjectEntry.getKey(), ifNotFoundRetryOtherwiseAddToSet(container, futureObjectEntry.getKey(),
futureObjectEntry.getValue(), objects); futureObjectEntry.getValue(), objects);
@ -103,20 +102,15 @@ public class GetAllBlobsInListAndRetryOnFailure implements GetBlobsInListStrateg
ListenableFuture<? extends Blob> value, Set<Blob> objects) throws InterruptedException, ListenableFuture<? extends Blob> value, Set<Blob> objects) throws InterruptedException,
ExecutionException, TimeoutException { ExecutionException, TimeoutException {
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
try {
Blob object = value.get(requestTimeoutMilliseconds, TimeUnit.MILLISECONDS); Blob object = value.get(requestTimeoutMilliseconds, TimeUnit.MILLISECONDS);
if (object == null) {
Thread.sleep(requestRetryMilliseconds);
value = connection.getBlob(container, key);
continue;
}
object.getMetadata().setName(key); object.getMetadata().setName(key);
objects.add(object); objects.add(object);
return; return;
} catch (Exception e) {
if (Iterables.size(Iterables.filter(Throwables.getCausalChain(e),
KeyNotFoundException.class)) >= 1) {
Thread.sleep(requestRetryMilliseconds);
value = connection.getBlob(container, key);
} else {
Throwables.propagate(e);
}
}
} }
} }
} }

View File

@ -19,22 +19,34 @@
package org.jclouds.blobstore.util; package org.jclouds.blobstore.util;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.util.Utils.propagateOrNull;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import org.jclouds.blobstore.BlobStore; import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.KeyNotFoundException;
import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.domain.BlobMetadata; import org.jclouds.blobstore.domain.BlobMetadata;
import org.jclouds.blobstore.domain.StorageMetadata; import org.jclouds.blobstore.domain.StorageMetadata;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;
import com.google.common.base.Throwables;
import com.google.common.collect.Iterables;
/** /**
* Encryption, Hashing, and IO Utilities needed to sign and verify S3 requests and responses. * Encryption, Hashing, and IO Utilities needed to sign and verify S3 requests and responses.
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public class BlobStoreUtils { public class BlobStoreUtils {
@SuppressWarnings("unchecked")
public static <T> T returnNullOnKeyNotFoundOrPropagate(Exception e) {
if (Iterables
.size(Iterables.filter(Throwables.getCausalChain(e), KeyNotFoundException.class)) >= 1)
return null;
return (T) propagateOrNull(e);
}
public static Blob newBlob(BlobStore blobStore, StorageMetadata blobMeta) { public static Blob newBlob(BlobStore blobStore, StorageMetadata blobMeta) {
Blob blob = blobStore.newBlob(blobMeta.getName()); Blob blob = blobStore.newBlob(blobMeta.getName());

View File

@ -25,6 +25,7 @@ import static org.jclouds.blobstore.options.GetOptions.Builder.ifUnmodifiedSince
import static org.jclouds.blobstore.options.GetOptions.Builder.range; import static org.jclouds.blobstore.options.GetOptions.Builder.range;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
@ -328,6 +329,8 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
object.getMetadata().setContentMD5(new JCEEncryptionService().md5(TEST_STRING.getBytes())); object.getMetadata().setContentMD5(new JCEEncryptionService().md5(TEST_STRING.getBytes()));
String containerName = getContainerName(); String containerName = getContainerName();
try { try {
assertNull(context.getBlobStore().blobMetadata(containerName, "powderpuff"));
addBlobToContainer(containerName, object); addBlobToContainer(containerName, object);
Blob newObject = validateContent(containerName, key); Blob newObject = validateContent(containerName, key);

View File

@ -21,7 +21,7 @@ package org.jclouds.blobstore.integration.internal;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.util.concurrent.Futures.immediateFailedFuture; import static com.google.common.util.concurrent.Futures.immediateFailedFuture;
import static com.google.common.util.concurrent.Futures.immediateFuture; import static com.google.common.util.concurrent.Futures.immediateFuture;
import static org.jclouds.concurrent.internal.ConcurrentUtils.makeListenable; import static org.jclouds.concurrent.ConcurrentUtils.makeListenable;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
@ -150,7 +150,6 @@ public class StubAsyncBlobStore implements AsyncBlobStore {
throw new UnsupportedOperationException("Content not supported " + data.getClass()); throw new UnsupportedOperationException("Content not supported " + data.getClass());
} }
return bytes; return bytes;
} }
public ListenableFuture<Blob> getBlob(final String bucketName, final String key) { public ListenableFuture<Blob> getBlob(final String bucketName, final String key) {
@ -158,7 +157,7 @@ public class StubAsyncBlobStore implements AsyncBlobStore {
return immediateFailedFuture(new ContainerNotFoundException(bucketName)); return immediateFailedFuture(new ContainerNotFoundException(bucketName));
Map<String, Blob> realContents = getContainerToBlobs().get(bucketName); Map<String, Blob> realContents = getContainerToBlobs().get(bucketName);
if (!realContents.containsKey(key)) if (!realContents.containsKey(key))
return immediateFailedFuture(new KeyNotFoundException(bucketName, key)); return immediateFuture(null);
Blob object = realContents.get(key); Blob object = realContents.get(key);
Blob returnVal = blobProvider.create(copy(object.getMetadata())); Blob returnVal = blobProvider.create(copy(object.getMetadata()));
returnVal.setPayload(object.getContent()); returnVal.setPayload(object.getContent());
@ -490,7 +489,7 @@ public class StubAsyncBlobStore implements AsyncBlobStore {
return immediateFailedFuture(new ContainerNotFoundException(bucketName)); return immediateFailedFuture(new ContainerNotFoundException(bucketName));
Map<String, Blob> realContents = getContainerToBlobs().get(bucketName); Map<String, Blob> realContents = getContainerToBlobs().get(bucketName);
if (!realContents.containsKey(key)) if (!realContents.containsKey(key))
return immediateFailedFuture(new KeyNotFoundException(bucketName, key)); return immediateFuture(null);
Blob object = realContents.get(key); Blob object = realContents.get(key);
@ -562,10 +561,12 @@ public class StubAsyncBlobStore implements AsyncBlobStore {
public ListenableFuture<BlobMetadata> blobMetadata(final String container, final String key) { public ListenableFuture<BlobMetadata> blobMetadata(final String container, final String key) {
try { try {
return immediateFuture((BlobMetadata) copy(getBlob(container, key).get().getMetadata())); Blob blob = getBlob(container, key).get();
return immediateFuture(blob != null ? (BlobMetadata) copy(blob.getMetadata()) : null);
} catch (Exception e) { } catch (Exception e) {
Throwables.propagateIfPossible(e, ContainerNotFoundException.class); if (Iterables.size(Iterables.filter(Throwables.getCausalChain(e),
Throwables.propagateIfPossible(e, KeyNotFoundException.class); KeyNotFoundException.class)) >= 1)
return immediateFuture(null);
return immediateFailedFuture(e); return immediateFailedFuture(e);
} }
} }

View File

@ -32,7 +32,6 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import org.jclouds.blobstore.AsyncBlobStore; import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.KeyNotFoundException;
import org.jclouds.blobstore.config.BlobStoreObjectModule; import org.jclouds.blobstore.config.BlobStoreObjectModule;
import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.domain.Blob.Factory; import org.jclouds.blobstore.domain.Blob.Factory;
@ -74,8 +73,8 @@ public class RetryOnNotFoundGetAllBlobsStrategyTest {
Blob object = blobProvider.create(null); Blob object = blobProvider.create(null);
object.getMetadata().setName("key"); object.getMetadata().setName("key");
object.setPayload("goo"); object.setPayload("goo");
expect(futureObject.get(map.requestTimeoutMilliseconds, TimeUnit.MILLISECONDS)).andThrow( expect(futureObject.get(map.requestTimeoutMilliseconds, TimeUnit.MILLISECONDS)).andReturn(
new KeyNotFoundException()); null);
context.getInstance(AsyncBlobStore.class).putBlob("container", object).get(); context.getInstance(AsyncBlobStore.class).putBlob("container", object).get();
replay(futureObject); replay(futureObject);
Set<Blob> objects = new HashSet<Blob>(); Set<Blob> objects = new HashSet<Blob>();
@ -99,8 +98,8 @@ public class RetryOnNotFoundGetAllBlobsStrategyTest {
ListenableFuture<Blob> futureObject = createMock(ListenableFuture.class); ListenableFuture<Blob> futureObject = createMock(ListenableFuture.class);
Blob object = createMock(Blob.class); Blob object = createMock(Blob.class);
expect(futureObject.get(map.requestTimeoutMilliseconds, TimeUnit.MILLISECONDS)).andThrow( expect(futureObject.get(map.requestTimeoutMilliseconds, TimeUnit.MILLISECONDS)).andReturn(
new KeyNotFoundException()).atLeastOnce(); null).atLeastOnce();
replay(futureObject); replay(futureObject);
Set<Blob> objects = new HashSet<Blob>(); Set<Blob> objects = new HashSet<Blob>();
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();

View File

@ -25,7 +25,6 @@ import static org.testng.Assert.assertNotNull;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Properties;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
@ -102,7 +101,7 @@ public abstract class BaseComputeServiceLiveTest {
user = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user"); user = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user");
password = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key"); password = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");
context = new ComputeServiceContextFactory().createContext(service, user, password, context = new ComputeServiceContextFactory().createContext(service, user, password,
ImmutableSet.of(new Log4JLoggingModule(), getSshModule()), new Properties()); ImmutableSet.of(new Log4JLoggingModule(), getSshModule()));
Injector injector = Guice.createInjector(getSshModule()); Injector injector = Guice.createInjector(getSshModule());
sshFactory = injector.getInstance(SshClient.Factory.class); sshFactory = injector.getInstance(SshClient.Factory.class);
SocketOpen socketOpen = injector.getInstance(SocketOpen.class); SocketOpen socketOpen = injector.getInstance(SocketOpen.class);

View File

@ -16,7 +16,7 @@
* limitations under the License. * limitations under the License.
* ==================================================================== * ====================================================================
*/ */
package org.jclouds.concurrent.internal; package org.jclouds.concurrent;
import java.util.concurrent.CancellationException; import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
@ -38,13 +38,21 @@ import com.google.common.util.concurrent.ListenableFuture;
*/ */
@Singleton @Singleton
public class ConcurrentUtils { public class ConcurrentUtils {
/**
* Converts an exception into an object, which is useful for transforming to null or false.
*/
public static <T> ListenableFuture<T> convertExceptionToValue(ListenableFuture<T> future,
Class<? extends Exception> clazz, T toValue) {
return new ConvertFutureExceptionToValue<T>(future, clazz, toValue);
}
/** /**
* Just like {@code Futures#makeListenable} except that we pass in an executorService. * Just like {@code Futures#makeListenable} except that we pass in an executorService.
* <p/> * <p/>
* Temporary hack until http://code.google.com/p/guava-libraries/issues/detail?id=317 is fixed. * Temporary hack until http://code.google.com/p/guava-libraries/issues/detail?id=317 is fixed.
*/ */
public static <T> ListenableFuture<T> makeListenable(Future<T> future, ExecutorService executorService) { public static <T> ListenableFuture<T> makeListenable(Future<T> future,
ExecutorService executorService) {
if (future instanceof ListenableFuture<?>) { if (future instanceof ListenableFuture<?>) {
return (ListenableFuture<T>) future; return (ListenableFuture<T>) future;
} }

View File

@ -0,0 +1,66 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.concurrent;
import static org.jclouds.util.Utils.propagateOrNull;
import java.util.List;
import javax.annotation.Nullable;
import com.google.common.base.Function;
import com.google.common.base.Throwables;
import com.google.common.collect.Iterables;
import com.google.common.util.concurrent.ListenableFuture;
/**
* Matches on a particular exception and converts the response to null.
*
* @author Adrian Cole
*/
public class ConvertFutureExceptionToValue<T> extends FutureExceptionParser<T> {
public static class ExceptionToValueOrPropagate<E extends Exception, T> implements
Function<Exception, T> {
private final Class<E> matchingClass;
private final T value;
public ExceptionToValueOrPropagate(Class<E> matchingClass, @Nullable T value) {
this.matchingClass = matchingClass;
this.value = value;
}
@SuppressWarnings("unchecked")
@Override
public T apply(Exception from) {
List<Throwable> throwables = Throwables.getCausalChain(from);
Iterable<E> matchingThrowables = Iterables.filter(throwables, matchingClass);
if (Iterables.size(matchingThrowables) >= 1)
return value;
return (T)propagateOrNull(from);
}
}
public <E extends Exception> ConvertFutureExceptionToValue(ListenableFuture<T> delegate,
Class<E> exceptionClass, @Nullable T value) {
super(delegate, new ExceptionToValueOrPropagate<E, T>(exceptionClass, value));
}
}

View File

@ -51,25 +51,20 @@ public class FutureExceptionParser<T> implements ListenableFuture<T> {
public T get() throws InterruptedException, ExecutionException { public T get() throws InterruptedException, ExecutionException {
try { try {
return delegate.get(); return delegate.get();
} catch (ExecutionException e) { } catch (Exception e) {
return attemptConvert(e); return attemptConvert(e);
} }
} }
private T attemptConvert(ExecutionException e) throws ExecutionException { private T attemptConvert(Exception e) {
if (e.getCause() instanceof Exception) { return function.apply(e instanceof ExecutionException ? (Exception) e.getCause() : e);
T returnVal = function.apply((Exception) e.getCause());
if (returnVal != null)
return returnVal;
}
throw e;
} }
public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException,
TimeoutException { TimeoutException {
try { try {
return delegate.get(timeout, unit); return delegate.get(timeout, unit);
} catch (ExecutionException e) { } catch (Exception e) {
return attemptConvert(e); return attemptConvert(e);
} }
} }

View File

@ -18,8 +18,6 @@
*/ */
package org.jclouds.http.functions; package org.jclouds.http.functions;
import java.lang.reflect.Constructor;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
@ -28,30 +26,13 @@ import com.google.common.base.Function;
import com.google.common.io.Closeables; import com.google.common.io.Closeables;
/** /**
* Simply returns true when the http response code is in the range 200-299.
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
@Singleton @Singleton
public class ReturnVoidIf2xx implements Function<HttpResponse, Void> { public class CloseContentAndReturn implements Function<HttpResponse, Void> {
static final Void v;
static {
Constructor<Void> cv;
try {
cv = Void.class.getDeclaredConstructor();
cv.setAccessible(true);
v = cv.newInstance();
} catch (Exception e) {
throw new Error("Error setting up class", e);
}
}
public Void apply(HttpResponse from) { public Void apply(HttpResponse from) {
Closeables.closeQuietly(from.getContent()); Closeables.closeQuietly(from.getContent());
int code = from.getStatusCode(); return null;
if (code >= 300 || code < 200) {
throw new IllegalStateException("incorrect code for this operation: " + from);
}
return v;
} }
} }

View File

@ -18,6 +18,8 @@
*/ */
package org.jclouds.http.functions; package org.jclouds.http.functions;
import static org.jclouds.util.Utils.propagateOrNull;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.http.HttpResponseException; import org.jclouds.http.HttpResponseException;
@ -38,7 +40,7 @@ public class ReturnFalseOn404 implements Function<Exception, Boolean> {
return false; return false;
} }
} }
return null; return Boolean.class.cast(propagateOrNull(from));
} }
} }

View File

@ -18,6 +18,8 @@
*/ */
package org.jclouds.http.functions; package org.jclouds.http.functions;
import static org.jclouds.util.Utils.propagateOrNull;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.http.HttpResponseException; import org.jclouds.http.HttpResponseException;
@ -34,7 +36,7 @@ public class ReturnTrueOn404 implements Function<Exception, Boolean> {
return true; return true;
} }
} }
return null; return Boolean.class.cast(propagateOrNull(from));
} }
} }

View File

@ -18,7 +18,7 @@
*/ */
package org.jclouds.http.internal; package org.jclouds.http.internal;
import static org.jclouds.concurrent.internal.ConcurrentUtils.makeListenable; import static org.jclouds.concurrent.ConcurrentUtils.makeListenable;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;

View File

@ -0,0 +1,47 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.rest;
/**
* Thrown when there is an authorization error.
*
* @author Adrian Cole
*/
public class AuthorizationException extends RuntimeException {
/** The serialVersionUID */
private static final long serialVersionUID = -2272965726680821281L;
public AuthorizationException() {
super();
}
public AuthorizationException(String arg0, Throwable arg1) {
super(arg0, arg1);
}
public AuthorizationException(String arg0) {
super(arg0);
}
public AuthorizationException(Throwable arg0) {
super(arg0);
}
}

View File

@ -48,7 +48,8 @@ public abstract class RestContextFactory<T, B extends RestContextBuilder<?, ?>>
* Initializes with the default properties built-in to jclouds. This is typically stored in the * Initializes with the default properties built-in to jclouds. This is typically stored in the
* classpath resource {@code filename} * classpath resource {@code filename}
* *
* @param filename name of the properties file to initialize from * @param filename
* name of the properties file to initialize from
* @throws IOException * @throws IOException
* if the default properties file cannot be loaded * if the default properties file cannot be loaded
* @see #getPropertiesFromResource * @see #getPropertiesFromResource
@ -125,6 +126,11 @@ public abstract class RestContextFactory<T, B extends RestContextBuilder<?, ?>>
return createContext(hint, null, null, modules, overrides); return createContext(hint, null, null, modules, overrides);
} }
public T createContext(String hint, @Nullable String account, @Nullable String key,
Iterable<? extends Module> modules) {
return createContext(hint, account, key, modules, new Properties());
}
/** /**
* Creates a new remote context. * Creates a new remote context.
* *

View File

@ -18,7 +18,10 @@
*/ */
package org.jclouds.rest.functions; package org.jclouds.rest.functions;
import static org.jclouds.util.Utils.propagateOrNull;
import org.jclouds.http.HttpResponseException; import org.jclouds.http.HttpResponseException;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.ResourceNotFoundException; import org.jclouds.rest.ResourceNotFoundException;
import com.google.common.base.Function; import com.google.common.base.Function;
@ -27,16 +30,19 @@ import com.google.common.base.Function;
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public class ThrowResourceNotFoundOn404 implements Function<Exception, Object> { public class MapHttp4xxCodesToExceptions implements Function<Exception, Object> {
public Object apply(Exception from) { public Object apply(Exception from) {
if (from instanceof HttpResponseException) { if (from instanceof HttpResponseException) {
HttpResponseException responseException = (HttpResponseException) from; HttpResponseException responseException = (HttpResponseException) from;
if (responseException.getResponse().getStatusCode() == 404) { switch (responseException.getResponse().getStatusCode()) {
case 401:
throw new AuthorizationException(from);
case 404:
throw new ResourceNotFoundException(from); throw new ResourceNotFoundException(from);
} }
} }
return null; return propagateOrNull(from);
} }
} }

View File

@ -98,9 +98,7 @@ public class AsyncRestClientProxy<T> implements InvocationHandler {
} }
} catch (RuntimeException e) { } catch (RuntimeException e) {
if (exceptionParser != null) { if (exceptionParser != null) {
final Object toReturn = exceptionParser.apply(e); Object toReturn = exceptionParser.apply(e);
if (toReturn == null)
throw e;
if (method.getReturnType().isAssignableFrom(ListenableFuture.class)) { if (method.getReturnType().isAssignableFrom(ListenableFuture.class)) {
ValueFuture<Object> returnVal = ValueFuture.create(); ValueFuture<Object> returnVal = ValueFuture.create();
returnVal.set(toReturn); returnVal.set(toReturn);

View File

@ -66,7 +66,7 @@ import org.jclouds.http.functions.ParseURIFromListOrLocationHeaderIf20x;
import org.jclouds.http.functions.ReturnInputStream; import org.jclouds.http.functions.ReturnInputStream;
import org.jclouds.http.functions.ReturnStringIf200; import org.jclouds.http.functions.ReturnStringIf200;
import org.jclouds.http.functions.ReturnTrueIf2xx; import org.jclouds.http.functions.ReturnTrueIf2xx;
import org.jclouds.http.functions.ReturnVoidIf2xx; import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.http.functions.ParseSax.HandlerWithResult; import org.jclouds.http.functions.ParseSax.HandlerWithResult;
import org.jclouds.http.options.HttpRequestOptions; import org.jclouds.http.options.HttpRequestOptions;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
@ -90,7 +90,7 @@ import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.SkipEncoding; import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.VirtualHost; import org.jclouds.rest.annotations.VirtualHost;
import org.jclouds.rest.annotations.XMLResponseParser; import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.rest.functions.ThrowResourceNotFoundOn404; import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function; import com.google.common.base.Function;
@ -216,7 +216,7 @@ public class RestAnnotationProcessor<T> {
if (annotation != null) { if (annotation != null) {
return injector.getInstance(annotation.value()); return injector.getInstance(annotation.value());
} }
return injector.getInstance(ThrowResourceNotFoundOn404.class); return injector.getInstance(MapHttp4xxCodesToExceptions.class);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -646,7 +646,7 @@ public class RestAnnotationProcessor<T> {
return ReturnStringIf200.class; return ReturnStringIf200.class;
} else if (method.getReturnType().equals(void.class) } else if (method.getReturnType().equals(void.class)
|| TypeLiteral.get(method.getGenericReturnType()).equals(futureVoidLiteral)) { || TypeLiteral.get(method.getGenericReturnType()).equals(futureVoidLiteral)) {
return ReturnVoidIf2xx.class; return CloseContentAndReturn.class;
} else if (method.getReturnType().equals(URI.class) } else if (method.getReturnType().equals(URI.class)
|| TypeLiteral.get(method.getGenericReturnType()).equals(futureURILiteral)) { || TypeLiteral.get(method.getGenericReturnType()).equals(futureURILiteral)) {
return ParseURIFromListOrLocationHeaderIf20x.class; return ParseURIFromListOrLocationHeaderIf20x.class;

View File

@ -38,6 +38,7 @@ import org.jclouds.logging.Logger;
import com.google.common.base.Charsets; import com.google.common.base.Charsets;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.base.Throwables;
import com.google.common.io.ByteStreams; import com.google.common.io.ByteStreams;
import com.google.common.io.Closeables; import com.google.common.io.Closeables;
import com.google.common.io.OutputSupplier; import com.google.common.io.OutputSupplier;
@ -50,6 +51,12 @@ import com.google.common.io.OutputSupplier;
public class Utils { public class Utils {
public static final String UTF8_ENCODING = "UTF-8"; public static final String UTF8_ENCODING = "UTF-8";
public static Object propagateOrNull(Exception from) {
Throwables.propagate(from);
assert false : "exception should have propogated";
return null;
}
public static String replaceTokens(String value, Collection<Entry<String, String>> tokenValues) { public static String replaceTokens(String value, Collection<Entry<String, String>> tokenValues) {
for (Entry<String, String> tokenValue : tokenValues) { for (Entry<String, String> tokenValue : tokenValues) {
value = replaceAll(value, TOKEN_TO_PATTERN.get(tokenValue.getKey()), tokenValue.getValue()); value = replaceAll(value, TOKEN_TO_PATTERN.get(tokenValue.getKey()), tokenValue.getValue());

View File

@ -18,7 +18,8 @@
*/ */
package org.jclouds.concurrent; package org.jclouds.concurrent;
import static org.jclouds.concurrent.internal.ConcurrentUtils.makeListenable; import static org.jclouds.concurrent.ConcurrentUtils.makeListenable;
import static org.jclouds.util.Utils.propagateOrNull;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
@ -30,6 +31,8 @@ import java.util.concurrent.TimeoutException;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Throwables;
import com.google.common.collect.Iterables;
import com.google.common.util.concurrent.Executors; import com.google.common.util.concurrent.Executors;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
@ -48,7 +51,7 @@ public class FutureExceptionParserTest {
assertEquals(future.get(), "foo"); assertEquals(future.get(), "foo");
} }
@Test(expectedExceptions = ExecutionException.class) @Test(expectedExceptions = Exception.class)
public void testGetUnmatched() throws InterruptedException, ExecutionException { public void testGetUnmatched() throws InterruptedException, ExecutionException {
ListenableFuture<?> future = createListenableFuture(new Exception("foo")); ListenableFuture<?> future = createListenableFuture(new Exception("foo"));
assertEquals(future.get(), "foo"); assertEquals(future.get(), "foo");
@ -61,7 +64,7 @@ public class FutureExceptionParserTest {
assertEquals(future.get(1, TimeUnit.SECONDS), "foo"); assertEquals(future.get(1, TimeUnit.SECONDS), "foo");
} }
@Test(expectedExceptions = ExecutionException.class) @Test(expectedExceptions = Exception.class)
public void testGetLongTimeUnitUnmatched() throws InterruptedException, ExecutionException, public void testGetLongTimeUnitUnmatched() throws InterruptedException, ExecutionException,
TimeoutException { TimeoutException {
ListenableFuture<?> future = createListenableFuture(new Exception("foo")); ListenableFuture<?> future = createListenableFuture(new Exception("foo"));
@ -81,7 +84,10 @@ public class FutureExceptionParserTest {
future = new FutureExceptionParser(future, new Function<Exception, String>() { future = new FutureExceptionParser(future, new Function<Exception, String>() {
public String apply(Exception from) { public String apply(Exception from) {
return (from instanceof RuntimeException) ? from.getMessage() : null; if (Iterables.size(Iterables.filter(Throwables.getCausalChain(from),
RuntimeException.class)) >= 1)
return from.getMessage();
return String.class.cast(propagateOrNull(from));
} }
}); });

View File

@ -18,7 +18,7 @@
*/ */
package org.jclouds.concurrent.internal; package org.jclouds.concurrent.internal;
import static org.jclouds.concurrent.internal.ConcurrentUtils.makeListenable; import static org.jclouds.concurrent.ConcurrentUtils.makeListenable;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;

View File

@ -29,7 +29,7 @@ import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.http.HttpUtils; import org.jclouds.http.HttpUtils;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
import org.jclouds.rest.config.RestModule; import org.jclouds.rest.config.RestModule;
import org.jclouds.rest.functions.ThrowResourceNotFoundOn404; import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;
@ -83,7 +83,7 @@ public abstract class RestClientTest<T> {
protected void assertExceptionParserClassEquals(Method method, @Nullable Class<?> parserClass) { protected void assertExceptionParserClassEquals(Method method, @Nullable Class<?> parserClass) {
if (parserClass == null) if (parserClass == null)
assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation( assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(
method).getClass(), ThrowResourceNotFoundOn404.class); method).getClass(), MapHttp4xxCodesToExceptions.class);
else else
assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation( assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(
method).getClass(), parserClass); method).getClass(), parserClass);

View File

@ -69,7 +69,7 @@ import org.jclouds.http.functions.ParseURIFromListOrLocationHeaderIf20x;
import org.jclouds.http.functions.ReturnInputStream; import org.jclouds.http.functions.ReturnInputStream;
import org.jclouds.http.functions.ReturnStringIf200; import org.jclouds.http.functions.ReturnStringIf200;
import org.jclouds.http.functions.ReturnTrueIf2xx; import org.jclouds.http.functions.ReturnTrueIf2xx;
import org.jclouds.http.functions.ReturnVoidIf2xx; import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.http.options.BaseHttpRequestOptions; import org.jclouds.http.options.BaseHttpRequestOptions;
import org.jclouds.http.options.GetOptions; import org.jclouds.http.options.GetOptions;
import org.jclouds.http.options.HttpRequestOptions; import org.jclouds.http.options.HttpRequestOptions;
@ -1530,7 +1530,7 @@ public class RestAnnotationProcessorTest {
assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections assertEquals(request.getHeaders().get(HttpHeaders.CONTENT_LENGTH), Collections
.singletonList("test".getBytes().length + "")); .singletonList("test".getBytes().length + ""));
assertEquals(processor.createResponseParser(method, request).getClass(), assertEquals(processor.createResponseParser(method, request).getClass(),
ReturnVoidIf2xx.class); CloseContentAndReturn.class);
} }
@Test @Test

View File

@ -19,7 +19,7 @@
package org.jclouds.http.pool; package org.jclouds.http.pool;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static org.jclouds.concurrent.internal.ConcurrentUtils.makeListenable; import static org.jclouds.concurrent.ConcurrentUtils.makeListenable;
import java.net.URI; import java.net.URI;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;

View File

@ -20,7 +20,6 @@ package org.jclouds.mezeo.pcs2.functions;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
import java.lang.reflect.Constructor;
import java.util.Map; import java.util.Map;
import javax.inject.Inject; import javax.inject.Inject;
@ -45,18 +44,6 @@ public class AddMetadataItemIntoMap implements Function<HttpResponse, Void>, Inv
this.returnIf200 = returnIf200; this.returnIf200 = returnIf200;
} }
static final Void v;
static {
Constructor<Void> cv;
try {
cv = Void.class.getDeclaredConstructor();
cv.setAccessible(true);
v = cv.newInstance();
} catch (Exception e) {
throw new Error("Error setting up class", e);
}
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Void apply(HttpResponse from) public Void apply(HttpResponse from)
@ -74,7 +61,7 @@ public class AddMetadataItemIntoMap implements Function<HttpResponse, Void>, Inv
checkState(key != null, "No String found in args, improper method declarations"); checkState(key != null, "No String found in args, improper method declarations");
map.put(key, returnIf200.apply(from).trim()); map.put(key, returnIf200.apply(from).trim());
return v; return null;
} }
public void setContext(GeneratedHttpRequest<?> request) { public void setContext(GeneratedHttpRequest<?> request) {

View File

@ -18,6 +18,8 @@
*/ */
package org.jclouds.mezeo.pcs2.functions; package org.jclouds.mezeo.pcs2.functions;
import static org.jclouds.util.Utils.propagateOrNull;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.blobstore.ContainerNotFoundException; import org.jclouds.blobstore.ContainerNotFoundException;
@ -35,7 +37,7 @@ public class ReturnFalseIfContainerNotFound implements Function<Exception, Boole
if (from instanceof ContainerNotFoundException) { if (from instanceof ContainerNotFoundException) {
return false; return false;
} }
return null; return Boolean.class.cast(propagateOrNull(from));
} }
} }

View File

@ -18,6 +18,8 @@
*/ */
package org.jclouds.mezeo.pcs2.functions; package org.jclouds.mezeo.pcs2.functions;
import static org.jclouds.util.Utils.propagateOrNull;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.http.HttpResponseException; import org.jclouds.http.HttpResponseException;
@ -38,7 +40,7 @@ public class ReturnTrueIfContainerAlreadyExists implements Function<Exception, B
return true; return true;
} }
} }
return null; return Boolean.class.cast(propagateOrNull(from));
} }
} }

View File

@ -41,7 +41,7 @@ import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseURIFromListOrLocationHeaderIf20x; import org.jclouds.http.functions.ParseURIFromListOrLocationHeaderIf20x;
import org.jclouds.http.functions.ReturnInputStream; import org.jclouds.http.functions.ReturnInputStream;
import org.jclouds.http.functions.ReturnVoidIf2xx; import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.logging.Logger.LoggerFactory;
import org.jclouds.mezeo.pcs2.blobstore.functions.BlobToPCSFile; import org.jclouds.mezeo.pcs2.blobstore.functions.BlobToPCSFile;
@ -53,7 +53,7 @@ import org.jclouds.mezeo.pcs2.options.PutBlockOptions;
import org.jclouds.mezeo.pcs2.xml.ContainerHandler; import org.jclouds.mezeo.pcs2.xml.ContainerHandler;
import org.jclouds.mezeo.pcs2.xml.FileHandler; import org.jclouds.mezeo.pcs2.xml.FileHandler;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.functions.ThrowResourceNotFoundOn404; import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
@ -115,7 +115,7 @@ public class PCSClientTest extends RestClientTest<PCSAsyncClient> {
assertEquals(httpMethod.getRequestLine(), "DELETE http://localhost/container/1234 HTTP/1.1"); assertEquals(httpMethod.getRequestLine(), "DELETE http://localhost/container/1234 HTTP/1.1");
assertEquals(httpMethod.getHeaders().size(), 0); assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(processor.createResponseParser(method, httpMethod).getClass(), assertEquals(processor.createResponseParser(method, httpMethod).getClass(),
ReturnVoidIf2xx.class); CloseContentAndReturn.class);
assertEquals(RestAnnotationProcessor.getSaxResponseParserClassOrNull(method), null); assertEquals(RestAnnotationProcessor.getSaxResponseParserClassOrNull(method), null);
assertEquals(httpMethod.getFilters().size(), 1); assertEquals(httpMethod.getFilters().size(), 1);
assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class); assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class);
@ -135,7 +135,7 @@ public class PCSClientTest extends RestClientTest<PCSAsyncClient> {
ContainerHandler.class); ContainerHandler.class);
assertEquals(httpMethod.getFilters().size(), 1); assertEquals(httpMethod.getFilters().size(), 1);
assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class); assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class);
assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ThrowResourceNotFoundOn404.class); assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), MapHttp4xxCodesToExceptions.class);
} }
public void testGetFileInfo() throws SecurityException, NoSuchMethodException { public void testGetFileInfo() throws SecurityException, NoSuchMethodException {
@ -185,7 +185,7 @@ public class PCSClientTest extends RestClientTest<PCSAsyncClient> {
assertHeadersEqual(httpMethod, "Content-Length: 5\n"); assertHeadersEqual(httpMethod, "Content-Length: 5\n");
assertPayloadEquals(httpMethod, "hello"); assertPayloadEquals(httpMethod, "hello");
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
@ -216,7 +216,7 @@ public class PCSClientTest extends RestClientTest<PCSAsyncClient> {
assertEquals(httpMethod.getRequestLine(), "DELETE http://localhost/contents/file HTTP/1.1"); assertEquals(httpMethod.getRequestLine(), "DELETE http://localhost/contents/file HTTP/1.1");
assertEquals(httpMethod.getHeaders().size(), 0); assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(processor.createResponseParser(method, httpMethod).getClass(), assertEquals(processor.createResponseParser(method, httpMethod).getClass(),
ReturnVoidIf2xx.class); CloseContentAndReturn.class);
assertEquals(RestAnnotationProcessor.getSaxResponseParserClassOrNull(method), null); assertEquals(RestAnnotationProcessor.getSaxResponseParserClassOrNull(method), null);
assertEquals(httpMethod.getFilters().size(), 1); assertEquals(httpMethod.getFilters().size(), 1);
assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class); assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class);
@ -238,9 +238,9 @@ public class PCSClientTest extends RestClientTest<PCSAsyncClient> {
assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections
.singletonList("application/unknown")); .singletonList("application/unknown"));
assertEquals("bar", httpMethod.getPayload().getRawContent()); assertEquals("bar", httpMethod.getPayload().getRawContent());
assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ThrowResourceNotFoundOn404.class); assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), MapHttp4xxCodesToExceptions.class);
assertEquals(processor.createResponseParser(method, httpMethod).getClass(), assertEquals(processor.createResponseParser(method, httpMethod).getClass(),
ReturnVoidIf2xx.class); CloseContentAndReturn.class);
} }
public void testAddEntryToMap() throws SecurityException, NoSuchMethodException { public void testAddEntryToMap() throws SecurityException, NoSuchMethodException {
@ -253,7 +253,7 @@ public class PCSClientTest extends RestClientTest<PCSAsyncClient> {
assertEquals(httpMethod.getRequestLine(), "GET http://localhost/pow/metadata/newkey HTTP/1.1"); assertEquals(httpMethod.getRequestLine(), "GET http://localhost/pow/metadata/newkey HTTP/1.1");
assertEquals(httpMethod.getHeaders().size(), 0); assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ThrowResourceNotFoundOn404.class); assertEquals(processor.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), MapHttp4xxCodesToExceptions.class);
assertEquals(processor.createResponseParser(method, httpMethod).getClass(), assertEquals(processor.createResponseParser(method, httpMethod).getClass(),
AddMetadataItemIntoMap.class); AddMetadataItemIntoMap.class);
} }

View File

@ -36,7 +36,7 @@ import org.jclouds.logging.Logger;
import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.logging.Logger.LoggerFactory;
import org.jclouds.mezeo.pcs2.xml.CloudXlinkHandler; import org.jclouds.mezeo.pcs2.xml.CloudXlinkHandler;
import org.jclouds.rest.config.RestModule; import org.jclouds.rest.config.RestModule;
import org.jclouds.rest.functions.ThrowResourceNotFoundOn404; import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
@ -69,7 +69,7 @@ public class PCSCloudTest {
assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class); assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class);
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
ThrowResourceNotFoundOn404.class); MapHttp4xxCodesToExceptions.class);
} }
private RestAnnotationProcessor<PCSCloud> processor; private RestAnnotationProcessor<PCSCloud> processor;

View File

@ -29,7 +29,7 @@ import org.jclouds.blobstore.binders.BindBlobToMultipartFormTest;
import org.jclouds.blobstore.config.BlobStoreObjectModule; import org.jclouds.blobstore.config.BlobStoreObjectModule;
import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.Blob;
import org.jclouds.http.functions.ReturnStringIf200; import org.jclouds.http.functions.ReturnStringIf200;
import org.jclouds.http.functions.ReturnVoidIf2xx; import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.logging.Logger.LoggerFactory;
import org.jclouds.nirvanix.sdn.filters.AddSessionTokenToRequest; import org.jclouds.nirvanix.sdn.filters.AddSessionTokenToRequest;
@ -97,7 +97,7 @@ public class SDNClientTest extends RestClientTest<SDNAsyncClient> {
assertPayloadEquals(httpMethod, expects.toString()); assertPayloadEquals(httpMethod, expects.toString());
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
@ -115,7 +115,7 @@ public class SDNClientTest extends RestClientTest<SDNAsyncClient> {
assertHeadersEqual(httpMethod, ""); assertHeadersEqual(httpMethod, "");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);

View File

@ -19,8 +19,9 @@
package org.jclouds.rackspace.cloudfiles.blobstore; package org.jclouds.rackspace.cloudfiles.blobstore;
import static com.google.common.util.concurrent.Futures.compose; import static com.google.common.util.concurrent.Futures.compose;
import static org.jclouds.concurrent.internal.ConcurrentUtils.makeListenable;
import static org.jclouds.blobstore.options.ListContainerOptions.Builder.recursive; import static org.jclouds.blobstore.options.ListContainerOptions.Builder.recursive;
import static org.jclouds.concurrent.ConcurrentUtils.convertExceptionToValue;
import static org.jclouds.concurrent.ConcurrentUtils.makeListenable;
import java.util.SortedSet; import java.util.SortedSet;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
@ -89,7 +90,8 @@ public class CloudFilesAsyncBlobStore extends BaseCloudFilesBlobStore implements
*/ */
public ListenableFuture<BlobMetadata> blobMetadata(String container, String key) { public ListenableFuture<BlobMetadata> blobMetadata(String container, String key) {
return compose(async.getObjectInfo(container, key), return compose(convertExceptionToValue(async.getObjectInfo(container, key),
KeyNotFoundException.class, null),
new Function<MutableObjectInfoWithMetadata, BlobMetadata>() { new Function<MutableObjectInfoWithMetadata, BlobMetadata>() {
@Override @Override
@ -139,7 +141,8 @@ public class CloudFilesAsyncBlobStore extends BaseCloudFilesBlobStore implements
org.jclouds.blobstore.options.GetOptions... optionsList) { org.jclouds.blobstore.options.GetOptions... optionsList) {
GetOptions httpOptions = blob2ObjectGetOptions.apply(optionsList); GetOptions httpOptions = blob2ObjectGetOptions.apply(optionsList);
ListenableFuture<CFObject> returnVal = async.getObject(container, key, httpOptions); ListenableFuture<CFObject> returnVal = async.getObject(container, key, httpOptions);
return compose(returnVal, object2Blob, service); return compose(convertExceptionToValue(returnVal, KeyNotFoundException.class, null),
object2Blob, service);
} }
public ListenableFuture<? extends ListResponse<? extends StorageMetadata>> list() { public ListenableFuture<? extends ListResponse<? extends StorageMetadata>> list() {

View File

@ -19,6 +19,7 @@
package org.jclouds.rackspace.cloudfiles.blobstore; package org.jclouds.rackspace.cloudfiles.blobstore;
import static org.jclouds.blobstore.options.ListContainerOptions.Builder.recursive; import static org.jclouds.blobstore.options.ListContainerOptions.Builder.recursive;
import static org.jclouds.blobstore.util.BlobStoreUtils.returnNullOnKeyNotFoundOrPropagate;
import java.util.SortedSet; import java.util.SortedSet;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
@ -26,7 +27,6 @@ import java.util.concurrent.ExecutorService;
import javax.inject.Inject; import javax.inject.Inject;
import org.jclouds.blobstore.BlobStore; import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.KeyNotFoundException;
import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.domain.BlobMetadata; import org.jclouds.blobstore.domain.BlobMetadata;
import org.jclouds.blobstore.domain.ListContainerResponse; import org.jclouds.blobstore.domain.ListContainerResponse;
@ -80,7 +80,11 @@ public class CloudFilesBlobStore extends BaseCloudFilesBlobStore implements Blob
* This implementation uses the CloudFiles HEAD Object command to return the result * This implementation uses the CloudFiles HEAD Object command to return the result
*/ */
public BlobMetadata blobMetadata(String container, String key) { public BlobMetadata blobMetadata(String container, String key) {
try {
return object2BlobMd.apply(sync.getObjectInfo(container, key)); return object2BlobMd.apply(sync.getObjectInfo(container, key));
} catch (Exception e) {
return returnNullOnKeyNotFoundOrPropagate(e);
}
} }
public void clearContainer(final String container) { public void clearContainer(final String container) {
@ -107,7 +111,11 @@ public class CloudFilesBlobStore extends BaseCloudFilesBlobStore implements Blob
public Blob getBlob(String container, String key, public Blob getBlob(String container, String key,
org.jclouds.blobstore.options.GetOptions... optionsList) { org.jclouds.blobstore.options.GetOptions... optionsList) {
GetOptions httpOptions = blob2ObjectGetOptions.apply(optionsList); GetOptions httpOptions = blob2ObjectGetOptions.apply(optionsList);
try {
return object2Blob.apply(sync.getObject(container, key, httpOptions)); return object2Blob.apply(sync.getObject(container, key, httpOptions));
} catch (Exception e) {
return returnNullOnKeyNotFoundOrPropagate(e);
}
} }
public ListResponse<? extends StorageMetadata> list() { public ListResponse<? extends StorageMetadata> list() {
@ -139,8 +147,8 @@ public class CloudFilesBlobStore extends BaseCloudFilesBlobStore implements Blob
try { try {
getDirectoryStrategy.execute(aBlobStore, containerName, directory); getDirectoryStrategy.execute(aBlobStore, containerName, directory);
return true; return true;
} catch (KeyNotFoundException e) { } catch (Exception e) {
return false; return (Boolean)returnNullOnKeyNotFoundOrPropagate(e);
} }
} }

View File

@ -41,6 +41,8 @@ public class BlobToObject implements Function<Blob, CFObject> {
} }
public CFObject apply(Blob from) { public CFObject apply(Blob from) {
if (from == null)
return null;
CFObject object = objectProvider.create(blob2ObjectMd.apply(from.getMetadata())); CFObject object = objectProvider.create(blob2ObjectMd.apply(from.getMetadata()));
if (from.getContentLength() != null) if (from.getContentLength() != null)
object.setContentLength(from.getContentLength()); object.setContentLength(from.getContentLength());

View File

@ -42,6 +42,8 @@ public class ObjectToBlob implements Function<CFObject, Blob> {
} }
public Blob apply(CFObject from) { public Blob apply(CFObject from) {
if (from == null)
return null;
Blob blob = blobFactory.create(object2BlobMd.apply(from.getInfo())); Blob blob = blobFactory.create(object2BlobMd.apply(from.getInfo()));
if (from.getContentLength() != null) if (from.getContentLength() != null)
blob.setContentLength(from.getContentLength()); blob.setContentLength(from.getContentLength());

View File

@ -47,6 +47,8 @@ public class ObjectToBlobMetadata implements Function<ObjectInfo, MutableBlobMet
} }
public MutableBlobMetadata apply(ObjectInfo from) { public MutableBlobMetadata apply(ObjectInfo from) {
if (from == null)
return null;
MutableBlobMetadata to = new MutableBlobMetadataImpl(); MutableBlobMetadata to = new MutableBlobMetadataImpl();
to.setContentMD5(from.getHash()); to.setContentMD5(from.getHash());
if (from.getContentType() != null) if (from.getContentType() != null)

View File

@ -43,22 +43,24 @@ public class ResourceToObjectInfo implements
this.encryptionService = encryptionService; this.encryptionService = encryptionService;
} }
public MutableObjectInfoWithMetadata apply(StorageMetadata base) { public MutableObjectInfoWithMetadata apply(StorageMetadata from) {
if (from == null)
return null;
MutableObjectInfoWithMetadata to = new MutableObjectInfoWithMetadataImpl(); MutableObjectInfoWithMetadata to = new MutableObjectInfoWithMetadataImpl();
if (base.getType() == StorageType.BLOB) { if (from.getType() == StorageType.BLOB) {
to.setContentType(((BlobMetadata) base).getContentType()); to.setContentType(((BlobMetadata) from).getContentType());
to.setHash(((BlobMetadata) base).getContentMD5()); to.setHash(((BlobMetadata) from).getContentMD5());
} else if (base.getType() == StorageType.RELATIVE_PATH) { } else if (from.getType() == StorageType.RELATIVE_PATH) {
to.setContentType("application/directory"); to.setContentType("application/directory");
} }
if (base.getETag() != null && to.getHash() == null) if (from.getETag() != null && to.getHash() == null)
to.setHash(encryptionService.fromHexString(base.getETag())); to.setHash(encryptionService.fromHexString(from.getETag()));
to.setName(base.getName()); to.setName(from.getName());
to.setLastModified(base.getLastModified()); to.setLastModified(from.getLastModified());
if (base.getSize() != null) if (from.getSize() != null)
to.setBytes(base.getSize()); to.setBytes(from.getSize());
if (base.getUserMetadata() != null) if (from.getUserMetadata() != null)
to.getMetadata().putAll(base.getUserMetadata()); to.getMetadata().putAll(from.getUserMetadata());
return to; return to;
} }

View File

@ -18,6 +18,8 @@
*/ */
package org.jclouds.rackspace.cloudfiles.functions; package org.jclouds.rackspace.cloudfiles.functions;
import static org.jclouds.util.Utils.propagateOrNull;
import org.jclouds.http.HttpResponseException; import org.jclouds.http.HttpResponseException;
import com.google.common.base.Function; import com.google.common.base.Function;
@ -33,7 +35,6 @@ public class ReturnTrueOn404FalseOn409 implements Function<Exception, Boolean> {
return false; return false;
} }
} }
return null; return Boolean.class.cast(propagateOrNull(from));
} }
} }

View File

@ -24,7 +24,6 @@ import static org.testng.Assert.assertNotNull;
import java.net.URI; import java.net.URI;
import java.util.List; import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.inject.Named; import javax.inject.Named;
@ -37,6 +36,7 @@ import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.rackspace.RackspaceAuthentication.AuthenticationResponse; import org.jclouds.rackspace.RackspaceAuthentication.AuthenticationResponse;
import org.jclouds.rackspace.config.RackspaceAuthenticationRestModule; import org.jclouds.rackspace.config.RackspaceAuthenticationRestModule;
import org.jclouds.rackspace.reference.RackspaceConstants; import org.jclouds.rackspace.reference.RackspaceConstants;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientFactory; import org.jclouds.rest.RestClientFactory;
import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContext;
@ -110,7 +110,7 @@ public class RackspaceAuthenticationLiveTest {
assertNotNull(response.getAuthToken()); assertNotNull(response.getAuthToken());
} }
@Test(expectedExceptions = ExecutionException.class) @Test(expectedExceptions = AuthorizationException.class)
public void testBadAuthentication() throws Exception { public void testBadAuthentication() throws Exception {
RackspaceAuthentication authentication = context.getAsyncApi(); RackspaceAuthentication authentication = context.getAsyncApi();
authentication.authenticate("foo", "bar").get(10, TimeUnit.SECONDS); authentication.authenticate("foo", "bar").get(10, TimeUnit.SECONDS);

View File

@ -68,7 +68,7 @@ import org.jclouds.rackspace.cloudservers.options.CreateSharedIpGroupOptions;
import org.jclouds.rackspace.cloudservers.options.ListOptions; import org.jclouds.rackspace.cloudservers.options.ListOptions;
import org.jclouds.rackspace.cloudservers.options.RebuildServerOptions; import org.jclouds.rackspace.cloudservers.options.RebuildServerOptions;
import org.jclouds.rest.config.RestModule; import org.jclouds.rest.config.RestModule;
import org.jclouds.rest.functions.ThrowResourceNotFoundOn404; import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
@ -176,7 +176,7 @@ public class CloudServersClientTest {
ParseServerFromJsonResponse.class); ParseServerFromJsonResponse.class);
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
ThrowResourceNotFoundOn404.class); MapHttp4xxCodesToExceptions.class);
assertNotNull(processor.getMapPayloadBinderOrNull(method, new Object[] { "", 1, 2, assertNotNull(processor.getMapPayloadBinderOrNull(method, new Object[] { "", 1, 2,
new CreateServerOptions[] { CreateServerOptions.Builder.withSharedIpGroup(1) } })); new CreateServerOptions[] { CreateServerOptions.Builder.withSharedIpGroup(1) } }));
} }
@ -212,7 +212,7 @@ public class CloudServersClientTest {
ParseServerListFromJsonResponse.class); ParseServerListFromJsonResponse.class);
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
ThrowResourceNotFoundOn404.class); MapHttp4xxCodesToExceptions.class);
} }
Date now = new Date(); Date now = new Date();
@ -233,7 +233,7 @@ public class CloudServersClientTest {
ParseServerListFromJsonResponse.class); ParseServerListFromJsonResponse.class);
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
ThrowResourceNotFoundOn404.class); MapHttp4xxCodesToExceptions.class);
} }
public void testListServersDetail() throws SecurityException, NoSuchMethodException { public void testListServersDetail() throws SecurityException, NoSuchMethodException {
@ -251,7 +251,7 @@ public class CloudServersClientTest {
ParseServerListFromJsonResponse.class); ParseServerListFromJsonResponse.class);
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
ThrowResourceNotFoundOn404.class); MapHttp4xxCodesToExceptions.class);
} }
public void testGetServer() throws SecurityException, NoSuchMethodException { public void testGetServer() throws SecurityException, NoSuchMethodException {
@ -268,7 +268,7 @@ public class CloudServersClientTest {
ParseServerFromJsonResponse.class); ParseServerFromJsonResponse.class);
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
ThrowResourceNotFoundOn404.class); MapHttp4xxCodesToExceptions.class);
} }
public void testListFlavors() throws SecurityException, NoSuchMethodException { public void testListFlavors() throws SecurityException, NoSuchMethodException {
@ -286,7 +286,7 @@ public class CloudServersClientTest {
ParseFlavorListFromJsonResponse.class); ParseFlavorListFromJsonResponse.class);
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
ThrowResourceNotFoundOn404.class); MapHttp4xxCodesToExceptions.class);
} }
public void testListFlavorsOptions() throws SecurityException, NoSuchMethodException { public void testListFlavorsOptions() throws SecurityException, NoSuchMethodException {
@ -305,7 +305,7 @@ public class CloudServersClientTest {
ParseFlavorListFromJsonResponse.class); ParseFlavorListFromJsonResponse.class);
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
ThrowResourceNotFoundOn404.class); MapHttp4xxCodesToExceptions.class);
} }
public void testListFlavorsDetail() throws SecurityException, NoSuchMethodException { public void testListFlavorsDetail() throws SecurityException, NoSuchMethodException {
@ -323,7 +323,7 @@ public class CloudServersClientTest {
ParseFlavorListFromJsonResponse.class); ParseFlavorListFromJsonResponse.class);
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
ThrowResourceNotFoundOn404.class); MapHttp4xxCodesToExceptions.class);
} }
public void testListFlavorsDetailOptions() throws SecurityException, NoSuchMethodException { public void testListFlavorsDetailOptions() throws SecurityException, NoSuchMethodException {
@ -342,7 +342,7 @@ public class CloudServersClientTest {
ParseFlavorListFromJsonResponse.class); ParseFlavorListFromJsonResponse.class);
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
ThrowResourceNotFoundOn404.class); MapHttp4xxCodesToExceptions.class);
} }
public void testGetFlavor() throws SecurityException, NoSuchMethodException { public void testGetFlavor() throws SecurityException, NoSuchMethodException {
@ -359,7 +359,7 @@ public class CloudServersClientTest {
ParseFlavorFromJsonResponse.class); ParseFlavorFromJsonResponse.class);
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
ThrowResourceNotFoundOn404.class); MapHttp4xxCodesToExceptions.class);
} }
public void testListImages() throws SecurityException, NoSuchMethodException { public void testListImages() throws SecurityException, NoSuchMethodException {
@ -377,7 +377,7 @@ public class CloudServersClientTest {
ParseImageListFromJsonResponse.class); ParseImageListFromJsonResponse.class);
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
ThrowResourceNotFoundOn404.class); MapHttp4xxCodesToExceptions.class);
} }
public void testListImagesDetail() throws SecurityException, NoSuchMethodException { public void testListImagesDetail() throws SecurityException, NoSuchMethodException {
@ -395,7 +395,7 @@ public class CloudServersClientTest {
ParseImageListFromJsonResponse.class); ParseImageListFromJsonResponse.class);
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
ThrowResourceNotFoundOn404.class); MapHttp4xxCodesToExceptions.class);
} }
public void testListImagesOptions() throws SecurityException, NoSuchMethodException { public void testListImagesOptions() throws SecurityException, NoSuchMethodException {
@ -414,7 +414,7 @@ public class CloudServersClientTest {
ParseImageListFromJsonResponse.class); ParseImageListFromJsonResponse.class);
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
ThrowResourceNotFoundOn404.class); MapHttp4xxCodesToExceptions.class);
} }
public void testListImagesDetailOptions() throws SecurityException, NoSuchMethodException { public void testListImagesDetailOptions() throws SecurityException, NoSuchMethodException {
@ -433,7 +433,7 @@ public class CloudServersClientTest {
ParseImageListFromJsonResponse.class); ParseImageListFromJsonResponse.class);
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
ThrowResourceNotFoundOn404.class); MapHttp4xxCodesToExceptions.class);
} }
public void testGetImage() throws SecurityException, NoSuchMethodException { public void testGetImage() throws SecurityException, NoSuchMethodException {
@ -450,7 +450,7 @@ public class CloudServersClientTest {
ParseImageFromJsonResponse.class); ParseImageFromJsonResponse.class);
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
ThrowResourceNotFoundOn404.class); MapHttp4xxCodesToExceptions.class);
} }
public void testDeleteServer() throws SecurityException, NoSuchMethodException { public void testDeleteServer() throws SecurityException, NoSuchMethodException {
@ -638,7 +638,7 @@ public class CloudServersClientTest {
ParseSharedIpGroupListFromJsonResponse.class); ParseSharedIpGroupListFromJsonResponse.class);
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
ThrowResourceNotFoundOn404.class); MapHttp4xxCodesToExceptions.class);
} }
public void testListSharedIpGroupsOptions() throws SecurityException, NoSuchMethodException { public void testListSharedIpGroupsOptions() throws SecurityException, NoSuchMethodException {
@ -657,7 +657,7 @@ public class CloudServersClientTest {
ParseSharedIpGroupListFromJsonResponse.class); ParseSharedIpGroupListFromJsonResponse.class);
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
ThrowResourceNotFoundOn404.class); MapHttp4xxCodesToExceptions.class);
} }
public void testListSharedIpGroupsDetail() throws SecurityException, NoSuchMethodException { public void testListSharedIpGroupsDetail() throws SecurityException, NoSuchMethodException {
@ -675,7 +675,7 @@ public class CloudServersClientTest {
ParseSharedIpGroupListFromJsonResponse.class); ParseSharedIpGroupListFromJsonResponse.class);
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
ThrowResourceNotFoundOn404.class); MapHttp4xxCodesToExceptions.class);
} }
public void testListSharedIpGroupsDetailOptions() throws SecurityException, public void testListSharedIpGroupsDetailOptions() throws SecurityException,
@ -695,7 +695,7 @@ public class CloudServersClientTest {
ParseSharedIpGroupListFromJsonResponse.class); ParseSharedIpGroupListFromJsonResponse.class);
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
ThrowResourceNotFoundOn404.class); MapHttp4xxCodesToExceptions.class);
} }
public void testGetSharedIpGroup() throws SecurityException, NoSuchMethodException { public void testGetSharedIpGroup() throws SecurityException, NoSuchMethodException {
@ -712,7 +712,7 @@ public class CloudServersClientTest {
ParseSharedIpGroupFromJsonResponse.class); ParseSharedIpGroupFromJsonResponse.class);
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
ThrowResourceNotFoundOn404.class); MapHttp4xxCodesToExceptions.class);
} }
private static final Class<? extends CreateSharedIpGroupOptions[]> createSharedIpGroupOptionsVarargsClass = new CreateSharedIpGroupOptions[] {} private static final Class<? extends CreateSharedIpGroupOptions[]> createSharedIpGroupOptionsVarargsClass = new CreateSharedIpGroupOptions[] {}
@ -756,7 +756,7 @@ public class CloudServersClientTest {
ParseSharedIpGroupFromJsonResponse.class); ParseSharedIpGroupFromJsonResponse.class);
assertEquals(processor assertEquals(processor
.createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(),
ThrowResourceNotFoundOn404.class); MapHttp4xxCodesToExceptions.class);
assertNotNull(processor.getMapPayloadBinderOrNull(method, new Object[] { "", assertNotNull(processor.getMapPayloadBinderOrNull(method, new Object[] { "",
new CreateSharedIpGroupOptions[] { withServer(2) } })); new CreateSharedIpGroupOptions[] { withServer(2) } }));
} }

View File

@ -18,6 +18,8 @@
*/ */
package org.jclouds.rimuhosting.miro.functions; package org.jclouds.rimuhosting.miro.functions;
import static org.jclouds.util.Utils.propagateOrNull;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
@ -39,6 +41,7 @@ import java.util.Map;
@Singleton @Singleton
public class ParseRimuHostingException implements Function<Exception, Object> { public class ParseRimuHostingException implements Function<Exception, Object> {
private Gson gson; private Gson gson;
@Inject @Inject
public ParseRimuHostingException(Gson gson) { public ParseRimuHostingException(Gson gson) {
this.gson = gson; this.gson = gson;
@ -51,9 +54,11 @@ public class ParseRimuHostingException implements Function<Exception, Object> {
Type setType = new TypeToken<Map<String, RimuHostingResponse>>() { Type setType = new TypeToken<Map<String, RimuHostingResponse>>() {
}.getType(); }.getType();
Map<String, RimuHostingResponse> responseMap = gson.fromJson(responseException.getContent(), setType); Map<String, RimuHostingResponse> responseMap = gson.fromJson(responseException
throw new RuntimeException(responseMap.values().iterator().next().getErrorInfo().getErrorClass()); .getContent(), setType);
throw new RuntimeException(responseMap.values().iterator().next().getErrorInfo()
.getErrorClass());
} }
return null; return propagateOrNull(e);
} }
} }

View File

@ -31,7 +31,7 @@ import java.util.Properties;
import javax.inject.Provider; import javax.inject.Provider;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ReturnVoidIf2xx; import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.logging.Logger.LoggerFactory;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
@ -381,7 +381,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
assertHeadersEqual(httpMethod, ""); assertHeadersEqual(httpMethod, "");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
@ -458,7 +458,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
assertHeadersEqual(httpMethod, ""); assertHeadersEqual(httpMethod, "");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
@ -488,7 +488,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
assertHeadersEqual(httpMethod, ""); assertHeadersEqual(httpMethod, "");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);

View File

@ -18,7 +18,8 @@
*/ */
package org.jclouds.vcloud.terremark.functions; package org.jclouds.vcloud.terremark.functions;
import java.lang.reflect.Constructor; import static org.jclouds.util.Utils.propagateOrNull;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import javax.inject.Singleton; import javax.inject.Singleton;
@ -38,25 +39,13 @@ public class ReturnVoidOnDeleteDefaultIp implements Function<Exception, Void> {
public static final Pattern MESSAGE_PATTERN = Pattern public static final Pattern MESSAGE_PATTERN = Pattern
.compile(".*Cannot release this Public IP as it is default oubound IP.*"); .compile(".*Cannot release this Public IP as it is default oubound IP.*");
static final Void v;
static {
Constructor<Void> cv;
try {
cv = Void.class.getDeclaredConstructor();
cv.setAccessible(true);
v = cv.newInstance();
} catch (Exception e) {
throw new Error("Error setting up class", e);
}
}
public Void apply(Exception from) { public Void apply(Exception from) {
if (from instanceof HttpResponseException) { if (from instanceof HttpResponseException) {
HttpResponseException hre = (HttpResponseException) from; HttpResponseException hre = (HttpResponseException) from;
if (hre.getResponse().getStatusCode() == 503 || hre.getResponse().getStatusCode() == 401 if (hre.getResponse().getStatusCode() == 503 || hre.getResponse().getStatusCode() == 401
|| MESSAGE_PATTERN.matcher(hre.getMessage()).matches()) || MESSAGE_PATTERN.matcher(hre.getMessage()).matches())
return v;
}
return null; return null;
} }
return Void.class.cast(propagateOrNull(from));
}
} }

View File

@ -34,7 +34,7 @@ import javax.inject.Provider;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ReturnVoidIf2xx; import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.logging.Logger.LoggerFactory;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
@ -283,7 +283,7 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
assertHeadersEqual(httpMethod, ""); assertHeadersEqual(httpMethod, "");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
@ -455,7 +455,7 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
assertHeadersEqual(httpMethod, ""); assertHeadersEqual(httpMethod, "");
assertPayloadEquals(httpMethod, null); assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); assertResponseParserClassEquals(method, httpMethod, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);