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 2016/03/09 10:57:19 UTC

[1/2] camel git commit: CAMEL-9680: Fixed camel-spring-boot to work with stream caching. Thanks to Jostein Gogstad for the unit test.

Repository: camel
Updated Branches:
  refs/heads/camel-2.16.x 731ae9e66 -> 46de24479
  refs/heads/master 1da0c37cf -> f54756531


CAMEL-9680: Fixed camel-spring-boot to work with stream caching. Thanks to Jostein Gogstad for the unit test.


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

Branch: refs/heads/master
Commit: f547565319c13fa8d5abe754ec85407f46053e36
Parents: 1da0c37
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Mar 9 10:56:36 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Mar 9 10:56:36 2016 +0100

----------------------------------------------------------------------
 components/camel-spring-boot/pom.xml            |  5 +
 .../camel/spring/boot/SpringTypeConverter.java  |  6 ++
 .../spring/boot/CamelAutoConfigurationTest.java |  3 +-
 .../boot/SpringConverterDelegationTest.java     |  2 +-
 .../spring/boot/issues/StreamCachingTest.java   | 96 ++++++++++++++++++++
 5 files changed, 110 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/f5475653/components/camel-spring-boot/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/pom.xml b/components/camel-spring-boot/pom.xml
index bb9bff2..b7067c8 100644
--- a/components/camel-spring-boot/pom.xml
+++ b/components/camel-spring-boot/pom.xml
@@ -63,6 +63,11 @@
 
     <!-- Testing dependencies -->
     <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-test</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <scope>test</scope>

http://git-wip-us.apache.org/repos/asf/camel/blob/f5475653/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SpringTypeConverter.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SpringTypeConverter.java b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SpringTypeConverter.java
index 4ce793c..d7020e5 100644
--- a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SpringTypeConverter.java
+++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SpringTypeConverter.java
@@ -19,6 +19,7 @@ package org.apache.camel.spring.boot;
 import java.util.List;
 
 import org.apache.camel.Exchange;
