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 2015/04/05 10:14:01 UTC
[2/4] camel git commit: CAMEL-4074: Make it easier to add custom type
converters manually from a class without having to use that META-INF marker
file. For example spring/blueprint users can then just add a .
CAMEL-4074: Make it easier to add custom type converters manually from a class without having to use that META-INF marker file. For example spring/blueprint users can then just add a <bean>.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/140ace54
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/140ace54
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/140ace54
Branch: refs/heads/master
Commit: 140ace545ce5cad52af025d82ba067843d9724a9
Parents: 14e9541
Author: Claus Ibsen <da...@apache.org>
Authored: Sun Apr 5 09:14:30 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Apr 5 09:14:30 2015 +0200
----------------------------------------------------------------------
.../xml/AbstractCamelContextFactoryBean.java | 10 +++++
.../converter/SpringTypeConvertersTest.java | 43 ++++++++++++++++++++
.../impl/converter/SpringTypeConvertersTest.xml | 32 +++++++++++++++
3 files changed, 85 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/140ace54/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
----------------------------------------------------------------------
diff --git a/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java b/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
index d3904e8..cc77527 100644
--- a/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
+++ b/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
@@ -34,6 +34,7 @@ import org.apache.camel.ManagementStatisticsLevel;
import org.apache.camel.RoutesBuilder;
import org.apache.camel.ShutdownRoute;
import org.apache.camel.ShutdownRunningTask;
+import org.apache.camel.TypeConverters;
import org.apache.camel.builder.ErrorHandlerBuilderRef;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.properties.PropertiesComponent;
@@ -236,6 +237,15 @@ public abstract class AbstractCamelContextFactoryBean<T extends ModelCamelContex
LOG.info("Using custom RuntimeEndpointRegistry: {}", runtimeEndpointRegistry);
getContext().setRuntimeEndpointRegistry(runtimeEndpointRegistry);
}
+ // custom type converters defined as <bean>s
+ Map<String, TypeConverters> typeConverters = getContext().getRegistry().findByTypeWithName(TypeConverters.class);
+ if (typeConverters != null && !typeConverters.isEmpty()) {
+ for (Entry<String, TypeConverters> entry : typeConverters.entrySet()) {
+ TypeConverters converter = entry.getValue();
+ LOG.info("Adding custom TypeConverters with id: {} and implementation: {}", entry.getKey(), converter);
+ getContext().getTypeConverterRegistry().addTypeConverters(converter);
+ }
+ }
// set the event notifier strategies if defined
Map<String, EventNotifier> eventNotifiers = getContext().getRegistry().findByTypeWithName(EventNotifier.class);
if (eventNotifiers != null && !eventNotifiers.isEmpty()) {
http://git-wip-us.apache.org/repos/asf/camel/blob/140ace54/components/camel-spring/src/test/java/org/apache/camel/spring/impl/converter/SpringTypeConvertersTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/impl/converter/SpringTypeConvertersTest.java b/components/camel-spring/src/test/java/org/apache/camel/spring/impl/converter/SpringTypeConvertersTest.java
new file mode 100644
index 0000000..afb5229
--- /dev/null
+++ b/components/camel-spring/src/test/java/org/apache/camel/spring/impl/converter/SpringTypeConvertersTest.java
@@ -0,0 +1,43 @@
+/**
+ * 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.impl.converter;
+
+import org.apache.camel.impl.converter.Country;
+import org.apache.camel.spring.SpringTestSupport;
+import org.junit.Test;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class SpringTypeConvertersTest extends SpringTestSupport {
+
+ @Override
+ protected AbstractXmlApplicationContext createApplicationContext() {
+ return new ClassPathXmlApplicationContext("org/apache/camel/spring/impl/converter/SpringTypeConvertersTest.xml");
+ }
+
+ @Test
+ public void testConvertersShouldBeAddedAutomaticBySpring() throws Exception {
+ Country country = context.getTypeConverter().convertTo(Country.class, "en");
+ assertNotNull(country);
+ assertEquals("England", country.getName());
+
+ String iso = context.getTypeConverter().convertTo(String.class, country);
+ assertNotNull(iso);
+ assertEquals("en", iso);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/140ace54/components/camel-spring/src/test/resources/org/apache/camel/spring/impl/converter/SpringTypeConvertersTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/spring/impl/converter/SpringTypeConvertersTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/spring/impl/converter/SpringTypeConvertersTest.xml
new file mode 100644
index 0000000..db0efda
--- /dev/null
+++ b/components/camel-spring/src/test/resources/org/apache/camel/spring/impl/converter/SpringTypeConvertersTest.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+ ">
+
+ <!-- this is our custom type converters implementation -->
+ <bean id="myConverters" class="org.apache.camel.impl.converter.MyConverters"/>
+
+ <!-- we just have an empty CamelContext as we test the converters without routes -->
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+ </camelContext>
+
+</beans>