camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r905594 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/ main/java/org/apache/camel/component/bean/ test/java/org/apache/camel/component/bean/ test/java/org/apache/camel/component/bean/issues/
Date Tue, 02 Feb 2010 11:58:48 GMT
Author: davsclaus
Date: Tue Feb  2 11:58:42 2010
New Revision: 905594

URL: http://svn.apache.org/viewvc?rev=905594&view=rev
Log:
CAMEL-2436: Bean component now detects void methods and accepts methods returning null as
a valid response. Removed @deprecated BEAN_HOLDER.

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanInvokeTest.java
      - copied, changed from r905527, camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanInvokeWithNullBodyTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/issues/FilterPojoIssueTest.java
  (with props)
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfo.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithPropertiesAndHeadersAndBodyInjectionTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java?rev=905594&r1=905593&r2=905594&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java Tue Feb  2 11:58:42
2010
@@ -43,8 +43,6 @@
     String BATCH_COMPLETE = "CamelBatchComplete";
 
     String BEAN_METHOD_NAME           = "CamelBeanMethodName";
-    @Deprecated
-    String BEAN_HOLDER                = "CamelBeanHolder";
     String BEAN_MULTI_PARAMETER_ARRAY = "CamelBeanMultiParameterArray";
 
     String BINDING = "CamelBinding";

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=905594&r1=905593&r2=905594&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
Tue Feb  2 11:58:42 2010
@@ -70,7 +70,6 @@
         boolean isExplicitMethod = ObjectHelper.isNotEmpty(method);
 
         Object bean = beanHolder.getBean();
-        exchange.setProperty(Exchange.BEAN_HOLDER, beanHolder);
         BeanInfo beanInfo = beanHolder.getBeanInfo();
 
         // do we have a custom adapter for this POJO to a Processor
@@ -151,8 +150,9 @@
                 in.setHeader(Exchange.BEAN_METHOD_NAME, prevMethod);
             }
         }
