Author: davsclaus
Date: Thu Oct 22 12:28:12 2009
New Revision: 828670

URL: http://svn.apache.org/viewvc?rev=828670&view=rev
Log:
CAMEL-2095, CAMEL-2100: Fixed issue with Camel Proxy not returning correct 
value. Also allowed proxies with single method parameters to use its parameter 
value as Camel body when routing.

Added:
    
camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanConverter.java
   (with props)
    
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/AnotherCamelProxyTest.java
   (with props)
    
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/CamelProxyTest.java
      - copied, changed from r828644, 
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/CamelContextAutoStartupTest.java
    
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/MyProxySender.java
   (with props)
    
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/AnotherCamelProxyTest.xml
   (with props)
    
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/CamelProxyTest.xml
      - copied, changed from r828644, 
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/CamelContextAutoStartupTestFalse.xml
Modified:
    
camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/CamelInvocationHandler.java
    
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/ToStringTypeConverter.java
    
camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/TypeConverter

Added: 
camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanConverter.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanConverter.java?rev=828670&view=auto
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanConverter.java
 (added)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanConverter.java
 Thu Oct 22 12:28:12 2009
@@ -0,0 +1,66 @@
+/**
+ * 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.component.bean;
+
+import org.apache.camel.Converter;
+import org.apache.camel.Exchange;
+import org.apache.camel.FallbackConverter;
+import org.apache.camel.TypeConverter;
+import org.apache.camel.spi.TypeConverterRegistry;
+
+/**
+ * A set of converter methods for working with beans
+ */
+...@converter
+public class BeanConverter {
+
+    private BeanConverter() {
+        // Helper Class
+    }
+
+    @FallbackConverter
+    @SuppressWarnings("unchecked")
+    public static Object convertTo(Class<?> type, Exchange exchange, Object 
value, TypeConverterRegistry registry) {
+        // use a fallback type converter so we can convert the embedded body 
if the value is GenericFile
+        if (BeanInvocation.class.isAssignableFrom(value.getClass())) {
+
+            BeanInvocation bi = (BeanInvocation) value;
+            if (bi.getArgs() == null || bi.getArgs().length != 1) {
+                // not possible to convert as we try to convert the data 
passed in at first argument
+                return null;
+
+            }
+
+            Class from = bi.getArgs()[0].getClass();
+            Object body = bi.getArgs()[0];
+
+            // maybe from is already the type we want
+            if (from.isAssignableFrom(type)) {
+                return body;
+            }
+
+            // no then try to lookup a type converter
+            TypeConverter tc = registry.lookup(type, from);
+            if (tc != null) {
+                return tc.convertTo(type, exchange, body);
+            }
+        }
+
+        return null;
+    }
+
+}

Propchange: 
camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanConverter.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/CamelInvocationHandler.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/CamelInvocationHandler.java?rev=828670&r1=828669&r2=828670&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/CamelInvocationHandler.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/CamelInvocationHandler.java
 Thu Oct 22 12:28:12 2009
@@ -66,6 +66,8 @@
             }
             throw new InvocationTargetException(fault);
         }
