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 2022/03/01 05:46:11 UTC
[camel] branch camel-3.11.x updated: CAMEL-17713: camel-aws2-s3 - support for S3 custom metadata
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch camel-3.11.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-3.11.x by this push:
new 9d898d8 CAMEL-17713: camel-aws2-s3 - support for S3 custom metadata
9d898d8 is described below
commit 9d898d89442162ed06dae466edab93ee6753b97f
Author: Jussi Wallin <ju...@beanbakers.fi>
AuthorDate: Mon Feb 28 19:13:33 2022 +0200
CAMEL-17713: camel-aws2-s3 - support for S3 custom metadata
Add support for providing custom metadata to files when uploading.
Makes use of the CamelAwsS3Metadata -header that is also used with the consumer endpoint.
---
.../src/main/docs/aws2-s3-component.adoc | 7 ++-
.../camel/component/aws2/s3/AWS2S3Producer.java | 5 ++
.../s3/integration/S3UploadWithUserMetadataIT.java | 73 ++++++++++++++++++++++
3 files changed, 82 insertions(+), 3 deletions(-)
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 ceddb8e..5141e8f 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
@@ -278,13 +278,12 @@ values.
|`CamelAwsS3Acl` |`software.amazon.awssdk.services.s3.model.BucketCannedACL` |A well constructed Amazon S3 Access Control List object.
see `software.amazon.awssdk.services.s3.model.BucketCannedACL` for more details
-|`CamelAwsS3Headers` |`Map<String,String>` |Support to get or set custom objectMetadata headers.
-
|`CamelAwsS3ServerSideEncryption` |String |Sets the server-side encryption algorithm when encrypting
the object using AWS-managed keys. For example use AES256.
|`CamelAwsS3VersionId` |`String` |The version Id of the object to be stored or returned from the current operation
-|`CamelAwsS3Metadata` |`Map<String, String>` |A map of metadata stored with the object in S3.
+|`CamelAwsS3Metadata` |`Map<String, String>` |A map of metadata to be stored with the object in S3. More details about
+metadata https://docs.aws.amazon.com/AmazonS3/latest/userguide/UsingMetadata.html[here].
|=======================================================================
=== Message headers set by the S3 producer
@@ -346,6 +345,8 @@ specify caching behavior along the HTTP request/reply chain.
|`CamelAwsS3ServerSideEncryption` |String |The server-side encryption algorithm when encrypting the
object using AWS-managed keys.
+|`CamelAwsS3Metadata` |`Map<String, String>` |A map of metadata stored with the object in S3. More details about
+metadata https://docs.aws.amazon.com/AmazonS3/latest/userguide/UsingMetadata.html[here].
|=======================================================================
=== S3 Producer operations
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 d20805e..0bdf9b1 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
@@ -611,6 +611,11 @@ public class AWS2S3Producer extends DefaultProducer {
objectMetadata.put("Content-Md5", String.valueOf(contentMD5));
}
+ Map<String, String> metadata = exchange.getIn().getHeader(AWS2S3Constants.METADATA, Map.class);
+ if (metadata != null) {
+ objectMetadata.putAll(metadata);
+ }
+
return objectMetadata;
}
diff --git a/components/camel-aws/camel-aws2-s3/src/test/java/org/apache/camel/component/aws2/s3/integration/S3UploadWithUserMetadataIT.java b/components/camel-aws/camel-aws2-s3/src/test/java/org/apache/camel/component/aws2/s3/integration/S3UploadWithUserMetadataIT.java
new file mode 100644
index 0000000..e51884a
--- /dev/null
+++ b/components/camel-aws/camel-aws2-s3/src/test/java/org/apache/camel/component/aws2/s3/integration/S3UploadWithUserMetadataIT.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.aws2.s3.integration;
+
+import java.util.Map;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.aws2.s3.AWS2S3Constants;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.infra.aws2.clients.AWSSDKClientUtils;
+import org.junit.jupiter.api.Test;
+import software.amazon.awssdk.core.ResponseInputStream;
+import software.amazon.awssdk.services.s3.S3Client;
+import software.amazon.awssdk.services.s3.model.GetObjectRequest;
+import software.amazon.awssdk.services.s3.model.GetObjectResponse;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class S3UploadWithUserMetadataIT extends Aws2S3Base {
+
+ @EndpointInject
+ private ProducerTemplate template;
+
+ @EndpointInject("mock:result")
+ private MockEndpoint result;
+
+ @Test
+ public void sendInWithUserMetadata() throws Exception {
+ result.expectedMessageCount(1);
+
+ template.send("direct:putObject", exchange -> {
+ exchange.getIn().setHeader(AWS2S3Constants.KEY, "camel-content-type.txt");
+ exchange.getIn().setHeader(AWS2S3Constants.METADATA, Map.of("user-metadata-example", "MetadataFromCamel"));
+ exchange.getIn().setBody("Camel rocks!");
+ });
+
+ S3Client s = AWSSDKClientUtils.newS3Client();
+ ResponseInputStream<GetObjectResponse> response
+ = s.getObject(GetObjectRequest.builder().bucket("mycamel").key("camel-content-type.txt").build());
+ assertTrue(response.response().hasMetadata());
+ assertEquals("MetadataFromCamel", response.response().metadata().get("user-metadata-example"));
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ String awsEndpoint = "aws2-s3://mycamel?autoCreateBucket=true";
+
+ from("direct:putObject").to(awsEndpoint);
+
+ }
+ };
+ }
+}