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 f6ae0a8f1bdceb7a0cf34be9323349fcf8d8c532 Author: Claus Ibsen <[email protected]> AuthorDate: Thu Jun 26 14:07:52 2025 +0200 CAMEL-22200: components that are resource endpoint based should have content cache true as default and make it configurable on component level. --- .../StringTemplateComponentConfigurer.java | 6 +++ .../component/stringtemplate/string-template.json | 5 +- .../stringtemplate/StringTemplateComponent.java | 18 ++++++- .../stringtemplate/StringTemplateEndpoint.java | 2 +- .../stringtemplate/StringTemplateRefTest.java | 57 +++++++++++++++++++++ .../thymeleaf/ThymeleafComponentConfigurer.java | 12 +++++ .../thymeleaf/ThymeleafEndpointConfigurer.java | 12 ++--- .../thymeleaf/ThymeleafEndpointUriFactory.java | 2 +- .../camel/component/thymeleaf/thymeleaf.json | 14 ++--- .../component/thymeleaf/ThymeleafComponent.java | 38 ++++++++++++-- .../component/thymeleaf/ThymeleafEndpoint.java | 59 ++++++++++++++-------- .../ThymeleafDefaultResolverAllParamsTest.java | 4 +- .../thymeleaf/ThymeleafDefaultResolverTest.java | 4 +- .../thymeleaf/ThymeleafResourceUriTest.java | 7 +-- .../ThymeleafStringResolverAllParamsTest.java | 4 +- .../thymeleaf/ThymeleafStringResolverTest.java | 4 +- .../thymeleaf/ThymeleafTemplateAsHeaderTest.java | 5 +- .../ThymeleafUrlResolverAllParamsTest.java | 10 ++-- .../thymeleaf/ThymeleafUrlResolverTest.java | 10 ++-- .../thymeleaf/ThymeleafVariableMapHeaderTest.java | 7 +-- 20 files changed, 204 insertions(+), 76 deletions(-) diff --git a/components/camel-stringtemplate/src/generated/java/org/apache/camel/component/stringtemplate/StringTemplateComponentConfigurer.java b/components/camel-stringtemplate/src/generated/java/org/apache/camel/component/stringtemplate/StringTemplateComponentConfigurer.java index 838317a2e1a..98b8606792f 100644 --- a/components/camel-stringtemplate/src/generated/java/org/apache/camel/component/stringtemplate/StringTemplateComponentConfigurer.java +++ b/components/camel-stringtemplate/src/generated/java/org/apache/camel/component/stringtemplate/StringTemplateComponentConfigurer.java @@ -29,6 +29,8 @@ public class StringTemplateComponentConfigurer extends PropertyConfigurerSupport 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; default: return false; @@ -44,6 +46,8 @@ public class StringTemplateComponentConfigurer extends PropertyConfigurerSupport 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; default: return null; @@ -60,6 +64,8 @@ public class StringTemplateComponentConfigurer extends PropertyConfigurerSupport 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(); default: return null; diff --git a/components/camel-stringtemplate/src/generated/resources/META-INF/org/apache/camel/component/stringtemplate/string-template.json b/components/camel-stringtemplate/src/generated/resources/META-INF/org/apache/camel/component/stringtemplate/string-template.json index 8bb992d3a57..7d502750dbf 100644 --- a/components/camel-stringtemplate/src/generated/resources/META-INF/org/apache/camel/component/stringtemplate/string-template.json +++ b/components/camel-stringtemplate/src/generated/resources/META-INF/org/apache/camel/component/stringtemplate/string-template.json @@ -26,8 +26,9 @@ "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 [...] + "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 [...] }, "headers": { "CamelStringTemplateResourceUri": { "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 configured.", "constantName": "org.apache.camel.component.stringtemplate.StringTemplateConstants#STRINGTEMPLATE_RESOURCE_URI" }, diff --git a/components/camel-stringtemplate/src/main/java/org/apache/camel/component/stringtemplate/StringTemplateComponent.java b/components/camel-stringtemplate/src/main/java/org/apache/camel/component/stringtemplate/StringTemplateComponent.java index 17c6e0a4ac6..8801cf051d7 100644 --- a/components/camel-stringtemplate/src/main/java/org/apache/camel/component/stringtemplate/StringTemplateComponent.java +++ b/components/camel-stringtemplate/src/main/java/org/apache/camel/component/stringtemplate/StringTemplateComponent.java @@ -27,9 +27,11 @@ import org.apache.camel.support.ResourceHelper; @Component("string-template") public class StringTemplateComponent 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; public StringTemplateComponent() { @@ -38,6 +40,7 @@ public class StringTemplateComponent extends DefaultComponent { @Override protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { StringTemplateEndpoint answer = new StringTemplateEndpoint(uri, this, remaining); + answer.setContentCache(contentCache); answer.setAllowTemplateFromHeader(allowTemplateFromHeader); answer.setAllowContextMapAll(allowContextMapAll); setProperties(answer, parameters); @@ -51,6 +54,17 @@ public class StringTemplateComponent extends DefaultComponent { return answer; } + 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-stringtemplate/src/main/java/org/apache/camel/component/stringtemplate/StringTemplateEndpoint.java b/components/camel-stringtemplate/src/main/java/org/apache/camel/component/stringtemplate/StringTemplateEndpoint.java index 71a51579c4a..8fee752f12f 100644 --- a/components/camel-stringtemplate/src/main/java/org/apache/camel/component/stringtemplate/StringTemplateEndpoint.java +++ b/components/camel-stringtemplate/src/main/java/org/apache/camel/component/stringtemplate/StringTemplateEndpoint.java @@ -41,7 +41,7 @@ import org.stringtemplate.v4.STGroup; headersClass = StringTemplateConstants.class) public class StringTemplateEndpoint extends ResourceEndpoint { - @UriParam(defaultValue = "false") + @UriParam private boolean allowTemplateFromHeader; @UriParam(defaultValue = "<") private char delimiterStart = STGroup.defaultGroup.delimiterStartChar; diff --git a/components/camel-stringtemplate/src/test/java/org/apache/camel/component/stringtemplate/StringTemplateRefTest.java b/components/camel-stringtemplate/src/test/java/org/apache/camel/component/stringtemplate/StringTemplateRefTest.java new file mode 100644 index 00000000000..b04cd0b49d6 --- /dev/null +++ b/components/camel-stringtemplate/src/test/java/org/apache/camel/component/stringtemplate/StringTemplateRefTest.java @@ -0,0 +1,57 @@ +/* + * 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.stringtemplate; + +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 StringTemplateRefTest extends CamelTestSupport { + + private static final String TEMP = "Hello <headers.name>. You ordered item <exchange.properties.item> on <body>."; + + @Test + public void testRef() { + Exchange exchange = template.request("direct:a", new Processor() { + @Override + public void process(Exchange exchange) { + exchange.getIn().setBody("Tuesday"); + exchange.getIn().setHeader("name", "Christian"); + exchange.setProperty("item", "8"); + } + }); + + assertEquals("Hello Christian. You ordered item 8 on Tuesday.", exchange.getMessage().getBody()); + assertEquals("Christian", exchange.getMessage().getHeader("name")); + } + + @Override + protected RouteBuilder createRouteBuilder() { + return new RouteBuilder() { + public void configure() { + context.getRegistry().bind("mytemp", TEMP); + + from("direct:a").to( + "string-template:ref:mytemp?allowContextMapAll=true"); + } + }; + } +} diff --git a/components/camel-thymeleaf/src/generated/java/org/apache/camel/component/thymeleaf/ThymeleafComponentConfigurer.java b/components/camel-thymeleaf/src/generated/java/org/apache/camel/component/thymeleaf/ThymeleafComponentConfigurer.java index f34e483a726..ceeec049879 100644 --- a/components/camel-thymeleaf/src/generated/java/org/apache/camel/component/thymeleaf/ThymeleafComponentConfigurer.java +++ b/components/camel-thymeleaf/src/generated/java/org/apache/camel/component/thymeleaf/ThymeleafComponentConfigurer.java @@ -23,6 +23,10 @@ public class ThymeleafComponentConfigurer extends PropertyConfigurerSupport impl public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) { ThymeleafComponent target = (ThymeleafComponent) obj; switch (ignoreCase ? name.toLowerCase() : name) { + case "allowcontextmapall": + case "allowContextMapAll": target.setAllowContextMapAll(property(camelContext, boolean.class, value)); return true; + case "allowtemplatefromheader": + 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 "lazystartproducer": @@ -34,6 +38,10 @@ public class ThymeleafComponentConfigurer extends PropertyConfigurerSupport impl @Override public Class<?> getOptionType(String name, boolean ignoreCase) { switch (ignoreCase ? name.toLowerCase() : name) { + case "allowcontextmapall": + case "allowContextMapAll": return boolean.class; + case "allowtemplatefromheader": + case "allowTemplateFromHeader": return boolean.class; case "autowiredenabled": case "autowiredEnabled": return boolean.class; case "lazystartproducer": @@ -46,6 +54,10 @@ public class ThymeleafComponentConfigurer extends PropertyConfigurerSupport impl public Object getOptionValue(Object obj, String name, boolean ignoreCase) { ThymeleafComponent target = (ThymeleafComponent) obj; switch (ignoreCase ? name.toLowerCase() : name) { + case "allowcontextmapall": + case "allowContextMapAll": return target.isAllowContextMapAll(); + case "allowtemplatefromheader": + case "allowTemplateFromHeader": return target.isAllowTemplateFromHeader(); case "autowiredenabled": case "autowiredEnabled": return target.isAutowiredEnabled(); case "lazystartproducer": diff --git a/components/camel-thymeleaf/src/generated/java/org/apache/camel/component/thymeleaf/ThymeleafEndpointConfigurer.java b/components/camel-thymeleaf/src/generated/java/org/apache/camel/component/thymeleaf/ThymeleafEndpointConfigurer.java index b277bab2c1b..e1201c41415 100644 --- a/components/camel-thymeleaf/src/generated/java/org/apache/camel/component/thymeleaf/ThymeleafEndpointConfigurer.java +++ b/components/camel-thymeleaf/src/generated/java/org/apache/camel/component/thymeleaf/ThymeleafEndpointConfigurer.java @@ -25,13 +25,13 @@ public class ThymeleafEndpointConfigurer extends PropertyConfigurerSupport imple switch (ignoreCase ? name.toLowerCase() : name) { case "allowcontextmapall": case "allowContextMapAll": target.setAllowContextMapAll(property(camelContext, boolean.class, value)); return true; + case "allowtemplatefromheader": + case "allowTemplateFromHeader": target.setAllowTemplateFromHeader(property(camelContext, boolean.class, value)); return true; case "cachetimetolive": case "cacheTimeToLive": target.setCacheTimeToLive(property(camelContext, java.lang.Long.class, value)); return true; case "cacheable": target.setCacheable(property(camelContext, java.lang.Boolean.class, value)); return true; case "checkexistence": case "checkExistence": target.setCheckExistence(property(camelContext, java.lang.Boolean.class, value)); return true; - case "contentcache": - case "contentCache": target.setContentCache(property(camelContext, boolean.class, value)); return true; case "encoding": target.setEncoding(property(camelContext, java.lang.String.class, value)); return true; case "lazystartproducer": case "lazyStartProducer": target.setLazyStartProducer(property(camelContext, boolean.class, value)); return true; @@ -50,13 +50,13 @@ public class ThymeleafEndpointConfigurer extends PropertyConfigurerSupport imple switch (ignoreCase ? name.toLowerCase() : name) { case "allowcontextmapall": case "allowContextMapAll": return boolean.class; + case "allowtemplatefromheader": + case "allowTemplateFromHeader": return boolean.class; case "cachetimetolive": case "cacheTimeToLive": return java.lang.Long.class; case "cacheable": return java.lang.Boolean.class; case "checkexistence": case "checkExistence": return java.lang.Boolean.class; - case "contentcache": - case "contentCache": return boolean.class; case "encoding": return java.lang.String.class; case "lazystartproducer": case "lazyStartProducer": return boolean.class; @@ -76,13 +76,13 @@ public class ThymeleafEndpointConfigurer extends PropertyConfigurerSupport imple switch (ignoreCase ? name.toLowerCase() : name) { case "allowcontextmapall": case "allowContextMapAll": return target.isAllowContextMapAll(); + case "allowtemplatefromheader": + case "allowTemplateFromHeader": return target.isAllowTemplateFromHeader(); case "cachetimetolive": case "cacheTimeToLive": return target.getCacheTimeToLive(); case "cacheable": return target.getCacheable(); case "checkexistence": case "checkExistence": return target.getCheckExistence(); - case "contentcache": - case "contentCache": return target.isContentCache(); case "encoding": return target.getEncoding(); case "lazystartproducer": case "lazyStartProducer": return target.isLazyStartProducer(); diff --git a/components/camel-thymeleaf/src/generated/java/org/apache/camel/component/thymeleaf/ThymeleafEndpointUriFactory.java b/components/camel-thymeleaf/src/generated/java/org/apache/camel/component/thymeleaf/ThymeleafEndpointUriFactory.java index d2fa4a96d43..15c7c3a915b 100644 --- a/components/camel-thymeleaf/src/generated/java/org/apache/camel/component/thymeleaf/ThymeleafEndpointUriFactory.java +++ b/components/camel-thymeleaf/src/generated/java/org/apache/camel/component/thymeleaf/ThymeleafEndpointUriFactory.java @@ -25,10 +25,10 @@ public class ThymeleafEndpointUriFactory extends org.apache.camel.support.compon static { Set<String> props = new HashSet<>(13); props.add("allowContextMapAll"); + props.add("allowTemplateFromHeader"); props.add("cacheTimeToLive"); props.add("cacheable"); props.add("checkExistence"); - props.add("contentCache"); props.add("encoding"); props.add("lazyStartProducer"); props.add("order"); diff --git a/components/camel-thymeleaf/src/generated/resources/META-INF/org/apache/camel/component/thymeleaf/thymeleaf.json b/components/camel-thymeleaf/src/generated/resources/META-INF/org/apache/camel/component/thymeleaf/thymeleaf.json index 72b13e00181..5e3b6ae1d4e 100644 --- a/components/camel-thymeleaf/src/generated/resources/META-INF/org/apache/camel/component/thymeleaf/thymeleaf.json +++ b/components/camel-thymeleaf/src/generated/resources/META-INF/org/apache/camel/component/thymeleaf/thymeleaf.json @@ -24,8 +24,10 @@ "remote": false }, "componentProperties": { - "lazyStartProducer": { "index": 0, "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": 1, "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 [...] + "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 [...] }, "headers": { "CamelThymeleafResourceUri": { "index": 0, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The name of the Thymeleaf template.", "constantName": "org.apache.camel.component.thymeleaf.ThymeleafConstants#THYMELEAF_RESOURCE_URI" }, @@ -36,10 +38,10 @@ "properties": { "resourceUri": { "index": 0, "kind": "path", "displayName": "Resource Uri", "group": "producer", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "supportFileReference": true, "description": "Path to the resource. You can prefix with: classpath, file, http, ref, or bean. classpath, file and http loads the resource using these protocols (classpath is default). ref will look [...] "allowContextMapAll": { "index": 1, "kind": "parameter", "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 C [...] - "cacheable": { "index": 2, "kind": "parameter", "displayName": "Cacheable", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "description": "Whether templates have to be considered cacheable or not." }, - "cacheTimeToLive": { "index": 3, "kind": "parameter", "displayName": "Cache Time To Live", "group": "producer", "label": "", "required": false, "type": "integer", "javaType": "java.lang.Long", "deprecated": false, "autowired": false, "secret": false, "description": "The cache Time To Live for templates, expressed in milliseconds." }, - "checkExistence": { "index": 4, "kind": "parameter", "displayName": "Check Existence", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "description": "Whether a template resources will be checked for existence before being returned." }, - "contentCache": { "index": 5, "kind": "parameter", "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" }, + "allowTemplateFromHeader": { "index": 2, "kind": "parameter", "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 s [...] + "cacheable": { "index": 3, "kind": "parameter", "displayName": "Cacheable", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "description": "Whether templates have to be considered cacheable or not." }, + "cacheTimeToLive": { "index": 4, "kind": "parameter", "displayName": "Cache Time To Live", "group": "producer", "label": "", "required": false, "type": "integer", "javaType": "java.lang.Long", "deprecated": false, "autowired": false, "secret": false, "description": "The cache Time To Live for templates, expressed in milliseconds." }, + "checkExistence": { "index": 5, "kind": "parameter", "displayName": "Check Existence", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "description": "Whether a template resources will be checked for existence before being returned." }, "templateMode": { "index": 6, "kind": "parameter", "displayName": "Template Mode", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "HTML", "XML", "TEXT", "JAVASCRIPT", "CSS", "RAW" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "HTML", "description": "The template mode to be applied to templates." }, "lazyStartProducer": { "index": 7, "kind": "parameter", "displayName": "Lazy Start Producer", "group": "producer (advanced)", "label": "producer,advanced", "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 produc [...] "encoding": { "index": 8, "kind": "parameter", "displayName": "Encoding", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The character encoding to be used for reading template resources." }, diff --git a/components/camel-thymeleaf/src/main/java/org/apache/camel/component/thymeleaf/ThymeleafComponent.java b/components/camel-thymeleaf/src/main/java/org/apache/camel/component/thymeleaf/ThymeleafComponent.java index 014a21e0d57..a3f4c459771 100644 --- a/components/camel-thymeleaf/src/main/java/org/apache/camel/component/thymeleaf/ThymeleafComponent.java +++ b/components/camel-thymeleaf/src/main/java/org/apache/camel/component/thymeleaf/ThymeleafComponent.java @@ -19,23 +19,55 @@ package org.apache.camel.component.thymeleaf; import java.util.Map; import org.apache.camel.Endpoint; +import org.apache.camel.spi.Metadata; import org.apache.camel.spi.annotations.Component; import org.apache.camel.support.DefaultComponent; @Component("thymeleaf") public class ThymeleafComponent extends DefaultComponent { - public ThymeleafComponent() { + @Metadata + private boolean allowTemplateFromHeader; + @Metadata + private boolean allowContextMapAll; + public ThymeleafComponent() { } @Override protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { - ThymeleafEndpoint endpoint = new ThymeleafEndpoint(uri, this, remaining); + endpoint.setAllowTemplateFromHeader(allowTemplateFromHeader); + endpoint.setAllowContextMapAll(allowContextMapAll); setProperties(endpoint, parameters); - return endpoint; } + public boolean isAllowContextMapAll() { + return allowContextMapAll; + } + + /** + * 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 CamelContext. Doing so impose + * a potential security risk as this opens access to the full power of CamelContext API. + */ + public void setAllowContextMapAll(boolean allowContextMapAll) { + this.allowContextMapAll = allowContextMapAll; + } + + public boolean isAllowTemplateFromHeader() { + return allowTemplateFromHeader; + } + + /** + * 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 + * security vulnerability if the header is coming from a malicious user, so use this with care. + */ + public void setAllowTemplateFromHeader(boolean allowTemplateFromHeader) { + this.allowTemplateFromHeader = allowTemplateFromHeader; + } + } diff --git a/components/camel-thymeleaf/src/main/java/org/apache/camel/component/thymeleaf/ThymeleafEndpoint.java b/components/camel-thymeleaf/src/main/java/org/apache/camel/component/thymeleaf/ThymeleafEndpoint.java index 0c7f49ef59c..28366d76896 100644 --- a/components/camel-thymeleaf/src/main/java/org/apache/camel/component/thymeleaf/ThymeleafEndpoint.java +++ b/components/camel-thymeleaf/src/main/java/org/apache/camel/component/thymeleaf/ThymeleafEndpoint.java @@ -24,6 +24,7 @@ import org.apache.camel.Exchange; import org.apache.camel.ExchangePattern; import org.apache.camel.RuntimeCamelException; import org.apache.camel.component.ResourceEndpoint; +import org.apache.camel.spi.Metadata; import org.apache.camel.spi.UriEndpoint; import org.apache.camel.spi.UriParam; import org.apache.camel.support.ExchangeHelper; @@ -47,6 +48,7 @@ import org.thymeleaf.web.servlet.JakartaServletWebApplication; @UriEndpoint(firstVersion = "4.1.0", scheme = "thymeleaf", title = "Thymeleaf", syntax = "thymeleaf:resourceUri", remote = false, producerOnly = true, category = { Category.TRANSFORMATION }, headersClass = ThymeleafConstants.class) +@Metadata(excludeProperties = "contentCache") public class ThymeleafEndpoint extends ResourceEndpoint { private TemplateEngine templateEngine; @@ -77,6 +79,8 @@ public class ThymeleafEndpoint extends ResourceEndpoint { private Long cacheTimeToLive; @UriParam(description = "Whether templates have to be considered cacheable or not.") private Boolean cacheable; + @UriParam + private boolean allowTemplateFromHeader; public ThymeleafEndpoint() { } @@ -243,6 +247,20 @@ public class ThymeleafEndpoint extends ResourceEndpoint { this.cacheable = cacheable; } + public boolean isAllowTemplateFromHeader() { + return allowTemplateFromHeader; + } + + /** + * 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 + * security vulnerability if the header is coming from a malicious user, so use this with care. + */ + public void setAllowTemplateFromHeader(boolean allowTemplateFromHeader) { + this.allowTemplateFromHeader = allowTemplateFromHeader; + } + protected TemplateEngine getTemplateEngine() { getInternalLock().lock(); try { @@ -316,27 +334,28 @@ public class ThymeleafEndpoint extends ResourceEndpoint { String path = getResourceUri(); ObjectHelper.notNull(path, "resourceUri"); - String newResourceUri = exchange.getIn().getHeader(ThymeleafConstants.THYMELEAF_RESOURCE_URI, String.class); - if (newResourceUri != null) { - // remove the header so that it is not propagated in the exchange - exchange.getIn().removeHeader(ThymeleafConstants.THYMELEAF_RESOURCE_URI); - - log.debug("{} set to {}, creating new endpoint to handle exchange", - ThymeleafConstants.THYMELEAF_RESOURCE_URI, newResourceUri); - try (ThymeleafEndpoint newEndpoint = findOrCreateEndpoint(getEndpointUri(), newResourceUri)) { - newEndpoint.onExchange(exchange); + if (allowTemplateFromHeader) { + String newResourceUri = exchange.getIn().getHeader(ThymeleafConstants.THYMELEAF_RESOURCE_URI, String.class); + if (newResourceUri != null) { + // remove the header so that it is not propagated in the exchange + exchange.getIn().removeHeader(ThymeleafConstants.THYMELEAF_RESOURCE_URI); + log.debug("{} set to {}, creating new endpoint to handle exchange", + ThymeleafConstants.THYMELEAF_RESOURCE_URI, newResourceUri); + try (ThymeleafEndpoint newEndpoint = findOrCreateEndpoint(getEndpointUri(), newResourceUri)) { + newEndpoint.onExchange(exchange); + } + return; } - - return; } - String template = exchange.getIn().getHeader(ThymeleafConstants.THYMELEAF_TEMPLATE, String.class); - if (template != null) { - this.template = template; + String template = null; + if (allowTemplateFromHeader) { + template = exchange.getIn().getHeader(ThymeleafConstants.THYMELEAF_TEMPLATE, String.class); // remove the header so that it is not propagated in the exchange exchange.getIn().removeHeader(ThymeleafConstants.THYMELEAF_TEMPLATE); - } else { - this.template = path; + } + if (template == null) { + template = path; } @SuppressWarnings("unchecked") @@ -345,21 +364,21 @@ public class ThymeleafEndpoint extends ResourceEndpoint { dataModel = ExchangeHelper.createVariableMap(exchange, isAllowContextMapAll()); } else { ExchangeHelper.populateVariableMap(exchange, dataModel, isAllowContextMapAll()); - // remove the header so that it is not propagated in the exchange exchange.getIn().removeHeader(ThymeleafConstants.THYMELEAF_VARIABLE_MAP); } - if (!resolver.equals(ThymeleafResolverType.URL) && ResourceHelper.hasScheme(this.template)) { + if (!resolver.equals(ThymeleafResolverType.URL) && ResourceHelper.hasScheme(template)) { // favour to use Camel to load via resource loader - this.template = IOHelper.loadText(getResourceAsInputStream()); + template = IOHelper.loadText(getResourceAsInputStream()); } + this.template = template; // let thymeleaf parse and generate the result TemplateEngine templateEngine = getTemplateEngine(); Context context = new Context(); context.setVariables(dataModel); - String buffer = templateEngine.process(this.template, context); + String buffer = templateEngine.process(template, context); // store the result in the exchange body ExchangeHelper.setInOutBodyPatternAware(exchange, buffer); diff --git a/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafDefaultResolverAllParamsTest.java b/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafDefaultResolverAllParamsTest.java index 8596c2fef59..58738a0c894 100644 --- a/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafDefaultResolverAllParamsTest.java +++ b/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafDefaultResolverAllParamsTest.java @@ -49,7 +49,7 @@ public class ThymeleafDefaultResolverAllParamsTest extends ThymeleafAbstractBase mock.assertIsSatisfied(); ThymeleafEndpoint thymeleafEndpoint = context.getEndpoint( - "thymeleaf:dontcare?allowContextMapAll=true&checkExistence=false&order=1&resolver=DEFAULT", + "thymeleaf:dontcare?allowTemplateFromHeader=true&allowContextMapAll=true&checkExistence=false&order=1&resolver=DEFAULT", ThymeleafEndpoint.class); assertAll("properties", @@ -87,7 +87,7 @@ public class ThymeleafDefaultResolverAllParamsTest extends ThymeleafAbstractBase from(DIRECT_START) .setBody(simple(SPAZZ_TESTING_SERVICE)) - .to("thymeleaf:dontcare?allowContextMapAll=true&checkExistence=false&order=1&resolver=DEFAULT") + .to("thymeleaf:dontcare?allowTemplateFromHeader=true&allowContextMapAll=true&checkExistence=false&order=1&resolver=DEFAULT") .to(MOCK_RESULT); } }; diff --git a/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafDefaultResolverTest.java b/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafDefaultResolverTest.java index 42c442186d9..204710063f5 100644 --- a/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafDefaultResolverTest.java +++ b/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafDefaultResolverTest.java @@ -49,7 +49,7 @@ public class ThymeleafDefaultResolverTest extends ThymeleafAbstractBaseTest { mock.assertIsSatisfied(); ThymeleafEndpoint thymeleafEndpoint = context.getEndpoint( - "thymeleaf:dontcare?templateMode=HTML&allowContextMapAll=true&resolver=DEFAULT", + "thymeleaf:dontcare?allowTemplateFromHeader=true&templateMode=HTML&allowContextMapAll=true&resolver=DEFAULT", ThymeleafEndpoint.class); assertAll("properties", @@ -87,7 +87,7 @@ public class ThymeleafDefaultResolverTest extends ThymeleafAbstractBaseTest { from(DIRECT_START) .setBody(simple(SPAZZ_TESTING_SERVICE)) - .to("thymeleaf:dontcare?templateMode=HTML&allowContextMapAll=true&resolver=DEFAULT") + .to("thymeleaf:dontcare?allowTemplateFromHeader=true&templateMode=HTML&allowContextMapAll=true&resolver=DEFAULT") .to(MOCK_RESULT); } }; diff --git a/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafResourceUriTest.java b/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafResourceUriTest.java index 0d3463a04eb..7110e739545 100644 --- a/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafResourceUriTest.java +++ b/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafResourceUriTest.java @@ -23,8 +23,7 @@ import org.junit.jupiter.api.Test; public class ThymeleafResourceUriTest extends ThymeleafAbstractBaseTest { @Test - public void testThymeleaf() throws InterruptedException { - + public void testThymeleaf() throws Exception { MockEndpoint mock = getMockEndpoint(MOCK_RESULT); mock.expectedMessageCount(1); mock.message(0).body().contains(THANK_YOU_FOR_YOUR_ORDER); @@ -39,14 +38,12 @@ public class ThymeleafResourceUriTest extends ThymeleafAbstractBaseTest { @Override protected RouteBuilder createRouteBuilder() { - return new RouteBuilder() { public void configure() { - from(DIRECT_START) .setBody(simple(SPAZZ_TESTING_SERVICE)) - .to("thymeleaf:dontcare?allowContextMapAll=true&resolver=CLASS_LOADER") + .to("thymeleaf:dontcare?allowTemplateFromHeader=true&allowContextMapAll=true&resolver=CLASS_LOADER") .to(MOCK_RESULT); } }; diff --git a/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafStringResolverAllParamsTest.java b/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafStringResolverAllParamsTest.java index e9f89f641e1..58811bb0ad3 100644 --- a/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafStringResolverAllParamsTest.java +++ b/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafStringResolverAllParamsTest.java @@ -48,7 +48,7 @@ public class ThymeleafStringResolverAllParamsTest extends ThymeleafAbstractBaseT mock.assertIsSatisfied(); ThymeleafEndpoint thymeleafEndpoint = context.getEndpoint( - "thymeleaf:dontcare?cacheable=true&cacheTimeToLive=500&checkExistence=true&order=1&allowContextMapAll=true&resolver=STRING", + "thymeleaf:dontcare?allowTemplateFromHeader=true&cacheable=true&cacheTimeToLive=500&checkExistence=true&order=1&allowContextMapAll=true&resolver=STRING", ThymeleafEndpoint.class); assertAll("properties", @@ -88,7 +88,7 @@ public class ThymeleafStringResolverAllParamsTest extends ThymeleafAbstractBaseT from(DIRECT_START) .setBody(simple(SPAZZ_TESTING_SERVICE)) - .to("thymeleaf:dontcare?cacheable=true&cacheTimeToLive=500&checkExistence=true&order=1&allowContextMapAll=true&resolver=STRING") + .to("thymeleaf:dontcare?allowTemplateFromHeader=true&cacheable=true&cacheTimeToLive=500&checkExistence=true&order=1&allowContextMapAll=true&resolver=STRING") .to(MOCK_RESULT); } }; diff --git a/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafStringResolverTest.java b/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafStringResolverTest.java index 1ca56bdc6df..ad40f9058e8 100644 --- a/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafStringResolverTest.java +++ b/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafStringResolverTest.java @@ -49,7 +49,7 @@ public class ThymeleafStringResolverTest extends ThymeleafAbstractBaseTest { mock.assertIsSatisfied(); ThymeleafEndpoint thymeleafEndpoint = context.getEndpoint( - "thymeleaf:dontcare?templateMode=HTML&allowContextMapAll=true&resolver=STRING", + "thymeleaf:dontcare?allowTemplateFromHeader=true&templateMode=HTML&allowContextMapAll=true&resolver=STRING", ThymeleafEndpoint.class); assertAll("properties", @@ -89,7 +89,7 @@ public class ThymeleafStringResolverTest extends ThymeleafAbstractBaseTest { from(DIRECT_START) .setBody(simple(SPAZZ_TESTING_SERVICE)) - .to("thymeleaf:dontcare?templateMode=HTML&allowContextMapAll=true&resolver=STRING") + .to("thymeleaf:dontcare?allowTemplateFromHeader=true&templateMode=HTML&allowContextMapAll=true&resolver=STRING") .to(MOCK_RESULT); } }; diff --git a/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafTemplateAsHeaderTest.java b/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafTemplateAsHeaderTest.java index 79d41afcdde..a6835f8b6fc 100644 --- a/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafTemplateAsHeaderTest.java +++ b/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafTemplateAsHeaderTest.java @@ -23,8 +23,7 @@ import org.junit.jupiter.api.Test; public class ThymeleafTemplateAsHeaderTest extends ThymeleafAbstractBaseTest { @Test - public void testThymeleaf() throws InterruptedException { - + public void testThymeleaf() throws Exception { MockEndpoint mock = getMockEndpoint(MOCK_RESULT); mock.expectedMessageCount(1); mock.message(0).body().contains(THANK_YOU_FOR_YOUR_ORDER); @@ -47,7 +46,7 @@ public class ThymeleafTemplateAsHeaderTest extends ThymeleafAbstractBaseTest { from(DIRECT_START) .setBody(simple(SPAZZ_TESTING_SERVICE)) - .to("thymeleaf:dontcare?templateMode=HTML&allowContextMapAll=true&resolver=DEFAULT") + .to("thymeleaf:dontcare?allowTemplateFromHeader=true&templateMode=HTML&allowContextMapAll=true&resolver=DEFAULT") .to(MOCK_RESULT); } }; diff --git a/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafUrlResolverAllParamsTest.java b/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafUrlResolverAllParamsTest.java index 50040e44253..bb7447eb277 100644 --- a/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafUrlResolverAllParamsTest.java +++ b/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafUrlResolverAllParamsTest.java @@ -39,8 +39,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; public class ThymeleafUrlResolverAllParamsTest extends ThymeleafAbstractBaseTest { @Test - public void testThymeleaf() throws InterruptedException { - + public void testThymeleaf() throws Exception { stubFor(get("/dontcare.html").willReturn(ok(fragment()))); MockEndpoint mock = getMockEndpoint(MOCK_RESULT); @@ -54,7 +53,7 @@ public class ThymeleafUrlResolverAllParamsTest extends ThymeleafAbstractBaseTest mock.assertIsSatisfied(); ThymeleafEndpoint thymeleafEndpoint = context.getEndpoint( - "thymeleaf:dontcare?allowContextMapAll=true&cacheTimeToLive=500&cacheable=false&encoding=UTF-8&order=1&prefix=&suffix=.html&resolver=URL&templateMode=HTML", + "thymeleaf:dontcare?allowTemplateFromHeader=true&allowContextMapAll=true&cacheTimeToLive=500&cacheable=false&encoding=UTF-8&order=1&prefix=&suffix=.html&resolver=URL&templateMode=HTML", ThymeleafEndpoint.class); assertAll("properties", @@ -90,20 +89,17 @@ public class ThymeleafUrlResolverAllParamsTest extends ThymeleafAbstractBaseTest @Override protected RouteBuilder createRouteBuilder() { - return new RouteBuilder() { public void configure() { - from(DIRECT_START) - .to("thymeleaf:dontcare?allowContextMapAll=true&cacheTimeToLive=500&cacheable=false&encoding=UTF-8&order=1&prefix=&suffix=.html&resolver=URL&templateMode=HTML") + .to("thymeleaf:dontcare?allowTemplateFromHeader=true&allowContextMapAll=true&cacheTimeToLive=500&cacheable=false&encoding=UTF-8&order=1&prefix=&suffix=.html&resolver=URL&templateMode=HTML") .to(MOCK_RESULT); } }; } protected String fragment() { - return """ <span th:fragment="test" th:remove="tag"> You will be notified when your order ships. diff --git a/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafUrlResolverTest.java b/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafUrlResolverTest.java index 9e4ea6531f5..0622dc1d186 100644 --- a/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafUrlResolverTest.java +++ b/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafUrlResolverTest.java @@ -39,8 +39,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; public class ThymeleafUrlResolverTest extends ThymeleafAbstractBaseTest { @Test - public void testThymeleaf() throws InterruptedException { - + public void testThymeleaf() throws Exception { stubFor(get("/dontcare.html").willReturn(ok(fragment()))); MockEndpoint mock = getMockEndpoint(MOCK_RESULT); @@ -54,7 +53,7 @@ public class ThymeleafUrlResolverTest extends ThymeleafAbstractBaseTest { mock.assertIsSatisfied(); ThymeleafEndpoint thymeleafEndpoint = context.getEndpoint( - "thymeleaf:dontcare?allowContextMapAll=true&resolver=URL", + "thymeleaf:dontcare?allowTemplateFromHeader=true&allowContextMapAll=true&resolver=URL", ThymeleafEndpoint.class); assertAll("properties", @@ -90,20 +89,17 @@ public class ThymeleafUrlResolverTest extends ThymeleafAbstractBaseTest { @Override protected RouteBuilder createRouteBuilder() { - return new RouteBuilder() { public void configure() { - from(DIRECT_START) - .to("thymeleaf:dontcare?allowContextMapAll=true&resolver=URL") + .to("thymeleaf:dontcare?allowTemplateFromHeader=true&allowContextMapAll=true&resolver=URL") .to(MOCK_RESULT); } }; } protected String fragment() { - return """ <span th:fragment="test" th:remove="tag"> You will be notified when your order ships. diff --git a/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafVariableMapHeaderTest.java b/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafVariableMapHeaderTest.java index a8515332d3b..7499e9a6786 100644 --- a/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafVariableMapHeaderTest.java +++ b/components/camel-thymeleaf/src/test/java/org/apache/camel/component/thymeleaf/ThymeleafVariableMapHeaderTest.java @@ -23,8 +23,7 @@ import org.junit.jupiter.api.Test; public class ThymeleafVariableMapHeaderTest extends ThymeleafAbstractBaseTest { @Test - public void testThymeleaf() throws InterruptedException { - + public void testThymeleaf() throws Exception { MockEndpoint mock = getMockEndpoint(MOCK_RESULT); mock.expectedMessageCount(1); mock.message(0).body().contains(THANK_YOU_FOR_YOUR_ORDER); @@ -40,14 +39,12 @@ public class ThymeleafVariableMapHeaderTest extends ThymeleafAbstractBaseTest { @Override protected RouteBuilder createRouteBuilder() { - return new RouteBuilder() { public void configure() { - from(DIRECT_START) .setBody(simple(SPAZZ_TESTING_SERVICE)) - .to("thymeleaf:dontcare?templateMode=HTML&resolver=DEFAULT") + .to("thymeleaf:dontcare?allowTemplateFromHeader=true&templateMode=HTML&resolver=DEFAULT") .to(MOCK_RESULT); } };
