camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject [1/2] camel git commit: Added option for path-style access to S3; useful when testing or for other S3 REST API providers (such as OpenStack Swift)
Date Tue, 14 Jun 2016 12:24:51 GMT
Repository: camel
Updated Branches:
  refs/heads/master 65b7a5ce2 -> 150240d9d


Added option for path-style access to S3; useful when testing or for other S3 REST API providers
(such as OpenStack Swift)


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/6977bf61
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/6977bf61
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/6977bf61

Branch: refs/heads/master
Commit: 6977bf612c0019996f574e15bc189789e5eb66a0
Parents: 65b7a5c
Author: Miloš Milivojević <fingolfintek@gmail.com>
Authored: Tue Jun 14 14:12:50 2016 +0200
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Tue Jun 14 14:19:09 2016 +0200

----------------------------------------------------------------------
 .../camel/component/aws/s3/S3Configuration.java | 19 ++++++++++++++
 .../camel/component/aws/s3/S3Endpoint.java      | 26 ++++++++++++--------
 2 files changed, 35 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/6977bf61/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 83c33d2..abaad4d 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
@@ -19,6 +19,7 @@ package org.apache.camel.component.aws.s3;
 import com.amazonaws.services.s3.AmazonS3;
 import org.apache.camel.spi.UriParam;
 import org.apache.camel.spi.UriParams;
+import org.apache.camel.util.ObjectHelper;
 
 @UriParams
 public class S3Configuration implements Cloneable {
@@ -58,6 +59,8 @@ public class S3Configuration implements Cloneable {
     private Integer proxyPort;
     @UriParam(label = "consumer", defaultValue = "true")
     private boolean includeBody = true;
+    @UriParam
+    private boolean pathStyleAccess;
 
     public long getPartSize() {
         return partSize;
@@ -265,4 +268,20 @@ public class S3Configuration implements Cloneable {
     public void setProxyPort(Integer proxyPort) {
         this.proxyPort = proxyPort;
     }
+
+    /**
+     * Whether or not the S3 client should use path style access
+     */
+    public void setPathStyleAccess(final boolean pathStyleAccess) {
+        this.pathStyleAccess = pathStyleAccess;
+    }
+
+    public boolean isPathStyleAccess() {
+        return pathStyleAccess;
+    }
+
+    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/6977bf61/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 9e5b2ad..038bc91 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
@@ -24,6 +24,7 @@ import com.amazonaws.auth.AWSCredentials;
 import com.amazonaws.auth.BasicAWSCredentials;
 import com.amazonaws.services.s3.AmazonS3;
 import com.amazonaws.services.s3.AmazonS3Client;
+import com.amazonaws.services.s3.S3ClientOptions;
 import com.amazonaws.services.s3.model.CreateBucketRequest;
 import com.amazonaws.services.s3.model.ListObjectsRequest;
 import com.amazonaws.services.s3.model.ObjectMetadata;
@@ -43,6 +44,7 @@ import org.apache.camel.spi.UriEndpoint;
 import org.apache.camel.spi.UriParam;
 import org.apache.camel.spi.UriPath;
 import org.apache.camel.util.ObjectHelper;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -130,7 +132,7 @@ public class S3Endpoint extends ScheduledPollEndpoint {
             createBucketRequest.setRegion(getConfiguration().getRegion());
         }
 
-        LOG.trace("Creating bucket [{}] in region [{}] with request [{}]...", new Object[]{configuration.getBucketName(),
configuration.getRegion(), createBucketRequest});
+        LOG.trace("Creating bucket [{}] in region [{}] with request [{}]...", configuration.getBucketName(),
configuration.getRegion(), createBucketRequest);
 
         s3Client.createBucket(createBucketRequest);
 
@@ -214,19 +216,23 @@ public class S3Endpoint extends ScheduledPollEndpoint {
      * Provide the possibility to override this method for an mock implementation
      */
     AmazonS3 createS3Client() {
-        AmazonS3 client = null;
         AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(),
configuration.getSecretKey());
-        if (ObjectHelper.isNotEmpty(configuration.getProxyHost()) && ObjectHelper.isNotEmpty(configuration.getProxyPort()))
{
-            ClientConfiguration clientConfiguration = new ClientConfiguration();
-            clientConfiguration.setProxyHost(configuration.getProxyHost());
-            clientConfiguration.setProxyPort(configuration.getProxyPort());
-            client = new AmazonS3Client(credentials, clientConfiguration);
-        } else {
-            client = new AmazonS3Client(credentials);
-        }
+        AmazonS3Client client = configuration.hasProxyConfiguration() ? createClientWithProxy(credentials)
: new AmazonS3Client(credentials);
+
+        S3ClientOptions clientOptions = S3ClientOptions.builder()
+            .setPathStyleAccess(configuration.isPathStyleAccess())
+            .build();
+        client.setS3ClientOptions(clientOptions);
         return client;
     }
 
+    private AmazonS3Client createClientWithProxy(final AWSCredentials credentials) {
+        ClientConfiguration clientConfiguration = new ClientConfiguration();
+        clientConfiguration.setProxyHost(configuration.getProxyHost());
+        clientConfiguration.setProxyPort(configuration.getProxyPort());
+        return new AmazonS3Client(credentials, clientConfiguration);
+    }
+
     public int getMaxMessagesPerPoll() {
         return maxMessagesPerPoll;
     }


Mime
View raw message