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/12/13 09:41:33 UTC
[3/4] camel git commit: CAMEL-10573: Align FallbackTypeConverter
loading in OSGI environments
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/05ba679d
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/05ba679d
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/05ba679d
Branch: refs/heads/camel-2.18.x
Commit: 05ba679d3906528cb19b855385b3b49438b9007b
Parents: 33a3904
Author: jpoth <po...@gmail.com>
Authored: Thu Dec 8 13:23:20 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Dec 13 10:41:14 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/05ba679d/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/05ba679d/tests/camel-itest-karaf/pom.xml
----------------------------------------------------------------------
diff --git a/tests/camel-itest-karaf/pom.xml b/tests/camel-itest-karaf/pom.xml
index e6d1dbe..f8941e3 100644
--- a/tests/camel-itest-karaf/pom.xml
+++ b/tests/camel-itest-karaf/pom.xml
@@ -121,6 +121,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/05ba679d/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/05ba679d/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