You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2013/09/13 10:47:33 UTC

git commit: CAMEL-6743: Bean parameter binding with boolean types should eval as predicates.

Updated Branches:
  refs/heads/camel-2.10.x 18bcc78c9 -> d475a37fc


CAMEL-6743: Bean parameter binding with boolean types should eval as predicates.


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

Branch: refs/heads/camel-2.10.x
Commit: d475a37fc771e6375b05ccd7487ee50a1b11de0a
Parents: 18bcc78
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Sep 13 10:46:16 2013 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Sep 13 10:47:03 2013 +0200

----------------------------------------------------------------------
 .../DefaultAnnotationExpressionFactory.java     | 10 ++-
 ...eanWithExpressionInjectionPredicateTest.java | 70 ++++++++++++++++++++
 2 files changed, 79 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/d475a37f/camel-core/src/main/java/org/apache/camel/component/bean/DefaultAnnotationExpressionFactory.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/bean/DefaultAnnotationExpressionFactory.java b/camel-core/src/main/java/org/apache/camel/component/bean/DefaultAnnotationExpressionFactory.java
index e215b4f..c971843 100644
--- a/camel-core/src/main/java/org/apache/camel/component/bean/DefaultAnnotationExpressionFactory.java
+++ b/camel-core/src/main/java/org/apache/camel/component/bean/DefaultAnnotationExpressionFactory.java
@@ -21,9 +21,11 @@ import java.lang.reflect.Method;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.Expression;
+import org.apache.camel.Predicate;
 import org.apache.camel.language.LanguageAnnotation;
 import org.apache.camel.spi.Language;
 import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.PredicateToExpressionAdapter;
 
 /**
  * Default implementation of the {@link AnnotationExpressionFactory}.
@@ -42,7 +44,13 @@ public class DefaultAnnotationExpressionFactory implements AnnotationExpressionF
             throw new IllegalArgumentException("Cannot find the language: " + languageName + " on the classpath");
         }
         String expression = getExpressionFromAnnotation(annotation);
-        return language.createExpression(expression);
+
+        if (expressionReturnType == Boolean.class || expressionReturnType == boolean.class) {
+            Predicate predicate = language.createPredicate(expression);
+            return PredicateToExpressionAdapter.toExpression(predicate);
+        } else {
+            return language.createExpression(expression);
+        }
     }
 
     protected String getExpressionFromAnnotation(Annotation annotation) {

http://git-wip-us.apache.org/repos/asf/camel/blob/d475a37f/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithExpressionInjectionPredicateTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithExpressionInjectionPredicateTest.java b/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithExpressionInjectionPredicateTest.java
new file mode 100644
index 0000000..62529c6
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/bean/BeanWithExpressionInjectionPredicateTest.java
@@ -0,0 +1,70 @@
+/**
+ * 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.builder.RouteBuilder;
+import org.apache.camel.language.Simple;
+import org.apache.camel.util.jndi.JndiContext;
+
+/**
+ * @version 
+ */
+public class BeanWithExpressionInjectionPredicateTest extends ContextTestSupport {
+    protected MyBean myBean = new MyBean();
+
+    public void testSendMessage() throws Exception {
+        template.sendBody("direct:in", "Hello");
+
+        assertEquals("Hello", myBean.body);
+        assertEquals(false, myBean.foo);
+    }
+
+    public void testSendMessageWithFoo() throws Exception {
+        template.sendBodyAndHeader("direct:in", "Hello", "foo", 123);
+
+        assertEquals("Hello", myBean.body);
+        assertEquals(true, myBean.foo);
+    }
+
+    @Override
+    protected Context createJndiContext() throws Exception {
+        JndiContext answer = new JndiContext();
+        answer.bind("myBean", myBean);
+        return answer;
+    }
+
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            public void configure() {
+                from("direct:in").beanRef("myBean");
+            }
+        };
+    }
+
+    public static class MyBean {
+        public String body;
+        public boolean foo;
+
+        public void read(String body, @Simple("${header.foo} != null") boolean foo) {
+            this.body = body;
+            this.foo = foo;
+        }
+    }
+}