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

davsclaus 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 c1cbf63181a9 CAMEL-24880: camel-core - the grouped body list prints 
its contents, the short List<Exchange> form is for exchanges only
c1cbf63181a9 is described below

commit c1cbf63181a9d272636818f09e68c814f35d94b1
Author: Claus Ibsen <[email protected]>
AuthorDate: Tue Sep 22 07:09:39 2026 +0200

    CAMEL-24880: camel-core - the grouped body list prints its contents, the 
short List<Exchange> form is for exchanges only
    
    Fixes https://issues.apache.org/jira/browse/CAMEL-24880
    
    `GroupedBodyAggregationStrategy` collects the bodies into the 
`GroupedExchangeList` of `AbstractListAggregationStrategy`, whose `toString()` 
answered `List<Exchange>(2 elements)` whatever the elements were. A route that 
aggregates with the grouped body strategy and logs `${body}` showed that 
instead of the list of bodies:
    
    ```
    INFO ... aggregator.camel.yaml:43 : Shipment for ORD-1001 complete: 
List<Exchange>(2 elements)
    ```
    
    The short form was meant to keep a list of exchanges out of the log, which 
is right for `GroupedExchangeAggregationStrategy`. The list now prints as a 
plain list unless its elements are exchanges. Tests: the grouped body test 
asserts `[A, B, C]`, the grouped exchange test asserts the short form is kept.
    
    Seen in the route/aggregator example of camel-jbang-examples, whose README 
says to log the shipment before marshalling it.
---
 .../processor/aggregate/AbstractListAggregationStrategy.java  | 11 ++++++++---
 .../AggregateGroupedExchangeCompletionSizeTest.java           |  6 ++++++
 .../aggregator/AggregationStrategyGroupedBodyTest.java        |  2 ++
 3 files changed, 16 insertions(+), 3 deletions(-)

diff --git 
a/core/camel-core-processor/src/main/java/org/apache/camel/processor/aggregate/AbstractListAggregationStrategy.java
 
b/core/camel-core-processor/src/main/java/org/apache/camel/processor/aggregate/AbstractListAggregationStrategy.java
index 3c9e0659b849..5c80538bea02 100644
--- 
a/core/camel-core-processor/src/main/java/org/apache/camel/processor/aggregate/AbstractListAggregationStrategy.java
+++ 
b/core/camel-core-processor/src/main/java/org/apache/camel/processor/aggregate/AbstractListAggregationStrategy.java
@@ -107,7 +107,8 @@ public abstract class AbstractListAggregationStrategy<V> 
implements AggregationS
     }
 
     /**
-     * A list to contains grouped {@link Exchange}s.
+     * A list to contains grouped {@link Exchange}s, or the values a subclass 
takes from them (the bodies with
+     * {@link GroupedBodyAggregationStrategy}).
      */
     private static final class GroupedExchangeList<E> extends ArrayList<E> {
 
@@ -115,8 +116,12 @@ public abstract class AbstractListAggregationStrategy<V> 
implements AggregationS
 
         @Override
         public String toString() {
-            // override toString, so we don't write data for all the Exchanges 
by default
-            return "List<Exchange>(" + size() + " elements)";
+            // a list of exchanges is not written in full by default; a list 
of bodies is what the user
+            // aggregated and is printed as any list (CAMEL-24880)
+            if (!isEmpty() && get(0) instanceof Exchange) {
+                return "List<Exchange>(" + size() + " elements)";
+            }
+            return super.toString();
         }
     }
 
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateGroupedExchangeCompletionSizeTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateGroupedExchangeCompletionSizeTest.java
index 69d6edad581d..63311da52df2 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateGroupedExchangeCompletionSizeTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateGroupedExchangeCompletionSizeTest.java
@@ -22,6 +22,8 @@ import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.processor.aggregate.GroupedExchangeAggregationStrategy;
 import org.junit.jupiter.api.Test;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
 /**
  * Unit test for aggregate grouped exchanges.
  */
@@ -40,6 +42,10 @@ public class AggregateGroupedExchangeCompletionSizeTest 
extends ContextTestSuppo
         template.sendBody("direct:start", "F");
 
         assertMockEndpointsSatisfied();
+
+        // the list of exchanges keeps its short form (CAMEL-24880 changed 
only the list of bodies)
+        Object body = result.getExchanges().get(0).getMessage().getBody();
+        assertEquals("List<Exchange>(3 elements)", body.toString());
     }
 
     @Override
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregationStrategyGroupedBodyTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregationStrategyGroupedBodyTest.java
index 8c488198ba3b..7a85de5b0af9 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregationStrategyGroupedBodyTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregationStrategyGroupedBodyTest.java
@@ -44,6 +44,8 @@ public class AggregationStrategyGroupedBodyTest extends 
ContextTestSupport {
         assertEquals("A", list.get(0));
         assertEquals("B", list.get(1));
         assertEquals("C", list.get(2));
+        // CAMEL-24880: the bodies print as any list, the short 
List<Exchange>(n elements) form is for exchanges only
+        assertEquals("[A, B, C]", list.toString());
     }
 
     @Override

Reply via email to