You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2017/09/26 13:48:13 UTC
[1/2] camel git commit: CAMEL-11844: camel-azure - Should work with
Camel file component OOTB
Repository: camel
Updated Branches:
refs/heads/camel-2.19.x f57a88ef9 -> d03f78bcf
refs/heads/master fb7d8d676 -> ec08a627f
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/ec08a627
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ec08a627
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ec08a627
Branch: refs/heads/master
Commit: ec08a627f5d8f2c4fd6eb8859794b1202d394127
Parents: fb7d8d6
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Sep 26 15:47:33 2017 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Sep 26 15:47:33 2017 +0200
----------------------------------------------------------------------
.../azure/blob/BlobServiceProducer.java | 35 ++++++++++++++------
1 file changed, 24 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/ec08a627/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 {
[2/2] camel git commit: CAMEL-11844: camel-azure - Should work with
Camel file component OOTB
Posted by da...@apache.org.
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 <da...@apache.org>
Authored: Tue Sep 26 15:47:33 2017 +0200
Committer: Claus Ibsen <da...@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 {