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 2017/01/05 15:22:19 UTC

[1/3] camel git commit: CAMEL-10641: Load Camel TypeConverters when a new TypeConverterLoader OSGI service is detected

Repository: camel
Updated Branches:
  refs/heads/master 1c1205d3c -> b2f42797f


CAMEL-10641: Load Camel TypeConverters when a new TypeConverterLoader OSGI service is detected


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

Branch: refs/heads/master
Commit: 65ca8e4e7dd139eba127d4c0cee7edccb709e8f7
Parents: c8322cb
Author: jpoth <po...@gmail.com>
Authored: Thu Jan 5 15:40:40 2017 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Jan 5 16:11:00 2017 +0100

----------------------------------------------------------------------
 .../camel/core/osgi/OsgiTypeConverter.java      |  9 ++
 .../camel/itest/CamelTypeConverterTest.java     | 98 ++++++++++++++++++++
 .../test/java/org/apache/camel/itest/Pojo.java  |  5 +
 .../camel/itest/typeconverter/MyConverter.java  | 39 ++++++++
 .../org/apache/camel/itest/TypeConverter        | 17 ++++
 5 files changed, 168 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/65ca8e4e/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiTypeConverter.java
----------------------------------------------------------------------
diff --git a/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiTypeConverter.java b/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiTypeConverter.java
index c4813c1..787ee8a 100644
--- a/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiTypeConverter.java
+++ b/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiTypeConverter.java
@@ -67,6 +67,15 @@ public class OsgiTypeConverter extends ServiceSupport implements TypeConverter,
     public Object addingService(ServiceReference<TypeConverterLoader> serviceReference) {
         LOG.trace("AddingService: {}, Bundle: {}", serviceReference, serviceReference.getBundle());        
         TypeConverterLoader loader = bundleContext.getService(serviceReference);
+        try {
+            LOG.debug("loading type converter from bundle: {}", serviceReference.getBundle().getSymbolicName());
+            if (delegate != null) {
+                loader.load(delegate);
+            }
+        } catch (Throwable t) {
+            throw new RuntimeCamelException("Error loading type converters from service: " + serviceReference + " due: " + t.getMessage(), t);
+        }
+       
         return loader;
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/65ca8e4e/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/CamelTypeConverterTest.java
----------------------------------------------------------------------
diff --git a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/CamelTypeConverterTest.java b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/CamelTypeConverterTest.java
new file mode 100644
index 0000000..f4f7b3b
--- /dev/null
+++ b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/CamelTypeConverterTest.java
@@ -0,0 +1,98 @@
+/**
+ * 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;
+
+import java.net.URL;
+import java.util.Locale;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.impl.DefaultExchange;
+import org.apache.camel.itest.typeconverter.MyConverter;
+import org.apache.camel.test.karaf.AbstractFeatureTest;
+import org.apache.camel.test.karaf.CamelKarafTestSupport;
+import org.apache.camel.util.ObjectHelper;
+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.ProbeBuilder;
+import org.ops4j.pax.exam.TestProbeBuilder;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.tinybundles.core.InnerClassStrategy;
+import org.ops4j.pax.tinybundles.core.TinyBundle;
+import org.ops4j.pax.tinybundles.core.TinyBundles;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
+
+@RunWith(PaxExam.class)
+public class CamelTypeConverterTest extends AbstractFeatureTest {
+
+    @Test
+    public void testTypeConverterInSameBundleAsCamelRoute() throws Exception {
+        // install the camel blueprint xml file and the Camel converter we use in this test
+        TinyBundle bundle = TinyBundles.bundle();
+        // install blueprint
+        URL blueprintUrl = ObjectHelper.loadResourceAsURL("org/apache/camel/itest/CamelJacksonFallbackConverterTest.xml", CamelJacksonFallbackConverterTest.class.getClassLoader());
+        String name = "CamelJacksonFallbackConverterTest";
+        bundle.add("OSGI-INF/blueprint/blueprint-" + name.toLowerCase(Locale.ENGLISH) + ".xml", blueprintUrl);
+        // install converter
+        URL converterDeclaration = ObjectHelper.loadResourceAsURL("org/apache/camel/itest/TypeConverter", CamelJacksonFallbackConverterTest.class.getClassLoader());
+        bundle.add("META-INF/services/org/apache/camel/TypeConverter", converterDeclaration);
+        bundle.add(MyConverter.class, InnerClassStrategy.NONE);
+        // set bundle headers
+        bundle.set("Manifest-Version", "2")
+                .set("Bundle-ManifestVersion", "2")
+                .set("Bundle-SymbolicName", name)
+                .set("Bundle-Version", "1.0.0")
+                .set(Constants.DYNAMICIMPORT_PACKAGE, "*");
+        // start bundle
+        Bundle answer = this.bundleContext.installBundle(name, bundle.build());
+        answer.start();
+
+        // lookup Camel from OSGi
+        CamelContext camel = getOsgiService(bundleContext, CamelContext.class);
+
+        final Pojo pojo = new Pojo();
+        String pojoName = "Constantine";
+        pojo.setName(pojoName);
+
+        final DefaultExchange exchange = new DefaultExchange(camel);
+        final String string = camel.getTypeConverter().mandatoryConvertTo(String.class, exchange, pojo);
+        LOG.info("POJO -> String: {}", string);
+        final Pojo copy = camel.getTypeConverter().mandatoryConvertTo(Pojo.class, exchange, string);
+        LOG.info("String -> POJO: {}", copy);
+        Assert.assertEquals(pojoName, copy.getName());
+    }
+
+    @Configuration
+    public Option[] configure() {
+        return CamelKarafTestSupport.configure("camel-test-karaf");
+    }
+
+    @ProbeBuilder
+    public TestProbeBuilder probeConfiguration(TestProbeBuilder probe) {
+        // Export Pojo class for TypeConverter bundle
+        probe.setHeader(Constants.EXPORT_PACKAGE, "org.apache.camel.itest");
+        return probe;
+    }
+
+
+
+
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/65ca8e4e/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/Pojo.java
----------------------------------------------------------------------
diff --git a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/Pojo.java b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/Pojo.java
index 258774c..008fcb5 100644
--- a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/Pojo.java
+++ b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/Pojo.java
@@ -69,4 +69,9 @@ public class Pojo {
         result = 31 * result + (name != null ? name.hashCode() : 0);
         return result;
     }
+
+    @Override
+    public String toString() {
+        return "Pojo{" + "id=" + id + ", name='" + name + '\'' + '}';
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/65ca8e4e/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/typeconverter/MyConverter.java
----------------------------------------------------------------------
diff --git a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/typeconverter/MyConverter.java b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/typeconverter/MyConverter.java
new file mode 100644
index 0000000..050d5e6
--- /dev/null
+++ b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/typeconverter/MyConverter.java
@@ -0,0 +1,39 @@
+/**
+ * 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.typeconverter;
+
+import org.apache.camel.Converter;
+import org.apache.camel.itest.Pojo;
+
+@Converter
+public class MyConverter {
+
+    public MyConverter() { }
+    
+    @Converter
+    public static Pojo toPojo(String name) {
+        Pojo pojo = new Pojo();
+        pojo.setName(name);
+        return pojo;
+    }
+    
+    @Converter
+    public String toString(Pojo pojo) {
+        return pojo.getName();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/65ca8e4e/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/TypeConverter
----------------------------------------------------------------------
diff --git a/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/TypeConverter b/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/TypeConverter
new file mode 100644
index 0000000..ddb6035
--- /dev/null
+++ b/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/TypeConverter
@@ -0,0 +1,17 @@
+/**
+ * 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.
+ */
+org.apache.camel.itest.typeconverter.MyConverter
\ No newline at end of file


[2/3] camel git commit: CAMEL-10672: Karaf itests will now have to specify the org.apache.camel.karaf/apache-camel version to use through the camelKarafFeatureVersion system property

Posted by da...@apache.org.
CAMEL-10672: Karaf itests will now have to specify the org.apache.camel.karaf/apache-camel version to use through the camelKarafFeatureVersion system property


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

Branch: refs/heads/master
Commit: c8322cb78253d208907098a5a6a0ac863a9ec93b
Parents: 1c1205d
Author: jpoth <po...@gmail.com>
Authored: Wed Jan 4 17:06:20 2017 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Jan 5 16:11:00 2017 +0100

----------------------------------------------------------------------
 .../org/apache/camel/test/karaf/AbstractFeatureTest.java | 11 ++++++++++-
 tests/camel-itest-karaf/pom.xml                          |  1 +
 tests/camel-itest-osgi/pom.xml                           |  5 ++---
 3 files changed, 13 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/c8322cb7/components/camel-test-karaf/src/main/java/org/apache/camel/test/karaf/AbstractFeatureTest.java
----------------------------------------------------------------------
diff --git a/components/camel-test-karaf/src/main/java/org/apache/camel/test/karaf/AbstractFeatureTest.java b/components/camel-test-karaf/src/main/java/org/apache/camel/test/karaf/AbstractFeatureTest.java
index 97b876b..050a1d4 100644
--- a/components/camel-test-karaf/src/main/java/org/apache/camel/test/karaf/AbstractFeatureTest.java
+++ b/components/camel-test-karaf/src/main/java/org/apache/camel/test/karaf/AbstractFeatureTest.java
@@ -219,7 +219,16 @@ public abstract class AbstractFeatureTest {
         return mavenBundle().
                 groupId("org.apache.camel.karaf").
                 artifactId("apache-camel").
-                versionAsInProject().type("xml/features");
+                version(getCamelKarafFeatureVersion()).
+                type("xml/features");
+    }
+
+    private static String getCamelKarafFeatureVersion() {
+        String camelKarafFeatureVersion = System.getProperty("camelKarafFeatureVersion");
+        if (camelKarafFeatureVersion == null) {
+            throw new RuntimeException("Please specify the maven artifact version to use for org.apache.camel.karaf/apache-camel through the camelKarafFeatureVersion System property");
+        }
+        return camelKarafFeatureVersion;
     }
 
     private static void switchPlatformEncodingToUTF8() {

http://git-wip-us.apache.org/repos/asf/camel/blob/c8322cb7/tests/camel-itest-karaf/pom.xml
----------------------------------------------------------------------
diff --git a/tests/camel-itest-karaf/pom.xml b/tests/camel-itest-karaf/pom.xml
index 0576fb5..4fe345a 100644
--- a/tests/camel-itest-karaf/pom.xml
+++ b/tests/camel-itest-karaf/pom.xml
@@ -231,6 +231,7 @@
               <argLine>-Dorg.ops4j.pax.url.mvn.localRepository=${maven.repo.local}</argLine>
               <systemPropertyVariables>
                 <karafVersion>${karaf-version}</karafVersion>
+                <camelKarafFeatureVersion>${project.version}</camelKarafFeatureVersion>
               </systemPropertyVariables>
             </configuration>
           </plugin>

http://git-wip-us.apache.org/repos/asf/camel/blob/c8322cb7/tests/camel-itest-osgi/pom.xml
----------------------------------------------------------------------
diff --git a/tests/camel-itest-osgi/pom.xml b/tests/camel-itest-osgi/pom.xml
index 5bd725f..c3eed42 100644
--- a/tests/camel-itest-osgi/pom.xml
+++ b/tests/camel-itest-osgi/pom.xml
@@ -29,9 +29,8 @@
   <artifactId>camel-itest-osgi</artifactId>
   <name>Camel :: Integration Tests :: OSGi</name>
   <description>Performs OSGi compliance integration tests</description>
-
+  
   <dependencies>
-
     <dependency>
       <groupId>org.apache.camel</groupId>
       <artifactId>camel-test-karaf</artifactId>
@@ -42,7 +41,6 @@
       <artifactId>camel-jackson</artifactId>
       <scope>test</scope>
     </dependency>
-
   </dependencies>
 
   <build>
@@ -58,6 +56,7 @@
           <!--<rerunFailingTestsCount>0</rerunFailingTestsCount>-->
           <systemPropertyVariables>
             <karafVersion>${karaf4-version}</karafVersion>
+            <camelKarafFeatureVersion>${project.version}</camelKarafFeatureVersion>
           </systemPropertyVariables>
         </configuration>
       </plugin>


[3/3] camel git commit: CAMEL-10641: Fixed test and use its own test instead of wrong copy/paste.

Posted by da...@apache.org.
CAMEL-10641: Fixed test and use its own test instead of wrong copy/paste.


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

Branch: refs/heads/master
Commit: b2f42797fad7a68a57cd6aa0430855ba4945e05a
Parents: 65ca8e4
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Jan 5 16:21:54 2017 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Jan 5 16:21:54 2017 +0100

----------------------------------------------------------------------
 .../camel/itest/CamelTypeConverterTest.java     |  8 +++---
 .../camel/itest/CamelTypeConverterTest.xml      | 26 ++++++++++++++++++++
 .../org/apache/camel/itest/TypeConverter        | 17 -------------
 3 files changed, 30 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b2f42797/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/CamelTypeConverterTest.java
----------------------------------------------------------------------
diff --git a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/CamelTypeConverterTest.java b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/CamelTypeConverterTest.java
index f4f7b3b..994e730 100644
--- a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/CamelTypeConverterTest.java
+++ b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/CamelTypeConverterTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.itest;
 
+import java.io.ByteArrayInputStream;
 import java.net.URL;
 import java.util.Locale;
 
@@ -47,12 +48,11 @@ public class CamelTypeConverterTest extends AbstractFeatureTest {
         // install the camel blueprint xml file and the Camel converter we use in this test
         TinyBundle bundle = TinyBundles.bundle();
         // install blueprint
-        URL blueprintUrl = ObjectHelper.loadResourceAsURL("org/apache/camel/itest/CamelJacksonFallbackConverterTest.xml", CamelJacksonFallbackConverterTest.class.getClassLoader());
-        String name = "CamelJacksonFallbackConverterTest";
+        URL blueprintUrl = ObjectHelper.loadResourceAsURL("org/apache/camel/itest/CamelTypeConverterTest.xml", CamelTypeConverterTest.class.getClassLoader());
+        String name = "CamelTypeConverterTest";
         bundle.add("OSGI-INF/blueprint/blueprint-" + name.toLowerCase(Locale.ENGLISH) + ".xml", blueprintUrl);
         // install converter
-        URL converterDeclaration = ObjectHelper.loadResourceAsURL("org/apache/camel/itest/TypeConverter", CamelJacksonFallbackConverterTest.class.getClassLoader());
-        bundle.add("META-INF/services/org/apache/camel/TypeConverter", converterDeclaration);
+        bundle.add("META-INF/services/org/apache/camel/TypeConverter", new ByteArrayInputStream("org.apache.camel.itest.typeconverter.MyConverter".getBytes()));
         bundle.add(MyConverter.class, InnerClassStrategy.NONE);
         // set bundle headers
         bundle.set("Manifest-Version", "2")

http://git-wip-us.apache.org/repos/asf/camel/blob/b2f42797/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/CamelTypeConverterTest.xml
----------------------------------------------------------------------
diff --git a/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/CamelTypeConverterTest.xml b/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/CamelTypeConverterTest.xml
new file mode 100644
index 0000000..bf8202b
--- /dev/null
+++ b/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/CamelTypeConverterTest.xml
@@ -0,0 +1,26 @@
+<?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.
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+           xsi:schemaLocation="
+             http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
+
+  <camelContext id="myCamel" xmlns="http://camel.apache.org/schema/blueprint">
+  </camelContext>
+
+</blueprint>

http://git-wip-us.apache.org/repos/asf/camel/blob/b2f42797/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/TypeConverter
----------------------------------------------------------------------
diff --git a/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/TypeConverter b/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/TypeConverter
deleted file mode 100644
index ddb6035..0000000
--- a/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/TypeConverter
+++ /dev/null
@@ -1,17 +0,0 @@
-/**
- * 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.
- */
-org.apache.camel.itest.typeconverter.MyConverter
\ No newline at end of file