[
https://issues.apache.org/jira/browse/CAMEL-12122?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16311063#comment-16311063
]
ASF GitHub Bot commented on CAMEL-12122:
----------------------------------------
oscerd closed pull request #2163: CAMEL-12122: S3: Add createDownloadLink
functionality
URL: https://github.com/apache/camel/pull/2163
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/components/camel-aws/src/main/docs/aws-s3-component.adoc
b/components/camel-aws/src/main/docs/aws-s3-component.adoc
index 95365821ea3..8d3b0275e28 100644
--- a/components/camel-aws/src/main/docs/aws-s3-component.adoc
+++ b/components/camel-aws/src/main/docs/aws-s3-component.adoc
@@ -168,7 +168,7 @@ aggregate this number of messages.
|`CamelAwsS3LastModified` |`java.util.Date` |*Camel 2.8.2:* The last modified
timestamp of this object.
-|`CamelAwsS3Operation` |`String` |*Camel 2.18*: The operation to perform
+|`CamelAwsS3Operation` |`String` |*Camel 2.18*: The operation to perform.
Permitted values are copyObject, listBuckets, deleteBucket, downloadLink
|`CamelAwsS3StorageClass` |`String` |*Camel 2.8.4:* The storage class of this
object.
@@ -196,6 +196,8 @@ the object using AWS-managed keys. For example use AES256.
|`CamelAwsS3VersionId` |`String` |The *optional* version ID of the newly
uploaded object.
+|`CamelAwsS3DownloadLinkExpiration` | `String` | The expiration (millis) of
URL download link. The link will be stored into *CamelAwsS3DownloadLink*
response header.
+
|=======================================================================
#### Message headers set by the S3 consumer
diff --git
a/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Constants.java
b/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Constants.java
index c337f19a45e..ce44574f7c8 100644
---
a/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Constants.java
+++
b/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Constants.java
@@ -30,6 +30,8 @@
String CONTENT_LENGTH = "CamelAwsS3ContentLength";
String CONTENT_MD5 = "CamelAwsS3ContentMD5";
String CONTENT_TYPE = "CamelAwsS3ContentType";
+ String DOWNLOAD_LINK_EXPIRATION =
"CamelAwsS3DownloadLinkExpiration";
+ String DOWNLOAD_LINK = "CamelAwsS3DownloadLink";
String E_TAG = "CamelAwsS3ETag";
String KEY = "CamelAwsS3Key";
String DESTINATION_KEY = "CamelAwsS3DestinationKey";
diff --git
a/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Operations.java
b/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Operations.java
index ab1b7a01ec5..297095fd962 100644
---
a/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Operations.java
+++
b/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Operations.java
@@ -21,5 +21,6 @@
copyObject,
deleteObject,
deleteBucket,
- listBuckets
+ listBuckets,
+ downloadLink
}
diff --git
a/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Producer.java
b/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Producer.java
index 317073cbdf3..4467bc236c1 100644
---
a/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Producer.java
+++
b/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Producer.java
@@ -16,17 +16,34 @@
*/
package org.apache.camel.component.aws.s3;
+import static
org.apache.camel.component.aws.common.AwsExchangeUtil.getMessageForResponse;
+
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.WrappedFile;
+import org.apache.camel.impl.DefaultProducer;
+import org.apache.camel.util.CastUtils;
+import org.apache.camel.util.FileUtil;
+import org.apache.camel.util.IOHelper;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.URISupport;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.amazonaws.HttpMethod;
import com.amazonaws.services.cloudfront.model.InvalidArgumentException;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.model.AbortMultipartUploadRequest;
@@ -39,6 +56,7 @@
import com.amazonaws.services.s3.model.CopyObjectResult;
import com.amazonaws.services.s3.model.DeleteBucketRequest;
import com.amazonaws.services.s3.model.DeleteObjectRequest;
+import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest;
import com.amazonaws.services.s3.model.InitiateMultipartUploadRequest;
import com.amazonaws.services.s3.model.InitiateMultipartUploadResult;
import com.amazonaws.services.s3.model.ObjectMetadata;
@@ -47,20 +65,6 @@
import com.amazonaws.services.s3.model.PutObjectResult;
import com.amazonaws.services.s3.model.StorageClass;
import com.amazonaws.services.s3.model.UploadPartRequest;
-import org.apache.camel.Endpoint;
-import org.apache.camel.Exchange;
-import org.apache.camel.Message;
-import org.apache.camel.WrappedFile;
-import org.apache.camel.impl.DefaultProducer;
-import org.apache.camel.util.CastUtils;
-import org.apache.camel.util.FileUtil;
-import org.apache.camel.util.IOHelper;
-import org.apache.camel.util.ObjectHelper;
-import org.apache.camel.util.URISupport;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import static
org.apache.camel.component.aws.common.AwsExchangeUtil.getMessageForResponse;
/**
* A Producer which sends messages to the Amazon Web Service Simple Storage
@@ -99,6 +103,9 @@ public void process(final Exchange exchange) throws
Exception {
case deleteBucket:
deleteBucket(getEndpoint().getS3Client(), exchange);
break;
+ case downloadLink:
+ createDownloadLink(getEndpoint().getS3Client(), exchange);
+ break;
default:
throw new IllegalArgumentException("Unsupported operation");
}
@@ -429,6 +436,43 @@ private ByteArrayOutputStream
determineLengthInputStream(InputStream is) throws
return out;
}
+ private void createDownloadLink(AmazonS3 s3Client, Exchange exchange) {
+ String bucketName =
exchange.getIn().getHeader(S3Constants.BUCKET_NAME, String.class);
+ if (ObjectHelper.isEmpty(bucketName)) {
+ bucketName = getConfiguration().getBucketName();
+ }
+
+ if (bucketName == null) {
+ throw new IllegalArgumentException("AWS S3 Bucket name header is
missing.");
+ }
+
+ String key = exchange.getIn().getHeader(S3Constants.KEY, String.class);
+ if (key == null) {
+ throw new IllegalArgumentException("AWS S3 Key header is
missing.");
+ }
+
+ Date expiration = new Date();
+ long milliSeconds = expiration.getTime();
+
+ Long expirationMillis =
exchange.getIn().getHeader(S3Constants.DOWNLOAD_LINK_EXPIRATION, Long.class);
+ if(expirationMillis != null) {
+ milliSeconds += expirationMillis;
+ } else {
+ milliSeconds += 1000 * 60 * 60; // Default: Add 1 hour.
+ }
+
+ expiration.setTime(milliSeconds);
+
+ GeneratePresignedUrlRequest generatePresignedUrlRequest = new
GeneratePresignedUrlRequest(bucketName, key);
+ generatePresignedUrlRequest.setMethod(HttpMethod.GET);
+ generatePresignedUrlRequest.setExpiration(expiration);
+
+ URL url = s3Client.generatePresignedUrl(generatePresignedUrlRequest);
+
+ Message message = getMessageForResponse(exchange);
+ message.setHeader(S3Constants.DOWNLOAD_LINK, url.toString());
+ }
+
protected S3Configuration getConfiguration() {
return getEndpoint().getConfiguration();
}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> S3: Add createDownloadLink functionality
> ----------------------------------------
>
> Key: CAMEL-12122
> URL: https://issues.apache.org/jira/browse/CAMEL-12122
> Project: Camel
> Issue Type: New Feature
> Components: camel-aws
> Reporter: Fabrizio Spataro
> Assignee: Fabrizio Spataro
> Fix For: 2.21.0
>
>
> Hello!
> I write code to add a new operation into producer to create a download s3 link
> The functionality, according with *CamelAwsS3DownloadLinkExpiration* header,
> must return an header *CamelAwsS3DownloadLink*
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)