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 2020/03/06 14:06:33 UTC

[camel] branch master updated (74812d7 -> 94adfdd)

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

acosentino pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git.


    from 74812d7  CAMEL-14668: camel-core - Optimize endpoint-dsl for getEndpoint
     new 7eb3955  CAMEL-14664 - Camel-AWS2-S3: add more integration tests, copyObject
     new 94adfdd  Camel-AWS2-S3: Fixed CS

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../camel/component/aws2/s3/AWS2S3Producer.java    | 18 +++---
 ...a => S3CopyObjectOperationIntegrationTest.java} | 66 ++++++++--------------
 2 files changed, 34 insertions(+), 50 deletions(-)
 copy components/camel-aws2-s3/src/test/java/org/apache/camel/component/aws2/s3/integration/{S3ObjectRangeOperationIntegrationTest.java => S3CopyObjectOperationIntegrationTest.java} (57%)


[camel] 02/02: Camel-AWS2-S3: Fixed CS

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 94adfddae0ed486b2977d15d8dde716a940098bf
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Fri Mar 6 15:05:07 2020 +0100

    Camel-AWS2-S3: Fixed CS
---
 .../apache/camel/component/aws2/s3/AWS2S3Producer.java | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/components/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Producer.java b/components/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Producer.java
index dcbd01d..7a13e2c 100644
--- a/components/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Producer.java
+++ b/components/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Producer.java
@@ -121,17 +121,17 @@ public class AWS2S3Producer extends DefaultProducer {
         } else {
             is = exchange.getIn().getMandatoryBody(InputStream.class);
             if (objectMetadata.containsKey(Exchange.CONTENT_LENGTH)) {
-            if (objectMetadata.get("Content-Length").equals("0") && ObjectHelper.isEmpty(exchange.getProperty(Exchange.CONTENT_LENGTH))) {
-                LOG.debug("The content length is not defined. It needs to be determined by reading the data into memory");
-                baos = determineLengthInputStream(is);
-                objectMetadata.put("Content-Length", String.valueOf(baos.size()));
-                is = new ByteArrayInputStream(baos.toByteArray());
-            } else {
-                if (ObjectHelper.isNotEmpty(exchange.getProperty(Exchange.CONTENT_LENGTH))) {
-                    objectMetadata.put("Content-Length", exchange.getProperty(Exchange.CONTENT_LENGTH, String.class));
+                if (objectMetadata.get("Content-Length").equals("0") && ObjectHelper.isEmpty(exchange.getProperty(Exchange.CONTENT_LENGTH))) {
+                    LOG.debug("The content length is not defined. It needs to be determined by reading the data into memory");
+                    baos = determineLengthInputStream(is);
+                    objectMetadata.put("Content-Length", String.valueOf(baos.size()));
+                    is = new ByteArrayInputStream(baos.toByteArray());
+                } else {
+                    if (ObjectHelper.isNotEmpty(exchange.getProperty(Exchange.CONTENT_LENGTH))) {
+                        objectMetadata.put("Content-Length", exchange.getProperty(Exchange.CONTENT_LENGTH, String.class));
+                    }
                 }
             }
-            }
         }
 
         final String bucketName = determineBucketName(exchange);


[camel] 01/02: CAMEL-14664 - Camel-AWS2-S3: add more integration tests, copyObject

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 7eb395519996479899913fd5b8b1bbc1c204f9b8
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Fri Mar 6 15:03:03 2020 +0100

    CAMEL-14664 - Camel-AWS2-S3: add more integration tests, copyObject
---
 .../camel/component/aws2/s3/AWS2S3Producer.java    |  2 +
 .../S3CopyObjectOperationIntegrationTest.java      | 90 ++++++++++++++++++++++
 2 files changed, 92 insertions(+)

diff --git a/components/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Producer.java b/components/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Producer.java
index f6c199b..dcbd01d 100644
--- a/components/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Producer.java
+++ b/components/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Producer.java
@@ -120,6 +120,7 @@ public class AWS2S3Producer extends DefaultProducer {
             is = new FileInputStream(filePayload);
         } else {
             is = exchange.getIn().getMandatoryBody(InputStream.class);
+            if (objectMetadata.containsKey(Exchange.CONTENT_LENGTH)) {
             if (objectMetadata.get("Content-Length").equals("0") && ObjectHelper.isEmpty(exchange.getProperty(Exchange.CONTENT_LENGTH))) {
                 LOG.debug("The content length is not defined. It needs to be determined by reading the data into memory");
                 baos = determineLengthInputStream(is);
@@ -130,6 +131,7 @@ public class AWS2S3Producer extends DefaultProducer {
                     objectMetadata.put("Content-Length", exchange.getProperty(Exchange.CONTENT_LENGTH, String.class));
                 }
             }
+            }
         }
 
         final String bucketName = determineBucketName(exchange);
diff --git a/components/camel-aws2-s3/src/test/java/org/apache/camel/component/aws2/s3/integration/S3CopyObjectOperationIntegrationTest.java b/components/camel-aws2-s3/src/test/java/org/apache/camel/component/aws2/s3/integration/S3CopyObjectOperationIntegrationTest.java
new file mode 100644
index 0000000..3b83e51
--- /dev/null
+++ b/components/camel-aws2-s3/src/test/java/org/apache/camel/component/aws2/s3/integration/S3CopyObjectOperationIntegrationTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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 org.apache.camel.BindToRegistry;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.aws2.s3.AWS2S3Constants;
+import org.apache.camel.component.aws2.s3.AWS2S3Operations;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Ignore;
+import org.junit.Test;
+import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
+import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
+import software.amazon.awssdk.regions.Region;
+import software.amazon.awssdk.services.s3.S3Client;
+
+@Ignore("Must be manually tested. Provide your own accessKey and secretKey!")
+public class S3CopyObjectOperationIntegrationTest extends CamelTestSupport {
+
+    @BindToRegistry("amazonS3Client")
+    S3Client client = S3Client.builder().credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("xxx", "yyy"))).region(Region.EU_WEST_1).build();
+    
+    @EndpointInject
+    private ProducerTemplate template;
+
+    @EndpointInject("mock:result")
+    private MockEndpoint result;
+
+    @Test
+    public void sendIn() throws Exception {
+        result.expectedMessageCount(1);
+
+        template.send("direct:putObject", new Processor() {
+
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(AWS2S3Constants.KEY, "test.txt");
+                exchange.getIn().setBody("Test");
+            }
+        });
+
+        template.send("direct:copyObject", new Processor() {
+
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(AWS2S3Constants.KEY, "test.txt");
+                exchange.getIn().setHeader(AWS2S3Constants.DESTINATION_KEY, "test1.txt");
+                exchange.getIn().setHeader(AWS2S3Constants.BUCKET_DESTINATION_NAME, "mycamel1");
+                exchange.getIn().setHeader(AWS2S3Constants.S3_OPERATION, AWS2S3Operations.copyObject);
+            }
+        });
+        
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                String awsEndpoint = "aws2-s3://mycamel?amazonS3Client=#amazonS3Client&autoCreateBucket=false";
+              
+                from("direct:putObject").to(awsEndpoint);
+                
+                from("direct:copyObject").to(awsEndpoint).to("mock:result");
+
+            }
+        };
+    }
+}