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

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


The following commit(s) were added to refs/heads/master by this push:
     new 27cb0f5  CAMEL-12412: Fixed camel-jclouds fallback type-converter 
issue when stream caching is enabled and consuming from a file where it would 
mistakenly attempt to convert to a jclouds type.
27cb0f5 is described below

commit 27cb0f51e53baf93cf1b3b8e2c5a62c51fafabde
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Wed Mar 28 16:03:39 2018 +0200

    CAMEL-12412: Fixed camel-jclouds fallback type-converter issue when stream 
caching is enabled and consuming from a file where it would mistakenly attempt 
to convert to a jclouds type.
---
 .../component/jclouds/JcloudsPayloadConverter.java | 16 +++----
 .../JcloudsFileConsumerStreamCachingIssueTest.java | 55 ++++++++++++++++++++++
 2 files changed, 62 insertions(+), 9 deletions(-)

diff --git 
a/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsPayloadConverter.java
 
b/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsPayloadConverter.java
index 5fc34a5..c0288df 100644
--- 
a/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsPayloadConverter.java
+++ 
b/components/camel-jclouds/src/main/java/org/apache/camel/component/jclouds/JcloudsPayloadConverter.java
@@ -21,18 +21,16 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
 import java.util.Date;
-
 import javax.xml.transform.stream.StreamSource;
 
 import com.google.common.io.ByteSource;
 import com.google.common.io.ByteStreams;
 import com.google.common.io.Files;
-
 import org.apache.camel.Converter;
 import org.apache.camel.Exchange;
 import org.apache.camel.FallbackConverter;
 import org.apache.camel.TypeConverter;
-import org.apache.camel.component.file.GenericFile;
+import org.apache.camel.WrappedFile;
 import org.apache.camel.converter.stream.StreamSourceCache;
 import org.apache.camel.spi.TypeConverterRegistry;
 import org.apache.camel.util.IOHelper;
@@ -132,13 +130,13 @@ public final class JcloudsPayloadConverter {
     @SuppressWarnings("unchecked")
     public static <T extends Payload> T convertTo(Class<T> type, Exchange 
exchange, Object value, TypeConverterRegistry registry) throws IOException {
         Class<?> sourceType = value.getClass();
-        if (GenericFile.class.isAssignableFrom(sourceType)) {
-            GenericFile<?> genericFile = (GenericFile<?>) value;
-            if (genericFile.getFile() != null) {
-                Class<?> genericFileType = genericFile.getFile().getClass();
-                TypeConverter converter = registry.lookup(Payload.class, 
genericFileType);
+        if (type == Payload.class && 
WrappedFile.class.isAssignableFrom(sourceType)) {
+            // attempt to convert to JClouds Payload from a file
+            WrappedFile wf = (WrappedFile) value;
+            if (wf.getFile() != null) {
+                TypeConverter converter = registry.lookup(Payload.class, 
wf.getFile().getClass());
                 if (converter != null) {
-                    return (T) converter.convertTo(Payload.class, 
genericFile.getFile());
+                    return (T) converter.tryConvertTo(Payload.class, 
wf.getFile());
                 }
             }
         }
diff --git 
a/components/camel-jclouds/src/test/java/org/apache/camel/component/jclouds/JcloudsFileConsumerStreamCachingIssueTest.java
 
b/components/camel-jclouds/src/test/java/org/apache/camel/component/jclouds/JcloudsFileConsumerStreamCachingIssueTest.java
new file mode 100644
index 0000000..04823e5
--- /dev/null
+++ 
b/components/camel-jclouds/src/test/java/org/apache/camel/component/jclouds/JcloudsFileConsumerStreamCachingIssueTest.java
@@ -0,0 +1,55 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jclouds;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+/**
+ * There is a jclouds fallback type-converter that may cause issue when stream 
caching is enabled.
+ */
+public class JcloudsFileConsumerStreamCachingIssueTest extends 
CamelTestSupport {
+
+    @Override
+    public void setUp() throws Exception {
+        deleteDirectory("target/foo");
+        super.setUp();
+    }
+
+    @Test
+    public void testFromFile() throws Exception {
+        getMockEndpoint("mock:foo").expectedMessageCount(1);
+
+        template.sendBodyAndHeader("file:target/foo", "Hello World", 
Exchange.FILE_NAME, "foo.txt");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RoutesBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("file:target/foo").streamCaching()
+                    .to("mock:foo");
+            }
+        };
+    }
+}

-- 
To stop receiving notification emails like this one, please contact
davscl...@apache.org.

Reply via email to