Repository: camel Updated Branches: refs/heads/camel-2.18.x 2e716342c -> 2dae076dd
CAMEL-10729: Camel-AWS: S3 autocloseBody option Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/3158579f Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/3158579f Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/3158579f Branch: refs/heads/camel-2.18.x Commit: 3158579fb2e94195e570460d81e3096510cf2a06 Parents: 2e71634 Author: Andrea Cosentino <anco...@gmail.com> Authored: Fri Jan 20 12:53:55 2017 +0100 Committer: Andrea Cosentino <anco...@gmail.com> Committed: Fri Jan 20 13:15:54 2017 +0100 ---------------------------------------------------------------------- .../camel/component/aws/s3/S3Configuration.java | 15 +++++++++++++++ .../apache/camel/component/aws/s3/S3Endpoint.java | 13 +++++++++++++ 2 files changed, 28 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/3158579f/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Configuration.java ---------------------------------------------------------------------- diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Configuration.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Configuration.java index d25d0da..aafec13 100644 --- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Configuration.java +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Configuration.java @@ -64,6 +64,8 @@ public class S3Configuration implements Cloneable { private boolean pathStyleAccess; @UriParam(label = "producer", enums = "copyObject,deleteBucket,listBuckets") private S3Operations operation; + @UriParam(label = "consumer", defaultValue = "true") + private boolean autocloseBody = true; public long getPartSize() { return partSize; @@ -294,7 +296,20 @@ public class S3Configuration implements Cloneable { this.operation = operation; } + public boolean isAutocloseBody() { + return autocloseBody; + } + + /** + * If this option is true and includeBody is true, then the S3Object.close() method will be called on exchange completion + */ + public void setAutocloseBody(boolean autocloseBody) { + this.autocloseBody = autocloseBody; + } + boolean hasProxyConfiguration() { return ObjectHelper.isNotEmpty(getProxyHost()) && ObjectHelper.isNotEmpty(getProxyPort()); } + + } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/3158579f/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Endpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Endpoint.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Endpoint.java index 038bc91..05a61f4 100644 --- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Endpoint.java +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Endpoint.java @@ -43,6 +43,7 @@ import org.apache.camel.spi.Metadata; import org.apache.camel.spi.UriEndpoint; import org.apache.camel.spi.UriParam; import org.apache.camel.spi.UriPath; +import org.apache.camel.support.SynchronizationAdapter; import org.apache.camel.util.ObjectHelper; import org.slf4j.Logger; @@ -191,6 +192,18 @@ public class S3Endpoint extends ScheduledPollEndpoint { s3Object.close(); } catch (IOException e) { } + } else { + if (configuration.isAutocloseBody()) { + exchange.addOnCompletion(new SynchronizationAdapter() { + @Override + public void onDone(Exchange exchange) { + try { + s3Object.close(); + } catch (IOException e) { + } + } + }); + } } return exchange;