Claus Ibsen created CAMEL-26115:
-----------------------------------

             Summary: camel-datasonnet, camel-hl7, camel-openfeature, 
camel-ognl, camel-python, camel-quickjs, camel-javascript, camel-python3 - 
small bugs of the languages found by the body type checks
                 Key: CAMEL-26115
                 URL: https://issues.apache.org/jira/browse/CAMEL-26115
             Project: Camel
          Issue Type: Bug
          Components: camel-hl7, camel-ognl, camel-script
    Affects Versions: 4.18.0, 4.22.0, 4.23.0
            Reporter: Claus Ibsen
             Fix For: 4.24.0


Found while adding the catalog body types of the last 13 languages 
(CAMEL-24961), checked with {{camel run}} on 4.24.0-SNAPSHOT (main 
ffe0255463d5). They are small, so they are in one ticket. Line numbers are on 
that commit.

h4. 1. datasonnet

* The {{source}} option is ignored when the message body is null: the 
empty-body check looks at the body, not at the payload {{source}} gave 
({{DatasonnetExpression}}, line 125), so the payload is replaced by an empty 
document. Checked: {{source: header:foo}} with a null body fails with 
"attempted to index a string", with a body it works.
* {{matches()}} sets the field {{outputMediaType}} of the expression to 
application/x-java-object (line 81), so a later evaluate on the same expression 
ignores the output media type of the header or the exchange property, and two 
threads share it.
* A stream body without a body media type fails: the stream cache is passed to 
Jackson as a Java object (lines 128-129) and fails with 
{{InaccessibleObjectException}}.
* An expression that gives null leaves a Document with null content, and 
{{$\{body\}}} then fails with "NullPointerException: this.content is null".

h4. 2. hl7terser

The body is converted to a HAPI Message with a conversion that may give null 
({{Hl7TerserLanguage}}, line 45), so a stream (an HTTP body with stream 
caching), a file of the file consumer, a Map or no body fails with a bare 
{{NullPointerException: Message may not be null}} from HAPI instead of an error 
that says what the body must be. The HL7 data format reads streams and files; 
the language does not.

*Proposed change*: use a mandatory conversion, and read a stream or a file like 
the data format does.

h4. 3. openfeature

* As an expression (setBody, setHeader, setProperty), a boolean flag is 
evaluated as a string flag ({{OpenFeatureLanguage}}, lines 128-133, only a 
Boolean result type evaluates a boolean), so it gives the default value "false" 
as text with a TYPE_MISMATCH warning, not the flag value. The language is 
described as a boolean feature flag language.
* Number and object flags cannot be read with the language: there is no option 
to choose the type of the evaluation.
* The doc says the flag is evaluated as a boolean (line 32) and later that the 
expression gives the string variant (line 159).

h4. 4. ognl

The doc lists a {{message}} variable, which does not exist: {{RootObject}} of 
camel-ognl has {{getRequest()}} but no {{getMessage()}}, and {{message.body}} 
fails with {{NoSuchPropertyException: RootObject.message}}. The RootObject of 
camel-spring (SpEL) has {{getMessage()}}.

*Proposed change*: add {{getMessage()}} to the RootObject of camel-ognl.

h4. 5. python

* The result is always the Python text, {{str()}}, of what the script returns 
({{PythonExpression}}, lines 87-90): a dict gives its Python text, a byte array 
body returned as it is gives "array('b', [...])", and None gives the text 
"None", so the body can never become null.
* An error while the script runs, such as a NameError, is reported as 
{{ExpressionIllegalSyntaxException}} (line 93).

h4. 6. quickjs

* A JavaScript Set comes back as an empty Map, so its values are lost; a 
Uint8Array comes back as a Map of index to value.
* {{camel.setBody(...)}} inside a script used in setBody or transform is 
replaced by the result of the script, which the doc does not say.

h4. 7. js and python3

* A script that returns a function gives a polyglot value tied to the closed 
context, whose {{toString()}} fails with "Context is invalid or closed".
* js: a Uint8Array comes back as a List of Integer. python3: bytes, bytearray 
and memoryview come back as a List of Integer, not a byte array 
({{Python3Language}}, lines 325-333).

_Claude Code on behalf of davsclaus_



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to