svn commit: r613509 - in /activemq/camel/trunk/camel-core/src: main/java/org/apache/camel/component/bean/BeanProcessor.java test/java/org/apache/camel/component/bean/ChainedBeanInvocationTest.java

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r613509 - in /activemq/camel/trunk/camel-core/src: main/java/org/apache/camel/component/bean/BeanProcessor.java test/java/org/apache/camel/component/bean/ChainedBeanInvocationTest.java

ningjiang
Author: ningjiang
Date: Sat Jan 19 21:39:38 2008
New Revision: 613509

URL: http://svn.apache.org/viewvc?rev=613509&view=rev
Log:
CAMEL-279 support override the bean invocation method name with the DSL

Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ChainedBeanInvocationTest.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java?rev=613509&r1=613508&r2=613509&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java Sat Jan 19 21:39:38 2008
@@ -34,7 +34,7 @@
 /**
  * A {@link Processor} which converts the inbound exchange to a method
  * invocation on a POJO
- *
+ *
  * @version $Revision: $
  */
 public class BeanProcessor extends ServiceSupport implements Processor {
@@ -94,21 +94,11 @@
         if (methodObject != null) {
             invocation = beanInfo.createInvocation(methodObject, bean, exchange);
         } else {
-            // lets pass in the method name to use if its specified
-            boolean hasToClearMethod = false;
-            try {
-                if (ObjectHelper.isNotNullAndNonEmpty(method)) {
-                    if (isNullOrBlank(in.getHeader(METHOD_NAME, String.class))) {
-                        in.setHeader(METHOD_NAME, method);
-                        hasToClearMethod = true;
-                    }
-                }
-                invocation = beanInfo.createInvocation(bean, exchange);
-            } finally {
-                if (hasToClearMethod) {
-                    in.removeHeader(METHOD_NAME);
-                }
+            // we just override the bean's invocation method name here
+            if (ObjectHelper.isNotNullAndNonEmpty(method)) {
+                in.setHeader(METHOD_NAME, method);
             }
+            invocation = beanInfo.createInvocation(bean, exchange);
         }
         if (invocation == null) {
             throw new IllegalStateException("No method invocation could be created, no maching method could be found on: " + bean);

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ChainedBeanInvocationTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ChainedBeanInvocationTest.java?rev=613509&r1=613508&r2=613509&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ChainedBeanInvocationTest.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/ChainedBeanInvocationTest.java Sat Jan 19 21:39:38 2008
@@ -31,7 +31,7 @@
 
     @Override
     protected void setUp() throws Exception {
-        beanMock = EasyMock.createStrictMock(MyBean.class);
+        beanMock = EasyMock.createMock(MyBean.class);
         super.setUp();
     }
 
@@ -48,17 +48,17 @@
             @Override
             public void configure() throws Exception {
                 from("direct:start")
-                    .to("bean:myBean?methodName=a")
-                    .bean(beanMock, "b")
+                    .to("bean:myBean?methodName=b")
+                    .bean(beanMock, "a")
                     .beanRef("myBean", "c");
             }
         };
     }
 
     public void testNormalInvocation() throws Throwable {
-        beanMock.a();
-        beanMock.b();
-        beanMock.c();
+        beanMock.a();        
+        beanMock.b();        
+        beanMock.c();        
         EasyMock.replay(beanMock);
         Exchange result = template.send("direct:start", new DefaultExchange(context));
         if (result.getException() != null) {
@@ -68,10 +68,11 @@
     }
 
     public void testMethodHeaderSet() throws Exception {
-        beanMock.b();
-        EasyMock.expectLastCall().times(3);
+        beanMock.a();        
+        beanMock.b();        
+        beanMock.c();        
         EasyMock.replay(beanMock);
-        template.sendBodyAndHeader("direct:start", "test", BeanProcessor.METHOD_NAME, "b");
+        template.sendBodyAndHeader("direct:start", "test", BeanProcessor.METHOD_NAME, "d");
         EasyMock.verify(beanMock);
     }