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 2012/01/19 11:28:32 UTC

svn commit: r1233269 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/converter/ components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/ tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/ tests/camel-it...

Author: davsclaus
Date: Thu Jan 19 10:28:31 2012
New Revision: 1233269

URL: http://svn.apache.org/viewvc?rev=1233269&view=rev
Log:
CAMEL-4915: Serialization data format should use ClassResolver API from Camel to work with other runtimes.

Added:
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/MySerialBean.java
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/core/dataformat/
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/core/dataformat/MySerialBean.java
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/core/dataformat/SerializationDataFormatTest.java
      - copied, changed from r1233154, camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/core/direct/DirectTest.java
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
    camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiClassResolver.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java?rev=1233269&r1=1233268&r2=1233269&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java Thu Jan 19 10:28:31 2012
@@ -335,7 +335,7 @@ public final class IOConverter {
                 @Override
                 protected Class<?> resolveClass(ObjectStreamClass objectStreamClass) throws IOException, ClassNotFoundException {
                     // need to let Camel be able to resolve class using ClassResolver SPI, to let class loading
-                    // work in OSGi and other runtimes
+                    // work in OSGi and other containers
                     Class<?>  answer = null;
                     String name = objectStreamClass.getName();
                     if (exchange != null) {

Modified: camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiClassResolver.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiClassResolver.java?rev=1233269&r1=1233268&r2=1233269&view=diff
==============================================================================
--- camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiClassResolver.java (original)
+++ camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiClassResolver.java Thu Jan 19 10:28:31 2012
@@ -39,10 +39,12 @@ public class OsgiClassResolver extends D
     }
     
     public Class<?> resolveClass(String name) {
+        LOG.trace("Resolve class {}", name);
         name = ObjectHelper.normalizeClassName(name);
         Class<?> clazz = ObjectHelper.loadSimpleType(name);
         if (clazz == null) {
             clazz = doLoadClass(name, bundleContext.getBundle());
+            LOG.trace("Loading class {} using BundleContext {} -> {}", new Object[]{name, bundleContext.getBundle(), clazz});
         }
         return clazz;
     }

Added: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/MySerialBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/MySerialBean.java?rev=1233269&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/MySerialBean.java (added)
+++ camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/MySerialBean.java Thu Jan 19 10:28:31 2012
@@ -0,0 +1,44 @@
+/**
+ * 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.osgi.blueprint;
+
+import java.io.Serializable;
+
+/**
+ *
+ */
+public class MySerialBean implements Serializable {
+
+    private int id;
+    private String name;
+
+    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;
+    }
+}

Added: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/core/dataformat/MySerialBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/core/dataformat/MySerialBean.java?rev=1233269&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/core/dataformat/MySerialBean.java (added)
+++ camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/core/dataformat/MySerialBean.java Thu Jan 19 10:28:31 2012
@@ -0,0 +1,44 @@
+/**
+ * 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.osgi.core.dataformat;
+
+import java.io.Serializable;
+
+/**
+ *
+ */
+public class MySerialBean implements Serializable {
+
+    private int id;
+    private String name;
+
+    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;
+    }
+}

Copied: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/core/dataformat/SerializationDataFormatTest.java (from r1233154, camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/core/direct/DirectTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/core/dataformat/SerializationDataFormatTest.java?p2=camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/core/dataformat/SerializationDataFormatTest.java&p1=camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/core/direct/DirectTest.java&r1=1233154&r2=1233269&rev=1233269&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/core/direct/DirectTest.java (original)
+++ camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/core/dataformat/SerializationDataFormatTest.java Thu Jan 19 10:28:31 2012
@@ -14,26 +14,33 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.itest.osgi.core.direct;
+package org.apache.camel.itest.osgi.core.dataformat;
 
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.itest.osgi.OSGiIntegrationTestSupport;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
 
 @RunWith(JUnit4TestRunner.class)
-public class DirectTest extends OSGiIntegrationTestSupport {
-    
+public class SerializationDataFormatTest extends OSGiIntegrationTestSupport {
+
     @Test
-    public void testSendMessage() throws Exception {
-        MockEndpoint mock =  getMandatoryEndpoint("mock:result", MockEndpoint.class);
-        assertNotNull("The mock endpoint should not be null", mock);
-        
-        mock.expectedBodiesReceived("Hello World");
-        template.sendBody("direct:start", "Hello World");
-        assertMockEndpointsSatisfied();        
+    public void testSerialization() throws Exception {
+        MySerialBean bean = new MySerialBean();
+        bean.setId(123);
+        bean.setName("Donald");
+
+        Object data = template.requestBody("direct:marshal", bean);
+        assertNotNull(data);
+
+        Object out = template.requestBody("direct:unmarshal", data);
+        assertNotNull(out);
+
+        MySerialBean outBean = context.getTypeConverter().convertTo(MySerialBean.class, out);
+        assertNotNull(outBean);
+        assertEquals(123, outBean.getId());
+        assertEquals("Donald", outBean.getName());
     }
 
     @Override
@@ -41,7 +48,11 @@ public class DirectTest extends OSGiInte
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("direct:start").to("mock:result");
+                from("direct:unmarshal")
+                        .unmarshal().serialization();
+
+                from("direct:marshal")
+                        .marshal().serialization();
             }
         };
     }