You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2025/01/29 14:49:17 UTC

(camel) branch main updated: CAMEL-21680 - Camel-AWS2-S3: Introducing Override Bucket Header in Producer operations (#16970)

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

acosentino 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 508f8a75604 CAMEL-21680 - Camel-AWS2-S3: Introducing Override Bucket Header in Producer operations (#16970)
508f8a75604 is described below

commit 508f8a756042550dbadd9a9b929e4d7596cdd56d
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Wed Jan 29 15:49:10 2025 +0100

    CAMEL-21680 - Camel-AWS2-S3: Introducing Override Bucket Header in Producer operations (#16970)
    
    Signed-off-by: Andrea Cosentino <an...@gmail.com>
---
 .../org/apache/camel/catalog/components/aws2-s3.json       |  3 ++-
 .../org/apache/camel/component/aws2/s3/aws2-s3.json        |  3 ++-
 .../apache/camel/component/aws2/s3/AWS2S3Constants.java    |  4 ++++
 .../org/apache/camel/component/aws2/s3/AWS2S3Producer.java |  2 +-
 .../apache/camel/component/aws2/s3/utils/AWS2S3Utils.java  |  2 +-
 .../component/aws2/s3/integration/S3HeadBucketIT.java      |  2 +-
 .../modules/ROOT/pages/camel-4x-upgrade-guide-4_10.adoc    |  6 ++++++
 .../builder/endpoint/dsl/AWS2S3EndpointBuilderFactory.java | 14 ++++++++++++++
 8 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/aws2-s3.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/aws2-s3.json
index f9e26d97c6f..3c6379baff2 100644
--- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/aws2-s3.json
+++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/aws2-s3.json
@@ -122,7 +122,8 @@
     "CamelAwsS3IfMatchCondition": { "index": 33, "kind": "header", "displayName": "", "group": "common", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Return\/copy the object only if its entity tag (ETag) is the same as the one specified in this header.", "constantName": "org.apache.camel.component.aws2.s3.AWS2S3Constants#IF_MATCH_CONDITION" },
     "CamelAwsS3IfModifiedSinceCondition": { "index": 34, "kind": "header", "displayName": "", "group": "common", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Return\/copy the object only if it has been modified since the specified time; otherwise, return a 304 Not Modified error.", "constantName": "org.apache.camel.component.aws2.s3.AWS2S3Constants#IF_MODIFIED_SINCE_CONDITION" },
     "CamelAwsS3IfNoneMatchCondition": { "index": 35, "kind": "header", "displayName": "", "group": "common", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Return\/copy the object only if its entity tag (ETag) is different from the one specified in this header.", "constantName": "org.apache.camel.component.aws2.s3.AWS2S3Constants#IF_NONE_MATCH_CONDITION" },
-    "CamelAwsS3IfUnmodifiedSinceCondition": { "index": 36, "kind": "header", "displayName": "", "group": "common", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Return\/copy the object only if it has not been modified since the specified time.", "constantName": "org.apache.camel.component.aws2.s3.AWS2S3Constants#IF_UNMODIFIED_SINCE_CONDITION" }
+    "CamelAwsS3IfUnmodifiedSinceCondition": { "index": 36, "kind": "header", "displayName": "", "group": "common", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Return\/copy the object only if it has not been modified since the specified time.", "constantName": "org.apache.camel.component.aws2.s3.AWS2S3Constants#IF_UNMODIFIED_SINCE_CONDITION" },
+    "CamelAwsS3OverrideBucketName": { "index": 37, "kind": "header", "displayName": "", "group": "common", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The bucket Name to override (can be dynamic using the simple language in the producer) which this object will be stored or which will be used for the current operation or in which this object is contained.", "constantName": "org.apach [...]
   },
   "properties": {
     "bucketNameOrArn": { "index": 0, "kind": "path", "displayName": "Bucket Name Or Arn", "group": "common", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Bucket name or ARN" },
diff --git a/components/camel-aws/camel-aws2-s3/src/generated/resources/META-INF/org/apache/camel/component/aws2/s3/aws2-s3.json b/components/camel-aws/camel-aws2-s3/src/generated/resources/META-INF/org/apache/camel/component/aws2/s3/aws2-s3.json
index f9e26d97c6f..3c6379baff2 100644
--- a/components/camel-aws/camel-aws2-s3/src/generated/resources/META-INF/org/apache/camel/component/aws2/s3/aws2-s3.json
+++ b/components/camel-aws/camel-aws2-s3/src/generated/resources/META-INF/org/apache/camel/component/aws2/s3/aws2-s3.json
@@ -122,7 +122,8 @@
     "CamelAwsS3IfMatchCondition": { "index": 33, "kind": "header", "displayName": "", "group": "common", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Return\/copy the object only if its entity tag (ETag) is the same as the one specified in this header.", "constantName": "org.apache.camel.component.aws2.s3.AWS2S3Constants#IF_MATCH_CONDITION" },
     "CamelAwsS3IfModifiedSinceCondition": { "index": 34, "kind": "header", "displayName": "", "group": "common", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Return\/copy the object only if it has been modified since the specified time; otherwise, return a 304 Not Modified error.", "constantName": "org.apache.camel.component.aws2.s3.AWS2S3Constants#IF_MODIFIED_SINCE_CONDITION" },
     "CamelAwsS3IfNoneMatchCondition": { "index": 35, "kind": "header", "displayName": "", "group": "common", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Return\/copy the object only if its entity tag (ETag) is different from the one specified in this header.", "constantName": "org.apache.camel.component.aws2.s3.AWS2S3Constants#IF_NONE_MATCH_CONDITION" },
-    "CamelAwsS3IfUnmodifiedSinceCondition": { "index": 36, "kind": "header", "displayName": "", "group": "common", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Return\/copy the object only if it has not been modified since the specified time.", "constantName": "org.apache.camel.component.aws2.s3.AWS2S3Constants#IF_UNMODIFIED_SINCE_CONDITION" }
+    "CamelAwsS3IfUnmodifiedSinceCondition": { "index": 36, "kind": "header", "displayName": "", "group": "common", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Return\/copy the object only if it has not been modified since the specified time.", "constantName": "org.apache.camel.component.aws2.s3.AWS2S3Constants#IF_UNMODIFIED_SINCE_CONDITION" },
+    "CamelAwsS3OverrideBucketName": { "index": 37, "kind": "header", "displayName": "", "group": "common", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The bucket Name to override (can be dynamic using the simple language in the producer) which this object will be stored or which will be used for the current operation or in which this object is contained.", "constantName": "org.apach [...]
   },
   "properties": {
     "bucketNameOrArn": { "index": 0, "kind": "path", "displayName": "Bucket Name Or Arn", "group": "common", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Bucket name or ARN" },
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 43409579bd5..31e0168634a 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
@@ -157,4 +157,8 @@ public interface AWS2S3Constants {
     @Metadata(description = "Return/copy the object only if it has not been modified since the specified time.",
               javaType = "String")
     String IF_UNMODIFIED_SINCE_CONDITION = "CamelAwsS3IfUnmodifiedSinceCondition";
+    @Metadata(description = "The bucket Name to override (can be dynamic using the simple language in the producer) which this object will be stored or which will be used for the current operation or in which this object is contained.",
+              javaType = "String")
+    String OVERRIDE_BUCKET_NAME = "CamelAwsS3OverrideBucketName";
+
 }
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 b46a68ac5e8..68b7f85fc26 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
@@ -704,7 +704,7 @@ public class AWS2S3Producer extends DefaultProducer {
     }
 
     private void headBucket(S3Client s3Client, Exchange exchange) {
-        String bucketName = exchange.getIn().getHeader(AWS2S3Constants.BUCKET_NAME, String.class);
+        String bucketName = exchange.getIn().getHeader(AWS2S3Constants.OVERRIDE_BUCKET_NAME, String.class);
         if (ObjectHelper.isEmpty(bucketName)) {
             throw new IllegalArgumentException(
                     "Head Bucket operation requires to specify a bucket name via Header");
diff --git a/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/utils/AWS2S3Utils.java b/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/utils/AWS2S3Utils.java
index aa17ce2a061..3ff68d36065 100644
--- a/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/utils/AWS2S3Utils.java
+++ b/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/utils/AWS2S3Utils.java
@@ -47,7 +47,7 @@ public final class AWS2S3Utils {
      * @throws IllegalArgumentException if the header could not be determined.
      */
     public static String determineBucketName(final Exchange exchange, AWS2S3Configuration configuration) {
-        String bucketName = exchange.getIn().getHeader(AWS2S3Constants.BUCKET_NAME, String.class);
+        String bucketName = exchange.getIn().getHeader(AWS2S3Constants.OVERRIDE_BUCKET_NAME, String.class);
         if (ObjectHelper.isEmpty(bucketName)) {
             bucketName = configuration.getBucketName();
         }
diff --git a/components/camel-aws/camel-aws2-s3/src/test/java/org/apache/camel/component/aws2/s3/integration/S3HeadBucketIT.java b/components/camel-aws/camel-aws2-s3/src/test/java/org/apache/camel/component/aws2/s3/integration/S3HeadBucketIT.java
index 58a15b2dafc..11e26cb2fde 100644
--- a/components/camel-aws/camel-aws2-s3/src/test/java/org/apache/camel/component/aws2/s3/integration/S3HeadBucketIT.java
+++ b/components/camel-aws/camel-aws2-s3/src/test/java/org/apache/camel/component/aws2/s3/integration/S3HeadBucketIT.java
@@ -47,7 +47,7 @@ public class S3HeadBucketIT extends Aws2S3Base {
         Exchange res = template.send("direct:headBucket", exchange -> {
             exchange.getIn().setBody("Hello World");
             exchange.getIn().setHeader(AWS2S3Constants.S3_OPERATION, AWS2S3Operations.headBucket);
-            exchange.getIn().setHeader(AWS2S3Constants.BUCKET_NAME, "doesnotexist" + UUID.randomUUID().toString());
+            exchange.getIn().setHeader(AWS2S3Constants.OVERRIDE_BUCKET_NAME, "doesnotexist" + UUID.randomUUID().toString());
         });
         if (res.getException() != null) {
             throw res.getException();
diff --git a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_10.adoc b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_10.adoc
index 66c5747156b..d763ede760c 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_10.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_10.adoc
@@ -158,6 +158,12 @@ this should only be used in advanced/rare use-cases. This option may in the futu
 
 The class `org.apache.camel.component.file.azure.FilesHeaders` has been renamed to `org.apache.camel.component.file.azure.FilesConstants`.
 
+=== camel-aws2-s3
+
+The header `CamelAwsS3BucketName` for setting a bucket to write to, on the producer side, cannot be used anymore: the header `CamelAwsS3OverrideBucketName` must be used 
+instead. This was done to avoid situation in which you're moving a file from a bucket to a different one, and the header coming from the S3 consumer is used as bucket name for S3 Producer.
+You can find more information on CAMEL-21680. 
+
 === camel-file
 
 The `camel-file` consumer has been optimized when filtering file names using name matching only,
diff --git a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/AWS2S3EndpointBuilderFactory.java b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/AWS2S3EndpointBuilderFactory.java
index f3bc2695a1f..fcef0911e93 100644
--- a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/AWS2S3EndpointBuilderFactory.java
+++ b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/AWS2S3EndpointBuilderFactory.java
@@ -4082,6 +4082,20 @@ public interface AWS2S3EndpointBuilderFactory {
         public String awsS3IfUnmodifiedSinceCondition() {
             return "CamelAwsS3IfUnmodifiedSinceCondition";
         }
+        /**
+         * The bucket Name to override (can be dynamic using the simple language
+         * in the producer) which this object will be stored or which will be
+         * used for the current operation or in which this object is contained.
+         * 
+         * The option is a: {@code String} type.
+         * 
+         * Group: common
+         * 
+         * @return the name of the header {@code AwsS3OverrideBucketName}.
+         */
+        public String awsS3OverrideBucketName() {
+            return "CamelAwsS3OverrideBucketName";
+        }
     }
     static AWS2S3EndpointBuilder endpointBuilder(String componentName, String path) {
         class AWS2S3EndpointBuilderImpl extends AbstractEndpointBuilder implements AWS2S3EndpointBuilder, AdvancedAWS2S3EndpointBuilder {