camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r790052 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/component/bean/BeanProcessor.java test/java/org/apache/camel/component/bean/BeanWithMethodHeaderTest.java
Date Wed, 01 Jul 2009 07:37:59 GMT
Author: ningjiang
Date: Wed Jul  1 07:37:58 2009
New Revision: 790052

URL: http://svn.apache.org/viewvc?rev=790052&view=rev
Log:
CAMEL-1777 Fixed the issue of resetting Exchange.Bean_METHOD_NAME header after the bean invocation

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

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java?rev=790052&r1=790051&r2=790052&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java
Wed Jul  1 07:37:58 2009
@@ -107,31 +107,15 @@
             throw new IllegalStateException(
                 "No method invocation could be created, no maching method could be found
on: " + bean);
         } else {
-            // set method name if not explict given
+            // set method name if not explicit given
             if (method == null) {
                 method = invocation.getMethod().getName();
             }
         }
-
+   
+        Object value = null;
         try {
-            Object value = invocation.proceed();
-            if (value != null) {
-                if (exchange.getPattern().isOutCapable()) {
-                    // force out creating if not already created (as its lazy)
-                    if (LOG.isDebugEnabled()) {
-                        LOG.debug("Setting bean invocation result on the OUT message: " +
value);
-                    }
-                    exchange.getOut().setBody(value);
-                    // propagate headers
-                    exchange.getOut().getHeaders().putAll(exchange.getIn().getHeaders());
-                } else {
-                    // if not out then set it on the in
-                    if (LOG.isDebugEnabled()) {
-                        LOG.debug("Setting bean invocation result on the IN message: " +
value);
-                    }
-                    exchange.getIn().setBody(value);
-                }
-            }
+            value = invocation.proceed();
         } catch (InvocationTargetException e) {
             // lets unwrap the exception
             Throwable throwable = e.getCause();
@@ -147,6 +131,24 @@
                 in.setHeader(Exchange.BEAN_METHOD_NAME, prevMethod);
             }
         }
+        
+        if (value != null) {
+            if (exchange.getPattern().isOutCapable()) {
+                // force out creating if not already created (as its lazy)
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Setting bean invocation result on the OUT message: " + value);
+                }
+                exchange.getOut().setBody(value);
+                // propagate headers
+                exchange.getOut().getHeaders().putAll(exchange.getIn().getHeaders());
+            } else {
+                // if not out then set it on the in
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Setting bean invocation result on the IN message: " + value);
+                }
+                exchange.getIn().setBody(value);
+            }
+        }
     }
 
     protected Processor getProcessor() {

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithMethodHeaderTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithMethodHeaderTest.java?rev=790052&r1=790051&r2=790052&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithMethodHeaderTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithMethodHeaderTest.java
Wed Jul  1 07:37:58 2009
@@ -20,6 +20,8 @@
 
 import org.apache.camel.CamelExecutionException;
 import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.util.jndi.JndiContext;
@@ -34,10 +36,32 @@
     public void testEcho() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedBodiesReceived("echo Hello World");
-
+        
         template.sendBody("direct:echo", "Hello World");
 
         assertMockEndpointsSatisfied();
+        assertNull("There should no Bean_METHOD_NAME header",
+                   mock.getExchanges().get(0).getIn().getHeader(Exchange.BEAN_METHOD_NAME));
+    }
+    
+    public void testEchoWithMethodHeaderHi() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceived("echo Hello World");
+        mock.expectedHeaderReceived(Exchange.BEAN_METHOD_NAME, "hi");
+
+        template.sendBodyAndHeader("direct:echo", ExchangePattern.InOut, "Hello World", Exchange.BEAN_METHOD_NAME,
"hi");
+
+        assertMockEndpointsSatisfied();
+    }
+    
+    public void testMixedBeanEndpoints() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceived("hi echo Hello World");
+        mock.expectedHeaderReceived(Exchange.BEAN_METHOD_NAME, "hi");
+
+        template.sendBodyAndHeader("direct:mixed", ExchangePattern.InOut, "Hello World",
Exchange.BEAN_METHOD_NAME, "hi");
+
+        assertMockEndpointsSatisfied();
     }
 
     public void testHi() throws Exception {
@@ -87,6 +111,8 @@
                 from("direct:echo").beanRef("myBean", "echo").to("mock:result");
 
                 from("direct:hi").beanRef("myBean", "hi").to("mock:result");
+                
+                from("direct:mixed").beanRef("myBean", "echo").beanRef("myBean", "hi").to("mock:result");
 
                 from("direct:fail").beanRef("myBean").to("mock:result");
 



Mime
View raw message