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 2025/06/26 14:20:50 UTC
(camel) 11/18: CAMEL-22200: components that are resource endpoint based should have content cache true as default and make it configurable on component level.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch re
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 8a92d1e948c9ef0e06bb2a8eb9684c6ef00fa7dc
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Jun 26 13:17:01 2025 +0200
CAMEL-22200: components that are resource endpoint based should have content cache true as default and make it configurable on component level.
---
.../apache/camel/catalog/components/mustache.json | 7 +--
.../mustache/MustacheComponentConfigurer.java | 11 +++++
.../apache/camel/component/mustache/mustache.json | 7 +--
.../component/mustache/MustacheComponent.java | 21 ++++++--
.../camel/component/mustache/MustacheEndpoint.java | 2 +-
.../camel/component/mustache/MustacheRefTest.java | 56 ++++++++++++++++++++++
6 files changed, 93 insertions(+), 11 deletions(-)
diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/mustache.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/mustache.json
index 96732818c3f..09fde2aa0d4 100644
--- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/mustache.json
+++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/mustache.json
@@ -26,9 +26,10 @@
"componentProperties": {
"allowContextMapAll": { "index": 0, "kind": "property", "displayName": "Allow Context Map All", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Sets whether the context map should allow access to all details. By default only the message body and headers can be accessed. This option can be enabled for full access to the current Exchange and Ca [...]
"allowTemplateFromHeader": { "index": 1, "kind": "property", "displayName": "Allow Template From Header", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to allow to use resource template from header or not (default false). Enabling this allows to specify dynamic templates via message header. However this can be seen as a potential se [...]
- "lazyStartProducer": { "index": 2, "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail [...]
- "autowiredEnabled": { "index": 3, "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching t [...]
- "mustacheFactory": { "index": 4, "kind": "property", "displayName": "Mustache Factory", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "com.github.mustachejava.MustacheFactory", "deprecated": false, "autowired": false, "secret": false, "description": "To use a custom MustacheFactory" }
+ "contentCache": { "index": 2, "kind": "property", "displayName": "Content Cache", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Sets whether to use resource content cache or not" },
+ "lazyStartProducer": { "index": 3, "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail [...]
+ "autowiredEnabled": { "index": 4, "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching t [...]
+ "mustacheFactory": { "index": 5, "kind": "property", "displayName": "Mustache Factory", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "com.github.mustachejava.MustacheFactory", "deprecated": false, "autowired": true, "secret": false, "description": "To use a custom MustacheFactory" }
},
"headers": {
"MustacheResourceUri": { "index": 0, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "A URI for the template resource to use instead of the endpoint.", "constantName": "org.apache.camel.component.mustache.MustacheConstants#MUSTACHE_RESOURCE_URI" },
diff --git a/components/camel-mustache/src/generated/java/org/apache/camel/component/mustache/MustacheComponentConfigurer.java b/components/camel-mustache/src/generated/java/org/apache/camel/component/mustache/MustacheComponentConfigurer.java
index e5bbf68bdc6..75c77dcc720 100644
--- a/components/camel-mustache/src/generated/java/org/apache/camel/component/mustache/MustacheComponentConfigurer.java
+++ b/components/camel-mustache/src/generated/java/org/apache/camel/component/mustache/MustacheComponentConfigurer.java
@@ -29,6 +29,8 @@ public class MustacheComponentConfigurer extends PropertyConfigurerSupport imple
case "allowTemplateFromHeader": target.setAllowTemplateFromHeader(property(camelContext, boolean.class, value)); return true;
case "autowiredenabled":
case "autowiredEnabled": target.setAutowiredEnabled(property(camelContext, boolean.class, value)); return true;
+ case "contentcache":
+ case "contentCache": target.setContentCache(property(camelContext, boolean.class, value)); return true;
case "lazystartproducer":
case "lazyStartProducer": target.setLazyStartProducer(property(camelContext, boolean.class, value)); return true;
case "mustachefactory":
@@ -37,6 +39,11 @@ public class MustacheComponentConfigurer extends PropertyConfigurerSupport imple
}
}
+ @Override
+ public String[] getAutowiredNames() {
+ return new String[]{"mustacheFactory"};
+ }
+
@Override
public Class<?> getOptionType(String name, boolean ignoreCase) {
switch (ignoreCase ? name.toLowerCase() : name) {
@@ -46,6 +53,8 @@ public class MustacheComponentConfigurer extends PropertyConfigurerSupport imple
case "allowTemplateFromHeader": return boolean.class;
case "autowiredenabled":
case "autowiredEnabled": return boolean.class;
+ case "contentcache":
+ case "contentCache": return boolean.class;
case "lazystartproducer":
case "lazyStartProducer": return boolean.class;
case "mustachefactory":
@@ -64,6 +73,8 @@ public class MustacheComponentConfigurer extends PropertyConfigurerSupport imple
case "allowTemplateFromHeader": return target.isAllowTemplateFromHeader();
case "autowiredenabled":
case "autowiredEnabled": return target.isAutowiredEnabled();
+ case "contentcache":
+ case "contentCache": return target.isContentCache();
case "lazystartproducer":
case "lazyStartProducer": return target.isLazyStartProducer();
case "mustachefactory":
diff --git a/components/camel-mustache/src/generated/resources/META-INF/org/apache/camel/component/mustache/mustache.json b/components/camel-mustache/src/generated/resources/META-INF/org/apache/camel/component/mustache/mustache.json
index 96732818c3f..09fde2aa0d4 100644
--- a/components/camel-mustache/src/generated/resources/META-INF/org/apache/camel/component/mustache/mustache.json
+++ b/components/camel-mustache/src/generated/resources/META-INF/org/apache/camel/component/mustache/mustache.json
@@ -26,9 +26,10 @@
"componentProperties": {
"allowContextMapAll": { "index": 0, "kind": "property", "displayName": "Allow Context Map All", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Sets whether the context map should allow access to all details. By default only the message body and headers can be accessed. This option can be enabled for full access to the current Exchange and Ca [...]
"allowTemplateFromHeader": { "index": 1, "kind": "property", "displayName": "Allow Template From Header", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to allow to use resource template from header or not (default false). Enabling this allows to specify dynamic templates via message header. However this can be seen as a potential se [...]
- "lazyStartProducer": { "index": 2, "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail [...]
- "autowiredEnabled": { "index": 3, "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching t [...]
- "mustacheFactory": { "index": 4, "kind": "property", "displayName": "Mustache Factory", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "com.github.mustachejava.MustacheFactory", "deprecated": false, "autowired": false, "secret": false, "description": "To use a custom MustacheFactory" }
+ "contentCache": { "index": 2, "kind": "property", "displayName": "Content Cache", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Sets whether to use resource content cache or not" },
+ "lazyStartProducer": { "index": 3, "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail [...]
+ "autowiredEnabled": { "index": 4, "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching t [...]
+ "mustacheFactory": { "index": 5, "kind": "property", "displayName": "Mustache Factory", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "com.github.mustachejava.MustacheFactory", "deprecated": false, "autowired": true, "secret": false, "description": "To use a custom MustacheFactory" }
},
"headers": {
"MustacheResourceUri": { "index": 0, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "A URI for the template resource to use instead of the endpoint.", "constantName": "org.apache.camel.component.mustache.MustacheConstants#MUSTACHE_RESOURCE_URI" },
diff --git a/components/camel-mustache/src/main/java/org/apache/camel/component/mustache/MustacheComponent.java b/components/camel-mustache/src/main/java/org/apache/camel/component/mustache/MustacheComponent.java
index 83ae0009c4e..57c539e47aa 100644
--- a/components/camel-mustache/src/main/java/org/apache/camel/component/mustache/MustacheComponent.java
+++ b/components/camel-mustache/src/main/java/org/apache/camel/component/mustache/MustacheComponent.java
@@ -36,12 +36,13 @@ import org.apache.camel.support.DefaultComponent;
@Component("mustache")
public class MustacheComponent extends DefaultComponent {
- @Metadata(defaultValue = "false")
+ @Metadata(defaultValue = "true", description = "Sets whether to use resource content cache or not")
+ private boolean contentCache;
+ @Metadata
private boolean allowTemplateFromHeader;
- @Metadata(defaultValue = "false")
+ @Metadata
private boolean allowContextMapAll;
-
- @Metadata(label = "advanced")
+ @Metadata(label = "advanced", autowired = true)
private MustacheFactory mustacheFactory = new DefaultMustacheFactory();
public MustacheComponent() {
@@ -51,6 +52,7 @@ public class MustacheComponent extends DefaultComponent {
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
MustacheEndpoint endpoint = new MustacheEndpoint(uri, this, remaining);
endpoint.setMustacheFactory(getMustacheFactory());
+ endpoint.setContentCache(contentCache);
endpoint.setAllowTemplateFromHeader(allowTemplateFromHeader);
endpoint.setAllowContextMapAll(allowContextMapAll);
setProperties(endpoint, parameters);
@@ -68,6 +70,17 @@ public class MustacheComponent extends DefaultComponent {
this.mustacheFactory = mustacheFactory;
}
+ public boolean isContentCache() {
+ return contentCache;
+ }
+
+ /**
+ * Sets whether to use resource content cache or not
+ */
+ public void setContentCache(boolean contentCache) {
+ this.contentCache = contentCache;
+ }
+
public boolean isAllowTemplateFromHeader() {
return allowTemplateFromHeader;
}
diff --git a/components/camel-mustache/src/main/java/org/apache/camel/component/mustache/MustacheEndpoint.java b/components/camel-mustache/src/main/java/org/apache/camel/component/mustache/MustacheEndpoint.java
index 9038f60deeb..9debf7fca3f 100644
--- a/components/camel-mustache/src/main/java/org/apache/camel/component/mustache/MustacheEndpoint.java
+++ b/components/camel-mustache/src/main/java/org/apache/camel/component/mustache/MustacheEndpoint.java
@@ -50,7 +50,7 @@ public class MustacheEndpoint extends ResourceEndpoint {
private MustacheFactory mustacheFactory;
private Mustache mustache;
- @UriParam(defaultValue = "false")
+ @UriParam
private boolean allowTemplateFromHeader;
@UriParam
private String encoding;
diff --git a/components/camel-mustache/src/test/java/org/apache/camel/component/mustache/MustacheRefTest.java b/components/camel-mustache/src/test/java/org/apache/camel/component/mustache/MustacheRefTest.java
new file mode 100644
index 00000000000..b7ca9be7362
--- /dev/null
+++ b/components/camel-mustache/src/test/java/org/apache/camel/component/mustache/MustacheRefTest.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.mustache;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class MustacheRefTest extends CamelTestSupport {
+
+ private static final String TEMP = "Dear {{headers.lastName}}, {{headers.firstName}}";
+
+ @Test
+ public void testRef() {
+ Exchange exchange = template.request("direct:a", new Processor() {
+ @Override
+ public void process(Exchange exchange) {
+ exchange.getIn().setBody("Hello");
+ exchange.getIn().setHeader("firstName", "Jack");
+ exchange.getIn().setHeader("lastName", "Sparrow");
+ }
+ });
+
+ assertEquals("Dear Sparrow, Jack", exchange.getMessage().getBody());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ context.getRegistry().bind("mytemp", TEMP);
+
+ from("direct:a").to(
+ "mustache:ref:mytemp");
+ }
+ };
+ }
+}