You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2023/08/01 09:30:40 UTC

[camel] branch camel-3.21.x updated (38887c37685 -> d5c48c34af2)

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

orpiske pushed a change to branch camel-3.21.x
in repository https://gitbox.apache.org/repos/asf/camel.git


    from 38887c37685 Backport CAMEL-19670 (#10939)
     new 26abf18c3bd CAMEL-19675: fixed not copying safe copy properties
     new d5c48c34af2 CAMEL-19675: added test case for aggregation strategy with attachment (#10895)

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:
 .../MulticastAggregationStrategyTest.java          | 83 ++++++++++++++++++++++
 .../java/org/apache/camel/ExtendedExchange.java    |  6 ++
 .../org/apache/camel/support/AbstractExchange.java |  6 ++
 .../org/apache/camel/support/ExchangeHelper.java   |  1 +
 4 files changed, 96 insertions(+)
 create mode 100644 components/camel-attachments/src/test/java/org/apache/camel/attachment/MulticastAggregationStrategyTest.java


[camel] 01/02: CAMEL-19675: fixed not copying safe copy properties

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

orpiske pushed a commit to branch camel-3.21.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 26abf18c3bd667114b4b4e14ca7526da809319e3
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Mon Jul 31 14:28:50 2023 +0200

    CAMEL-19675: fixed not copying safe copy properties
    
    This could cause it to lose attachments when using multicast EIP
    
    It adapts the patch fc0981455208ef91da94d56ece7c9d7b539020eb from Camel
    4 to Camel 3.
---
 core/camel-api/src/main/java/org/apache/camel/ExtendedExchange.java | 6 ++++++
 .../src/main/java/org/apache/camel/support/AbstractExchange.java    | 6 ++++++
 .../src/main/java/org/apache/camel/support/ExchangeHelper.java      | 1 +
 3 files changed, 13 insertions(+)

diff --git a/core/camel-api/src/main/java/org/apache/camel/ExtendedExchange.java b/core/camel-api/src/main/java/org/apache/camel/ExtendedExchange.java
index 929b7c0a943..5f8e1f6ef4f 100644
--- a/core/camel-api/src/main/java/org/apache/camel/ExtendedExchange.java
+++ b/core/camel-api/src/main/java/org/apache/camel/ExtendedExchange.java
@@ -239,4 +239,10 @@ public interface ExtendedExchange extends Exchange {
      * @see SafeCopyProperty
      */
     <T> T getSafeCopyProperty(String key, Class<T> type);
+
+    /**
+     * Copy the safe copy properties from this exchange to the target exchange
+     */
+    void copySafeCopyPropertiesTo(ExtendedExchange target);
+
 }
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/AbstractExchange.java b/core/camel-support/src/main/java/org/apache/camel/support/AbstractExchange.java
index 6e480f18227..92bd3aec906 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/AbstractExchange.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/AbstractExchange.java
@@ -210,6 +210,12 @@ class AbstractExchange implements ExtendedExchange {
         });
     }
 
+    @Override
+    public void copySafeCopyPropertiesTo(ExtendedExchange target) {
+        safeCopyProperties.entrySet()
+                .forEach(entry -> target.setSafeCopyProperty(entry.getKey(), entry.getValue().safeCopy()));
+    }
+
     @Override
     public CamelContext getContext() {
         return context;
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/ExchangeHelper.java b/core/camel-support/src/main/java/org/apache/camel/support/ExchangeHelper.java
index de09fa7238f..1ae4a687384 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/ExchangeHelper.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/ExchangeHelper.java
@@ -390,6 +390,7 @@ public final class ExchangeHelper {
             result.getProperties().putAll(source.getProperties());
         }
         source.adapt(ExtendedExchange.class).copyInternalProperties(result);
+        source.adapt(ExtendedExchange.class).copySafeCopyPropertiesTo(result);
 
         // copy over state
         result.setRouteStop(source.isRouteStop());


[camel] 02/02: CAMEL-19675: added test case for aggregation strategy with attachment (#10895)

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

orpiske pushed a commit to branch camel-3.21.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit d5c48c34af2ecfe957e3b4a23d1aafd28219c4d6
Author: rvanderhallen <54...@users.noreply.github.com>
AuthorDate: Mon Jul 31 10:34:48 2023 +0200

    CAMEL-19675: added test case for aggregation strategy with attachment (#10895)
    
    This reworks the patch contributed on
    4703fe669da87748b9cd6fe2e948fc6a4cba9844 to adjust it to Camel 3
    
    Co-authored-by: Robin Vanderhallen <ro...@aviobook.aero>
---
 .../MulticastAggregationStrategyTest.java          | 83 ++++++++++++++++++++++
 1 file changed, 83 insertions(+)

diff --git a/components/camel-attachments/src/test/java/org/apache/camel/attachment/MulticastAggregationStrategyTest.java b/components/camel-attachments/src/test/java/org/apache/camel/attachment/MulticastAggregationStrategyTest.java
new file mode 100644
index 00000000000..4127d6b464d
--- /dev/null
+++ b/components/camel-attachments/src/test/java/org/apache/camel/attachment/MulticastAggregationStrategyTest.java
@@ -0,0 +1,83 @@
+/*
+ * 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.attachment;
+
+import javax.activation.DataHandler;
+
+import org.apache.camel.AggregationStrategy;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.Builder;
+import org.apache.camel.builder.ExchangeBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class MulticastAggregationStrategyTest extends CamelTestSupport {
+
+    @Test
+    void testAggregationStrategyWithAttachment() {
+        Exchange exchange = ExchangeBuilder.anExchange(new DefaultCamelContext()).build();
+
+        template.send("direct:start", exchange);
+
+        AttachmentMessage msg = exchange.getMessage(AttachmentMessage.class);
+
+        assertTrue(msg.hasAttachments());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                from("direct:start")
+                    .multicast(new AttachmentMessageAggregationStrategy()).stopOnException()
+                        .to("direct:setBody", "direct:setAttachment")
+                    .end();
+
+                from("direct:setBody")
+                        .setBody(Builder.constant("body"));
+
+                from("direct:setAttachment")
+                        .setBody(Builder.constant("attachment".getBytes()));
+            }
+        };
+    }
+
+    private static class AttachmentMessageAggregationStrategy implements AggregationStrategy {
+
+        @Override
+        public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
+            if (oldExchange == null) {
+                return newExchange;
+            }
+
+            if (newExchange.getIn().getBody() instanceof String) {
+                oldExchange.getMessage().setBody(newExchange.getIn().getBody());
+            } else {
+                byte[] data = newExchange.getIn().getBody(byte[].class);
+                oldExchange.getMessage(AttachmentMessage.class).addAttachment("attachment",
+                        new DataHandler(data, "text/plain"));
+            }
+
+            return oldExchange;
+        }
+    }
+}