Claus Ibsen created CAMEL-24873:
-----------------------------------

             Summary: camel-jbang - Custom simple functions in Groovy: auto-add 
camel-groovy, honour @BindToRegistry, refresh YAML beans on --dev reload
                 Key: CAMEL-24873
                 URL: https://issues.apache.org/jira/browse/CAMEL-24873
             Project: Camel
          Issue Type: Improvement
          Components: camel-jbang, camel-yaml-dsl, camel-groovy
            Reporter: Claus Ibsen


The blog https://camel.apache.org/blog/2026/09/camel-simple-customfunction/ 
shows a custom {{SimpleFunction}} written in Java and run with {{camel run 
route.camel.yaml MaskEmailFunction.java}}. For low-code users that are not Java 
developers the natural variants are the same class as a {{.groovy}} file, or an 
inline groovy bean in the YAML file, edited with {{camel run --dev}} for a fast 
feedback loop. Verified on 4.23.0-SNAPSHOT that none of these work end to end 
today:

# {{camel run route.camel.yaml MaskEmailFunction.groovy}}: the groovy file is 
not compiled at all unless {{--dep=camel-groovy}} is given explicitly 
({{camel.jbang.groovyFiles}} is set, but the {{DefaultGroovyScriptCompiler}} 
lives in camel-groovy which is not auto-detected from the file).
# With {{--dep=camel-groovy}} the class compiles, but {{@BindToRegistry}} on 
the groovy class is ignored, so the function stays unknown ({{Unknown function: 
maskEmail}}). Binding it via a YAML {{beans:}} entry with {{type: 
MaskEmailFunction}} fails with {{ClassNotFoundException}} because bean 
pre-parsing runs before the groovy sources are compiled.
# An inline groovy bean in the YAML file works ({{scriptLanguage: groovy}} with 
{{return [getName: { 'maskEmail' }, apply: { ex, in -> ... }] as 
SimpleFunction}}), but with {{--dev}} an edit of the script reloads the routes 
while the simple function keeps the old behaviour: the bean is not re-created 
on reload ({{BeansDeserializer.bindBean}} does unbind/rebind, and 
{{DefaultSimpleFunctionRegistry.getFunction}} re-looks-up the registry in the 
dev profile, so the intent is there but something in between does not refresh).

Proposed:
* auto-add camel-groovy when a {{.groovy}} file is passed to {{camel run}} (as 
is done for other file types)
* honour {{@BindToRegistry}} on classes compiled by the groovy script compiler
* make the inline groovy bean (and YAML beans in general) refresh on {{--dev}} 
reload so a custom simple function edit is picked up
* add a sample for a custom simple function written in Groovy to the 
simple-advanced docs (the map coercion idiom is the one part a small local 
model cannot invent)



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to