Claus Ibsen created CAMEL-27258:
-----------------------------------

             Summary: camel-kamelet - the output data type of a source Kamelet 
is applied after the consuming route instead of before it
                 Key: CAMEL-27258
                 URL: https://issues.apache.org/jira/browse/CAMEL-27258
             Project: Camel
          Issue Type: Bug
          Components: camel-kamelet, camel-yaml-dsl
            Reporter: Claus Ibsen


The YAML loader ({{KameletRoutesBuilderLoader.configureDataTypes}}) turns 
{{spec.dataTypes.out.default}} of a Kamelet into the {{outputType}} of its 
template route, and {{ContractAdvice.after()}} applies it when that route 
completes. That is right for sinks and actions, but not for a source: a source 
hands each message on with {{to("kamelet:sink")}}, and {{KameletProducer}} runs 
the whole consuming route synchronously, inside the template route. So for a 
source Kamelet:

* *The consuming route never sees the declared type.* A source declaring {{out: 
binary}} that gives {{"hello"}}: the first step of the consuming route sees 
{{java.lang.String}} and no {{Content-Type}}.
* *The exchange fails at the end* when the consuming route leaves a body the 
transformer cannot convert, such as a {{Map}}: {{CamelExecutionException: 
Failed to convert body to 'java:[B' ... at 
ContractAdvice.after(ContractAdvice.java:104)}}, after all the work of the 
consuming route is done.

Reproduced with {{camel run}} on 4.24.0-SNAPSHOT. The loader code is in 4.18.1+ 
and 4.22.0+. In the Kamelet catalog it affects the source Kamelets that declare 
an {{out}} default, such as aws-sqs-source, azure-eventhubs-source and 
slack-source.

h3. Fix
The output type of a source Kamelet is applied to the message when it is handed 
to {{kamelet:sink}}, before the consuming route runs: the loader records it as 
a route property of the template route instead of its {{outputType}}, and 
{{KameletProducer}} for the {{sink}} endpoint applies it with a 
{{DataTypeProcessor}}. It is no longer applied when the template route 
completes. Sinks and actions are unchanged.

Once the type is applied for real, the {{binary}} 
({{application-octet-stream}}) transformer must not read a stream into a 
{{byte[]}}: source Kamelets such as aws-s3-source and azure-storage-blob-source 
declare {{binary}} and give the object as a stream, which may be large. A 
stream is already binary, so the transformer keeps a stream body as it is and 
only sets the {{Content-Type}}.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to