You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by oa...@apache.org on 2021/02/26 11:33:21 UTC

[camel] branch camel-3.7.x updated: CAMEL-16252: Remove the explicit stream mark check (#5139)

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

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


The following commit(s) were added to refs/heads/camel-3.7.x by this push:
     new da728e5  CAMEL-16252: Remove the explicit stream mark check (#5139)
da728e5 is described below

commit da728e502185902087257cbd600a458efdf2cd8e
Author: Omar Al-Safi <om...@gmail.com>
AuthorDate: Fri Feb 26 12:32:57 2021 +0100

    CAMEL-16252: Remove the explicit stream mark check (#5139)
---
 .../services/org/apache/camel/component.properties |  2 +-
 .../azure/storage/blob/azure-storage-blob.json     |  2 +-
 .../azure/storage/blob/BlobStreamAndLength.java    |  4 ----
 .../component/azure/storage/blob/BlobUtils.java    |  4 ----
 .../blob/integration/BlobOperationsITTest.java     | 28 ++++++++++++++++++++++
 5 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/components/camel-azure-storage-blob/src/generated/resources/META-INF/services/org/apache/camel/component.properties b/components/camel-azure-storage-blob/src/generated/resources/META-INF/services/org/apache/camel/component.properties
index 5d923e7..fcd9fb6 100644
--- a/components/camel-azure-storage-blob/src/generated/resources/META-INF/services/org/apache/camel/component.properties
+++ b/components/camel-azure-storage-blob/src/generated/resources/META-INF/services/org/apache/camel/component.properties
@@ -2,6 +2,6 @@
 components=azure-storage-blob
 groupId=org.apache.camel
 artifactId=camel-azure-storage-blob
-version=3.7.2-SNAPSHOT
+version=3.7.3-SNAPSHOT
 projectName=Camel :: Azure Storage Blob
 projectDescription=Camel Azure Blob Storage Service Component
diff --git a/components/camel-azure-storage-blob/src/generated/resources/org/apache/camel/component/azure/storage/blob/azure-storage-blob.json b/components/camel-azure-storage-blob/src/generated/resources/org/apache/camel/component/azure/storage/blob/azure-storage-blob.json
index 65fcb3a..90a0374 100644
--- a/components/camel-azure-storage-blob/src/generated/resources/org/apache/camel/component/azure/storage/blob/azure-storage-blob.json
+++ b/components/camel-azure-storage-blob/src/generated/resources/org/apache/camel/component/azure/storage/blob/azure-storage-blob.json
@@ -11,7 +11,7 @@
     "supportLevel": "Stable",
     "groupId": "org.apache.camel",
     "artifactId": "camel-azure-storage-blob",
-    "version": "3.7.2-SNAPSHOT",
+    "version": "3.7.3-SNAPSHOT",
     "scheme": "azure-storage-blob",
     "extendsScheme": "",
     "syntax": "azure-storage-blob:accountName\/containerName",
diff --git a/components/camel-azure-storage-blob/src/main/java/org/apache/camel/component/azure/storage/blob/BlobStreamAndLength.java b/components/camel-azure-storage-blob/src/main/java/org/apache/camel/component/azure/storage/blob/BlobStreamAndLength.java
index da0595a..a38a604 100644
--- a/components/camel-azure-storage-blob/src/main/java/org/apache/camel/component/azure/storage/blob/BlobStreamAndLength.java
+++ b/components/camel-azure-storage-blob/src/main/java/org/apache/camel/component/azure/storage/blob/BlobStreamAndLength.java
@@ -47,10 +47,6 @@ public final class BlobStreamAndLength {
         }
 
         if (body instanceof InputStream) {
-            // Note: InputStream has to support mark/reset operations
-            if (!((InputStream) body).markSupported()) {
-                throw new IllegalArgumentException("InputStream of body exchange does not support mark/rest operations.");
-            }
             return new BlobStreamAndLength((InputStream) body, BlobUtils.getInputStreamLength((InputStream) body));
         }
         if (body instanceof File) {
diff --git a/components/camel-azure-storage-blob/src/main/java/org/apache/camel/component/azure/storage/blob/BlobUtils.java b/components/camel-azure-storage-blob/src/main/java/org/apache/camel/component/azure/storage/blob/BlobUtils.java
index 4a2c702..02ada37 100644
--- a/components/camel-azure-storage-blob/src/main/java/org/apache/camel/component/azure/storage/blob/BlobUtils.java
+++ b/components/camel-azure-storage-blob/src/main/java/org/apache/camel/component/azure/storage/blob/BlobUtils.java
@@ -34,10 +34,6 @@ public final class BlobUtils {
     }
 
     public static Long getInputStreamLength(final InputStream inputStream) throws IOException {
-        if (!inputStream.markSupported()) {
-            throw new IllegalArgumentException(
-                    "Reset inputStream is not supported, provide an inputstream with supported mark/reset.");
-        }
         final long length = IOUtils.toByteArray(inputStream).length;
         inputStream.reset();
 
diff --git a/components/camel-azure-storage-blob/src/test/java/org/apache/camel/component/azure/storage/blob/integration/BlobOperationsITTest.java b/components/camel-azure-storage-blob/src/test/java/org/apache/camel/component/azure/storage/blob/integration/BlobOperationsITTest.java
index ea5a5a1..e10e33e 100644
--- a/components/camel-azure-storage-blob/src/test/java/org/apache/camel/component/azure/storage/blob/integration/BlobOperationsITTest.java
+++ b/components/camel-azure-storage-blob/src/test/java/org/apache/camel/component/azure/storage/blob/integration/BlobOperationsITTest.java
@@ -43,6 +43,7 @@ import org.apache.camel.component.azure.storage.blob.client.BlobContainerClientW
 import org.apache.camel.component.azure.storage.blob.client.BlobServiceClientWrapper;
 import org.apache.camel.component.azure.storage.blob.operations.BlobOperationResponse;
 import org.apache.camel.component.azure.storage.blob.operations.BlobOperations;
+import org.apache.camel.converter.stream.FileInputStreamCache;
 import org.apache.camel.support.DefaultExchange;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
@@ -198,6 +199,33 @@ class BlobOperationsITTest extends BaseIT {
     }
 
     @Test
+    void testUploadBlockBlobAsCachedStream() throws Exception {
+        final BlobClientWrapper blobClientWrapper = blobContainerClientWrapper.getBlobClientWrapper("upload_test_file");
+        final BlobOperations operations = new BlobOperations(configuration, blobClientWrapper);
+
+        final File fileToUpload
+                = new File(Objects.requireNonNull(getClass().getClassLoader().getResource("upload_test_file")).getFile());
+        final Exchange exchange = new DefaultExchange(context);
+        exchange.getIn().setBody(new FileInputStreamCache(fileToUpload));
+
+        final BlobOperationResponse response = operations.uploadBlockBlob(exchange);
+
+        assertNotNull(response);
+        assertTrue((boolean) response.getBody());
+        // check for eTag and md5 to make sure is uploaded
+        assertNotNull(response.getHeaders().get(BlobConstants.E_TAG));
+        assertNotNull(response.getHeaders().get(BlobConstants.CONTENT_MD5));
+
+        // check content
+        final BlobOperationResponse getBlobResponse = operations.getBlob(null);
+
+        assertEquals("awesome camel to upload!",
+                IOUtils.toString((InputStream) getBlobResponse.getBody(), Charset.defaultCharset()));
+
+        blobClientWrapper.delete(null, null, null);
+    }
+
+    @Test
     void testCommitAndStageBlockBlob() throws Exception {
         final BlobClientWrapper blobClientWrapper = blobContainerClientWrapper.getBlobClientWrapper("upload_test_file");
         final BlobOperations operations = new BlobOperations(configuration, blobClientWrapper);