davsclaus opened a new pull request, #3299:
URL: https://github.com/apache/camel-kamelets/pull/3299

   Part of #3117, batch 8 (actions). Adds a default data type where the body an 
action reads is fixed. Camel runs the transformer of a default on every 
message, so each change was checked with `camel run` (the body class and 
`Content-Type` before and after, against `main`) and with the Citrus tests.
   
   ## What changes
   
   | Kamelet | in | out | What changes (before → after) |
   |---|---|---|---|
   | `json-deserialize-action` | `binary` | - | Text is turned into `byte[]` 
before parsing. Output unchanged: a Jackson `JsonNode`, `Content-Type` removed. 
|
   | `jslt-action` | `binary` | `json` (kept) | Parsed JSON (a Jackson 
`JsonNode`, such as the output of `json-deserialize-action`): fails → is 
written as JSON text first and transformed. A `Map` still fails, now at the 
start. Output unchanged. |
   | `crypto-encrypt-action` | `binary` | `binary` (kept) | Text is turned into 
`byte[]` before encrypting. Output unchanged. |
   | `crypto-decrypt-action` | `binary` | - | `Content-Type` after it: kept as 
it came → `application/octet-stream`. Body unchanged (the original data as a 
stream). Directly after `crypto-encrypt-action` Camel skips the input 
transformer, because the message is already `binary`, so a `Content-Type` set 
between the two is kept. |
   | `message-timestamp-router-action` | `json` | `json` (kept) | The input is 
always read as JSON, and `Content-Type: application/json` is no longer needed. 
Text, bytes, a `Map` and a `JsonNode` gave the same result before and after. |
   | `value-to-key-action` | `json` | `json` (kept) | As 
`message-timestamp-router-action`. |
   | `nominatim-geocode-action` | `text` | `json` (kept) | Bytes or a stream 
are read as text. No visible change: the output default sets `Content-Type` 
again. |
   | `ogcapi-features-action` | `text` | - | Bytes are read as text, and an 
empty body stays empty. No visible change: the HTTP request is a GET without a 
body, and the response sets `Content-Type`. |
   
   The descriptions of `jslt-action`, `crypto-decrypt-action`, 
`message-timestamp-router-action` and `value-to-key-action` were updated. The 
`Content-Type` input header was dropped from the `dataTypes` of the two Kafka 
routing actions, since they no longer read it.
   
   ## Not done: `out: struct` on the deserialize actions and `jsonata-action`
   
   The plan was an `application-x-struct` output default on 
`json-deserialize-action`, `avro-deserialize-action`, 
`protobuf-deserialize-action` and `jsonata-action`. `struct` itself works: with 
`camel-jackson` and `camel-jackson3` both on the classpath, in either order, 
`application-x-struct` resolves to the Jackson 3 transformer and gives a 
`tools.jackson.databind.node.ObjectNode`. JSONPath, jq and `marshal: json` then 
work on that body.
   
   The problem is in Camel. 
`DefaultTransformerRegistry.resolveTransformer(from, to)` looks up the 
transformer of the `from` type before it lazy-loads the `to` transformer. A 
message that leaves a Kamelet as `application-x-struct` and goes straight into 
a Kamelet with an input default whose transformer has not been used yet is then 
given the struct transformer. That transformer keeps a `JsonNode` as it is, so 
the input transformer has no effect. The alias is cached, so every later 
message is handled the same way.
   
   Example (`camel run`, fresh JVM): `json-deserialize-action` → 
`value-to-key-action`.
   - With `out: struct`, the debug log says `Found transformer 
JsonStructDataTypeTransformer for key application-x-struct/application-json 
using alias application-x-struct`.
   - The input stays an `ObjectNode`. `value-to-key-action` then skips its 
marshal, and Camel skips its `out: json`, because the message already says 
`application-json`.
   - It gives an `ObjectNode` with no `Content-Type` instead of JSON bytes.
   - `json-deserialize-action` → `jsonata-action` → `pdf-action` resolves the 
struct transformer for `text-plain` in the same way.
   
   Without the struct output the `from` is the Java type 
(`java:...ObjectNode`), and the right transformer is found. So the struct 
outputs wait for that Camel fix. The four Kamelets already give a Jackson 3 
`JsonNode`, as their descriptions say. `camel-jackson3-avro` and 
`camel-jackson3-protobuf` do depend on `camel-jackson3`, and `jsonata-action` 
would need `camel:jackson3` added with its `struct` output.
   
   ## Tests
   
   - `CommonIT#json+transformation+crypto+kafkaRouter+geo`: 30 of 30 pass.
   - `AvroIT`, `ProtobufIT`: `avro-serdes-action` and `protobuf-serdes-action` 
pass. `avro-data-type-test` and `protobuf-data-type-test` fail locally with 
`null value for (non-nullable) string at User.id` in the receiving 
`data-type-action avro-x-struct`. They fail the same way when run against the 
Kamelets of `main` (`-Dkamelets.local.dir`), and they passed in the last `main` 
CI run, so the cause is the local Camel snapshot in `~/.m2`, not this change. 
CI will show it.
   - `crypto/crypto-action-route` now also checks the body class and 
`Content-Type` after `crypto-decrypt-action`: `InputStreamCache`, 
`application/octet-stream`.
   - New `transformation/jslt-action-jsonnode-route`: `json-deserialize-action` 
→ `jslt-action` gives the transformed JSON. Before this change it failed with 
"Allowed body types are String, Reader, File, byte[] or InputStream".
   - `kafkarouter/value-to-key-action-route` no longer sets `Content-Type: 
application/json` before the action.
   - The avro and protobuf deserialize routes were not extended, because those 
Kamelets don't change here.
   - `./mvnw clean install` from the root, twice: green.
   
   ## Overlap
   
   #3285 also changes `nominatim-geocode-action` (the `language` option). This 
PR only adds the `in` block under `dataTypes`, next to the new option, so 
whichever merges second needs a one-line rebase.
   
   ## Upgrade note for #3190 (Data types section)
   
   - **Default data types on the data format, crypto, Kafka routing and geo 
actions (#NNNN):**
     - `json-deserialize-action`, `jslt-action`, `crypto-encrypt-action` and 
`crypto-decrypt-action` (`in: binary`) turn text into `byte[]` before they read 
it. A stream is kept as it is.
     - `jslt-action` now also accepts parsed JSON (a Jackson `JsonNode`), such 
as the output of `json-deserialize-action`. Before, that failed.
     - After `crypto-decrypt-action`, `Content-Type` is 
`application/octet-stream`, also when the encrypted data came with another 
`Content-Type`. Set it again to the type of the original data when the next 
step needs it.
     - `message-timestamp-router-action` and `value-to-key-action` (`in: json`) 
always read the body as JSON. `Content-Type: application/json` is no longer 
needed.
     - `nominatim-geocode-action` and `ogcapi-features-action` (`in: text`) 
read the body as text. Nothing else changes.
   
   _Claude Code on behalf of Claus Ibsen_
   
   🤖 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]

Reply via email to