You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2026/08/25 15:26:38 UTC

(camel) branch fix/CAMEL-24486 created (now 808c354d211a)

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

davsclaus pushed a change to branch fix/CAMEL-24486
in repository https://gitbox.apache.org/repos/asf/camel.git


      at 808c354d211a CAMEL-24486: camel-core - Simple language init block custom function lookup fails in dev profile

This branch includes the following new commits:

     new 808c354d211a CAMEL-24486: camel-core - Simple language init block custom function lookup fails in dev profile

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(camel) 01/01: CAMEL-24486: camel-core - Simple language init block custom function lookup fails in dev profile

Posted by da...@apache.org.
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 <cl...@gmail.com>
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 <no...@anthropic.com>
    Signed-off-by: Claus Ibsen <cl...@gmail.com>
---
 .../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)
+    }
+
 }