[
https://issues.apache.org/jira/browse/CAMEL-25934?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18131136#comment-18131136
]
Claus Ibsen commented on CAMEL-25934:
-------------------------------------
Fixed in PR https://github.com/apache/camel/pull/28372
_Claude Code on behalf of davsclaus_
> camel-ibm-cos - putObject takes the length from a stale
> CamelIBMCOSContentLength header, so a body the route changed after a consumer
> or getObject fails to upload
> ------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> Key: CAMEL-25934
> URL: https://issues.apache.org/jira/browse/CAMEL-25934
> Project: Camel
> Issue Type: Bug
> Affects Versions: 4.18.0, 4.22.0, 4.23.0
> Reporter: Claus Ibsen
> Assignee: Claus Ibsen
> Priority: Minor
> Fix For: 4.24.0
>
>
> The ibm-cos producer takes the content length of putObject from the
> {{CamelIBMCOSContentLength}} header whenever it is set, and only looks at the
> body when it is not ({{IBMCOSProducer}}, main 4065a7464c45, lines 142-144):
> {code:java}
> Long contentLength =
> exchange.getIn().getHeader(IBMCOSConstants.CONTENT_LENGTH, Long.class);
> if (contentLength != null) {
> metadata.setContentLength(contentLength);
> {code}
> The consumer sets that header to the length of the object it read
> ({{IBMCOSConsumer}} line 228), getObject does the same (producer line 226),
> and the header stays on the message when the route changes the body. So a
> route that reads an object, changes it and writes it fails, as the SDK checks
> the length against the data:
> * a longer body: {{SdkClientException: More data read than expected:
> dataLength=52; expectedLength=11}}
> * a shorter body: {{SdkClientException: Data read has a different length than
> the expected: dataLength=2; expectedLength=11}}
> Checked on 4.24.0-SNAPSHOT against an S3 API ({{camel infra run aws s3}})
> with a {{cosClient}} built with HMAC keys: getObject of an 11-byte object,
> then {{setBody}}, then putObject to another key. With {{removeHeader:
> CamelIBMCOSContentLength}} before the upload, the new body is stored.
> CAMEL-25743 fixed the same in camel-aws2-s3, where the SDK cut the body to
> the old length instead of failing. CAMEL-25898 is another header of the
> ibm-cos consumer that steers its producer.
> *Proposed change*: as CAMEL-25743 did for aws2-s3, take the length from the
> body when it is known (a byte array, a String, the stream cache, the
> WrappedFile), and use the header only for a stream of unknown length.
> _Claude Code on behalf of davsclaus_
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)