davsclaus opened a new pull request, #30453: URL: https://github.com/apache/camel/pull/30453
[CAMEL-27258](https://issues.apache.org/jira/browse/CAMEL-27258) ### The problem The YAML loader turns `spec.dataTypes.out.default` of a Kamelet into the `outputType` of its template route. `ContractAdvice.after()` applies it when that route completes. For a **source** Kamelet that is too late. A source hands each message on with `to: kamelet:sink`, and `KameletProducer` runs the whole consuming route synchronously, inside the template route. So: - the consuming route never sees the declared type; - the exchange fails at the end when the consuming route leaves a body that can't be converted, such as a `Map` for `binary`: `Failed to convert body to 'java:[B' ... at ContractAdvice.after(ContractAdvice.java:104)`, after all the work is done. It affects the 16 source Kamelets of the catalog that declare an `out` default, such as aws-sqs-source, slack-source and aws-s3-source. Reproduced with `camel run`. ### The change - **`KameletRoutesBuilderLoader`**: for a Kamelet labelled `camel.apache.org/kamelet.type: source`, the out default becomes the route property `kameletSourceOutputType` instead of the `outputType`. Sinks, actions and Kamelets without the label are unchanged. - **`KameletProducer`**: for `kamelet:sink`, it reads that property from the route of the exchange (looked up once) and applies the type with a `DataTypeProcessor` before it calls the consuming route. - **`ByteArrayDataTypeTransformer`** (`application-octet-stream`, `binary`): an `InputStream` body, such as a stream cache, is kept and only gets `Content-Type: application/octet-stream`. Before, it was read into a `byte[]`. Now that the type of a source is applied for real, this keeps the object sources (aws-s3-source, azure-storage-blob-source, google-storage-source, …) streaming, since an object may be large. The `@BodyTypes` out is now bytes or a stream; the generated metadata and the catalog copy are updated. - Upgrade guide 4.24: two notes, one per behaviour change. ### Tests - `KameletLoaderTest`: - a labelled source has no `outputType`, only the route property; - end to end, the consuming route's first step gets a `byte[]` with the `Content-Type`, and leaving a `Map` at the end no longer fails the exchange. - `ByteArrayDataTypeTransformerTest`: a stream is kept as the same instance and gets the header; the body types are updated. - Run locally: - camel-core: the transformer, `EipBodyTypesTest`, `TransformerContractTest`, `DataTypeProcessorTest`: 33 pass; - camel-kamelet: all 169 pass (2 skipped); - camel-yaml-dsl Kamelet tests: 35 pass; - camel-yaml-dsl-validator `TextBodyFlowTest`: 91 of 92 pass. The one failure is the Bedrock converse check of #30441, which needs the current catalog; my local catalog jar predates #30441. - `camel run` against the built jars: a labelled `binary` source fed a String gives the consuming route `[B` with `ct=application/octet-stream`, and a Map at the end does not fail. A source fed a stream gives `ByteArrayInputStreamCache` with the same header. _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]
