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

davsclaus pushed a commit to branch azure-blob
in repository https://gitbox.apache.org/repos/asf/camel.git

commit b1b4a7609c4d91989585fbd1866026445c202bf3
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Tue Apr 30 15:43:06 2024 +0200

    CAMEL-20727: camel-azure - Blob uploadPage should not read content into 
memory
---
 .../component/azure/storage/blob/operations/BlobOperations.java  | 9 ++++-----
 .../azure/storage/blob/integration/BlobOperationsIT.java         | 8 ++++----
 2 files changed, 8 insertions(+), 9 deletions(-)

diff --git 
a/components/camel-azure/camel-azure-storage-blob/src/main/java/org/apache/camel/component/azure/storage/blob/operations/BlobOperations.java
 
b/components/camel-azure/camel-azure-storage-blob/src/main/java/org/apache/camel/component/azure/storage/blob/operations/BlobOperations.java
index a7f3cd8f2e6..9d3716bdebc 100644
--- 
a/components/camel-azure/camel-azure-storage-blob/src/main/java/org/apache/camel/component/azure/storage/blob/operations/BlobOperations.java
+++ 
b/components/camel-azure/camel-azure-storage-blob/src/main/java/org/apache/camel/component/azure/storage/blob/operations/BlobOperations.java
@@ -374,7 +374,7 @@ public class BlobOperations {
         return BlobOperationResponse.createWithEmptyBody(response);
     }
 
-    public BlobOperationResponse uploadPageBlob(final Exchange exchange) 
throws IOException {
+    public BlobOperationResponse uploadPageBlob(final Exchange exchange) 
throws Exception {
         ObjectHelper.notNull(exchange, MISSING_EXCHANGE);
 
         final boolean createPageBlob = 
configurationProxy.isCreatePageBlob(exchange);
@@ -384,22 +384,21 @@ public class BlobOperations {
             createPageBlob(exchange);
         }
 
-        final BlobStreamAndLength streamAndLength = 
BlobStreamAndLength.createBlobStreamAndLengthFromExchangeBody(exchange);
+        final InputStream is = 
exchange.getMessage().getMandatoryBody(InputStream.class);
         final BlobCommonRequestOptions requestOptions = 
getCommonRequestOptions(exchange);
         final PageRange pageRange = configurationProxy.getPageRange(exchange);
-
         if (pageRange == null) {
             throw new IllegalArgumentException("You need to set page range in 
the exchange headers.");
         }
 
         try {
             final Response<PageBlobItem> response
-                    = client.uploadPageBlob(pageRange, 
streamAndLength.getInputStream(), requestOptions.getContentMD5(),
+                    = client.uploadPageBlob(pageRange, is, 
requestOptions.getContentMD5(),
                             requestOptions.getBlobRequestConditions(), 
requestOptions.getTimeout());
 
             return BlobOperationResponse.createWithEmptyBody(response);
         } finally {
-            closeInputStreamIfNeeded(streamAndLength.getInputStream());
+            closeInputStreamIfNeeded(is);
         }
     }
 
diff --git 
a/components/camel-azure/camel-azure-storage-blob/src/test/java/org/apache/camel/component/azure/storage/blob/integration/BlobOperationsIT.java
 
b/components/camel-azure/camel-azure-storage-blob/src/test/java/org/apache/camel/component/azure/storage/blob/integration/BlobOperationsIT.java
index 4f6dee9314c..32fd56dbd2f 100644
--- 
a/components/camel-azure/camel-azure-storage-blob/src/test/java/org/apache/camel/component/azure/storage/blob/integration/BlobOperationsIT.java
+++ 
b/components/camel-azure/camel-azure-storage-blob/src/test/java/org/apache/camel/component/azure/storage/blob/integration/BlobOperationsIT.java
@@ -330,7 +330,7 @@ class BlobOperationsIT extends Base {
     }
 
     @Test
-    void testCreateAndUploadPageBlob() throws IOException {
+    void testCreateAndUploadPageBlob() throws Exception {
         final BlobClientWrapper blobClientWrapper = 
blobContainerClientWrapper.getBlobClientWrapper("upload_test_file.txt");
         final BlobOperations operations = new BlobOperations(configuration, 
blobClientWrapper);
 
@@ -361,7 +361,7 @@ class BlobOperationsIT extends Base {
     }
 
     @Test
-    void testResizePageBlob() throws IOException {
+    void testResizePageBlob() throws Exception {
         final BlobClientWrapper blobClientWrapper = 
blobContainerClientWrapper.getBlobClientWrapper("upload_test_file.txt");
         final BlobOperations operations = new BlobOperations(configuration, 
blobClientWrapper);
 
@@ -396,7 +396,7 @@ class BlobOperationsIT extends Base {
     }
 
     @Test
-    void testClearPages() throws IOException {
+    void testClearPages() throws Exception {
         final BlobClientWrapper blobClientWrapper = 
blobContainerClientWrapper.getBlobClientWrapper("upload_test_file.txt");
         final BlobOperations operations = new BlobOperations(configuration, 
blobClientWrapper);
 
@@ -426,7 +426,7 @@ class BlobOperationsIT extends Base {
     }
 
     @Test
-    void testGetPageBlobRanges() throws IOException {
+    void testGetPageBlobRanges() throws Exception {
         final BlobClientWrapper blobClientWrapper = 
blobContainerClientWrapper.getBlobClientWrapper("upload_test_file.txt");
         final BlobOperations operations = new BlobOperations(configuration, 
blobClientWrapper);
 

Reply via email to