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

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

commit 2ef563021ddabc0847051ba553bb45367c7304b0
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Jul 16 13:58:46 2020 +0200

    CAMEL-15270: camel-main can configure route templates from properties files.
---
 .../org/apache/camel/main/BaseMainSupport.java     |  6 ++---
 .../apache/camel/main/MainRouteTemplateTest.java   |  2 ++
 .../src/test/resources/mytemplate.properties       | 12 +++++-----
 .../modules/ROOT/pages/route-template.adoc         | 28 ++++++++++++++++++++++
 4 files changed, 39 insertions(+), 9 deletions(-)

diff --git 
a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java 
b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
index 35307f7..8c499b5 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
@@ -832,10 +832,10 @@ public abstract class BaseMainSupport extends BaseService 
{
                 String option = key.substring(10);
                 validateOptionAndValue(key, option, value);
                 lraProperties.put(optionKey(option), value);
-            } else if (key.startsWith("camel.routetemplate")) {
+            } else if (key.startsWith("camel.route-template")) {
                 // grab the value
                 String value = prop.getProperty(key);
-                String option = key.substring(19);
+                String option = key.substring(20);
                 validateOptionAndValue(key, option, value);
                 routeTemplateProperties.put(optionKey(option), value);
             } else if (key.startsWith("camel.beans.")) {
@@ -1053,7 +1053,7 @@ public abstract class BaseMainSupport extends BaseService 
{
         // lets sort by keys
         Map<String, Object> sorted = new TreeMap<>(routeTemplateProperties);
         sorted.forEach((k, v) -> {
-            autoConfiguredProperties.put("camel.routetemplate" + k, 
v.toString());
+            autoConfiguredProperties.put("camel.route-template" + k, 
v.toString());
         });
         routeTemplateProperties.clear();
 
diff --git 
a/core/camel-main/src/test/java/org/apache/camel/main/MainRouteTemplateTest.java
 
b/core/camel-main/src/test/java/org/apache/camel/main/MainRouteTemplateTest.java
index 272bc00..a46e0e4 100644
--- 
a/core/camel-main/src/test/java/org/apache/camel/main/MainRouteTemplateTest.java
+++ 
b/core/camel-main/src/test/java/org/apache/camel/main/MainRouteTemplateTest.java
@@ -34,6 +34,8 @@ public class MainRouteTemplateTest {
             @Override
             public void configure() throws Exception {
                 routeTemplate("mytemplate")
+                    .templateParameter("input")
+                    .templateParameter("result")
                     .from("direct:{{input}}")
                         .to("mock:{{result}}");
             }
diff --git a/core/camel-main/src/test/resources/mytemplate.properties 
b/core/camel-main/src/test/resources/mytemplate.properties
index a440508..51b7e3c 100644
--- a/core/camel-main/src/test/resources/mytemplate.properties
+++ b/core/camel-main/src/test/resources/mytemplate.properties
@@ -15,10 +15,10 @@
 ## limitations under the License.
 ## ---------------------------------------------------------------------------
 
-camel.routetemplate[one].template-id=mytemplate
-camel.routetemplate[one].input=foo
-camel.routetemplate[one].result=cheese
+camel.route-template[one].template-id=mytemplate
+camel.route-template[one].input=foo
+camel.route-template[one].result=cheese
 
-camel.routetemplate[two].template-id=mytemplate
-camel.routetemplate[two].input=bar
-camel.routetemplate[two].result=cheese
+camel.route-template[two].template-id=mytemplate
+camel.route-template[two].input=bar
+camel.route-template[two].result=cheese
diff --git a/docs/user-manual/modules/ROOT/pages/route-template.adoc 
b/docs/user-manual/modules/ROOT/pages/route-template.adoc
index aba0734..f744eaa 100644
--- a/docs/user-manual/modules/ROOT/pages/route-template.adoc
+++ b/docs/user-manual/modules/ROOT/pages/route-template.adoc
@@ -138,6 +138,34 @@ Or with the fluent builder:
 
 The route templates can be dumped as XML from the `ManagedCamelContextMBean` 
MBean via the `dumpRouteTemplatesAsXml` operation.
 
+== Creating routes from properties file
+
+When using `camel-main` you can specify the parameters for route templates in 
`application.properties` file.
+
+For example given the route template below (from a `RouteBuilder` class):
+
+[source,java]
+----
+routeTemplate("mytemplate")
+    .templateParameter("input")
+    .templateParameter("result")
+    .from("direct:{{input}}")
+        .to("mock:{{result}}");
+----
+
+Then we can create two routes from this template by configuring the values in 
the `application.properties` file:
+
+[source,properties]
+----
+camel.route-template[one].template-id=mytemplate
+camel.route-template[one].input=foo
+camel.route-template[one].result=cheese
+
+camel.route-template[two].template-id=mytemplate
+camel.route-template[two].input=bar
+camel.route-template[two].result=cheese
+----
+
 == See Also
 
 See the example 
https://github.com/apache/camel-examples/tree/master/examples/camel-example-routetemplate[camel-example-routetemplate].

Reply via email to