camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r790055 - in /camel/branches/camel-1.x/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 08:11:50 GMT
Author: ningjiang
Date: Wed Jul  1 08:11:50 2009
New Revision: 790055

URL: http://svn.apache.org/viewvc?rev=790055&view=rev
Log:
CAMEL-1777 Fixed the Bean method name header issue on camel-1.x branch

Added:
    camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithMethodHeaderTest.java
  (with props)
Modified:
    camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java

Modified: camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java?rev=790055&r1=790054&r2=790055&view=diff
==============================================================================
--- camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java
(original)
+++ camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java
Wed Jul  1 08:11:50 2009
@@ -114,25 +114,9 @@
             throw new IllegalStateException(
                 "No method invocation could be created, no maching method could be found
on: " + bean);
         }
+        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(true).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();
@@ -148,6 +132,24 @@
                 in.setHeader(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(true).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() {

Added: camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithMethodHeaderTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithMethodHeaderTest.java?rev=790055&view=auto
==============================================================================
--- camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithMethodHeaderTest.java
(added)
+++ camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithMethodHeaderTest.java
Wed Jul  1 08:11:50 2009
@@ -0,0 +1,109 @@
+/**
+ * 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 javax.naming.Context;
+
+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;
+
+/**
+ * @version $Revision$
+ */
+public class BeanWithMethodHeaderTest extends ContextTestSupport {
+
+    private MyBean bean;
+
+    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(BeanProcessor.METHOD_NAME));
+    }
+    
+    public void testEchoWithMethodHeaderHi() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceived("echo Hello World");
+        mock.expectedHeaderReceived(BeanProcessor.METHOD_NAME, "hi");
+
+        template.sendBodyAndHeader("direct:echo", ExchangePattern.InOut, "Hello World", BeanProcessor.METHOD_NAME,
"hi");
+
+        assertMockEndpointsSatisfied();
+    }
+    
+    public void testMixedBeanEndpoints() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceived("hi echo Hello World");
+        mock.expectedHeaderReceived(BeanProcessor.METHOD_NAME, "hi");
+
+        template.sendBodyAndHeader("direct:mixed", ExchangePattern.InOut, "Hello World",
BeanProcessor.METHOD_NAME, "hi");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testHi() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceived("hi Hello World");
+
+        template.sendBody("direct:hi", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+   
+    protected Context createJndiContext() throws Exception {
+        JndiContext answer = new JndiContext();
+        bean = new MyBean();
+        answer.bind("myBean", bean);
+        return answer;
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                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");
+             
+            }
+        };
+    }
+
+    public static class MyBean {
+
+        public String hi(String s) {
+            return "hi " + s;
+        }
+
+        public String echo(String s) {
+            return "echo " + s;
+        }
+    }
+
+}
\ No newline at end of file

Propchange: camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithMethodHeaderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithMethodHeaderTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message