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 <davscl...@apache.org> Authored: Tue Sep 26 15:47:33 2017 +0200 Committer: Claus Ibsen <davscl...@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 {