This is an automated email from the ASF dual-hosted git repository.

zhfeng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 50445c35ad0 CAMEL-18167: camel-aws2-s3 - Show a message when download 
link url is… (#7727)
50445c35ad0 is described below

commit 50445c35ad03da37b6f30a7e4c6f3d29ba772d6d
Author: Amos Feng <zh.f...@gmail.com>
AuthorDate: Wed Jun 8 21:34:58 2022 +0800

    CAMEL-18167: camel-aws2-s3 - Show a message when download link url is… 
(#7727)
    
    * CAMEL-18167: camel-aws2-s3 - Show a message when download link url is not 
browser compatible
    
    * Fix CS
    
    * reduce the logging level to DEBUG and add a header 
DOWNLOAD_LINK_BROWSER_COMPATIBLE
    
    * Regen
    
    * add DOWNLOAD_LINK_HTTP_REQUEST_HEADERS and DOWNLOAD_LINK_SIGNED_PAYLOAD
---
 .../resources/org/apache/camel/component/aws2/s3/aws2-s3.json |  3 +++
 .../camel-aws2-s3/src/main/docs/aws2-s3-component.adoc        |  2 ++
 .../org/apache/camel/component/aws2/s3/AWS2S3Constants.java   | 10 ++++++++++
 .../org/apache/camel/component/aws2/s3/AWS2S3Producer.java    | 11 +++++++++++
 4 files changed, 26 insertions(+)

diff --git 
a/components/camel-aws/camel-aws2-s3/src/generated/resources/org/apache/camel/component/aws2/s3/aws2-s3.json
 
b/components/camel-aws/camel-aws2-s3/src/generated/resources/org/apache/camel/component/aws2/s3/aws2-s3.json
index 979e7527ea1..0b7df983a34 100644
--- 
a/components/camel-aws/camel-aws2-s3/src/generated/resources/org/apache/camel/component/aws2/s3/aws2-s3.json
+++ 
b/components/camel-aws/camel-aws2-s3/src/generated/resources/org/apache/camel/component/aws2/s3/aws2-s3.json
@@ -98,6 +98,9 @@
     "CamelAwsS3RangeStart": { "kind": "header", "displayName": "", "group": 
"producer", "label": "producer", "required": false, "javaType": "String", 
"deprecated": false, "deprecationNote": "", "autowired": false, "secret": 
false, "description": "The position of the first byte to get", "constantName": 
"org.apache.camel.component.aws2.s3.AWS2S3Constants#RANGE_START" },
     "CamelAwsS3RangeEnd": { "kind": "header", "displayName": "", "group": 
"producer", "label": "producer", "required": false, "javaType": "String", 
"deprecated": false, "deprecationNote": "", "autowired": false, "secret": 
false, "description": "The position of the last byte to get", "constantName": 
"org.apache.camel.component.aws2.s3.AWS2S3Constants#RANGE_END" },
     "CamelAwsS3DowloadLinkExpirationTime": { "kind": "header", "displayName": 
"", "group": "producer", "label": "producer", "required": false, "javaType": 
"Long", "deprecated": false, "deprecationNote": "", "autowired": false, 
"secret": false, "description": "The expiration time of the download link in 
milliseconds", "constantName": 
"org.apache.camel.component.aws2.s3.AWS2S3Constants#DOWNLOAD_LINK_EXPIRATION_TIME"
 },
+    "CamelAwsS3DownloadLinkBrowserCompatible": { "kind": "header", 
"displayName": "", "group": "producer", "label": "producer", "required": false, 
"javaType": "boolean", "deprecated": false, "deprecationNote": "", "autowired": 
false, "secret": false, "description": "Whether the download link is browser 
compatible", "constantName": 
"org.apache.camel.component.aws2.s3.AWS2S3Constants#DOWNLOAD_LINK_BROWSER_COMPATIBLE"
 },
+    "CamelAwsS3DownloadLinkHttpRequestHeaders": { "kind": "header", 
"displayName": "", "group": "producer", "label": "producer", "required": false, 
"javaType": "Map<String, List<String>>", "deprecated": false, 
"deprecationNote": "", "autowired": false, "secret": false, "description": "The 
headers that are needed by the service (not needed when BrowserCompatible is 
true)", "constantName": 
"org.apache.camel.component.aws2.s3.AWS2S3Constants#DOWNLOAD_LINK_HTTP_REQUEST_HEADERS"
 },
+    "CamelAwsS3DownloadLinkSignedPayload": { "kind": "header", "displayName": 
"", "group": "producer", "label": "producer", "required": false, "javaType": 
"String", "deprecated": false, "deprecationNote": "", "autowired": false, 
"secret": false, "description": "The request payload that is needed by the 
service (not needed when BrowserCompatible is true)", "constantName": 
"org.apache.camel.component.aws2.s3.AWS2S3Constants#DOWNLOAD_LINK_SIGNED_PAYLOAD"
 },
     "CamelAwsS3Metadata": { "kind": "header", "displayName": "", "group": 
"common", "label": "", "required": false, "javaType": "Map<String, String>", 
"deprecated": false, "deprecationNote": "", "autowired": false, "secret": 
false, "description": "A map of metadata to be stored or stored with the object 
in S3. More details about metadata 
https:\/\/docs.aws.amazon.com\/AmazonS3\/latest\/userguide\/UsingMetadata.htmlhere.",
 "constantName": "org.apache.camel.component.aws2.s3.AWS2S3Constant [...]
     "CamelMessageTimestamp": { "kind": "header", "displayName": "", "group": 
"consumer", "label": "consumer", "required": false, "javaType": "long", 
"deprecated": false, "deprecationNote": "", "autowired": false, "secret": 
false, "description": "The timestamp of the message", "constantName": 
"org.apache.camel.component.aws2.s3.AWS2S3Constants#MESSAGE_TIMESTAMP" }
   },
diff --git 
a/components/camel-aws/camel-aws2-s3/src/main/docs/aws2-s3-component.adoc 
b/components/camel-aws/camel-aws2-s3/src/main/docs/aws2-s3-component.adoc
index 217c7bc8136..7f287efb1fb 100644
--- a/components/camel-aws/camel-aws2-s3/src/main/docs/aws2-s3-component.adoc
+++ b/components/camel-aws/camel-aws2-s3/src/main/docs/aws2-s3-component.adoc
@@ -292,6 +292,8 @@ This operation will return an S3Object instance related to 
the camelKey object i
 This operation will return a download link url for the file camel-key in the 
bucket mycamelbucket and region region.
 Parameters (`accessKey`, `secretKey` and `region`) are mandatory for this 
operation, if S3 client is autowired from the registry.
 
+NOTE: If checksum validations are enabled, the url will no longer be browser 
compatible because it adds a signed header that must be included in the HTTP 
request.
+
 == Streaming Upload mode
 
 With the stream mode enabled users will be able to upload data to S3 without 
knowing ahead of time the dimension of the data, by leveraging multipart upload.
diff --git 
a/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Constants.java
 
b/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Constants.java
index b8a914ce313..112184f7d5e 100644
--- 
a/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Constants.java
+++ 
b/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Constants.java
@@ -113,6 +113,16 @@ public interface AWS2S3Constants {
     String RANGE_END = "CamelAwsS3RangeEnd";
     @Metadata(label = "producer", description = "The expiration time of the 
download link in milliseconds", javaType = "Long")
     String DOWNLOAD_LINK_EXPIRATION_TIME = 
"CamelAwsS3DowloadLinkExpirationTime";
+    @Metadata(label = "producer", description = "Whether the download link is 
browser compatible", javaType = "boolean")
+    String DOWNLOAD_LINK_BROWSER_COMPATIBLE = 
"CamelAwsS3DownloadLinkBrowserCompatible";
+    @Metadata(label = "producer",
+              description = "The headers that are needed by the service (not 
needed when BrowserCompatible is true)",
+              javaType = "Map<String, List<String>>")
+    String DOWNLOAD_LINK_HTTP_REQUEST_HEADERS = 
"CamelAwsS3DownloadLinkHttpRequestHeaders";
+    @Metadata(label = "producer",
+              description = "The request payload that is needed by the service 
(not needed when BrowserCompatible is true)",
+              javaType = "String")
+    String DOWNLOAD_LINK_SIGNED_PAYLOAD = 
"CamelAwsS3DownloadLinkSignedPayload";
     @Metadata(description = "A map of metadata to be stored or stored with the 
object in S3. More details about\n" +
                             "metadata 
https://docs.aws.amazon.com/AmazonS3/latest/userguide/UsingMetadata.html[here].";,
               javaType = "Map<String, String>")
diff --git 
a/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Producer.java
 
b/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Producer.java
index c039132edb7..dcc59ee63dc 100644
--- 
a/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Producer.java
+++ 
b/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Producer.java
@@ -582,6 +582,17 @@ public class AWS2S3Producer extends DefaultProducer {
 
         Message message = getMessageForResponse(exchange);
         message.setBody(presignedGetObjectRequest.url().toString());
+        message.setHeader(AWS2S3Constants.DOWNLOAD_LINK_BROWSER_COMPATIBLE, 
presignedGetObjectRequest.isBrowserExecutable());
+
+        if (!presignedGetObjectRequest.isBrowserExecutable()) {
+            LOG.debug(
+                    "The download link url is not browser compatible and 
please check the option of checksum validations in Amazon S3 client");
+            
message.setHeader(AWS2S3Constants.DOWNLOAD_LINK_HTTP_REQUEST_HEADERS,
+                    presignedGetObjectRequest.httpRequest().headers());
+            presignedGetObjectRequest.signedPayload().ifPresent(payload -> {
+                
message.setHeader(AWS2S3Constants.DOWNLOAD_LINK_SIGNED_PAYLOAD, 
payload.asUtf8String());
+            });
+        }
 
         if (ObjectHelper.isEmpty(getConfiguration().getAmazonS3Presigner())) {
             presigner.close();

Reply via email to