CAMEL-5402: Camel proxy allows to bind to method interface using @Body @Header 
and @ExchangeProperty to bind arguments to the exchange


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

Branch: refs/heads/master
Commit: eb2958c76d8cfde92094f70bb8c9e5a6d0c4cdd2
Parents: 7a88681
Author: Claus Ibsen <davscl...@apache.org>
Authored: Mon Aug 10 20:28:48 2015 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Mon Aug 10 20:28:48 2015 +0200

----------------------------------------------------------------------
 .../component/bean/AbstractCamelInvocationHandler.java    |  8 ++++++++
 .../camel/spring/remoting/CamelServiceExporter.java       |  7 +++----
 .../java/org/apache/camel/spring/produce/MyListener.java  |  4 +---
 .../apache/camel/spring/produce/MyListenerService.java    |  5 -----
 .../java/org/apache/camel/spring/produce/ProduceTest.java |  7 -------
 .../spring/remoting/spring-with-exporter-namespace.xml    |  2 +-
 .../camel/spring/remoting/spring-with-exporter-proxy.xml  |  2 +-
 .../apache/camel/spring/remoting/spring-with-exporter.xml |  1 +
 .../spring/remoting/spring-with-two-camelcontext.xml      | 10 ++++++----
 .../resources/org/apache/camel/spring/remoting/spring.xml |  8 +++-----
 10 files changed, 24 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/eb2958c7/camel-core/src/main/java/org/apache/camel/component/bean/AbstractCamelInvocationHandler.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/component/bean/AbstractCamelInvocationHandler.java
 
b/camel-core/src/main/java/org/apache/camel/component/bean/AbstractCamelInvocationHandler.java
index c346690..5a244da 100644
--- 
a/camel-core/src/main/java/org/apache/camel/component/bean/AbstractCamelInvocationHandler.java
+++ 
b/camel-core/src/main/java/org/apache/camel/component/bean/AbstractCamelInvocationHandler.java
@@ -23,6 +23,7 @@ import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.Map;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
@@ -37,6 +38,7 @@ import org.apache.camel.Exchange;
 import org.apache.camel.ExchangePattern;
 import org.apache.camel.ExchangeProperty;
 import org.apache.camel.Header;
+import org.apache.camel.Headers;
 import org.apache.camel.InvalidPayloadException;
 import org.apache.camel.Producer;
 import org.apache.camel.RuntimeCamelException;
@@ -99,6 +101,7 @@ public abstract class AbstractCamelInvocationHandler 
implements InvocationHandle
 
     public abstract Object doInvokeProxy(final Object proxy, final Method 
method, final Object[] args) throws Throwable;
 
+    @SuppressWarnings("unchecked")
     protected Object invokeProxy(final Method method, final ExchangePattern 
pattern, Object[] args, boolean binding) throws Throwable {
         final Exchange exchange = new DefaultExchange(endpoint, pattern);
         // use method info to map to exchange
@@ -116,6 +119,11 @@ public abstract class AbstractCamelInvocationHandler 
implements InvocationHandle
                             Header header = (Header) ann;
                             String name = header.value();
                             exchange.getIn().setHeader(name, value);
+                        } else if 
(ann.annotationType().isAssignableFrom(Headers.class)) {
+                            Map map = 
exchange.getContext().getTypeConverter().tryConvertTo(Map.class, exchange, 
value);
+                            if (map != null) {
+                                exchange.getIn().getHeaders().putAll(map);
+                            }
                         } else if 
