This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch fix/CAMEL-24486 in repository https://gitbox.apache.org/repos/asf/camel.git
commit 808c354d211ad56ad25086656f50f242ae6e1d94 Author: Claus Ibsen <[email protected]> AuthorDate: Tue Aug 25 17:26:23 2026 +0200 CAMEL-24486: camel-core - Simple language init block custom function lookup fails in dev profile DefaultSimpleFunctionRegistry.getFunction() always ignored its own function cache when the CamelContext profile is dev (to support hot-reloading SimpleFunction beans from the registry), but custom functions defined via the Simple language init block ($foo ~:= ...;) are not backed by a registry bean, so the dev-mode lookup always missed them and threw "No custom simple function with name: X". Fall back to the already registered function when no SimpleFunction bean is found. Co-Authored-By: Claude Sonnet 5 <[email protected]> Signed-off-by: Claus Ibsen <[email protected]> --- .../impl/engine/DefaultSimpleFunctionRegistry.java | 4 ++ .../camel/dsl/yaml/SimpleInitBlockTest.groovy | 65 ++++++++++++++++++++++ 2 files changed, 69 insertions(+) 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 706d14c14521..5f1927fd086d 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 @@ -110,6 +110,10 @@ public class DefaultSimpleFunctionRegistry extends ServiceSupport implements Sim removeFunction(name); addFunction(sf); exp = functions.get(name); + } else if (dev) { + // fallback to an already registered function (eg from a simple language init block) + // that is not backed by a SimpleFunction bean in the registry + exp = functions.get(name); } } return exp; diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/SimpleInitBlockTest.groovy b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/SimpleInitBlockTest.groovy index b24a58b38049..7f326742b653 100644 --- a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/SimpleInitBlockTest.groovy +++ b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/SimpleInitBlockTest.groovy @@ -57,4 +57,69 @@ class SimpleInitBlockTest extends YamlTestSupport { MockEndpoint.assertIsSatisfied(context) } + def "initBlockCompactCustomFunction"() { + setup: + loadRoutes ''' + - route: + from: + uri: direct:map + steps: + - setBody: + simple: |- + $init{ + $foo ~:= ${uppercase()}; + }init$ + ${foo('hello')} + - to: + uri: mock:result + ''' + withMock('mock:result') { + expectedMessageCount(1) + message(0).body().isEqualTo("HELLO") + } + + when: + context.start() + + withTemplate { + to('direct:map').withBody('test').send() + } + + then: + MockEndpoint.assertIsSatisfied(context) + } + + def "initBlockCustomFunctionInDevProfile"() { + setup: + context.getCamelContextExtension().setProfile("dev") + loadRoutes ''' + - route: + from: + uri: direct:map + steps: + - setBody: + simple: |- + $init{ + $foo ~:= ${uppercase()}; + }init$ + ${foo('hello')} + - to: + uri: mock:result + ''' + withMock('mock:result') { + expectedMessageCount(1) + message(0).body().isEqualTo("HELLO") + } + + when: + context.start() + + withTemplate { + to('direct:map').withBody('test').send() + } + + then: + MockEndpoint.assertIsSatisfied(context) + } + }
