davsclaus commented on code in PR #30453:
URL: https://github.com/apache/camel/pull/30453#discussion_r4634999219
##########
components/camel-kamelet/src/main/java/org/apache/camel/component/kamelet/KameletProducer.java:
##########
@@ -126,6 +141,37 @@ public boolean process(Exchange exchange, AsyncCallback
originalCallback) {
}
}
+ /**
+ * The output data type of the source Kamelet whose route the exchange is
in, from the route property that the
+ * Kamelet YAML loader sets, or null when it has none.
+ */
+ private DataTypeProcessor sourceOutputType(Exchange exchange) throws
Exception {
+ if (!sourceOutputTypeResolved) {
+ synchronized (this) {
+ if (!sourceOutputTypeResolved) {
+ Route route = ExchangeHelper.getRoute(exchange);
+ Object type = route != null ?
route.getProperties().get(Kamelet.SOURCE_OUTPUT_TYPE_PROPERTY) : null;
+ if (type != null) {
+ DataTypeProcessor processor = new
DataTypeProcessor(null, type.toString());
+
processor.setCamelContext(getEndpoint().getCamelContext());
+ ServiceHelper.startService(processor);
Review Comment:
Thanks, fixed in 03dce980. `KameletProducer` now keeps the old outcome when
no transformer resolves:
- a `java:` type is converted with the type converter, as `ContractAdvice`
did for an output type of the route (`java:java.lang.String` with a body of
`42` gives `"42"`);
- any other type logs one WARN (naming the route and the type) and the
message is handed on unchanged.
The outcome is looked up once and kept, so there's no lookup per message.
Your reproducer is in `KameletLoaderTest` as
`sourceKameletOutputTypeWithoutTransformerHandsMessagesOnUnchanged`, next to
`sourceKameletJavaOutputTypeIsConverted`. Both fail on 028a8e6 and pass now.
The upgrade guide note says so too.
_Claude Code on behalf of Claus Ibsen_
##########
core/camel-core-processor/src/main/java/org/apache/camel/processor/transformer/ByteArrayDataTypeTransformer.java:
##########
@@ -27,19 +29,25 @@
/**
* Generic binary data type uses Camel message body converter mechanism to
convert content to byte array representation.
+ * A stream body is binary already, so it is kept as it is: a large body, such
as an object read from a bucket, is not
+ * read into memory.
*/
@DataTypeTransformer(name = "application-octet-stream")
@BodyTypes(transformerIn = @BodyType(value = { Carrier.TEXT, Carrier.BYTES,
Carrier.STREAM, Carrier.FILE },
description = "A body Camel can convert
to a byte array: a number or a null body"
+ " fails"),
- transformerOut = @BodyType(value = Carrier.BYTES, javaType =
"byte[]"))
+ transformerOut = @BodyType(value = { Carrier.BYTES, Carrier.STREAM
},
+ description = "A stream body is kept as
it is; any other body becomes a byte"
+ + " array"))
public class ByteArrayDataTypeTransformer extends Transformer {
private static final Transformer DELEGATE = new
TypeConverterTransformer(byte[].class);
@Override
public void transform(Message message, DataType from, DataType to) throws
Exception {
- DELEGATE.transform(message, from, to);
+ if (!(message.getBody() instanceof InputStream)) {
Review Comment:
Agreed, thanks. Fixed in 03dce980 as you suggested:
`ByteArrayDataTypeTransformer` keeps only a `StreamCache` body, and any other
`InputStream` is read into a `byte[]` as before. A large object from a source
Kamelet still streams with stream caching on (the default).
`shouldKeepInputStream` is now `shouldKeepStreamCache` (a
`ByteArrayInputStreamCache`), plus `shouldReadOtherInputStreamToBytes`. Your
one-shot stream reproducer was added as `BinaryDataTypeOneShotStreamTest`: it
fails on 028a8e6 and passes now. The `@BodyTypes` description, the generated
JSON with its catalog copy, and the upgrade guide note now say "stream cache".
_Claude Code on behalf of Claus Ibsen_
--
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]