This is an automated email from the ASF dual-hosted git repository. btellier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 95456efc99f2b4e3ac737ed71aa698dbd8a6b8bb Author: Tran Tien Duc <dt...@linagora.com> AuthorDate: Fri Jul 5 17:16:57 2019 +0700 JAMES-2806 ObjectStorage Swift should retry when saving empty blob The KeyNotFound exception thrown when saving empty blob in non existing bucket, we need to catch it also with the HttpResponseException --- .../objectstorage/StreamCompatibleBlobPutter.java | 33 +++++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/StreamCompatibleBlobPutter.java b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/StreamCompatibleBlobPutter.java index 1bac8e2..9a3a21f 100644 --- a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/StreamCompatibleBlobPutter.java +++ b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/StreamCompatibleBlobPutter.java @@ -20,11 +20,13 @@ package org.apache.james.blob.objectstorage; import java.time.Duration; +import java.util.Optional; import java.util.function.Supplier; import org.apache.james.blob.api.BlobId; import org.apache.james.blob.api.BucketName; import org.jclouds.blobstore.BlobStore; +import org.jclouds.blobstore.KeyNotFoundException; import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.options.CopyOptions; import org.jclouds.domain.Location; @@ -74,12 +76,35 @@ public class StreamCompatibleBlobPutter implements BlobPutter { } private boolean needToCreateBucket(Throwable throwable, BucketName bucketName) { - if (throwable instanceof HttpResponseException) { - HttpResponseException ex = (HttpResponseException) throwable; - return ex.getCommand().getCurrentRequest().getMethod().equals("PUT") - && !blobStore.containerExists(bucketName.asString()); + if (throwable instanceof HttpResponseException + || throwable instanceof KeyNotFoundException) { + + return extractHttpException(throwable) + .map(ex -> isPutMethod(ex) && !bucketExisted(bucketName)) + .orElse(false); } return false; } + + private boolean isPutMethod(HttpResponseException ex) { + return ex.getCommand() + .getCurrentRequest() + .getMethod() + .equals("PUT"); + } + + private boolean bucketExisted(BucketName bucketName) { + return blobStore.containerExists(bucketName.asString()); + } + + private Optional<HttpResponseException> extractHttpException(Throwable throwable) { + if (throwable instanceof HttpResponseException) { + return Optional.of((HttpResponseException) throwable); + } else if (throwable.getCause() instanceof HttpResponseException) { + return Optional.of((HttpResponseException) throwable.getCause()); + } + + return Optional.empty(); + } } \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org