Claus Ibsen created CAMEL-27817:
-----------------------------------
Summary: camel-thymeleaf: classpath:/file: resource URIs fail with
the default resolver, resolver=DEFAULT always renders the first template
Key: CAMEL-27817
URL: https://issues.apache.org/jira/browse/CAMEL-27817
Project: Camel
Issue Type: Bug
Reporter: Claus Ibsen
Fix For: 4.25.0
Found while improving the option descriptions of camel-thymeleaf for
CAMEL-23832 (pull request https://github.com/apache/camel/pull/31140).
These are separate problems of the component; the descriptions change only
documents the current behavior.
h4. 1. A resource URI with a scheme fails with the default resolver
When the resource URI has a scheme (classpath:, file:, ref:, http:) and the
resolver is not URL, {{ThymeleafEndpoint.onExchange}} loads the text and passes
it to TemplateEngine.process as the template name, which fails with
"ClassLoader resource ... could not be resolved". So thymeleaf:classpath:...
and the doc example thymeleaf:file://... do not work with the default
CLASS_LOADER resolver (nor FILE / WEB_APP).
Proposed change: render the loaded text with a StringTemplateResolver, or strip
the scheme and let the configured resolver resolve the path.
h4. 2. The CamelThymeleafTemplate header is a template name unless
resolver=STRING
With CLASS_LOADER, FILE, URL or WEB_APP the header text is used as a template
name.
Proposed change: render the header text with a StringTemplateResolver whatever
the resolver.
h4. 3. resolver=DEFAULT renders the first template forever
getTemplateEngine() builds the engine once, and
DefaultTemplateResolver.setTemplate gets the first message's template; later
messages render that first template.
Proposed change: do not cache the engine for DEFAULT, or deprecate DEFAULT in
favour of STRING.
h4. 4. The resource URI header builds a broken endpoint URI
{{findOrCreateEndpoint}} uses {{uri.replace(getResourceUri(),
newResourceUri)}}, which replaces every occurrence in the URI; for example
thymeleaf:a?allowTemplateFromHeader=true fails with NoSuchEndpointException.
Each new endpoint is closed after use but stays in the registry.
Proposed change: rebuild the URI from scheme, new resource and query.
h4. 5. resolver=WEB_APP cannot work from a URI
The JakartaServletWebApplication can only be set from Java, so a URI with
resolver=WEB_APP always fails ("Web Application object cannot be null"). The
URL resolver never applies checkExistence.
Proposed change: document it, or add an option for the web application.
_Claude Code on behalf of davsclaus_
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)