allthingssecurity opened a new pull request, #27592: URL: https://github.com/apache/camel/pull/27592
# Description [CAMEL-25455](https://issues.apache.org/jira/browse/CAMEL-25455) The `wasm` language never matched as a predicate unless the function result was converted to a Jackson `BooleanNode`. `WasmExpression.matches()` only recognised a `BooleanNode` or a non-empty `java.util.Collection`; every other value was `false`. The default result type of the language is `byte[]` (the raw bytes the function returns), so `filter().wasm("is_valid", "functions.wasm")` dropped every message, and so did `resultType` `Boolean` or `String`: with `resultType=Boolean` the expression evaluates to `Boolean.TRUE` while the predicate returns `false`. The checks were copied from camel-jq in the original contribution (CAMEL-20336), where the result is always a `JsonNode`; they do not fit a language whose result is raw bytes. This change evaluates the result with the standard Camel rules (`ObjectHelper.evaluateValuePredicate`, as `ExpressionSupport`, camel-bean and camel-quickjs do): a `Boolean` is used as is, the text `true`/`false` (any case) is parsed, empty is `false`, any other non-null value is `true`. A `byte[]` result is first converted to a `String` with the exchange charset, so a function can simply return `true` or `false`. A `JsonNode` result keeps its previous behaviour: only the JSON boolean `true` matches. The extra cost is one byte-to-String conversion per evaluation, only when the expression is used as a predicate. Docs: a "Using Wasm as a predicate" section in `wasm-language.adoc` (catalog copy regenerated). Upgrade guide: a 4-line `camel-wasm - the wasm predicate` note, since filters and choices that never matched can now match. Tests: new parameterized `WasmLanguageTest.testPredicate` (`byte[]`, `String`, `Boolean` result types) uses the existing `functions.wasm` (its `transform` function upper-cases the body): it sends `false`, an empty body and `true` through `filter().wasm("transform", "functions.wasm", resultType)` and expects only `true` to pass. No new test binary. Without the main-code change (two runs): ``` WasmLanguageTest.testPredicate(Class)[1] (byte[]): mock://result Received message count. Expected: <1> but was: <0> WasmLanguageTest.testPredicate(Class)[2] (String): mock://result Received message count. Expected: <1> but was: <0> WasmLanguageTest.testPredicate(Class)[3] (Boolean): mock://result Received message count. Expected: <1> but was: <0> ``` With the change the camel-wasm tests pass (9). No other module depends on camel-wasm (only the BOM, catalog and coverage aggregators). # Target - [x] I checked that the commit is targeting the correct branch (Camel 4 uses the `main` branch) # Tracking - [x] If this is a large change, bug fix, or code improvement, I checked there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it). # Apache Camel coding standards and style - [x] I checked that each commit in the pull request has a meaningful subject line and body. - [ ] I have run `mvn clean install -DskipTests` locally from root folder and I have committed all auto-generated changes. (I built and tested the affected module with `-am`, including the formatter and import-sort plugins, and copied the changed doc to the catalog. I did not run the full root build.) # AI-assisted contributions - [x] If this PR includes AI-generated code, commits have proper co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR description identifies the AI tool used. This PR was prepared with Claude Code (Claude Opus 5.5). The commit carries a `Co-Authored-By` trailer. _Claude Code on behalf of allthingssecurity_ 🤖 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]
