CAMEL-7682 Added multiParameterArray option to bean DSL

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

Branch: refs/heads/master
Commit: 759a4d62bf6bc95bc240f075813541235e918305
Parents: ab8d810
Author: Willem Jiang <willem.ji...@gmail.com>
Authored: Tue Aug 12 16:00:58 2014 +0800
Committer: Willem Jiang <willem.ji...@gmail.com>
Committed: Tue Aug 12 16:00:58 2014 +0800

----------------------------------------------------------------------
 .../org/apache/camel/model/BeanDefinition.java  | 15 +++++
 .../apache/camel/model/ProcessorDefinition.java | 65 +++++++++++++++++++-
 .../cxf/jaxrs/CxfRsConsumerWithBeanTest.java    | 12 +++-
 3 files changed, 87 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/759a4d62/camel-core/src/main/java/org/apache/camel/model/BeanDefinition.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/model/BeanDefinition.java 
b/camel-core/src/main/java/org/apache/camel/model/BeanDefinition.java
index 0211bbc..182f661 100644
--- a/camel-core/src/main/java/org/apache/camel/model/BeanDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/BeanDefinition.java
@@ -50,6 +50,8 @@ public class BeanDefinition extends 
NoOutputDefinition<BeanDefinition> {
     private String beanType;
     @XmlAttribute
     private Boolean cache;
+    @XmlAttribute
+    private Boolean multiParameterArray;
     @XmlTransient
     private Class<?> beanClass;
     @XmlTransient
@@ -139,6 +141,14 @@ public class BeanDefinition extends 
NoOutputDefinition<BeanDefinition> {
     public void setCache(Boolean cache) {
         this.cache = cache;
     }
+    
+    public Boolean getMultiParameterArray() {
+        return multiParameterArray;
+    }
+    
+    public void setMultiParameterArray(Boolean multiParameterArray) {
+        this.multiParameterArray = multiParameterArray;
+    }
 
     // Fluent API
     //-------------------------------------------------------------------------
@@ -257,6 +267,11 @@ public class BeanDefinition extends 
NoOutputDefinition<BeanDefinition> {
             beanHolder = bean != null ? new ConstantBeanHolder(bean, 
routeContext.getCamelContext()) : new ConstantTypeBeanHolder(clazz, 
routeContext.getCamelContext());
             answer = new BeanProcessor(beanHolder);
         }
+        
+        // check for multiParameterArray setting
+        if (multiParameterArray != null) {
+            answer.setMultiParameterArray(multiParameterArray);
+        }
 
         // check for method exists
         if (method != null) {

http://git-wip-us.apache.org/repos/asf/camel/blob/759a4d62/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java 
b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
index 0f98218..a704e05 100644
--- a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
@@ -2569,6 +2569,26 @@ public abstract class ProcessorDefinition<Type extends 
ProcessorDefinition<Type>
         addOutput(answer);
         return (Type) this;
     }
+    
+    /**
+     * <a href="http://camel.apache.org/message-translator.html";>Message 
Translator EIP:</a>
+     * Adds a bean which is invoked which could be a final destination, or 
could be a transformation in a pipeline
+     *
+     * @param bean  the bean to invoke
+     * @param method  the method name to invoke on the bean (can be used to 
avoid ambiguity)
+     * @param multiparameterArray if it is ture, camel will treat the message 
body as an object array which holds
+     *  the multi parameter 
+     * @return the builder
+     */
+    @SuppressWarnings("unchecked")
+    public Type bean(Object bean, String method, boolean multiParameterArray) {
+        BeanDefinition answer = new BeanDefinition();
+        answer.setBean(bean);
+        answer.setMethod(method);
+        answer.setMultiParameterArray(multiParameterArray);
+        addOutput(answer);
+        return (Type) this;
+    }
 
     /**
      * <a href="http://camel.apache.org/message-translator.html";>Message 
Translator EIP:</a>
@@ -2601,6 +2621,26 @@ public abstract class ProcessorDefinition<Type extends 
ProcessorDefinition<Type>
         addOutput(answer);
         return (Type) this;
     }
+    
+    /**
+     * <a href="http://camel.apache.org/message-translator.html";>Message 
Translator EIP:</a>
+     * Adds a bean which is invoked which could be a final destination, or 
could be a transformation in a pipeline
+     *
+     * @param  beanType  the bean class, Camel will instantiate an object at 
runtime
+     * @param method  the method name to invoke on the bean (can be used to 
avoid ambiguity)
+     * @param multiparameterArray if it is ture, camel will treat the message 
body as an object array which holds
+     *  the multi parameter 
+     * @return the builder
+     */
+    @SuppressWarnings("unchecked")
+    public Type bean(Class<?> beanType, String method, boolean 
multiParameterArray) {
+        BeanDefinition answer = new BeanDefinition();
+        answer.setBeanType(beanType);
+        answer.setMethod(method);
+        answer.setMultiParameterArray(multiParameterArray);
+        addOutput(answer);
+        return (Type) this;
+    }
 
     /**
      * <a href="http://camel.apache.org/message-translator.html";>Message 
Translator EIP:</a>
@@ -2615,7 +2655,7 @@ public abstract class ProcessorDefinition<Type extends 
ProcessorDefinition<Type>
         addOutput(answer);
         return (Type) this;
     }
-
+    
     /**
      * <a href="http://camel.apache.org/message-translator.html";>Message 
Translator EIP:</a>
      * Adds a bean which is invoked which could be a final destination, or 
could be a transformation in a pipeline
@@ -2647,7 +2687,7 @@ public abstract class ProcessorDefinition<Type extends 
ProcessorDefinition<Type>
         addOutput(answer);
         return (Type) this;
     }
-
+    
     /**
      * <a href="http://camel.apache.org/message-translator.html";>Message 
Translator EIP:</a>
      * Adds a bean which is invoked which could be a final destination, or 
could be a transformation in a pipeline
@@ -2668,6 +2708,27 @@ public abstract class ProcessorDefinition<Type extends 
ProcessorDefinition<Type>
 
     /**
      * <a href="http://camel.apache.org/message-translator.html";>Message 
Translator EIP:</a>
+     * Adds a bean which is invoked which could be a final destination, or 
could be a transformation in a pipeline
+     *
+     * @param ref  reference to a bean to lookup in the registry
+     * @param method  the method name to invoke on the bean (can be used to 
avoid ambiguity)
+     * @param cache  if enabled, Camel will cache the result of the first 
Registry look-up.
+     *               Cache can be enabled if the bean in the Registry is 
defined as a singleton scope.
+     * @param multiparameterArray if it is ture, camel will treat the message 
body as an object array which holds
+     *               the multi parameter 
+     * @return the builder
+     */
+    @SuppressWarnings("unchecked")
+    public Type beanRef(String ref, String method, boolean cache, boolean 
multiParameterArray) {
+        BeanDefinition answer = new BeanDefinition(ref, method);
+        answer.setCache(cache);
+        answer.setMultiParameterArray(multiParameterArray);
+        addOutput(answer);
+        return (Type) this;
+    }
+
+    /**
+     * <a href="http://camel.apache.org/message-translator.html";>Message 
Translator EIP:</a>
      * Adds a processor which sets the body on the IN message
      *
      * @return a expression builder clause to set the body

http://git-wip-us.apache.org/repos/asf/camel/blob/759a4d62/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumerWithBeanTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumerWithBeanTest.java
 
b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumerWithBeanTest.java
index 8d98975..70706fe 100644
--- 
a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumerWithBeanTest.java
+++ 
b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumerWithBeanTest.java
@@ -33,7 +33,8 @@ import org.junit.Test;
 public class CxfRsConsumerWithBeanTest extends CamelTestSupport {
     private static final String CXT = CXFTestSupport.getPort1() + 
"/CxfRsConsumerWithBeanTest";
     private static final String CXF_RS_ENDPOINT_URI = 
"cxfrs://http://localhost:"; + CXT + 
"/rest?resourceClasses=org.apache.camel.component.cxf.jaxrs.testbean.CustomerServiceResource";
-
+    private static final String CXF_RS_ENDPOINT_URI_2 = 
"cxfrs://http://localhost:"; + CXT + 
"/rest2?resourceClasses=org.apache.camel.component.cxf.jaxrs.testbean.CustomerServiceResource";
+    
     @Override
     protected Context createJndiContext() throws Exception {
         Context context = super.createJndiContext();
@@ -46,14 +47,19 @@ public class CxfRsConsumerWithBeanTest extends 
CamelTestSupport {
         return new RouteBuilder() {
             public void configure() {
                 
from(CXF_RS_ENDPOINT_URI).to("bean://service?multiParameterArray=true");
+                from(CXF_RS_ENDPOINT_URI_2).bean(ServiceUtil.class, "invoke", 
true);
             };
         };
     }
 
     @Test
     public void testPutConsumer() throws Exception {
-        
-        HttpPut put = new HttpPut("http://localhost:"; + CXT + 
"/rest/customerservice/c20");
+        sendPutRequest("http://localhost:"; + CXT + 
"/rest/customerservice/c20");
+        sendPutRequest("http://localhost:"; + CXT + 
"/rest2/customerservice/c20");
+    }
+    
+    private void sendPutRequest(String uri) throws Exception {
+        HttpPut put = new HttpPut(uri);
         StringEntity entity = new StringEntity("string");
         entity.setContentType("text/plain");
         put.setEntity(entity);

Reply via email to