Claus Ibsen created CAMEL-24882:
-----------------------------------
Summary: camel-jbang - say that a script returning
'resource:file:x' returns the text, not the file (validator hint and error
diagnose)
Key: CAMEL-24882
URL: https://issues.apache.org/jira/browse/CAMEL-24882
Project: Camel
Issue Type: Improvement
Components: camel-jbang
Reporter: Claus Ibsen
Fix For: 4.23.0
The {{resource:}} prefix is resolved on the text of an expression: {{constant:
"resource:file:order.json"}} makes the file's content the body, {{simple:
"resource:file:${...}"}} picks the file per message, {{groovy:
"resource:file:script.groovy"}} loads the script. A value *returned* by a
script is never resolved. In the camel-jbang-mcp stepwise benchmark
(transform/groovy, "pick the file by the timer counter") the local model wrote
{code}
- setBody:
expression:
groovy: |
def counter = exchange.getProperty('CamelTimerCounter', Integer) ?: 0
counter == 0 ? 'resource:file:order.json' :
'resource:file:order-bad-email.json'
- unmarshal:
json:
library: Jackson
{code}
so the body became the text {{resource:file:order.json}} and the unmarshal
failed with {{Unrecognized token 'resource'}}; two of five runs recovered by
reading the log, one did not. Nothing at write time or run time says what
happened.
Two deterministic hints, no change to how {{resource:}} works:
* validator (camel validate, camel_write_file): a script expression (groovy,
jq, ...) whose text holds a quoted {{'resource:file:}} /
{{"resource:classpath:}} literal gets: "a script that returns 'resource:file:x'
returns that text; to load a file as the body write constant:
\"resource:file:x\", or simple: \"resource:file:${...}\" for a name chosen per
message"
* camel_error_diagnose: a JSON/XML parse failure whose body is a string
starting with {{resource:}} gets the same explanation.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)