camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/2] camel git commit: CAMEL-11844: camel-azure - Should work with Camel file component OOTB
Date Tue, 26 Sep 2017 13:48:14 GMT
CAMEL-11844: camel-azure - Should work with Camel file component OOTB


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/d03f78bc
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/d03f78bc
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/d03f78bc

Branch: refs/heads/camel-2.19.x
Commit: d03f78bcf6ed1c581ec8309c8fbc03460f028785
Parents: f57a88e
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Tue Sep 26 15:47:33 2017 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Tue Sep 26 15:48:06 2017 +0200

----------------------------------------------------------------------
 .../azure/blob/BlobServiceProducer.java         | 35 ++++++++++++++------
 1 file changed, 24 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/d03f78bc/components/camel-azure/src/main/java/org/apache/camel/component/azure/blob/BlobServiceProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-azure/src/main/java/org/apache/camel/component/azure/blob/BlobServiceProducer.java
b/components/camel-azure/src/main/java/org/apache/camel/component/azure/blob/BlobServiceProducer.java
index 360b4aa..6a93c7e 100644
--- a/components/camel-azure/src/main/java/org/apache/camel/component/azure/blob/BlobServiceProducer.java
+++ b/components/camel-azure/src/main/java/org/apache/camel/component/azure/blob/BlobServiceProducer.java
@@ -41,6 +41,7 @@ import com.microsoft.azure.storage.blob.ListBlobItem;
 import com.microsoft.azure.storage.blob.PageRange;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
+import org.apache.camel.WrappedFile;
 import org.apache.camel.component.azure.common.ExchangeUtil;
 import org.apache.camel.impl.DefaultProducer;
 import org.apache.camel.util.ObjectHelper;
@@ -461,19 +462,31 @@ public class BlobServiceProducer extends DefaultProducer {
     }
     
     private InputStream getInputStreamFromExchange(Exchange exchange) throws Exception {
-        Object blobObject = exchange.getIn().getMandatoryBody();
-        InputStream inputStream = null;
-        if (blobObject instanceof String) {
-            String charset = getCharsetName(exchange);
-            inputStream = new ByteArrayInputStream(((String)blobObject).getBytes(charset));
-        } else if (blobObject instanceof InputStream) {
-            inputStream = (InputStream)blobObject;
-        } else if (blobObject instanceof File) {
-            inputStream = new FileInputStream((File)blobObject);
+        Object body = exchange.getIn().getBody();
+
+        if (body instanceof WrappedFile) {
+            // unwrap file
+            body = ((WrappedFile) body).getFile();
+        }
+
+        InputStream is;
+        if (body instanceof InputStream) {
+            is = (InputStream) body;
+        } else if (body instanceof File) {
+            is = new FileInputStream((File)body);
+        } else if (body instanceof byte[]) {
+            is = new ByteArrayInputStream((byte[]) body);
         } else {
-            throw new IllegalArgumentException("Unsupported blob type:" + blobObject.getClass().getName());
+            // try as input stream
+            is = exchange.getContext().getTypeConverter().tryConvertTo(InputStream.class,
exchange, body);
         }
-        return inputStream;
+
+        if (is == null) {
+            // fallback to string based
+            throw new IllegalArgumentException("Unsupported blob type:" + body.getClass().getName());
+        }
+
+        return is;
     }
     
     private void closeInputStreamIfNeeded(InputStream inputStream) throws IOException {


Mime
View raw message