Claus Ibsen created CAMEL-27651:
-----------------------------------
Summary: camel-chunk: unused extension option, NPE for theme
folders, themeFolder not found in a JAR
Key: CAMEL-27651
URL: https://issues.apache.org/jira/browse/CAMEL-27651
Project: Camel
Issue Type: Bug
Components: camel-chunk
Reporter: Claus Ibsen
Fix For: 4.24.0
Found while improving the option descriptions of camel-chunk for CAMEL-23832
(commit
https://github.com/apache/camel/commit/5755784879e61cc8862f6bbb5f88b2d8efd60bad).
These are separate problems of the component; the descriptions commit only
documents the current behavior.
h4. 1. The extension option does nothing
{{ChunkEndpoint}} stores the {{extension}} option, but
{{ChunkEndpoint.getOrCreateTheme()}} never passes it to the Chunk {{Theme}}. It
creates the theme with {{new Theme()}} or {{new Theme(folder, subfolder)}}, so
Chunk always uses its default extension {{chtml}}. With {{extension=html}},
Chunk still looks for {{mytemplate.chtml}} and does not find
{{mytemplate.html}}. {{ChunkDifferentThemeFolderSubfolderAndExtensionTest}}
sets {{extension=file}} and passes only because its template is a {{.chtml}}
file.
Proposed change: pass the extension to Chunk, with {{new Theme(folder, layers,
extension)}} or {{Theme.setDefaultFileExtension()}}, and fix the test so that
it uses a template with another extension.
h4. 2. themeSubfolder without themeFolder, or a themeFolder that is not on the
classpath, fails with a NullPointerException
{{ChunkEndpoint.getOrCreateTheme()}} (called from {{doStart()}}) goes to the
last branch when only {{themeSubfolder}} is set, and calls
{{getClassResolver().loadResourceAsURL(themeFolder)}} with {{themeFolder}}
null. When {{themeFolder}} names a folder that is not on the classpath,
{{loadResourceAsURL()}} returns null and {{url.getPath()}} throws. In both
cases the route fails to start with a NullPointerException and no hint about
the option.
Proposed change: use the default {{themes}} folder when only {{themeSubfolder}}
is set (or reject it with a clear message), and throw an exception that names
the folder when it is not found.
h4. 3. themeFolder does not work for a folder inside a JAR
{{ChunkEndpoint.getOrCreateTheme()}} resolves {{themeFolder}} on the classpath
and passes {{URL.getPath()}} to {{new Theme(path, ...)}}, which Chunk uses as a
file system folder. For a folder inside a JAR the path is
{{file:/.../app.jar!/folder}}, which is not a folder, so Chunk does not find
the templates there. It falls back to the classpath folder {{/themes}}, which
is never changed to {{themeFolder}}. This breaks a packaged application (Spring
Boot fat JAR, Camel Main uber JAR) that works from the IDE.
Proposed change: also set the classpath folder with
{{Theme.setClasspathThemesFolder("/" + themeFolder)}}, so Chunk finds the
templates in a JAR.
h4. 4. The doc page has wrong statements about where templates are found
{{chunk-component.adoc}} says that Chunk looks for templates "with extensions
.chtml or .cxml", and that {{templateName}} is "the classpath-local URI of the
template". Chunk 3.6.2 has no {{cxml}} extension, it uses {{chtml}} only. A
{{resourceUri}} without a scheme is looked up in the {{themes}} folder of the
working directory first, then in {{/themes}} on the classpath; a
{{resourceUri}} with a scheme ({{classpath:}}, {{file:}}, {{http:}}, ...) is
loaded as a resource.
Proposed change: correct these two sentences.
_Claude Code on behalf of davsclaus_
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)