Claus Ibsen created CAMEL-25934:
-----------------------------------
Summary: 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
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
(v8.20.10#820010)