+
+        // TODO: type convert to method signature
         if (pattern.isOutCapable()) {
             return exchange.getOut().getBody();
         } else {

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/ToStringTypeConverter.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/ToStringTypeConverter.java?rev=828670&r1=828669&r2=828670&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/ToStringTypeConverter.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/ToStringTypeConverter.java
 Thu Oct 22 12:28:12 2009
@@ -21,6 +21,7 @@
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
 import org.apache.camel.TypeConverter;
+import org.apache.camel.component.bean.BeanInvocation;
 import org.apache.camel.component.file.GenericFile;
 
 /**
@@ -45,6 +46,11 @@
                 return (T) Void.TYPE;
             }
 
+            // should not try to bean invocations
+            if (BeanInvocation.class.isAssignableFrom(value.getClass())) {
+                return (T) Void.TYPE;
+            }
+
             // should not try to convert files
             if (GenericFile.class.isAssignableFrom(value.getClass())) {
                 return (T) Void.TYPE;

Modified: 
camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/TypeConverter?rev=828670&r1=828669&r2=828670&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
 (original)
+++ 
camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
 Thu Oct 22 12:28:12 2009
@@ -16,4 +16,5 @@
 #
 
 org.apache.camel.converter
+org.apache.camel.component.bean
 org.apache.camel.component.file
\ No newline at end of file

Added: 
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/AnotherCamelProxyTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/AnotherCamelProxyTest.java?rev=828670&view=auto
==============================================================================
--- 
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/AnotherCamelProxyTest.java
 (added)
+++ 
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/AnotherCamelProxyTest.java
 Thu Oct 22 12:28:12 2009
@@ -0,0 +1,37 @@
+/**
+ * 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.config;
+
+import junit.framework.TestCase;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * @version $Revision$
+ */
+public class AnotherCamelProxyTest extends TestCase {
+
+    public void testAnotherCamelProxy() throws Exception {
+        ApplicationContext ac = new 
ClassPathXmlApplicationContext("org/apache/camel/spring/config/AnotherCamelProxyTest.xml");
+
+        MyProxySender sender = (MyProxySender) ac.getBean("myProxySender");
+        String reply = sender.hello("Camel");
+
+        assertEquals("Bye Camel", reply);
+    }
+
+}
\ No newline at end of file

Propchange: 
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/AnotherCamelProxyTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/AnotherCamelProxyTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Copied: 
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/CamelProxyTest.java
 (from r828644, 
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/CamelContextAutoStartupTest.java)
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/CamelProxyTest.java?p2=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/CamelProxyTest.java&p1=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/CamelContextAutoStartupTest.java&r1=828644&r2=828670&rev=828670&view=diff
==============================================================================
--- 
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/CamelContextAutoStartupTest.java
 (original)
+++ 
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/CamelProxyTest.java
 Thu Oct 22 12:28:12 2009
@@ -17,65 +17,21 @@
 package org.apache.camel.spring.config;
 
 import junit.framework.TestCase;
-import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.spring.SpringCamelContext;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
 /**
  * @version $Revision$
  */
-public class CamelContextAutoStartupTest extends TestCase {
+public class CamelProxyTest extends TestCase {
 
-    private static final transient Log LOG = 
LogFactory.getLog(CamelContextAutoStartupTest.class);
+    public void testCamelProxy() throws Exception {
+        ApplicationContext ac = new 
ClassPathXmlApplicationContext("org/apache/camel/spring/config/CamelProxyTest.xml");
 
-    public void testAutoStartupFalse() throws Exception {
-        ApplicationContext ac = new 
ClassPathXmlApplicationContext("org/apache/camel/spring/config/CamelContextAutoStartupTestFalse.xml");
+        MyProxySender sender = (MyProxySender) ac.getBean("myProxySender");
+        String reply = sender.hello("World");
 
-        SpringCamelContext camel = (SpringCamelContext) ac.getBean("myCamel");
-        assertEquals("myCamel", camel.getName());
-        assertEquals(false, camel.isStarted());
-        assertEquals(false, camel.isAutoStartup());
-        assertEquals(0, camel.getRoutes().size());
-
-        // now start Camel
-        LOG.info("******** now starting Camel manually *********");
-        camel.start();
-
-        // now its started
-        assertEquals(true, camel.isStarted());
-        // but auto startup is still fasle
-        assertEquals(false, camel.isAutoStartup());
-        // but now we have one route
-        assertEquals(1, camel.getRoutes().size());
-
-        // and now we can send a message to the route and see that it works
-        MockEndpoint mock = camel.getEndpoint("mock:result", 
MockEndpoint.class);
-        mock.expectedMessageCount(1);
-
-        camel.createProducerTemplate().sendBody("direct:start", "Hello World");
-
-        mock.assertIsSatisfied();
-    }
-
-    public void testAutoStartupTrue() throws Exception {
-        ApplicationContext ac = new 
ClassPathXmlApplicationContext("org/apache/camel/spring/config/CamelContextAutoStartupTestTrue.xml");
-
-        SpringCamelContext camel = (SpringCamelContext) ac.getBean("myCamel");
-        assertEquals("myCamel", camel.getName());
-        assertEquals(true, camel.isStarted());
-        assertEquals(true, camel.isAutoStartup());
-        assertEquals(1, camel.getRoutes().size());
-
-        // send a message to the route and see that it works
-        MockEndpoint mock = camel.getEndpoint("mock:result", 
MockEndpoint.class);
-        mock.expectedMessageCount(1);
-
-        camel.createProducerTemplate().sendBody("direct:start", "Hello World");
-
-        mock.assertIsSatisfied();
+        assertEquals("Hello World", reply);
     }
 
-}
+}
\ No newline at end of file

Added: 
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/MyProxySender.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/MyProxySender.java?rev=828670&view=auto
==============================================================================
--- 
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/MyProxySender.java
 (added)
+++ 
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/MyProxySender.java
 Thu Oct 22 12:28:12 2009
@@ -0,0 +1,26 @@
+/**
+ * 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.config;
+
+/**
+ * @version $Revision$
+ */
+public interface MyProxySender {
+
+    String hello(String name);
+
+}

Propchange: 
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/MyProxySender.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/MyProxySender.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/AnotherCamelProxyTest.xml
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/AnotherCamelProxyTest.xml?rev=828670&view=auto
==============================================================================
--- 
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/AnotherCamelProxyTest.xml
 (added)
+++ 
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/AnotherCamelProxyTest.xml
 Thu Oct 22 12:28:12 2009
@@ -0,0 +1,45 @@
+<?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-2.5.xsd
+       http://camel.apache.org/schema/spring 
http://camel.apache.org/schema/spring/camel-spring.xsd
+    ">
+
+    <!-- START SNIPPET: e1 -->
+    <camelContext id="myCamel" xmlns="http://camel.apache.org/schema/spring";>
+
+        <!-- create a proxy that will route to the direct:start endpoint when 
invoked -->
+        <proxy id="myProxySender"
+               serviceInterface="org.apache.camel.spring.config.MyProxySender"
+               serviceUrl="direct:start"/>
+
+        <!-- this is the route that our proxy will routed when invoked
+             and the output from this route is returned as reply on the proxy 
--> 
+        <route>
+            <from uri="direct:start"/>
+            <transform>
+                <simple>Bye ${body}</simple>
+            </transform>
+        </route>
+
+    </camelContext>
+    <!-- END SNIPPET: e1 -->
+
+</beans>

Propchange: 
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/AnotherCamelProxyTest.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/AnotherCamelProxyTest.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: 
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/AnotherCamelProxyTest.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Copied: 
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/CamelProxyTest.xml
 (from r828644, 
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/CamelContextAutoStartupTestFalse.xml)
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/CamelProxyTest.xml?p2=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/CamelProxyTest.xml&p1=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/CamelContextAutoStartupTestFalse.xml&r1=828644&r2=828670&rev=828670&view=diff
==============================================================================
--- 
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/CamelContextAutoStartupTestFalse.xml
 (original)
+++ 
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/CamelProxyTest.xml
 Thu Oct 22 12:28:12 2009
@@ -22,11 +22,25 @@
        http://camel.apache.org/schema/spring 
http://camel.apache.org/schema/spring/camel-spring.xsd
     ">
 
-    <camelContext id="myCamel" xmlns="http://camel.apache.org/schema/spring"; 
autoStartup="false">
+    <!-- START SNIPPET: e1 -->
+    <camelContext id="myCamel" xmlns="http://camel.apache.org/schema/spring";>
+
+        <!-- create a proxy that will route to the direct:start endpoint when 
invoked -->
+        <proxy id="myProxySender"
+               serviceInterface="org.apache.camel.spring.config.MyProxySender"
+               serviceUrl="direct:start"/>
+
+        <!-- this is the route that our proxy will routed when invoked
+             and the output from this route is returned as reply on the proxy 
--> 
         <route>
             <from uri="direct:start"/>
-            <to uri="mock:result"/>
+            <to uri="log:foo"/>
+            <transform>
+                <constant>Hello World</constant>
+            </transform>
         </route>
+
     </camelContext>
+    <!-- END SNIPPET: e1 -->
 
 </beans>


Reply via email to