(ann.annotationType().isAssignableFrom(ExchangeProperty.class)) {
                             ExchangeProperty ep = (ExchangeProperty) ann;
                             String name = ep.value();

http://git-wip-us.apache.org/repos/asf/camel/blob/eb2958c7/components/camel-spring/src/main/java/org/apache/camel/spring/remoting/CamelServiceExporter.java
----------------------------------------------------------------------
diff --git 
a/components/camel-spring/src/main/java/org/apache/camel/spring/remoting/CamelServiceExporter.java
 
b/components/camel-spring/src/main/java/org/apache/camel/spring/remoting/CamelServiceExporter.java
index 89d787f..fd5bb4e 100644
--- 
a/components/camel-spring/src/main/java/org/apache/camel/spring/remoting/CamelServiceExporter.java
+++ 
b/components/camel-spring/src/main/java/org/apache/camel/spring/remoting/CamelServiceExporter.java
@@ -24,6 +24,7 @@ import org.apache.camel.component.bean.BeanProcessor;
 import org.apache.camel.spring.util.CamelContextResolverHelper;
 import org.apache.camel.util.CamelContextHelper;
 import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.ServiceHelper;
 import org.springframework.beans.BeansException;
 import org.springframework.beans.factory.DisposableBean;
 import org.springframework.beans.factory.FactoryBean;
@@ -98,13 +99,11 @@ public class CamelServiceExporter extends RemoteExporter 
implements Initializing
         Object proxy = getProxyForService();
 
         consumer = endpoint.createConsumer(new BeanProcessor(proxy, 
camelContext));
-        consumer.start();
+        ServiceHelper.startService(consumer);
     }
 
     public void destroy() throws Exception {
-        if (consumer != null) {
-            consumer.stop();
-        }
+        ServiceHelper.startService(consumer);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/eb2958c7/components/camel-spring/src/test/java/org/apache/camel/spring/produce/MyListener.java
----------------------------------------------------------------------
diff --git 
a/components/camel-spring/src/test/java/org/apache/camel/spring/produce/MyListener.java
 
b/components/camel-spring/src/test/java/org/apache/camel/spring/produce/MyListener.java
index 800ff67..8237d3c 100644
--- 
a/components/camel-spring/src/test/java/org/apache/camel/spring/produce/MyListener.java
+++ 
b/components/camel-spring/src/test/java/org/apache/camel/spring/produce/MyListener.java
@@ -26,8 +26,6 @@ import org.apache.camel.Headers;
  */
 public interface MyListener {
 
-    String sayHello(String name);
-    
-    String greet(@Headers Map<String, Object>headers, @Body String name);
+    String greet(@Headers Map<String, Object> headers, @Body String name);
 
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/eb2958c7/components/camel-spring/src/test/java/org/apache/camel/spring/produce/MyListenerService.java
----------------------------------------------------------------------
diff --git 
a/components/camel-spring/src/test/java/org/apache/camel/spring/produce/MyListenerService.java
 
b/components/camel-spring/src/test/java/org/apache/camel/spring/produce/MyListenerService.java
index 0da9e33..6d1e75c 100644
--- 
a/components/camel-spring/src/test/java/org/apache/camel/spring/produce/MyListenerService.java
+++ 
b/components/camel-spring/src/test/java/org/apache/camel/spring/produce/MyListenerService.java
@@ -35,11 +35,6 @@ public class MyListenerService implements MyListener {
         LOG.debug("Instantiated service: " + this);
     }
     
-    public String sayHello(String name) {
-        LOG.debug("Invoked sayHello with: " + name);
-        return "Hello " + name;
-    }
-
     @Consume(uri = "direct:end")
     public String greet(Map<String, Object> headers, String name) {
         return headers.get("greeter") + name;

http://git-wip-us.apache.org/repos/asf/camel/blob/eb2958c7/components/camel-spring/src/test/java/org/apache/camel/spring/produce/ProduceTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-spring/src/test/java/org/apache/camel/spring/produce/ProduceTest.java
 
b/components/camel-spring/src/test/java/org/apache/camel/spring/produce/ProduceTest.java
index 886358c..2047b31 100644
--- 
a/components/camel-spring/src/test/java/org/apache/camel/spring/produce/ProduceTest.java
+++ 
b/components/camel-spring/src/test/java/org/apache/camel/spring/produce/ProduceTest.java
@@ -34,13 +34,6 @@ public class ProduceTest extends SpringRunWithTestSupport {
     protected MyListener producer;
 
     @Test
-    public void testInvokeService() throws Exception {
-        // lets send a message
-        String actual = producer.sayHello("James");
-        assertEquals("response", "Hello James", actual);
-    }
-    
-    @Test
     public void testInvokeServiceWithMessageHeader() throws Exception {
         Map<String, Object> headers = new HashMap<String, Object>();
         headers.put("greeter", "Nihao ");

http://git-wip-us.apache.org/repos/asf/camel/blob/eb2958c7/components/camel-spring/src/test/resources/org/apache/camel/spring/remoting/spring-with-exporter-namespace.xml
----------------------------------------------------------------------
diff --git 
a/components/camel-spring/src/test/resources/org/apache/camel/spring/remoting/spring-with-exporter-namespace.xml
 
b/components/camel-spring/src/test/resources/org/apache/camel/spring/remoting/spring-with-exporter-namespace.xml
index dd915dd..de7706a 100644
--- 
a/components/camel-spring/src/test/resources/org/apache/camel/spring/remoting/spring-with-exporter-namespace.xml
+++ 
b/components/camel-spring/src/test/resources/org/apache/camel/spring/remoting/spring-with-exporter-namespace.xml
@@ -29,7 +29,7 @@
   <camelContext xmlns="http://camel.apache.org/schema/spring";>
      <!-- START SNIPPET: proxy -->
      <!--  Creates a proxy to the direct:say endpoint. -->
-     <camel:proxy id="sayProxy" serviceUrl="direct:say"
+     <camel:proxy id="sayProxy" serviceUrl="direct:say" binding="false"
                       
serviceInterface="org.apache.camel.spring.remoting.ISay"/>
      <!-- END SNIPPET: proxy -->
      <!-- START SNIPPET: export --> 

http://git-wip-us.apache.org/repos/asf/camel/blob/eb2958c7/components/camel-spring/src/test/resources/org/apache/camel/spring/remoting/spring-with-exporter-proxy.xml
----------------------------------------------------------------------
diff --git 
a/components/camel-spring/src/test/resources/org/apache/camel/spring/remoting/spring-with-exporter-proxy.xml
 
b/components/camel-spring/src/test/resources/org/apache/camel/spring/remoting/spring-with-exporter-proxy.xml
index 4d575f6..6b57562 100644
--- 
a/components/camel-spring/src/test/resources/org/apache/camel/spring/remoting/spring-with-exporter-proxy.xml
+++ 
b/components/camel-spring/src/test/resources/org/apache/camel/spring/remoting/spring-with-exporter-proxy.xml
@@ -25,7 +25,7 @@
 
   <bean id="sayService" class="org.apache.camel.spring.remoting.SayService"/>
 
-  <camel:proxy id="sayProxy" serviceUrl="direct:say"
+  <camel:proxy id="sayProxy" serviceUrl="direct:say" binding="false"
                      serviceInterface="org.apache.camel.spring.remoting.ISay"/>
   <camel:export id="say" uri="direct:sayImpl" serviceRef="sayService"
                          
serviceInterface="org.apache.camel.spring.remoting.ISay"/>

http://git-wip-us.apache.org/repos/asf/camel/blob/eb2958c7/components/camel-spring/src/test/resources/org/apache/camel/spring/remoting/spring-with-exporter.xml
----------------------------------------------------------------------
diff --git 
a/components/camel-spring/src/test/resources/org/apache/camel/spring/remoting/spring-with-exporter.xml
 
b/components/camel-spring/src/test/resources/org/apache/camel/spring/remoting/spring-with-exporter.xml
index 27377ad..e57a472 100644
--- 
a/components/camel-spring/src/test/resources/org/apache/camel/spring/remoting/spring-with-exporter.xml
+++ 
b/components/camel-spring/src/test/resources/org/apache/camel/spring/remoting/spring-with-exporter.xml
@@ -27,6 +27,7 @@
   <bean id="sayProxy" 
class="org.apache.camel.spring.remoting.CamelProxyFactoryBean">
     <property name="serviceUrl" value="direct:say"/>
     <property name="serviceInterface" 
value="org.apache.camel.spring.remoting.ISay"/>
+    <property name="binding" value="false"/>
   </bean>
   <!-- END SNIPPET: proxy -->
 

http://git-wip-us.apache.org/repos/asf/camel/blob/eb2958c7/components/camel-spring/src/test/resources/org/apache/camel/spring/remoting/spring-with-two-camelcontext.xml
----------------------------------------------------------------------
diff --git 
a/components/camel-spring/src/test/resources/org/apache/camel/spring/remoting/spring-with-two-camelcontext.xml
 
b/components/camel-spring/src/test/resources/org/apache/camel/spring/remoting/spring-with-two-camelcontext.xml
index 121c47e..e390c4b 100644
--- 
a/components/camel-spring/src/test/resources/org/apache/camel/spring/remoting/spring-with-two-camelcontext.xml
+++ 
b/components/camel-spring/src/test/resources/org/apache/camel/spring/remoting/spring-with-two-camelcontext.xml
@@ -36,12 +36,14 @@
                </route>
        </camelContext>
 
-   <camel:proxy id="sayProxy1"
-                    serviceInterface="org.apache.camel.spring.remoting.ISay"
-                    serviceUrl="direct:foo"
+  <camel:proxy id="sayProxy1"
+               binding="false"
+                    serviceInterface="org.apache.camel.spring.remoting.ISay"
+                    serviceUrl="direct:foo"
                     camelContextId="context-1"/>
 
-       <camel:proxy id="sayProxy2"
+  <camel:proxy id="sayProxy2"
+               binding="false"
                     serviceInterface="org.apache.camel.spring.remoting.ISay"
                     serviceUrl="direct:foo"
                     camelContextId="context-2"/>

http://git-wip-us.apache.org/repos/asf/camel/blob/eb2958c7/components/camel-spring/src/test/resources/org/apache/camel/spring/remoting/spring.xml
----------------------------------------------------------------------
diff --git 
a/components/camel-spring/src/test/resources/org/apache/camel/spring/remoting/spring.xml
 
b/components/camel-spring/src/test/resources/org/apache/camel/spring/remoting/spring.xml
index bb6b5e6..f5ca265 100644
--- 
a/components/camel-spring/src/test/resources/org/apache/camel/spring/remoting/spring.xml
+++ 
b/components/camel-spring/src/test/resources/org/apache/camel/spring/remoting/spring.xml
@@ -22,10 +22,6 @@
        http://camel.apache.org/schema/spring 
http://camel.apache.org/schema/spring/camel-spring.xsd
     ">
 
-  <!-- START SNIPPET: export -->
-  <bean id="sayService" class="org.apache.camel.spring.remoting.SayService" 
scope="singleton"/>
-  <!-- END SNIPPET: export -->
-
   <!-- START SNIPPET: proxy -->
   <!--  Creates a proxy to the direct:say endpoint. -->
   <bean id="sayProxy" 
class="org.apache.camel.spring.remoting.CamelProxyFactoryBean">
@@ -38,7 +34,9 @@
   <camelContext xmlns="http://camel.apache.org/schema/spring";>
     <route>
       <from uri="direct:say"/>
-      <to uri="bean:sayService"/>
+      <transform>
+        <constant>Hello</constant>
+      </transform>
     </route>
   </camelContext>
   <!-- END SNIPPET: example -->

Reply via email to