camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject [3/3] camel git commit: CAMEL-10729: Camel-AWS: S3 autocloseBody option
Date Fri, 20 Jan 2017 12:19:51 GMT
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/0af37d91
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0af37d91
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0af37d91

Branch: refs/heads/master
Commit: 0af37d91f2394d578f200041f265a5ced095fbf7
Parents: 6e95af2
Author: Andrea Cosentino <ancosen@gmail.com>
Authored: Fri Jan 20 12:53:55 2017 +0100
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Fri Jan 20 13:19:32 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/0af37d91/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/0af37d91/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 0c8bbcd..f39463d 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;
@@ -193,6 +194,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;


Mime
View raw message