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 cd4cf66f37f8 Update simple doc and fix split function to accept
new-line
cd4cf66f37f8 is described below
commit cd4cf66f37f85458286af7b769d70ec57e728635
Author: Claus Ibsen <[email protected]>
AuthorDate: Sat Jan 24 11:23:15 2026 +0100
Update simple doc and fix split function to accept new-line
---
.../modules/languages/pages/simple-language.adoc | 80 +++++++++++++++++++++-
.../simple/ast/SimpleFunctionExpression.java | 2 +
.../apache/camel/language/simple/SimpleTest.java | 7 ++
.../org/apache/camel/support/GroupIterator.java | 2 +-
4 files changed, 89 insertions(+), 2 deletions(-)
diff --git
a/core/camel-core-languages/src/main/docs/modules/languages/pages/simple-language.adoc
b/core/camel-core-languages/src/main/docs/modules/languages/pages/simple-language.adoc
index afc0b306a4a7..e1cddce74e50 100644
---
a/core/camel-core-languages/src/main/docs/modules/languages/pages/simple-language.adoc
+++
b/core/camel-core-languages/src/main/docs/modules/languages/pages/simple-language.adoc
@@ -186,12 +186,54 @@ NOTE: Some functions take 1 or more arguments enclosed in
parentheses, and argum
|`variables.size` | `int` | The number of `Exchange` variables
|====
+The Camel functions are as the name implies specific to Apache Camel and these
functions are primary used
+to access Camel functionality and content of the message being routed.
+
+These functions are powerful to give easy access to the current `Exchange` /
`Message` being routed so
+you can get the message body, headers, variables and exchange properties.
+
+During routing, you can use the xref:eips:log-eip.adoc[LogEIP] to write to the
log, for example:
+
+[tabs]
+====
+Java::
++
+[source,java]
+----
+from("direct:email")
+ .log("Sending welcome email to customer ${header.id} with status
${variable.level}");
+----
+
+XML::
++
+[source,xml]
+----
+<route>
+ <from uri="direct:email"/>
+ <log message="Sending welcome email to customer ${header.id} with status
${variable.level}"/>
+</route>
+----
+
+YAML::
++
+[source,yaml]
+----
+- from:
+ uri: direct:email
+ steps:
+ - log:
+ message: "Sending welcome email to customer ${header.id} with status
${variable.level}"
+----
+====
+
+NOTE: The Camel functions are often also used for basic data mapping to easily
get the part of the message payload you desire.
+
=== Array & List Functions
[width="100%",cols="10%,10%,80%",options="header",]
|====
|Function |Response Type |Description
-|`collate(size)` | `List` | The collate function iterates the message body and
groups the data into sub lists of specified size. This can be used with the
Splitter EIP to split a message body and group/batch the split sub message into
a group of N sub lists. This method works similar to the collate method in
Groovy.
+|`collate(size)` | `Iterator<List>` | The collate function iterates the
message body and groups the data into sub lists of specified size. This can be
used with the Splitter EIP to split a message body and group/batch the split
sub message into a group of N sub lists. This method works similar to the
collate method in Groovy.
|`distinct(val1,val2,...)` | `Set` | Returns a set of all the values with
duplicates removed
|`empty(kind)` | `<T>` | *Deprecated* Use `createEmpty` instead.
|`forEach(exp,fun)` | `<List>` | Returns a List containing the values returned
by the function when applied to each value from the input expression. This
function is not supported when using csimple.
@@ -205,6 +247,42 @@ NOTE: Some functions take 1 or more arguments enclosed in
parentheses, and argum
|`split(exp,separator)` | `String[]` | Splits the expression as a `String`
value using the separator into a `String` array. The separator is comma by
default.
|====
+The array and list functions are less commonly used as they are more advanced
and require to work with data that are structured
+in arrays or lists.
+
+The `collate` function is used for grouping together data into smaller
subgroups. Suppose you have a message body containing a list of 9 elements.
+Then by using `${collate(2)}` will transform this into an `java.util.Iterator`
that will return each sub list.
+As there are 9 elements as input then the output will be 5 sub lists with 2 2
2 2 and 1 element each.
+
+The `distinct` function takes one or more values as input and then returns a
`Set` with only the unique values.
+The input values can single objects or arrays or lists as well. If no values
is provided then the `${distinct()}` function will use the message body as
input.
+For example `${distinct('Z','X','Z','A','B','A','C','D','B','E')}` will return
a `Set` with values `[Z, X, A, B, C, D, E]`.
+
+The `forEach` function is like a for loop that loops the input values and
apply the function to each item, and aggregates their responses into a `List`
as result.
+
+For example suppose the message body contains a comma separated String with
`Camel,World,Cheese` then
+executing `${forEach($\{body},'Hello $\{body}')}` will return a List with 3
values: `["Hello Camel", "Hello World", "Hello Cheese"]`.
+
+The `list` function is used for taking all input values and putting them into
a single `List` as response.
+For example if the message body contains '4' then `${list(1,2,3,$\{body})}`
will return a list with 4 elements. `[1,2,3,4]`.
+
+The `map` function is similar to the `list` function but for creating a `Map`
instead where the values are grouped in pairs 2 by 2.
+For example `${map(1,a,2,b,3,c)}` will return a map with 3 elements `{1=a,
2=b, 3=c}`.
+
+The `createEmpty` function is for creating an empty object which can either be
an empty `String` or a `List`, `Map` or `Set`.
+To create an empty `Map` use `${createEmpty(map)}`.
+
+The `reverse` function is to reverse the order of the values.
+For example `${reverse(1,2,3,4,5)}` will return a `List` with the values
`5,4,3,2,1`.
+And the `shuffle` function will randomize the order of the values.
+
+The `skip` function is used for skipping the first number of elements. For
example suppose you have a CSV file that contains a header line,
+and you want to skip this line, then you can use `${skip(1)}` that then
returns an `Iterator` that starts at the 2nd line.
+
+The `split` function is as the name implies used for splitting the message
body or the value (using a separator) into an array of sub elements.
+For example if the message body a CSV payload then using `${split(\\n)}` (you
need to escape the new-line character) will split
+this into a `String[]` separated by new-line.
+
=== Boolean Functions
[width="100%",cols="10%,10%,80%",options="header",]
diff --git
a/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java
b/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java
index 321bcc0e4f45..97f70aa4c004 100644
---
a/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java
+++
b/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java
@@ -1068,6 +1068,8 @@ public class SimpleFunctionExpression extends
LiteralExpression {
} else {
separator = tokens[0];
}
+ } else if ("\n".equals(values)) {
+ separator = values;
}
return SimpleExpressionBuilder.splitStringExpression(exp,
separator);
}
diff --git
a/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java
b/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java
index 4e52015f8054..353aa0a33b79 100644
---
a/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java
+++
b/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java
@@ -2713,6 +2713,13 @@ public class SimpleTest extends LanguageTestSupport {
expression =
context.resolveLanguage("simple").createExpression("${split(${header.myHead},;)}");
s = expression.evaluate(exchange, String[].class);
assertArrayEquals(arr2, s);
+
+ body = "A1,B1,C1\nA2,B2,C2\nA3,B3,C3";
+ arr = body.split("\n");
+ exchange.getMessage().setBody(body);
+ expression =
context.resolveLanguage("simple").createExpression("${split(\\n)}");
+ s = expression.evaluate(exchange, String[].class);
+ assertArrayEquals(arr, s);
}
@Test
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/GroupIterator.java
b/core/camel-support/src/main/java/org/apache/camel/support/GroupIterator.java
index bdd464fb6c6a..b14df74938d7 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/GroupIterator.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/GroupIterator.java
@@ -29,7 +29,7 @@ import org.apache.camel.util.IOHelper;
* Group based {@link Iterator} which groups the given {@link Iterator} a
number of times and then return a combined
* response as a <tt>List</tt>.
* <p/>
- * This implementation uses a internal array list, to combine the response.
+ * This implementation uses an internal array list, to combine the response.
*
* @see GroupTokenIterator
*/