-        
-        if (value != null) {
+
+        // if the method returns something then set the value returned on the Exchange
+        if (!invocation.getMethod().getReturnType().equals(Void.TYPE) && value !=
Void.TYPE) {
             if (exchange.getPattern().isOutCapable()) {
                 // force out creating if not already created (as its lazy)
                 if (LOG.isDebugEnabled()) {

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfo.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfo.java?rev=905594&r1=905593&r2=905594&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfo.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfo.java Tue
Feb  2 11:58:42 2010
@@ -134,7 +134,8 @@
                 if (recipientList != null) {
                     recipientList.sendToRecipientList(exchange, result);
                     // we don't want to return the list of endpoints
-                    return null;
+                    // return Void to indicate to BeanProcessor that there is no reply
+                    return Void.TYPE;
                 }
                 return result;
             }

Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanInvokeTest.java
(from r905527, camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanInvokeWithNullBodyTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanInvokeTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanInvokeTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanInvokeWithNullBodyTest.java&r1=905527&r2=905594&rev=905594&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanInvokeWithNullBodyTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanInvokeTest.java
Tue Feb  2 11:58:42 2010
@@ -18,43 +18,69 @@
 
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.component.mock.MockEndpoint;
 
 /**
  * @version $Revision$
  */
-public class BeanInvokeWithNullBodyTest extends ContextTestSupport {
+public class BeanInvokeTest extends ContextTestSupport {
 
-    public void testWithHelloWorld() throws Exception {
-        getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
+    public void testA() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:a");
 
-        template.sendBody("direct:start", "Hello World");
+        mock.expectedBodiesReceived("Hello World");
+        template.sendBody("direct:a", "Hello World");
+        assertMockEndpointsSatisfied();
+
+        mock.reset();
+        mock.expectedBodiesReceived("");
+        template.sendBody("direct:a", "");
+        assertMockEndpointsSatisfied();
 
+        mock.reset();
+        mock.expectedMessageCount(1);
+        mock.message(0).body().isNull();
+        template.sendBody("direct:a", null);
         assertMockEndpointsSatisfied();
     }
 
-    public void testWithEmptyBody() throws Exception {
-        getMockEndpoint("mock:result").expectedBodiesReceived("");
+    public void testB() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:b");
 
-        template.sendBody("direct:start", "");
+        mock.expectedBodiesReceived("Bye World");
+        template.sendBody("direct:b", "Hello World");
+        assertMockEndpointsSatisfied();
 
+        mock.reset();
+        mock.expectedMessageCount(1);
+        mock.message(0).body().isNull();
+        template.sendBody("direct:b", "");
+        assertMockEndpointsSatisfied();
+
+        mock.reset();
+        mock.expectedMessageCount(1);
+        mock.message(0).body().isNull();
+        template.sendBody("direct:b", null);
         assertMockEndpointsSatisfied();
     }
 
-    public void testWithNullBody() throws Exception {
-        getMockEndpoint("mock:result").expectedMessageCount(1);
-        getMockEndpoint("mock:result").message(0).body().isNull();
+    public void testC() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:c");
 
-        template.sendBody("direct:start", null);
+        mock.expectedBodiesReceived("Hello World");
+        template.sendBody("direct:c", "Hello World");
+        assertMockEndpointsSatisfied();
 
+        mock.reset();
+        mock.expectedBodiesReceived("");
+        template.sendBody("direct:c", "");
         assertMockEndpointsSatisfied();
-    }
 
-    @Override
-    protected JndiRegistry createRegistry() throws Exception {
-        JndiRegistry jndi = super.createRegistry();
-        jndi.bind("foo", new MyNullFooBean());
-        return jndi;
+        mock.reset();
+        mock.expectedMessageCount(1);
+        mock.message(0).body().isNull();
+        template.sendBody("direct:c", null);
+        assertMockEndpointsSatisfied();
     }
 
     @Override
@@ -62,15 +88,25 @@
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("direct:start").to("bean:foo").to("mock:result");
+                from("direct:a").bean(BeanInvokeTest.class, "doSomething").to("mock:a");
+                from("direct:b").bean(BeanInvokeTest.class, "changeSomething").to("mock:b");
+                from("direct:c").bean(BeanInvokeTest.class, "doNothing").to("mock:c");
             }
         };
     }
 
-    private class MyNullFooBean {
+    public String doSomething(String s) {
+        return s;
+    }
 
-        public String doSomething(String s) {
-            return s;
+    public String changeSomething(String s) {
+        if ("Hello World".equals(s)) {
+            return "Bye World";
         }
+        return null;
     }
-}
+
+    public void doNothing(String s) {
+    }
+
+}
\ No newline at end of file

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithPropertiesAndHeadersAndBodyInjectionTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithPropertiesAndHeadersAndBodyInjectionTest.java?rev=905594&r1=905593&r2=905594&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithPropertiesAndHeadersAndBodyInjectionTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithPropertiesAndHeadersAndBodyInjectionTest.java
Tue Feb  2 11:58:42 2010
@@ -50,10 +50,6 @@
 
         assertEquals("Should not fail", false, out.isFailed());
 
-        BeanHolder holder = out.getProperty(Exchange.BEAN_HOLDER, BeanHolder.class);
-        assertNotNull("BeanHolder is missing", holder);
-        assertEquals(myBean, holder.getBean());
-
         Map foo = myBean.foo;
         Map bar = myBean.bar;
         assertNotNull("myBean.foo", foo);

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/issues/FilterPojoIssueTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/issues/FilterPojoIssueTest.java?rev=905594&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/issues/FilterPojoIssueTest.java
(added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/issues/FilterPojoIssueTest.java
Tue Feb  2 11:58:42 2010
@@ -0,0 +1,64 @@
+/**
+ * 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.issues;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version $Revision$
+ */
+public class FilterPojoIssueTest extends ContextTestSupport {
+
+    public String doSomething(String body) {
+        if ("Hello World".equals(body)) {
+            return "Bye World";
+        }
+        return null;
+    }
+
+    public void testFilterPojo() throws Exception {
+        getMockEndpoint("mock:filter").expectedBodiesReceived("Bye World");
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testFilterPojoNull() throws Exception {
+        getMockEndpoint("mock:filter").expectedMessageCount(0);
+
+        template.sendBody("direct:start", "Foo");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                    .bean(FilterPojoIssueTest.class, "doSomething")
+                    .to("log:foo")
+                    .filter(body().isNotNull())
+                        .to("mock:filter")
+                    .end();
+            }
+        };
+    }
+}

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/issues/FilterPojoIssueTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/issues/FilterPojoIssueTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message