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

   Part of #3117: default data types on the Transformation, JSON and EIP 
actions. This PR is built on #3262 (the Citrus tests of these families), and 
its diff over #3262 updates the expected body types those tests record.
   
   An action only gets a default where the body it takes or gives is always the 
same kind. The transformer must also not change the data itself, only its Java 
type and `Content-Type`.
   
   | Kamelet | `in` | `out` | What changes |
   |---|---|---|---|
   | `avro-deserialize-action`, `protobuf-deserialize-action` | `binary` | | A 
stream in is read into bytes first. The output does not change: the action 
removes `Content-Type` |
   | `json-serialize-action` | | `json` | The body is `byte[]` instead of a 
stream (`InputStreamCache`) |
   | `hoist-field-action` | | `json` | The body is `byte[]` instead of a 
`String` |
   | `jslt-action` | | `json` | The body is `byte[]` instead of a `String`, and 
`Content-Type` is set to `application/json`. Before, the incoming one was kept |
   | `pdf-action` | `text` | `binary` | The body is `byte[]` instead of a 
`ByteArrayOutputStream`, and `Content-Type` is set to 
`application/octet-stream`. Before, the incoming one was kept, for example 
`text/plain` for the text that was turned into the PDF |
   | `crypto-encrypt-action` | | `binary` | The body is `byte[]` instead of a 
stream, and `Content-Type` is set to `application/octet-stream`. Before, the 
incoming one was kept, for example `text/plain` on the encrypted data. 
`crypto-decrypt-action` keeps the headers, so after it `Content-Type` is 
`application/octet-stream`. Its description now says to set it again, and the 
crypto Citrus test does so |
   
   `jslt-action` now depends on `camel:jackson3`, which has the JSON 
transformers.
   
   ### No default
   - **Parsed JSON out** (`json-deserialize-action`, `jsonata-action`, 
`avro-deserialize-action`, `protobuf-deserialize-action`): `struct` 
(`application-x-struct`) would fit, but `camel-jackson` (Jackson 2) and 
`camel-jackson3` both register a transformer of that name, and which one runs 
depends on the classpath.
     - In a `camel run` with both, the Jackson 2 one ran. It failed on the 
Jackson 3 `JsonNode` these actions give: `Cannot construct instance of 
com.fasterxml.jackson.databind.JsonNode`.
     - The `application-json` of both versions handles text, bytes and a stream 
the same way, so the `json` defaults above are safe.
     - I noted this on #3117: it needs a fix in Camel.
   - **`crypto-decrypt-action`**: the original data can be text or JSON, so 
`binary` would label it wrongly.
   - **The template actions** (`freemarker-`, `velocity-`, `mustache-`, 
`mvel-`, `string-template-action`) and `set-body-action` give text, but the 
text can be JSON or XML. A `text` default would set `Content-Type: text/plain` 
on it, and an `http-sink` after would then send JSON as `text/plain`.
   - **The field actions** (`drop-`, `insert-`, `mask-`, `replace-`, 
`extract-field-action`), `xj-identity-action` and `xj-template-action` give 
JSON text or parsed JSON, or JSON or XML, depending on `Content-Type` or on 
their options.
   - **The EIP actions and the filters** (`predicate-filter-action`, 
`json-schema-validator-action`, `data-type-action`, 
`resolve-pojo-schema-action`) pass any body on unchanged.
   - **No transformer fits:**
     - `jolt-transformation-action` gives a `Map`, and `application-x-struct` 
fails on a `Map`.
     - `avro-serialize-action` and `protobuf-serialize-action` give bytes with 
`application/avro` and `application/protobuf`, which `application-octet-stream` 
would replace.
   
     I noted both on #3117.
   
   ### Upgrade note
   For #3190, under "Changed behaviour", when this is merged:
   - `json-serialize-action`, `hoist-field-action`, `jslt-action`, `pdf-action` 
and `crypto-encrypt-action` give `byte[]`.
   - `jslt-action` sets `Content-Type: application/json`, and `pdf-action` and 
`crypto-encrypt-action` set `application/octet-stream`, which 
`crypto-decrypt-action` keeps.
   
   A route that read the body as a `String` or a stream converts it, as Camel 
does when asked.
   
   ### Tests
   - **Citrus:** `CommonIT#transformation+json+xj+crypto`, `AvroIT` and 
`ProtobufIT`: all pass. The #3262 tests of `json-serialize-action`, 
`jslt-action` and `pdf-action` now expect `[B` and the new `Content-Type`. The 
PDF test checks the `%PDF-` signature through a header, as Citrus reads an 
`application/octet-stream` body as bytes.
   - **Build:** `./mvnw clean install` from the root passes, run twice.
   
   _Claude Code on behalf of Claus Ibsen_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   
   🤖 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