davsclaus opened a new pull request, #28889: URL: https://github.com/apache/camel/pull/28889
Fixes [CAMEL-25973](https://issues.apache.org/jira/browse/CAMEL-25973). ## What was wrong With `binary=true`, only a script with the `resource:` prefix gave the content of the resource as a stream. - `language:constant:classpath:data.bin?binary=true` (or `file:...`): `LanguageProducer` opened the resource, skipped reading it because of `binary`, and then evaluated the text of the uri. The body was the String `classpath:data.bin`, and the opened stream was never closed. - With `cacheScript=true` as well, `LanguageEndpoint` pre-loaded the resource as a String expression at startup. The body was the content converted to text, so binary bytes were corrupted (the 10249 bytes logo came back as 18536 bytes). ## What changed - `LanguageProducer`: with `binary=true` and an opened resource, the stream is the result as-is, as for a `resource:` script. With `transform=false` the stream is not used, so it is closed. - `LanguageEndpoint`: with `binary=true`, the script is not pre-loaded as an expression in `doInit`/`createProducer` (a stream cannot be cached; it is opened for each message). ## Tests Three new tests in `ConstantLanguageBinaryResourceTest` (camel-core, where the language component tests live): a `classpath:` script, a `classpath:` script with `cacheScript=true` (two messages), and a `file:` script with bytes that are not valid UTF-8. All three failed before the fix (36 bytes of uri text, 18536 bytes of converted text, 87 bytes of uri text) and pass after. All tests in `org.apache.camel.component.language` and `org.apache.camel.language` (938) and the other camel-core tests that use `language:` endpoints pass. ## Docs Added a short "Binary content" section to `language-component.adoc` and copied it to the catalog. No option or generated JSON changes. No upgrade guide entry: the old result (the uri text) was not usable. ## Not changed A script in the `CamelLanguageScript` header (with `allowTemplateFromHeader=true`) is still always read as text; `binary` applies to the endpoint script only, as before. _Claude Code on behalf of Claus Ibsen (davsclaus)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