+import org.apache.camel.StreamCache;
 import org.apache.camel.TypeConversionException;
 import org.apache.camel.support.TypeConverterSupport;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -35,6 +36,11 @@ public class SpringTypeConverter extends TypeConverterSupport {
 
     @Override
     public <T> T convertTo(Class<T> type, Exchange exchange, Object value) throws TypeConversionException {
+        // do not attempt to convert Camel types
+        if (type.getCanonicalName().startsWith("org.apache")) {
+            return null;
+        }
+
         for (ConversionService conversionService : conversionServices) {
             if (conversionService.canConvert(value.getClass(), type)) {
                 return conversionService.convert(value, type);

http://git-wip-us.apache.org/repos/asf/camel/blob/f5475653/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelAutoConfigurationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelAutoConfigurationTest.java b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelAutoConfigurationTest.java
index 2b09479..7a1e31f 100644
--- a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelAutoConfigurationTest.java
+++ b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelAutoConfigurationTest.java
@@ -45,7 +45,8 @@ import static org.mockito.Mockito.verify;
 @IntegrationTest({
         "camel.springboot.consumerTemplateCacheSize=100",
         "camel.springboot.jmxEnabled=true",
-        "camel.springboot.name=customName"})
+        "camel.springboot.name=customName",
+        "camel.springboot.typeConversion=true"})
 public class CamelAutoConfigurationTest extends Assert {
 
     // Collaborators fixtures

http://git-wip-us.apache.org/repos/asf/camel/blob/f5475653/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/SpringConverterDelegationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/SpringConverterDelegationTest.java b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/SpringConverterDelegationTest.java
index 58a5b70..c961740 100644
--- a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/SpringConverterDelegationTest.java
+++ b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/SpringConverterDelegationTest.java
@@ -31,7 +31,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 @RunWith(SpringJUnit4ClassRunner.class)
 @EnableAutoConfiguration
 @SpringApplicationConfiguration(classes = SpringConverterDelegationTest.class)
-@IntegrationTest
+@IntegrationTest("camel.springboot.typeConversion=true")
 public class SpringConverterDelegationTest extends Assert {
 
     @Autowired

http://git-wip-us.apache.org/repos/asf/camel/blob/f5475653/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/issues/StreamCachingTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/issues/StreamCachingTest.java b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/issues/StreamCachingTest.java
new file mode 100644
index 0000000..d0a5fea
--- /dev/null
+++ b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/issues/StreamCachingTest.java
@@ -0,0 +1,96 @@
+/**
+ * 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.spring.boot.issues;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.List;
+
+import static java.util.Arrays.asList;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.boot.SpringTypeConverter;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.core.convert.ConversionService;
+import org.springframework.core.convert.converter.Converter;
+import org.springframework.core.convert.support.DefaultConversionService;
+
+public class StreamCachingTest extends CamelTestSupport {
+
+    public static final String URI_END_OF_ROUTE = "mock:end_of_route";
+
+    @EndpointInject(uri = URI_END_OF_ROUTE)
+    private MockEndpoint endOfRoute;
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                context.getTypeConverterRegistry().addFallbackTypeConverter(springTypeConverter(context, new ConversionService[]{new DefaultConversionService()}), true);
+
+                from("direct:foo")
+                    .streamCaching()
+                    .bean(MyBean.class)
+                    .to(URI_END_OF_ROUTE);
+            }
+        };
+    }
+
+    @Test
+    public void streamCachingWithSpring() throws Exception {
+        endOfRoute.expectedMessageCount(1);
+
+        template.sendBody("direct:foo", new FileInputStream(new File("src/test/resources/logback.xml")));
+
+        endOfRoute.assertIsSatisfied();
+    }
+
+    public static class MyBean {
+        public List<Integer> someNumbers() {
+            return asList(1, 2, 3);
+        }
+    }
+
+    /**
+     * Copied from org.apache.camel.spring.boot.TypeConversionConfiguration (they are package protected)
+     **/
+    @Bean
+    SpringTypeConverter springTypeConverter(CamelContext camelContext, ConversionService[] conversionServices) {
+        SpringTypeConverter springTypeConverter = new SpringTypeConverter(asList(conversionServices));
+        camelContext.getTypeConverterRegistry().addFallbackTypeConverter(springTypeConverter, true);
+        return springTypeConverter;
+    }
+
+    @ConditionalOnMissingBean
+    @Bean
+    ConversionService defaultCamelConversionService(ApplicationContext applicationContext) {
+        DefaultConversionService service = new DefaultConversionService();
+        for (Converter converter : applicationContext.getBeansOfType(Converter.class).values()) {
+            service.addConverter(converter);
+        }
+        return service;
+    }
+
+}
\ No newline at end of file


[2/2] camel git commit: CAMEL-9680: Fixed camel-spring-boot to work with stream caching. Thanks to Jostein Gogstad for the unit test.

Posted by da...@apache.org.
CAMEL-9680: Fixed camel-spring-boot to work with stream caching. Thanks to Jostein Gogstad for the unit test.


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

Branch: refs/heads/camel-2.16.x
Commit: 46de24479194c837a3d401bdf2e93b3ec76b3530
Parents: 731ae9e
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Mar 9 10:56:36 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Mar 9 10:57:06 2016 +0100

----------------------------------------------------------------------
 components/camel-spring-boot/pom.xml            |  5 +
 .../camel/spring/boot/SpringTypeConverter.java  |  6 ++
 .../spring/boot/CamelAutoConfigurationTest.java |  3 +-
 .../boot/SpringConverterDelegationTest.java     |  2 +-
 .../spring/boot/issues/StreamCachingTest.java   | 96 ++++++++++++++++++++
 5 files changed, 110 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/46de2447/components/camel-spring-boot/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/pom.xml b/components/camel-spring-boot/pom.xml
index ec54d91..b0b0be1 100644
--- a/components/camel-spring-boot/pom.xml
+++ b/components/camel-spring-boot/pom.xml
@@ -63,6 +63,11 @@
 
     <!-- Testing dependencies -->
     <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-test</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <scope>test</scope>

http://git-wip-us.apache.org/repos/asf/camel/blob/46de2447/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SpringTypeConverter.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SpringTypeConverter.java b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SpringTypeConverter.java
index 4ce793c..d7020e5 100644
--- a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SpringTypeConverter.java
+++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SpringTypeConverter.java
@@ -19,6 +19,7 @@ package org.apache.camel.spring.boot;
 import java.util.List;
 
 import org.apache.camel.Exchange;
+import org.apache.camel.StreamCache;
 import org.apache.camel.TypeConversionException;
 import org.apache.camel.support.TypeConverterSupport;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -35,6 +36,11 @@ public class SpringTypeConverter extends TypeConverterSupport {
 
     @Override
     public <T> T convertTo(Class<T> type, Exchange exchange, Object value) throws TypeConversionException {
+        // do not attempt to convert Camel types
+        if (type.getCanonicalName().startsWith("org.apache")) {
+            return null;
+        }
+
         for (ConversionService conversionService : conversionServices) {
             if (conversionService.canConvert(value.getClass(), type)) {
                 return conversionService.convert(value, type);

http://git-wip-us.apache.org/repos/asf/camel/blob/46de2447/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelAutoConfigurationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelAutoConfigurationTest.java b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelAutoConfigurationTest.java
index 2b09479..7a1e31f 100644
--- a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelAutoConfigurationTest.java
+++ b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelAutoConfigurationTest.java
@@ -45,7 +45,8 @@ import static org.mockito.Mockito.verify;
 @IntegrationTest({
         "camel.springboot.consumerTemplateCacheSize=100",
         "camel.springboot.jmxEnabled=true",
-        "camel.springboot.name=customName"})
+        "camel.springboot.name=customName",
+        "camel.springboot.typeConversion=true"})
 public class CamelAutoConfigurationTest extends Assert {
 
     // Collaborators fixtures

http://git-wip-us.apache.org/repos/asf/camel/blob/46de2447/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/SpringConverterDelegationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/SpringConverterDelegationTest.java b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/SpringConverterDelegationTest.java
index 58a5b70..c961740 100644
--- a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/SpringConverterDelegationTest.java
+++ b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/SpringConverterDelegationTest.java
@@ -31,7 +31,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 @RunWith(SpringJUnit4ClassRunner.class)
 @EnableAutoConfiguration
 @SpringApplicationConfiguration(classes = SpringConverterDelegationTest.class)
-@IntegrationTest
+@IntegrationTest("camel.springboot.typeConversion=true")
 public class SpringConverterDelegationTest extends Assert {
 
     @Autowired

http://git-wip-us.apache.org/repos/asf/camel/blob/46de2447/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/issues/StreamCachingTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/issues/StreamCachingTest.java b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/issues/StreamCachingTest.java
new file mode 100644
index 0000000..d0a5fea
--- /dev/null
+++ b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/issues/StreamCachingTest.java
@@ -0,0 +1,96 @@
+/**
+ * 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.spring.boot.issues;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.List;
+
+import static java.util.Arrays.asList;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.boot.SpringTypeConverter;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.core.convert.ConversionService;
+import org.springframework.core.convert.converter.Converter;
+import org.springframework.core.convert.support.DefaultConversionService;
+
+public class StreamCachingTest extends CamelTestSupport {
+
+    public static final String URI_END_OF_ROUTE = "mock:end_of_route";
+
+    @EndpointInject(uri = URI_END_OF_ROUTE)
+    private MockEndpoint endOfRoute;
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                context.getTypeConverterRegistry().addFallbackTypeConverter(springTypeConverter(context, new ConversionService[]{new DefaultConversionService()}), true);
+
+                from("direct:foo")
+                    .streamCaching()
+                    .bean(MyBean.class)
+                    .to(URI_END_OF_ROUTE);
+            }
+        };
+    }
+
+    @Test
+    public void streamCachingWithSpring() throws Exception {
+        endOfRoute.expectedMessageCount(1);
+
+        template.sendBody("direct:foo", new FileInputStream(new File("src/test/resources/logback.xml")));
+
+        endOfRoute.assertIsSatisfied();
+    }
+
+    public static class MyBean {
+        public List<Integer> someNumbers() {
+            return asList(1, 2, 3);
+        }
+    }
+
+    /**
+     * Copied from org.apache.camel.spring.boot.TypeConversionConfiguration (they are package protected)
+     **/
+    @Bean
+    SpringTypeConverter springTypeConverter(CamelContext camelContext, ConversionService[] conversionServices) {
+        SpringTypeConverter springTypeConverter = new SpringTypeConverter(asList(conversionServices));
+        camelContext.getTypeConverterRegistry().addFallbackTypeConverter(springTypeConverter, true);
+        return springTypeConverter;
+    }
+
+    @ConditionalOnMissingBean
+    @Bean
+    ConversionService defaultCamelConversionService(ApplicationContext applicationContext) {
+        DefaultConversionService service = new DefaultConversionService();
+        for (Converter converter : applicationContext.getBeansOfType(Converter.class).values()) {
+            service.addConverter(converter);
+        }
+        return service;
+    }
+
+}
\ No newline at end of file