camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r1407826 - in /camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3: S3Constants.java S3Producer.java
Date Sat, 10 Nov 2012 14:46:47 GMT
Author: ningjiang
Date: Sat Nov 10 14:46:47 2012
New Revision: 1407826

URL: http://svn.apache.org/viewvc?rev=1407826&view=rev
Log:
CAMEL-5781 Applied patch with thanks to Massyl

Modified:
    camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Constants.java
    camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Producer.java

Modified: camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Constants.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Constants.java?rev=1407826&r1=1407825&r2=1407826&view=diff
==============================================================================
--- camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Constants.java
(original)
+++ camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Constants.java
Sat Nov 10 14:46:47 2012
@@ -18,20 +18,22 @@ package org.apache.camel.component.aws.s
 
 /**
  * Constants used in Camel AWS S3 module
- *
+ * 
  */
 public interface S3Constants {
 
-    String BUCKET_NAME = "CamelAwsS3BucketName";
-    String CACHE_CONTROL = "CamelAwsS3ContentControl";
+    String BUCKET_NAME         = "CamelAwsS3BucketName";
+    String CACHE_CONTROL       = "CamelAwsS3ContentControl";
     String CONTENT_DISPOSITION = "CamelAwsS3ContentDisposition";
-    String CONTENT_ENCODING = "CamelAwsS3ContentEncoding";
-    String CONTENT_LENGTH = "CamelAwsS3ContentLength";
-    String CONTENT_MD5 = "CamelAwsS3ContentMD5";
-    String CONTENT_TYPE = "CamelAwsS3ContentType";
-    String E_TAG = "CamelAwsS3ETag";
-    String KEY = "CamelAwsS3Key";
-    String LAST_MODIFIED = "CamelAwsS3LastModified";
-    String STORAGE_CLASS = "CamelAwsS3StorageClass";
-    String VERSION_ID = "CamelAwsS3VersionId";
+    String CONTENT_ENCODING    = "CamelAwsS3ContentEncoding";
+    String CONTENT_LENGTH      = "CamelAwsS3ContentLength";
+    String CONTENT_MD5         = "CamelAwsS3ContentMD5";
+    String CONTENT_TYPE        = "CamelAwsS3ContentType";
+    String E_TAG               = "CamelAwsS3ETag";
+    String KEY                 = "CamelAwsS3Key";
+    String LAST_MODIFIED       = "CamelAwsS3LastModified";
+    String STORAGE_CLASS       = "CamelAwsS3StorageClass";
+    String VERSION_ID          = "CamelAwsS3VersionId";
+    String CANNED_ACL          = "CamelAwsS3CannedAcl";
+    String ACL                 = "CamelAwsS3Acl";
 }
\ No newline at end of file

Modified: camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Producer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Producer.java?rev=1407826&r1=1407825&r2=1407826&view=diff
==============================================================================
--- camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Producer.java
(original)
+++ camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Producer.java
Sat Nov 10 14:46:47 2012
@@ -19,6 +19,8 @@ package org.apache.camel.component.aws.s
 import java.io.InputStream;
 import java.util.Date;
 
+import com.amazonaws.services.s3.model.AccessControlList;
+import com.amazonaws.services.s3.model.CannedAccessControlList;
 import com.amazonaws.services.s3.model.ObjectMetadata;
 import com.amazonaws.services.s3.model.PutObjectRequest;
 import com.amazonaws.services.s3.model.PutObjectResult;
