This is an automated email from the ASF dual-hosted git repository.

fmariani pushed a commit to branch camel-4.18.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-4.18.x by this push:
     new 8866e09d9586 camel-minio error writing to object store
8866e09d9586 is described below

commit 8866e09d9586baabe7150cb72b6fcb6e60f450dc
Author: Croway <[email protected]>
AuthorDate: Fri Feb 27 17:17:26 2026 +0100

    camel-minio error writing to object store
---
 .../BlobUploadBlockBlobBodyTypesIT.java            | 150 +++++++++++++++++++++
 .../component/huaweicloud/obs/OBSProducer.java     |   8 +-
 .../camel/component/minio/MinioProducer.java       |   3 -
 .../integration/MinioPutObjectBodyTypesIT.java     | 147 ++++++++++++++++++++
 4 files changed, 302 insertions(+), 6 deletions(-)

diff --git 
a/components/camel-azure/camel-azure-storage-blob/src/test/java/org/apache/camel/component/azure/storage/blob/integration/BlobUploadBlockBlobBodyTypesIT.java
 
b/components/camel-azure/camel-azure-storage-blob/src/test/java/org/apache/camel/component/azure/storage/blob/integration/BlobUploadBlockBlobBodyTypesIT.java
new file mode 100644
index 000000000000..fcf817cbdf19
--- /dev/null
+++ 
b/components/camel-azure/camel-azure-storage-blob/src/test/java/org/apache/camel/component/azure/storage/blob/integration/BlobUploadBlockBlobBodyTypesIT.java
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.azure.storage.blob.integration;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+
+import com.azure.storage.blob.BlobContainerClient;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.WrappedFile;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.azure.storage.blob.BlobConstants;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+/**
+ * Integration tests for uploadBlockBlob with various body types.
+ *
+ * Verifies that String, InputStream, byte[], and WrappedFile bodies are all 
correctly uploaded to Azure Blob Storage
+ * with proper content-length handling.
+ */
+class BlobUploadBlockBlobBodyTypesIT extends Base {
+
+    private static final String CONTENT = "Hello from Camel Azure Storage Blob 
test";
+
+    @TempDir
+    File tempDir;
+
+    @EndpointInject
+    private ProducerTemplate template;
+
+    private BlobContainerClient containerClient;
+
+    @BeforeAll
+    public void prepare() {
+        containerClient = serviceClient.getBlobContainerClient(containerName);
+        containerClient.create();
+    }
+
+    @Test
+    void uploadBlockBlobWithStringBody() throws Exception {
+        Exchange result = template.send("direct:uploadBlockBlob", exchange -> {
+            exchange.getIn().setHeader(BlobConstants.BLOB_NAME, 
"string-body.txt");
+            exchange.getIn().setBody(CONTENT);
+        });
+
+        assertNull(result.getException(), "Exchange should not have an 
exception");
+        assertEquals(CONTENT, downloadBlob("string-body.txt"));
+    }
+
+    @Test
+    void uploadBlockBlobWithInputStreamBody() throws Exception {
+        Exchange result = template.send("direct:uploadBlockBlob", exchange -> {
+            exchange.getIn().setHeader(BlobConstants.BLOB_NAME, 
"stream-body.txt");
+            exchange.getIn().setBody(new 
ByteArrayInputStream(CONTENT.getBytes(StandardCharsets.UTF_8)));
+        });
+
+        assertNull(result.getException(), "Exchange should not have an 
exception");
+        assertEquals(CONTENT, downloadBlob("stream-body.txt"));
+    }
+
+    @Test
+    void uploadBlockBlobWithByteArrayBody() throws Exception {
+        Exchange result = template.send("direct:uploadBlockBlob", exchange -> {
+            exchange.getIn().setHeader(BlobConstants.BLOB_NAME, 
"bytes-body.txt");
+            exchange.getIn().setBody(CONTENT.getBytes(StandardCharsets.UTF_8));
+        });
+
+        assertNull(result.getException(), "Exchange should not have an 
exception");
+        assertEquals(CONTENT, downloadBlob("bytes-body.txt"));
+    }
+
+    @Test
+    void uploadBlockBlobWithWrappedFileBody() throws Exception {
+        File tempFile = new File(tempDir, "wrapped-test.txt");
+        Files.writeString(tempFile.toPath(), CONTENT);
+
+        WrappedFile<File> wrappedFile = new WrappedFile<>() {
+            @Override
+            public File getFile() {
+                return tempFile;
+            }
+
+            @Override
+            public Object getBody() {
+                return tempFile;
+            }
+
+            @Override
+            public long getFileLength() {
+                return tempFile.length();
+            }
+        };
+
+        Exchange result = template.send("direct:uploadBlockBlob", exchange -> {
+            exchange.getIn().setHeader(BlobConstants.BLOB_NAME, 
"wrapped-file-body.txt");
+            exchange.getIn().setBody(wrappedFile);
+        });
+
+        assertNull(result.getException(), "Exchange should not have an 
exception");
+        assertEquals(CONTENT, downloadBlob("wrapped-file-body.txt"));
+    }
+
+    private String downloadBlob(String blobName) {
+        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+        containerClient.getBlobClient(blobName).downloadStream(outputStream);
+        return outputStream.toString(StandardCharsets.UTF_8);
+    }
+
+    @AfterAll
+    public void deleteContainer() {
+        containerClient.delete();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                from("direct:uploadBlockBlob")
+                        
.to(String.format("azure-storage-blob://cameldev/%s?operation=uploadBlockBlob", 
containerName));
+            }
+        };
+    }
+}
diff --git 
a/components/camel-huawei/camel-huaweicloud-obs/src/main/java/org/apache/camel/component/huaweicloud/obs/OBSProducer.java
 
b/components/camel-huawei/camel-huaweicloud-obs/src/main/java/org/apache/camel/component/huaweicloud/obs/OBSProducer.java
index c4e678da8618..575ccb7999c4 100644
--- 
a/components/camel-huawei/camel-huaweicloud-obs/src/main/java/org/apache/camel/component/huaweicloud/obs/OBSProducer.java
+++ 
b/components/camel-huawei/camel-huaweicloud-obs/src/main/java/org/apache/camel/component/huaweicloud/obs/OBSProducer.java
@@ -18,7 +18,6 @@ package org.apache.camel.component.huaweicloud.obs;
 
 import java.io.ByteArrayInputStream;
 import java.io.File;
-import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
@@ -109,7 +108,7 @@ public class OBSProducer extends DefaultProducer {
         }
     }
 
-    private void putObject(Exchange exchange, ClientConfigurations 
clientConfigurations) throws IOException {
+    private void putObject(Exchange exchange, ClientConfigurations 
clientConfigurations) throws Exception {
 
         Object body = exchange.getMessage().getBody();
 
@@ -166,7 +165,10 @@ public class OBSProducer extends DefaultProducer {
                     clientConfigurations.getObjectName(), (InputStream) body);
 
         } else {
-            throw new IllegalArgumentException("Body should be of type file, 
string or an input stream");
+            // fallback: convert via the exchange (e.g., GenericFile from 
SFTP/FTP)
+            InputStream is = 
exchange.getMessage().getMandatoryBody(InputStream.class);
+            putObjectResult = 
obsClient.putObject(clientConfigurations.getBucketName(),
+                    clientConfigurations.getObjectName(), is);
         }
         exchange.getMessage().setBody(gson.toJson(putObjectResult));
     }
diff --git 
a/components/camel-minio/src/main/java/org/apache/camel/component/minio/MinioProducer.java
 
b/components/camel-minio/src/main/java/org/apache/camel/component/minio/MinioProducer.java
index 0daf1cdb73c4..01583c3199ab 100644
--- 
a/components/camel-minio/src/main/java/org/apache/camel/component/minio/MinioProducer.java
+++ 
b/components/camel-minio/src/main/java/org/apache/camel/component/minio/MinioProducer.java
@@ -162,9 +162,6 @@ public class MinioProducer extends DefaultProducer {
                     if (contentLength <= 0) {
                         contentLength = filePayload.length();
                     }
-                } else if (object instanceof InputStream is) {
-                    // Use the InputStream directly (e.g., from 
WrappedFile.getFile())
-                    inputStream = is;
                 } else {
                     inputStream = 
exchange.getMessage().getMandatoryBody(InputStream.class);
                     if (contentLength <= 0) {
diff --git 
a/components/camel-minio/src/test/java/org/apache/camel/component/minio/integration/MinioPutObjectBodyTypesIT.java
 
b/components/camel-minio/src/test/java/org/apache/camel/component/minio/integration/MinioPutObjectBodyTypesIT.java
new file mode 100644
index 000000000000..c85531b4c373
--- /dev/null
+++ 
b/components/camel-minio/src/test/java/org/apache/camel/component/minio/integration/MinioPutObjectBodyTypesIT.java
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.minio.integration;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+
+import io.minio.GetObjectArgs;
+import io.minio.MinioClient;
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.WrappedFile;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.minio.MinioConstants;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+/**
+ * Integration tests for MinioProducer putObject with various body types.
+ *
+ * Verifies that String, InputStream, byte[], and WrappedFile bodies are all 
correctly uploaded to Minio with proper
+ * content-length handling.
+ *
+ */
+class MinioPutObjectBodyTypesIT extends MinioIntegrationTestSupport {
+
+    private static final String BUCKET = "test-body-types";
+    private static final String CONTENT = "Hello from Camel Minio test";
+
+    @TempDir
+    File tempDir;
+
+    @BindToRegistry("minioClient")
+    MinioClient client = MinioClient.builder()
+            .endpoint("http://"; + service.host(), service.port(), false)
+            .credentials(service.accessKey(), service.secretKey())
+            .build();
+
+    @EndpointInject
+    private ProducerTemplate template;
+
+    @Test
+    void putObjectWithStringBody() throws Exception {
+        Exchange result = template.send("direct:putObject", exchange -> {
+            exchange.getIn().setHeader(MinioConstants.OBJECT_NAME, 
"string-body.txt");
+            exchange.getIn().setBody(CONTENT);
+        });
+
+        assertNull(result.getException(), "Exchange should not have an 
exception");
+        assertEquals(CONTENT, readObject("string-body.txt"));
+    }
+
+    @Test
+    void putObjectWithInputStreamBody() throws Exception {
+        Exchange result = template.send("direct:putObject", exchange -> {
+            exchange.getIn().setHeader(MinioConstants.OBJECT_NAME, 
"stream-body.txt");
+            exchange.getIn().setBody(new 
ByteArrayInputStream(CONTENT.getBytes(StandardCharsets.UTF_8)));
+        });
+
+        assertNull(result.getException(), "Exchange should not have an 
exception");
+        assertEquals(CONTENT, readObject("stream-body.txt"));
+    }
+
+    @Test
+    void putObjectWithByteArrayBody() throws Exception {
+        Exchange result = template.send("direct:putObject", exchange -> {
+            exchange.getIn().setHeader(MinioConstants.OBJECT_NAME, 
"bytes-body.txt");
+            exchange.getIn().setBody(CONTENT.getBytes(StandardCharsets.UTF_8));
+        });
+
+        assertNull(result.getException(), "Exchange should not have an 
exception");
+        assertEquals(CONTENT, readObject("bytes-body.txt"));
+    }
+
+    @Test
+    void putObjectWithWrappedFileBody() throws Exception {
+        File tempFile = new File(tempDir, "wrapped-test.txt");
+        Files.writeString(tempFile.toPath(), CONTENT);
+
+        WrappedFile<File> wrappedFile = new WrappedFile<>() {
+            @Override
+            public File getFile() {
+                return tempFile;
+            }
+
+            @Override
+            public Object getBody() {
+                return tempFile;
+            }
+
+            @Override
+            public long getFileLength() {
+                return tempFile.length();
+            }
+        };
+
+        Exchange result = template.send("direct:putObject", exchange -> {
+            exchange.getIn().setHeader(MinioConstants.OBJECT_NAME, 
"wrapped-file-body.txt");
+            exchange.getIn().setBody(wrappedFile);
+        });
+
+        assertNull(result.getException(), "Exchange should not have an 
exception");
+        assertEquals(CONTENT, readObject("wrapped-file-body.txt"));
+    }
+
+    private String readObject(String objectName) throws Exception {
+        try (InputStream is = client.getObject(GetObjectArgs.builder()
+                .bucket(BUCKET)
+                .object(objectName)
+                .build())) {
+            return new String(is.readAllBytes(), StandardCharsets.UTF_8);
+        }
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                from("direct:putObject")
+                        .to("minio://" + BUCKET + "?autoCreateBucket=true");
+            }
+        };
+    }
+}

Reply via email to