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 bffbac31b3022675e37b373618982ad5d7cc8016 Author: Claus Ibsen <[email protected]> AuthorDate: Thu Jun 26 14:12:32 2025 +0200 CAMEL-22200: components that are resource endpoint based should have content cache true as default and make it configurable on component level. --- .../velocity/VelocityComponentConfigurer.java | 11 +++++++++++ .../apache/camel/component/velocity/velocity.json | 7 ++++--- .../camel/component/velocity/VelocityComponent.java | 21 +++++++++++++++++---- .../camel/component/velocity/VelocityEndpoint.java | 2 +- 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/components/camel-velocity/src/generated/java/org/apache/camel/component/velocity/VelocityComponentConfigurer.java b/components/camel-velocity/src/generated/java/org/apache/camel/component/velocity/VelocityComponentConfigurer.java index 11dbbdb3fbd..e941a91c0cb 100644 --- a/components/camel-velocity/src/generated/java/org/apache/camel/component/velocity/VelocityComponentConfigurer.java +++ b/components/camel-velocity/src/generated/java/org/apache/camel/component/velocity/VelocityComponentConfigurer.java @@ -29,6 +29,8 @@ public class VelocityComponentConfigurer 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 "velocityengine": @@ -37,6 +39,11 @@ public class VelocityComponentConfigurer extends PropertyConfigurerSupport imple } } + @Override + public String[] getAutowiredNames() { + return new String[]{"velocityEngine"}; + } + @Override public Class<?> getOptionType(String name, boolean ignoreCase) { switch (ignoreCase ? name.toLowerCase() : name) { @@ -46,6 +53,8 @@ public class VelocityComponentConfigurer 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 "velocityengine": @@ -64,6 +73,8 @@ public class VelocityComponentConfigurer 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 "velocityengine": diff --git a/components/camel-velocity/src/generated/resources/META-INF/org/apache/camel/component/velocity/velocity.json b/components/camel-velocity/src/generated/resources/META-INF/org/apache/camel/component/velocity/velocity.json index dcd7590efc5..d3fbb8ae517 100644 --- a/components/camel-velocity/src/generated/resources/META-INF/org/apache/camel/component/velocity/velocity.json +++ b/components/camel-velocity/src/generated/resources/META-INF/org/apache/camel/component/velocity/velocity.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 [...] - "velocityEngine": { "index": 4, "kind": "property", "displayName": "Velocity Engine", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.apache.velocity.app.VelocityEngine", "deprecated": false, "autowired": false, "secret": false, "description": "To use the VelocityEngine otherwise a new engine is created" } + "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 [...] + "velocityEngine": { "index": 5, "kind": "property", "displayName": "Velocity Engine", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.apache.velocity.app.VelocityEngine", "deprecated": false, "autowired": true, "secret": false, "description": "To use the VelocityEngine otherwise a new engine is created" } }, "headers": { "CamelVelocityResourceUri": { "index": 0, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The name of the velocity template.", "constantName": "org.apache.camel.component.velocity.VelocityConstants#VELOCITY_RESOURCE_URI" }, diff --git a/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityComponent.java b/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityComponent.java index a6e0c7554b2..cbaa6ced3a7 100644 --- a/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityComponent.java +++ b/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityComponent.java @@ -28,11 +28,13 @@ import org.apache.velocity.app.VelocityEngine; @Component("velocity") public class VelocityComponent extends DefaultComponent { - @Metadata(defaultValue = "false") + @Metadata(defaultValue = "true", description = "Sets whether to use resource content cache or not") + private boolean contentCache = true; + @Metadata private boolean allowTemplateFromHeader; - @Metadata(defaultValue = "false") + @Metadata private boolean allowContextMapAll; - @Metadata(label = "advanced") + @Metadata(label = "advanced", autowired = true) private VelocityEngine velocityEngine; public VelocityComponent() { @@ -49,6 +51,17 @@ public class VelocityComponent extends DefaultComponent { this.velocityEngine = velocityEngine; } + 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; } @@ -78,7 +91,7 @@ public class VelocityComponent extends DefaultComponent { @Override protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { - boolean cache = getAndRemoveParameter(parameters, "contentCache", Boolean.class, Boolean.TRUE); + boolean cache = getAndRemoveParameter(parameters, "contentCache", Boolean.class, contentCache); VelocityEndpoint answer = new VelocityEndpoint(uri, this, remaining); answer.setContentCache(cache); diff --git a/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java b/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java index 425ef61f76a..52317dd6bfd 100644 --- a/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java +++ b/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java @@ -51,7 +51,7 @@ public class VelocityEndpoint extends ResourceEndpoint { private VelocityEngine velocityEngine; - @UriParam(defaultValue = "false") + @UriParam private boolean allowTemplateFromHeader; @UriParam(defaultValue = "true") private boolean loaderCache = true;
