Repository: camel Updated Branches: refs/heads/camel-2.18.x 33a390480 -> dac569062 refs/heads/master 161fff1fb -> 85bd238d4
CAMEL-10573: Align FallbackTypeConverter loading in OSGI environments Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/e0c53ced Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/e0c53ced Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/e0c53ced Branch: refs/heads/master Commit: e0c53ced3bdfd4d946f6a48873f724bdd6659029 Parents: 161fff1 Author: jpoth <[email protected]> Authored: Thu Dec 8 13:23:20 2016 +0100 Committer: Claus Ibsen <[email protected]> Committed: Tue Dec 13 10:13:02 2016 +0100 ---------------------------------------------------------------------- .../org/apache/camel/impl/osgi/Activator.java | 4 +- tests/camel-itest-karaf/pom.xml | 5 ++ .../org/apache/camel/itest/karaf/bean/Pojo.java | 72 ++++++++++++++++++++ .../CamelJacksonFallbackConverterTest.java | 60 ++++++++++++++++ 4 files changed, 138 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/e0c53ced/camel-core/src/main/java/org/apache/camel/impl/osgi/Activator.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/impl/osgi/Activator.java b/camel-core/src/main/java/org/apache/camel/impl/osgi/Activator.java index 2071912..5eb3ced 100644 --- a/camel-core/src/main/java/org/apache/camel/impl/osgi/Activator.java +++ b/camel-core/src/main/java/org/apache/camel/impl/osgi/Activator.java @@ -425,9 +425,7 @@ public class Activator implements BundleActivator, BundleTrackerCustomizer { LOG.trace("Loading {} class", pkg); try { Class<?> clazz = bundle.loadClass(pkg); - if (test.matches(clazz)) { - classes.add(clazz); - } + classes.add(clazz); // the class could be found and loaded so continue to next continue; } catch (Throwable t) { http://git-wip-us.apache.org/repos/asf/camel/blob/e0c53ced/tests/camel-itest-karaf/pom.xml ---------------------------------------------------------------------- diff --git a/tests/camel-itest-karaf/pom.xml b/tests/camel-itest-karaf/pom.xml index 0576fb5..ecb52cc 100644 --- a/tests/camel-itest-karaf/pom.xml +++ b/tests/camel-itest-karaf/pom.xml @@ -122,6 +122,11 @@ <scope>test</scope> </dependency> <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-jackson</artifactId> + <scope>test</scope> + </dependency> + <dependency> <groupId>org.apache.camel.karaf</groupId> <artifactId>apache-camel</artifactId> <version>${project.version}</version> http://git-wip-us.apache.org/repos/asf/camel/blob/e0c53ced/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/bean/Pojo.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/bean/Pojo.java b/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/bean/Pojo.java new file mode 100644 index 0000000..4468913 --- /dev/null +++ b/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/bean/Pojo.java @@ -0,0 +1,72 @@ +/** + * 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.itest.karaf.bean; + +public class Pojo { + private int id; + private String name; + + public Pojo(int id, String name) { + this.id = id; + this.name = name; + } + + public Pojo() { + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof Pojo)) { + return false; + } + + + Pojo pojo = (Pojo) o; + + if (id != pojo.getId()) { + return false; + } + return name != null ? name.equals(pojo.getName()) : pojo.getName() == null; + + } + + @Override + public int hashCode() { + int result = id; + result = 31 * result + (name != null ? name.hashCode() : 0); + return result; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/e0c53ced/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/converters/CamelJacksonFallbackConverterTest.java ---------------------------------------------------------------------- diff --git a/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/converters/CamelJacksonFallbackConverterTest.java b/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/converters/CamelJacksonFallbackConverterTest.java new file mode 100644 index 0000000..136da20 --- /dev/null +++ b/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/converters/CamelJacksonFallbackConverterTest.java @@ -0,0 +1,60 @@ +/** + * 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.itest.karaf.converters; + +import org.apache.camel.CamelContext; +import org.apache.camel.component.jackson.JacksonConstants; +import org.apache.camel.impl.DefaultExchange; +import org.apache.camel.itest.karaf.BaseKarafTest; +import org.apache.camel.itest.karaf.bean.Pojo; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.ops4j.pax.exam.Configuration; +import org.ops4j.pax.exam.Option; +import org.ops4j.pax.exam.junit.PaxExam; + +import static org.junit.Assert.assertNotNull; + +@RunWith(PaxExam.class) +public class CamelJacksonFallbackConverterTest extends BaseKarafTest { + + @Configuration + public static Option[] configure() { + return BaseKarafTest.configure("camel-jackson"); + } + + @Test + public void test() throws Exception { + CamelContext context = getOsgiService(bundleContext, CamelContext.class, "(camel.context.name=myCamel)", SERVICE_TIMEOUT); + assertNotNull("Cannot find CamelContext with name myCamel", context); + + // enable Jackson json type converter + context.getProperties().put(JacksonConstants.ENABLE_TYPE_CONVERTER, "true"); + // allow Jackson json to convert to pojo types also (by default jackson only converts to String and other simple types) + context.getProperties().put(JacksonConstants.TYPE_CONVERTER_TO_POJO, "true"); + + // test type conversion + final Pojo pojo = new Pojo(1337, "Constantine"); + final DefaultExchange exchange = new DefaultExchange(context); + final String string = context.getTypeConverter().mandatoryConvertTo(String.class, exchange, pojo); + final Pojo copy = context.getTypeConverter().mandatoryConvertTo(Pojo.class, exchange, string); + Assert.assertEquals(pojo, copy); + } + + +} \ No newline at end of file
