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 5a89cd78cd11 CAMEL-16861: Update docs
5a89cd78cd11 is described below
commit 5a89cd78cd11b02b69d984f93bbcf363366d8e3e
Author: Claus Ibsen <[email protected]>
AuthorDate: Tue Feb 17 20:36:49 2026 +0100
CAMEL-16861: Update docs
---
.../src/main/docs/modules/eips/pages/sort-eip.adoc | 127 ++++++++++++++++++---
.../camel/builder/ExpressionClauseSupport.java | 16 ++-
.../language/TokenizerExpressionReifier.java | 2 +-
.../apache/camel/main/stub/StubBeanRepository.java | 5 +
4 files changed, 130 insertions(+), 20 deletions(-)
diff --git
a/core/camel-core-engine/src/main/docs/modules/eips/pages/sort-eip.adoc
b/core/camel-core-engine/src/main/docs/modules/eips/pages/sort-eip.adoc
index 9d1de48b6432..d89c027e04bc 100644
--- a/core/camel-core-engine/src/main/docs/modules/eips/pages/sort-eip.adoc
+++ b/core/camel-core-engine/src/main/docs/modules/eips/pages/sort-eip.adoc
@@ -41,6 +41,11 @@ Imagine you consume text files and before processing each
file, you want to be s
In the route below, it will read the file content and tokenize by line breaks
so each line can be sorted.
+[tabs]
+====
+
+Java::
++
[source,java]
----
from("file:inbox")
@@ -48,41 +53,133 @@ from("file:inbox")
.to("bean:MyServiceBean.processLine");
----
-You can pass in your own comparator as a second argument:
+XML::
++
+[source,xml]
+----
+<route>
+ <from uri="file:inbox"/>
+ <sort>
+ <tokenize token="\n"/>
+ </sort>
+ <to uri="bean:myServiceBean.processLine"/>
+</route>
+----
+
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: file:inbox
+ steps:
+ - sort:
+ expression:
+ tokenize:
+ token: "\n"
+ - to:
+ uri: bean:myServiceBean.processLine
+----
+====
+
+You can control how to sort using a custom `java.util.Comparator`:
+
+[tabs]
+====
+Java::
++
[source,java]
----
from("file:inbox")
- .sort(body().tokenize("\n"), new MyReverseComparator())
+ .sort().tokenize("\n").comparator("myComparator")
.to("bean:MyServiceBean.processLine");
----
-In the route below, it will read the file content and tokenize by line breaks
so each line can be sorted.
-In XML, you use the xref:components:languages:tokenize-language.adoc[Tokenize]
language as shown:
-
+XML::
++
[source,xml]
----
<route>
- <from uri="file:inbox"/>
- <sort>
- <tokenize>\n</tokenize>
- </sort>
- <to uri="bean:myServiceBean.processLine"/>
+ <from uri="file:inbox"/>
+ <sort comparator="myComparator">
+ <tokenize token="\n"/>
+ </sort>
+ <to uri="bean:MyServiceBean.processLine"/>
</route>
----
-And to use our own `Comparator` we do as follows:
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: file:inbox
+ steps:
+ - sort:
+ comparator: myComparator
+ expression:
+ tokenize:
+ token: "\n"
+ - to:
+ uri: bean:MyServiceBean.processLine
+----
+====
+
+TIP: You can also refer to the custom comparator using `#class:` syntax as
shown below:
+
+[tabs]
+====
+Java::
++
+[source,java]
+----
+from("file:inbox")
+
.sort().tokenize("\n").comparator("#class:com.mycompany.MyReverseComparator")
+ .to("bean:MyServiceBean.processLine");
+----
++
+In Java DSL you can also provide the custom `Comparator` directly as the
object as follows:
++
+[source,java]
+----
+from("file:inbox")
+ .sort().body().comparator(new MyReverseComparator())
+ .to("bean:MyServiceBean.processLine");
+----
+
+XML::
++
[source,xml]
----
<route>
<from uri="file:inbox"/>
<sort comparator="#class:com.mycompany.MyReverseComparator">
- <simple>${body}</simple>
+ <tokenize token="\n"/>
</sort>
- <beanRef ref="MyServiceBean" method="processLine"/>
+ <bean ref="MyServiceBean" method="processLine"/>
</route>
----
-Notice how we use `<simple>$\{body}</simple>` in the example above to tell
Sort EIP that it should use the message body for sorting.
-This is needed when you use a custom `Comparator`.
+YAML::
++
+[source,yaml]
+----
+- route:
+ from:
+ uri: file:inbox
+ steps:
+ - sort:
+ comparator: "#class:com.mycompany.MyReverseComparator"
+ expression:
+ tokenize:
+ token: "\n"
+ - bean:
+ ref: MyServiceBean
+ method: processLine
+----
+====
+
diff --git
a/core/camel-core-model/src/main/java/org/apache/camel/builder/ExpressionClauseSupport.java
b/core/camel-core-model/src/main/java/org/apache/camel/builder/ExpressionClauseSupport.java
index a45d6f1b33b7..4dcfaebd62ff 100644
---
a/core/camel-core-model/src/main/java/org/apache/camel/builder/ExpressionClauseSupport.java
+++
b/core/camel-core-model/src/main/java/org/apache/camel/builder/ExpressionClauseSupport.java
@@ -902,7 +902,9 @@ public class ExpressionClauseSupport<T> implements
ExpressionFactoryAware, Predi
public T tokenize(String token, boolean regex) {
TokenizerExpression expression = new TokenizerExpression();
expression.setToken(token);
- expression.setRegex(Boolean.toString(regex));
+ if (regex) {
+ expression.setRegex("true");
+ }
expression(expression);
return result;
}
@@ -918,7 +920,9 @@ public class ExpressionClauseSupport<T> implements
ExpressionFactoryAware, Predi
public T tokenize(String token, boolean regex, int group) {
TokenizerExpression expression = new TokenizerExpression();
expression.setToken(token);
- expression.setRegex(Boolean.toString(regex));
+ if (regex) {
+ expression.setRegex("true");
+ }
expression.setGroup(Integer.toString(group));
expression(expression);
return result;
@@ -936,7 +940,9 @@ public class ExpressionClauseSupport<T> implements
ExpressionFactoryAware, Predi
public T tokenize(String token, boolean regex, int group, boolean
skipFirst) {
TokenizerExpression expression = new TokenizerExpression();
expression.setToken(token);
- expression.setRegex(Boolean.toString(regex));
+ if (regex) {
+ expression.setRegex("true");
+ }
expression.setSkipFirst(Boolean.toString(skipFirst));
expression.setGroup(Integer.toString(group));
expression.setSkipFirst(Boolean.toString(skipFirst));
@@ -956,7 +962,9 @@ public class ExpressionClauseSupport<T> implements
ExpressionFactoryAware, Predi
public T tokenize(String token, boolean regex, String group, boolean
skipFirst) {
TokenizerExpression expression = new TokenizerExpression();
expression.setToken(token);
- expression.setRegex(Boolean.toString(regex));
+ if (regex) {
+ expression.setRegex("true");
+ }
expression.setSkipFirst(Boolean.toString(skipFirst));
expression.setGroup(group);
expression.setSkipFirst(Boolean.toString(skipFirst));
diff --git
a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/TokenizerExpressionReifier.java
b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/TokenizerExpressionReifier.java
index e25056e1bc2f..e1c7bd553418 100644
---
a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/TokenizerExpressionReifier.java
+++
b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/language/TokenizerExpressionReifier.java
@@ -33,7 +33,7 @@ public class TokenizerExpressionReifier extends
SingleInputTypedExpressionReifie
// special for new line tokens, if defined from XML then its 2
// characters, so we replace that back to a single char
String token = definition.getToken();
- if (token.startsWith("\\n")) {
+ if (token != null && token.startsWith("\\n")) {
token = '\n' + token.substring(2);
}
properties[2] = parseString(token);
diff --git
a/dsl/camel-kamelet-main-support/src/main/java/org/apache/camel/main/stub/StubBeanRepository.java
b/dsl/camel-kamelet-main-support/src/main/java/org/apache/camel/main/stub/StubBeanRepository.java
index d60ca6cde734..a4e1264d53bf 100644
---
a/dsl/camel-kamelet-main-support/src/main/java/org/apache/camel/main/stub/StubBeanRepository.java
+++
b/dsl/camel-kamelet-main-support/src/main/java/org/apache/camel/main/stub/StubBeanRepository.java
@@ -17,6 +17,7 @@
package org.apache.camel.main.stub;
import java.util.Collections;
+import java.util.Comparator;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
@@ -53,6 +54,7 @@ public class StubBeanRepository implements BeanRepository {
private final AggregationStrategy service5 = new
GroupedBodyAggregationStrategy();
private final AggregateController service6 = new
DefaultAggregateController();
private final LoadBalancer service7 = new RoundRobinLoadBalancer();
+ private final Comparator<?> service8 = (o1, o2) -> 0;
private final String stubPattern;
@@ -121,6 +123,9 @@ public class StubBeanRepository implements BeanRepository {
if (LoadBalancer.class.isAssignableFrom(type)) {
return (T) service7;
}
+ if (Comparator.class.isAssignableFrom(type)) {
+ return (T) service8;
+ }
if (Logger.class.isAssignableFrom(type)) {
return (T) LOG;
}