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 29775d35191 CAMEL-22185: camel-core: DSL to support inlined scripts 
using Camels property placeholder directly. (#18425)
29775d35191 is described below

commit 29775d3519191adcc798c36a2d33b8b89152847d
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Fri Jun 20 12:47:17 2025 +0200

    CAMEL-22185: camel-core: DSL to support inlined scripts using Camels 
property placeholder directly. (#18425)
---
 .../apache/camel/catalog/models/beanFactory.json   |  7 +--
 .../apache/camel/catalog/schemas/camel-spring.xsd  |  9 ++++
 .../apache/camel/catalog/schemas/camel-xml-io.xsd  |  9 ++++
 .../java/org/apache/camel/impl/DefaultModel.java   |  3 ++
 .../org/apache/camel/model/beanFactory.json        |  7 +--
 .../apache/camel/model/BeanFactoryDefinition.java  | 30 +++++++++++
 .../org/apache/camel/model/BeanModelHelper.java    | 15 ++++--
 .../java/org/apache/camel/xml/in/ModelParser.java  |  1 +
 .../java/org/apache/camel/xml/out/ModelWriter.java |  1 +
 .../org/apache/camel/yaml/out/ModelWriter.java     |  1 +
 .../dsl/yaml/deserializers/ModelDeserializers.java |  6 +++
 .../generated/resources/schema/camelYamlDsl.json   |  5 ++
 .../camel-yaml-dsl/src/main/docs/yaml-dsl.adoc     | 36 +++++++++++++
 .../org/apache/camel/dsl/yaml/BeansTest.groovy     | 59 ++++++++++++++++++++++
 14 files changed, 180 insertions(+), 9 deletions(-)

diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/beanFactory.json
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/beanFactory.json
index c65c44d2cf6..906a3b03df1 100644
--- 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/beanFactory.json
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/beanFactory.json
@@ -21,8 +21,9 @@
     "builderClass": { "index": 6, "kind": "attribute", "displayName": "Builder 
Class", "group": "common", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"description": "Fully qualified class name of builder class to use for creating 
and configuring the bean. The builder will use the properties values to 
configure the bean." },
     "builderMethod": { "index": 7, "kind": "attribute", "displayName": 
"Builder Method", "group": "common", "required": false, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "defaultValue": "build", "description": "Name of method when 
using builder class. This method is invoked after configuring to create the 
actual bean. This method is often named build (used by default)." },
     "scriptLanguage": { "index": 8, "kind": "attribute", "displayName": 
"Script Language", "group": "advanced", "label": "advanced", "required": false, 
"type": "string", "javaType": "java.lang.String", "deprecated": false, 
"autowired": false, "secret": false, "description": "The script language to use 
when using inlined script for creating the bean, such as groovy, java, 
javascript etc." },
-    "constructors": { "index": 9, "kind": "element", "displayName": 
"Constructors", "group": "common", "required": false, "type": "object", 
"javaType": "java.util.Map<java.lang.Integer, java.lang.Object>", "deprecated": 
false, "autowired": false, "secret": false, "description": "Optional 
constructor arguments for creating the bean. Arguments correspond to specific 
index of the constructor argument list, starting from zero." },
-    "properties": { "index": 10, "kind": "element", "displayName": 
"Properties", "group": "common", "required": false, "type": "object", 
"javaType": "java.util.Map<java.lang.String, java.lang.Object>", "deprecated": 
false, "autowired": false, "secret": false, "description": "Optional properties 
to set on the created bean." },
-    "script": { "index": 11, "kind": "element", "displayName": "Script", 
"group": "advanced", "label": "advanced", "required": false, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "description": "The script to execute that creates the bean 
when using scripting languages. If the script use the prefix resource: such as 
resource:classpath:com\/foo\/myscript.groovy, 
resource:file:\/var\/myscript.groovy, then its loaded from the ex [...]
+    "scriptPropertyPlaceholders": { "index": 9, "kind": "attribute", 
"displayName": "Script Property Placeholders", "group": "advanced", "label": 
"advanced", "required": false, "type": "boolean", "javaType": 
"java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, 
"defaultValue": true, "description": "Whether the script should support using 
Camel property placeholder syntax {{ }}." },
+    "constructors": { "index": 10, "kind": "element", "displayName": 
"Constructors", "group": "common", "required": false, "type": "object", 
"javaType": "java.util.Map<java.lang.Integer, java.lang.Object>", "deprecated": 
false, "autowired": false, "secret": false, "description": "Optional 
constructor arguments for creating the bean. Arguments correspond to specific 
index of the constructor argument list, starting from zero." },
+    "properties": { "index": 11, "kind": "element", "displayName": 
"Properties", "group": "common", "required": false, "type": "object", 
"javaType": "java.util.Map<java.lang.String, java.lang.Object>", "deprecated": 
false, "autowired": false, "secret": false, "description": "Optional properties 
to set on the created bean." },
+    "script": { "index": 12, "kind": "element", "displayName": "Script", 
"group": "advanced", "label": "advanced", "required": false, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "description": "The script to execute that creates the bean 
when using scripting languages. If the script use the prefix resource: such as 
resource:classpath:com\/foo\/myscript.groovy, 
resource:file:\/var\/myscript.groovy, then its loaded from the ex [...]
   }
 }
diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd
index bffbe6ee933..8551d9b1dcb 100644
--- 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd
@@ -4315,6 +4315,15 @@ is often named build (used by default). Default value: 
build
         <xs:documentation xml:lang="en">
 <![CDATA[
 The script language to use when using inlined script for creating the bean, 
such as groovy, java, javascript etc.
+]]>
+        </xs:documentation>
+      </xs:annotation>
+    </xs:attribute>
+    <xs:attribute name="scriptPropertyPlaceholders" type="xs:string">
+      <xs:annotation>
+        <xs:documentation xml:lang="en">
+<![CDATA[
+Whether the script should support using Camel property placeholder syntax {{ 
}}. Default value: true
 ]]>
         </xs:documentation>
       </xs:annotation>
diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-xml-io.xsd
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-xml-io.xsd
index 1566ea1afde..86034864896 100644
--- 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-xml-io.xsd
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-xml-io.xsd
@@ -2976,6 +2976,15 @@ is often named build (used by default). Default value: 
build
         <xs:documentation xml:lang="en">
 <![CDATA[
 The script language to use when using inlined script for creating the bean, 
such as groovy, java, javascript etc.
+]]>
+        </xs:documentation>
+      </xs:annotation>
+    </xs:attribute>
+    <xs:attribute name="scriptPropertyPlaceholders" type="xs:string">
+      <xs:annotation>
+        <xs:documentation xml:lang="en">
+<![CDATA[
+Whether the script should support using Camel property placeholder syntax {{ 
}}. Default value: true
 ]]>
         </xs:documentation>
       </xs:annotation>
diff --git 
a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultModel.java 
b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultModel.java
index ec4e85e8f5c..b457f31322e 100644
--- 
a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultModel.java
+++ 
b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultModel.java
@@ -604,6 +604,9 @@ public class DefaultModel implements Model {
     private static void addTemplateBeans(RouteTemplateContext 
routeTemplateContext, RouteTemplateDefinition target)
             throws Exception {
         for (BeanFactoryDefinition b : target.getTemplateBeans()) {
+            // route template beans do not directly support property 
placeholders
+            // but need to use rtc.property API calls
+            b.setScriptPropertyPlaceholders("false");
             BeanModelHelper.bind(b, routeTemplateContext);
         }
     }
diff --git 
a/core/camel-core-model/src/generated/resources/META-INF/org/apache/camel/model/beanFactory.json
 
b/core/camel-core-model/src/generated/resources/META-INF/org/apache/camel/model/beanFactory.json
index c65c44d2cf6..906a3b03df1 100644
--- 
a/core/camel-core-model/src/generated/resources/META-INF/org/apache/camel/model/beanFactory.json
+++ 
b/core/camel-core-model/src/generated/resources/META-INF/org/apache/camel/model/beanFactory.json
@@ -21,8 +21,9 @@
     "builderClass": { "index": 6, "kind": "attribute", "displayName": "Builder 
Class", "group": "common", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"description": "Fully qualified class name of builder class to use for creating 
and configuring the bean. The builder will use the properties values to 
configure the bean." },
     "builderMethod": { "index": 7, "kind": "attribute", "displayName": 
"Builder Method", "group": "common", "required": false, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "defaultValue": "build", "description": "Name of method when 
using builder class. This method is invoked after configuring to create the 
actual bean. This method is often named build (used by default)." },
     "scriptLanguage": { "index": 8, "kind": "attribute", "displayName": 
"Script Language", "group": "advanced", "label": "advanced", "required": false, 
"type": "string", "javaType": "java.lang.String", "deprecated": false, 
"autowired": false, "secret": false, "description": "The script language to use 
when using inlined script for creating the bean, such as groovy, java, 
javascript etc." },
-    "constructors": { "index": 9, "kind": "element", "displayName": 
"Constructors", "group": "common", "required": false, "type": "object", 
"javaType": "java.util.Map<java.lang.Integer, java.lang.Object>", "deprecated": 
false, "autowired": false, "secret": false, "description": "Optional 
constructor arguments for creating the bean. Arguments correspond to specific 
index of the constructor argument list, starting from zero." },
-    "properties": { "index": 10, "kind": "element", "displayName": 
"Properties", "group": "common", "required": false, "type": "object", 
"javaType": "java.util.Map<java.lang.String, java.lang.Object>", "deprecated": 
false, "autowired": false, "secret": false, "description": "Optional properties 
to set on the created bean." },
-    "script": { "index": 11, "kind": "element", "displayName": "Script", 
"group": "advanced", "label": "advanced", "required": false, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "description": "The script to execute that creates the bean 
when using scripting languages. If the script use the prefix resource: such as 
resource:classpath:com\/foo\/myscript.groovy, 
resource:file:\/var\/myscript.groovy, then its loaded from the ex [...]
+    "scriptPropertyPlaceholders": { "index": 9, "kind": "attribute", 
"displayName": "Script Property Placeholders", "group": "advanced", "label": 
"advanced", "required": false, "type": "boolean", "javaType": 
"java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, 
"defaultValue": true, "description": "Whether the script should support using 
Camel property placeholder syntax {{ }}." },
+    "constructors": { "index": 10, "kind": "element", "displayName": 
"Constructors", "group": "common", "required": false, "type": "object", 
"javaType": "java.util.Map<java.lang.Integer, java.lang.Object>", "deprecated": 
false, "autowired": false, "secret": false, "description": "Optional 
constructor arguments for creating the bean. Arguments correspond to specific 
index of the constructor argument list, starting from zero." },
+    "properties": { "index": 11, "kind": "element", "displayName": 
"Properties", "group": "common", "required": false, "type": "object", 
"javaType": "java.util.Map<java.lang.String, java.lang.Object>", "deprecated": 
false, "autowired": false, "secret": false, "description": "Optional properties 
to set on the created bean." },
+    "script": { "index": 12, "kind": "element", "displayName": "Script", 
"group": "advanced", "label": "advanced", "required": false, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "description": "The script to execute that creates the bean 
when using scripting languages. If the script use the prefix resource: such as 
resource:classpath:com\/foo\/myscript.groovy, 
resource:file:\/var\/myscript.groovy, then its loaded from the ex [...]
   }
 }
diff --git 
a/core/camel-core-model/src/main/java/org/apache/camel/model/BeanFactoryDefinition.java
 
b/core/camel-core-model/src/main/java/org/apache/camel/model/BeanFactoryDefinition.java
index 4aa6b66acb0..f0e10b12466 100644
--- 
a/core/camel-core-model/src/main/java/org/apache/camel/model/BeanFactoryDefinition.java
+++ 
b/core/camel-core-model/src/main/java/org/apache/camel/model/BeanFactoryDefinition.java
@@ -72,6 +72,9 @@ public class BeanFactoryDefinition<P> implements 
ResourceAware {
     @XmlAttribute
     @Metadata(label = "advanced")
     private String scriptLanguage;
+    @XmlAttribute
+    @Metadata(javaType = "java.lang.Boolean", label = "advanced", defaultValue 
= "true")
+    private String scriptPropertyPlaceholders;
     @XmlElement(name = "constructors")
     @XmlJavaTypeAdapter(BeanConstructorsAdapter.class)
     private Map<Integer, Object> constructors;
@@ -234,6 +237,17 @@ public class BeanFactoryDefinition<P> implements 
ResourceAware {
         this.scriptLanguage = scriptLanguage;
     }
 
+    public String getScriptPropertyPlaceholders() {
+        return scriptPropertyPlaceholders;
+    }
+
+    /**
+     * Whether the script should support using Camel property placeholder 
syntax {{ }}.
+     */
+    public void setScriptPropertyPlaceholders(String 
scriptPropertyPlaceholders) {
+        this.scriptPropertyPlaceholders = scriptPropertyPlaceholders;
+    }
+
     /**
      * The script to execute that creates the bean when using scripting 
languages.
      *
@@ -518,6 +532,22 @@ public class BeanFactoryDefinition<P> implements 
ResourceAware {
         return this;
     }
 
+    /**
+     * Whether the script should support using Camel property placeholder 
syntax {{ }}.
+     */
+    public BeanFactoryDefinition<P> scriptPropertyPlaceholders(boolean 
scriptPropertyPlaceholders) {
+        this.scriptPropertyPlaceholders = scriptPropertyPlaceholders ? "true" 
: "false";
+        return this;
+    }
+
+    /**
+     * Whether the script should support using Camel property placeholder 
syntax {{ }}.
+     */
+    public BeanFactoryDefinition<P> scriptPropertyPlaceholders(String 
scriptPropertyPlaceholders) {
+        this.scriptPropertyPlaceholders = scriptPropertyPlaceholders;
+        return this;
+    }
+
     public P end() {
         return parent;
     }
diff --git 
a/core/camel-core-model/src/main/java/org/apache/camel/model/BeanModelHelper.java
 
b/core/camel-core-model/src/main/java/org/apache/camel/model/BeanModelHelper.java
index f5fc40967cf..fe1d11674df 100644
--- 
a/core/camel-core-model/src/main/java/org/apache/camel/model/BeanModelHelper.java
+++ 
b/core/camel-core-model/src/main/java/org/apache/camel/model/BeanModelHelper.java
@@ -64,6 +64,7 @@ public final class BeanModelHelper {
 
         // script bean
         if (def.getScriptLanguage() != null && def.getScript() != null) {
+            String script = resolveScript(context, def);
             // create bean via the script
             final Language lan = 
context.resolveLanguage(def.getScriptLanguage());
             final ScriptingLanguage slan = lan instanceof ScriptingLanguage ? 
(ScriptingLanguage) lan : null;
@@ -76,10 +77,10 @@ public final class BeanModelHelper {
                 // scripting language should be evaluated with context as 
binding
                 Map<String, Object> bindings = new HashMap<>();
                 bindings.put("context", context);
-                target = slan.evaluate(def.getScript(), bindings, clazz);
+                target = slan.evaluate(script, bindings, clazz);
             } else {
                 Exchange dummy = ExchangeHelper.getDummy(context);
-                String text = 
ScriptHelper.resolveOptionalExternalScript(context, dummy, def.getScript());
+                String text = 
ScriptHelper.resolveOptionalExternalScript(context, dummy, script);
                 Expression exp = lan.createExpression(text);
                 target = exp.evaluate(dummy, clazz);
             }
@@ -176,7 +177,7 @@ public final class BeanModelHelper {
             } else {
                 clazz = Object.class;
             }
-            final String script = def.getScript();
+            final String script = resolveScript(camelContext, def);
             final ScriptingLanguage slan = lan instanceof ScriptingLanguage ? 
(ScriptingLanguage) lan : null;
             if (slan != null) {
                 // scripting language should be evaluated with route template 
context as binding
@@ -300,4 +301,12 @@ public final class BeanModelHelper {
                                                + ". To refer to a class then 
prefix the value with #class such as: #class:fullyQualifiedClassName");
         }
     }
+
+    private static String resolveScript(CamelContext camelContext, 
BeanFactoryDefinition<?> def) {
+        String answer = def.getScript();
+        if (answer != null && 
!"false".equals(def.getScriptPropertyPlaceholders())) {
+            answer = camelContext.resolvePropertyPlaceholders(answer);
+        }
+        return answer;
+    }
 }
diff --git 
a/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java 
b/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java
index a97693f4c29..338b55ee63a 100644
--- 
a/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java
+++ 
b/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java
@@ -176,6 +176,7 @@ public class ModelParser extends BaseParser {
                 case "initMethod": def.setInitMethod(val); yield true;
                 case "name": def.setName(val); yield true;
                 case "scriptLanguage": def.setScriptLanguage(val); yield true;
+                case "scriptPropertyPlaceholders": 
def.setScriptPropertyPlaceholders(val); yield true;
                 case "type": def.setType(val); yield true;
                 default: yield false;
             }, (def, key) -> switch (key) {
diff --git 
a/core/camel-xml-io/src/generated/java/org/apache/camel/xml/out/ModelWriter.java
 
b/core/camel-xml-io/src/generated/java/org/apache/camel/xml/out/ModelWriter.java
index abc7713fb95..062ff02bfe0 100644
--- 
a/core/camel-xml-io/src/generated/java/org/apache/camel/xml/out/ModelWriter.java
+++ 
b/core/camel-xml-io/src/generated/java/org/apache/camel/xml/out/ModelWriter.java
@@ -884,6 +884,7 @@ public class ModelWriter extends BaseWriter {
         doWriteAttribute("builderClass", def.getBuilderClass(), null);
         doWriteAttribute("type", def.getType(), null);
         doWriteAttribute("factoryBean", def.getFactoryBean(), null);
+        doWriteAttribute("scriptPropertyPlaceholders", 
def.getScriptPropertyPlaceholders(), "true");
         doWriteAttribute("initMethod", def.getInitMethod(), null);
         doWriteAttribute("name", def.getName(), null);
         doWriteAttribute("builderMethod", def.getBuilderMethod(), "build");
diff --git 
a/core/camel-yaml-io/src/generated/java/org/apache/camel/yaml/out/ModelWriter.java
 
b/core/camel-yaml-io/src/generated/java/org/apache/camel/yaml/out/ModelWriter.java
index f5654fd238e..a3a33eea40b 100644
--- 
a/core/camel-yaml-io/src/generated/java/org/apache/camel/yaml/out/ModelWriter.java
+++ 
b/core/camel-yaml-io/src/generated/java/org/apache/camel/yaml/out/ModelWriter.java
@@ -884,6 +884,7 @@ public class ModelWriter extends BaseWriter {
         doWriteAttribute("builderClass", def.getBuilderClass(), null);
         doWriteAttribute("type", def.getType(), null);
         doWriteAttribute("factoryBean", def.getFactoryBean(), null);
+        doWriteAttribute("scriptPropertyPlaceholders", 
def.getScriptPropertyPlaceholders(), "true");
         doWriteAttribute("initMethod", def.getInitMethod(), null);
         doWriteAttribute("name", def.getName(), null);
         doWriteAttribute("builderMethod", def.getBuilderMethod(), "build");
diff --git 
a/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializers.java
 
b/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializers.java
index 39921d7868f..74538f108a2 100644
--- 
a/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializers.java
+++ 
b/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializers.java
@@ -1181,6 +1181,7 @@ public final class ModelDeserializers extends 
YamlDeserializerSupport {
                     @YamlProperty(name = "properties", type = "object", 
description = "Optional properties to set on the created bean.", displayName = 
"Properties"),
                     @YamlProperty(name = "script", type = "string", 
description = "The script to execute that creates the bean when using scripting 
languages. If the script use the prefix resource: such as 
resource:classpath:com/foo/myscript.groovy, resource:file:/var/myscript.groovy, 
then its loaded from the external resource.", displayName = "Script"),
                     @YamlProperty(name = "scriptLanguage", type = "string", 
description = "The script language to use when using inlined script for 
creating the bean, such as groovy, java, javascript etc.", displayName = 
"Script Language"),
+                    @YamlProperty(name = "scriptPropertyPlaceholders", type = 
"boolean", description = "Whether the script should support using Camel 
property placeholder syntax {{ }}.", displayName = "Script Property 
Placeholders"),
                     @YamlProperty(name = "type", type = "string", required = 
true, description = "The class name (fully qualified) of the bean", displayName 
= "Type")
             }
     )
@@ -1254,6 +1255,11 @@ public final class ModelDeserializers extends 
YamlDeserializerSupport {
                     target.setScriptLanguage(val);
                     break;
                 }
+                case "scriptPropertyPlaceholders": {
+                    String val = asText(node);
+                    target.setScriptPropertyPlaceholders(val);
+                    break;
+                }
                 case "type": {
                     String val = asText(node);
                     target.setType(val);
diff --git 
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl.json
 
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl.json
index e466dbb118d..6bc5311fb97 100644
--- 
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl.json
+++ 
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl.json
@@ -635,6 +635,11 @@
             "title" : "Script Language",
             "description" : "The script language to use when using inlined 
script for creating the bean, such as groovy, java, javascript etc."
           },
+          "scriptPropertyPlaceholders" : {
+            "type" : "boolean",
+            "title" : "Script Property Placeholders",
+            "description" : "Whether the script should support using Camel 
property placeholder syntax {{ }}."
+          },
           "type" : {
             "type" : "string",
             "title" : "Type",
diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/docs/yaml-dsl.adoc 
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/docs/yaml-dsl.adoc
index 25d60874613..adb282cca8c 100644
--- a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/docs/yaml-dsl.adoc
+++ b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/docs/yaml-dsl.adoc
@@ -309,6 +309,42 @@ This gives flexibility to use a bit of programming to 
create and configure the b
 
 NOTE: When using `script` then constructors and factory bean/method is not in 
use
 
+You can refer to property placeholder values using `{{ }}` syntax inside the 
script, such as:
+
+[source,yaml]
+----
+- beans:
+  - name: myBean
+    type: com.acme.MyBean
+    scriptLanguage: groovy
+    script: >
+      // some groovy script here to create the bean
+      bean = ...
+      bean.street = '{{addressLine1}}`
+      bean.street2 = '{{addressLine2}}`
+      ...
+      return bean
+----
+
+If there is some problems with using `{{ }}` inside the script, then this can 
be turned off by setting `scriptPropertyPlaceholders: false`.
+Instead, you can invoke the APIs on `CamelContext` such as:
+
+[source,yaml]
+----
+- beans:
+  - name: myBean
+    type: com.acme.MyBean
+    scriptLanguage: groovy
+    scriptPropertyPlaceholders: false
+    script: >
+      // some groovy script here to create the bean
+      bean = ...
+      bean.street = context.resolvePropertyPlaceholders('addressLine1')
+      bean.street2 = context.resolvePropertyPlaceholders('addressLine2')
+      ...
+      return bean
+----
+
 === Using init and destroy methods on beans
 
 Sometimes beans need to do some initialization and cleanup work before a bean 
is ready to be used.
diff --git 
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/BeansTest.groovy
 
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/BeansTest.groovy
index e7b05bf71e2..3c305225825 100644
--- 
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/BeansTest.groovy
+++ 
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/BeansTest.groovy
@@ -230,6 +230,65 @@ class BeansTest extends YamlTestSupport {
         }
     }
 
+    def "beans with script property placeholder default"() {
+        when:
+        context.getPropertiesComponent().addInitialProperty("cheese", "gauda")
+        context.getPropertiesComponent().addInitialProperty("cake", 
"strawberry")
+        loadRoutes """
+                - beans:
+                  - name: myBean
+                    type: ${MyBean.class.name}
+                    scriptLanguage: groovy
+                    script: "var b = new ${MyBean.class.name}(); b.field1 = 
'{{cheese}}'; b.field2 = '{{cake}}'; return b"
+            """
+
+        then:
+        with(context.registry.lookupByName('myBean'), MyBean) {
+            it.field1 == 'gauda'
+            it.field2 == 'strawberry'
+        }
+    }
+
+    def "beans with script property placeholder true"() {
+        when:
+        context.getPropertiesComponent().addInitialProperty("cheese", "gauda")
+        context.getPropertiesComponent().addInitialProperty("cake", 
"strawberry")
+        loadRoutes """
+                - beans:
+                  - name: myBean
+                    type: ${MyBean.class.name}
+                    scriptLanguage: groovy
+                    scriptPropertyPlaceholders: true
+                    script: "var b = new ${MyBean.class.name}(); b.field1 = 
'{{cheese}}'; b.field2 = '{{cake}}'; return b"
+            """
+
+        then:
+        with(context.registry.lookupByName('myBean'), MyBean) {
+            it.field1 == 'gauda'
+            it.field2 == 'strawberry'
+        }
+    }
+
+    def "beans with script property placeholder false"() {
+        when:
+        context.getPropertiesComponent().addInitialProperty("cheese", "gauda")
+        context.getPropertiesComponent().addInitialProperty("cake", 
"strawberry")
+        loadRoutes """
+                - beans:
+                  - name: myBean
+                    type: ${MyBean.class.name}
+                    scriptLanguage: groovy
+                    scriptPropertyPlaceholders: false
+                    script: "var b = new ${MyBean.class.name}(); b.field1 = 
'{{cheese}}'; b.field2 = '{{cake}}'; return b"
+            """
+
+        then:
+        with(context.registry.lookupByName('myBean'), MyBean) {
+            it.field1 == '{{cheese}}'
+            it.field2 == '{{cake}}'
+        }
+    }
+
     def "beans with builder class"() {
         when:
         loadRoutes """

Reply via email to