@@ -32,115 +34,125 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * A Producer which sends messages to the Amazon Web Service Simple Storage Service
- * <a href="http://aws.amazon.com/s3/">AWS S3</a>
+ * A Producer which sends messages to the Amazon Web Service Simple Storage Service <a
+ * href="http://aws.amazon.com/s3/">AWS S3</a>
  */
 public class S3Producer extends DefaultProducer {
 
     private static final Logger LOG = LoggerFactory.getLogger(S3Producer.class);
 
-    public S3Producer(Endpoint endpoint) {
+    public S3Producer(final Endpoint endpoint) {
         super(endpoint);
     }
 
-    public void process(Exchange exchange) throws Exception {
+    @Override
+    public void process(final Exchange exchange) throws Exception {
         ObjectMetadata objectMetadata = new ObjectMetadata();
-        
+
         Long contentLength = exchange.getIn().getHeader(S3Constants.CONTENT_LENGTH, Long.class);
         if (contentLength != null) {
             objectMetadata.setContentLength(contentLength);
         }
-        
+
         String contentType = exchange.getIn().getHeader(S3Constants.CONTENT_TYPE, String.class);
         if (contentType != null) {
             objectMetadata.setContentType(contentType);
         }
-        
+
         String cacheControl = exchange.getIn().getHeader(S3Constants.CACHE_CONTROL, String.class);
         if (cacheControl != null) {
             objectMetadata.setCacheControl(cacheControl);
         }
-        
+
         String contentDisposition = exchange.getIn().getHeader(S3Constants.CONTENT_DISPOSITION,
String.class);
         if (contentDisposition != null) {
             objectMetadata.setContentDisposition(contentDisposition);
         }
-        
+
         String contentEncoding = exchange.getIn().getHeader(S3Constants.CONTENT_ENCODING,
String.class);
         if (contentEncoding != null) {
             objectMetadata.setContentEncoding(contentEncoding);
         }
-        
+
         String contentMD5 = exchange.getIn().getHeader(S3Constants.CONTENT_MD5, String.class);
         if (contentMD5 != null) {
             objectMetadata.setContentMD5(contentMD5);
         }
-        
+
         Date lastModified = exchange.getIn().getHeader(S3Constants.LAST_MODIFIED, Date.class);
         if (lastModified != null) {
             objectMetadata.setLastModified(lastModified);
         }
-        
-        PutObjectRequest putObjectRequest = new PutObjectRequest(
-                getConfiguration().getBucketName(),
-                determineKey(exchange),
-                exchange.getIn().getMandatoryBody(InputStream.class),
-                objectMetadata);
+
+        PutObjectRequest putObjectRequest = new PutObjectRequest(getConfiguration().getBucketName(),
+                determineKey(exchange), exchange.getIn().getMandatoryBody(InputStream.class),
objectMetadata);
 
         String storageClass = determineStorageClass(exchange);
         if (storageClass != null) {
             putObjectRequest.setStorageClass(storageClass);
         }
 
+        String cannedAcl = exchange.getIn().getHeader(S3Constants.CANNED_ACL, String.class);
+        if (cannedAcl != null) {
+            CannedAccessControlList objectAcl = CannedAccessControlList.valueOf(cannedAcl);
+            putObjectRequest.setCannedAcl(objectAcl);
+        }
+
+        AccessControlList acl = exchange.getIn().getHeader(S3Constants.ACL, AccessControlList.class);
+        if (acl != null) {
+            // note: if cannedacl and acl are both specified the last one will be used. refer
to
+            // PutObjectRequest#setAccessControlList for more details
+            putObjectRequest.setAccessControlList(acl);
+        }
         LOG.trace("Put object [{}] from exchange [{}]...", putObjectRequest, exchange);
-        
+
         PutObjectResult putObjectResult = getEndpoint().getS3Client().putObject(putObjectRequest);
 
         LOG.trace("Received result [{}]", putObjectResult);
-        
+
         Message message = getMessageForResponse(exchange);
         message.setHeader(S3Constants.E_TAG, putObjectResult.getETag());
         if (putObjectResult.getVersionId() != null) {
-            message.setHeader(S3Constants.VERSION_ID, putObjectResult.getVersionId());  
         
+            message.setHeader(S3Constants.VERSION_ID, putObjectResult.getVersionId());
         }
     }
-    
-    private String determineKey(Exchange exchange) {
+
+    private String determineKey(final Exchange exchange) {
         String key = exchange.getIn().getHeader(S3Constants.KEY, String.class);
         if (key == null) {
             throw new IllegalArgumentException("AWS S3 Key header missing.");
         }
         return key;
     }
-    
-    private String determineStorageClass(Exchange exchange) {
+
+    private String determineStorageClass(final Exchange exchange) {
         String storageClass = exchange.getIn().getHeader(S3Constants.STORAGE_CLASS, String.class);
         if (storageClass == null) {
             storageClass = getConfiguration().getStorageClass();
         }
-        
+
         return storageClass;
     }
 
-    private Message getMessageForResponse(Exchange exchange) {
+    private Message getMessageForResponse(final Exchange exchange) {
         if (exchange.getPattern().isOutCapable()) {
             Message out = exchange.getOut();
             out.copyFrom(exchange.getIn());
             return out;
         }
-        
+
         return exchange.getIn();
     }
-    
+
     protected S3Configuration getConfiguration() {
         return getEndpoint().getConfiguration();
     }
-    
+
     @Override
     public String toString() {
         return "S3Producer[" + URISupport.sanitizeUri(getEndpoint().getEndpointUri()) + "]";
     }
-    
+
     @Override
     public S3Endpoint getEndpoint() {
         return (S3Endpoint) super.getEndpoint();



Mime
View raw message