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 7e2a5ffbae08 CAMEL-22935: camel-core - Allow to add custom functions
to simple language
7e2a5ffbae08 is described below
commit 7e2a5ffbae08213038d956b3a4b9e0c208f77f18
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Feb 5 09:44:52 2026 +0100
CAMEL-22935: camel-core - Allow to add custom functions to simple language
---
.../impl/engine/DefaultSimpleFunctionRegistry.java | 28 +++++++++++++++-------
1 file changed, 19 insertions(+), 9 deletions(-)
diff --git
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultSimpleFunctionRegistry.java
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultSimpleFunctionRegistry.java
index 0cbb5d553580..143f8a110d6d 100644
---
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultSimpleFunctionRegistry.java
+++
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultSimpleFunctionRegistry.java
@@ -100,21 +100,31 @@ public class DefaultSimpleFunctionRegistry extends
ServiceSupport implements Sim
@Override
public Expression getFunction(String name) {
- Expression exp = functions.get(name);
+ // in dev mode then always lookup function as it may be updated due to
a live reload
+ boolean dev =
"dev".equals(camelContext.getCamelContextExtension().getProfile());
+ Expression exp = dev ? null : functions.get(name);
if (exp == null) {
- // lookup if there is a function with the given name
- var custom =
camelContext.getRegistry().findByType(SimpleFunction.class);
- for (SimpleFunction sf : custom) {
- if (name.equals(sf.getName())) {
- addFunction(sf);
- exp = functions.get(name);
- break;
- }
+ SimpleFunction sf = lookupFunction(name);
+ if (sf != null) {
+ removeFunction(name);
+ addFunction(sf);
+ exp = functions.get(name);
}
}
return exp;
}
+ private SimpleFunction lookupFunction(String name) {
+ // lookup if there is a function with the given name
+ var custom =
camelContext.getRegistry().findByType(SimpleFunction.class);
+ for (SimpleFunction sf : custom) {
+ if (name.equals(sf.getName())) {
+ return sf;
+ }
+ }
+ return null;
+ }
+
@Override
public Set<String> getCustomFunctionNames() {
return functions.keySet();