Repository: camel
Updated Branches:
  refs/heads/master eb69733b4 -> e5cbba043


Optimise - Bean component - Only try to choose methods if there is 2 or more to 
choose amongas otherwise we can just use the default method.


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

Branch: refs/heads/master
Commit: e5cbba043819e2f17fb25c5d0ac162f3c32acc11
Parents: 09eb151
Author: Claus Ibsen <davscl...@apache.org>
Authored: Fri Jun 2 10:10:05 2017 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Fri Jun 2 10:10:11 2017 +0200

----------------------------------------------------------------------
 .../apache/camel/component/bean/BeanInfo.java   |  8 ++--
 .../bean/BeanInvokeSingleMethodNoBodyTest.java  | 43 ++++++++++++++++++++
 .../bean/MySingleMethodNoBodyBean.java          | 24 +++++++++++
 3 files changed, 71 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/e5cbba04/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java 
b/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
index 3448ff8..43ddb9b 100644
--- a/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
+++ b/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
@@ -211,14 +211,14 @@ public class BeanInfo {
             // do not use qualifier for name
             String name = methodName;
             if (methodName.contains("(")) {
-                name = ObjectHelper.before(methodName, "(");
+                name = StringHelper.before(methodName, "(");
                 // the must be a ending parenthesis
                 if (!methodName.endsWith(")")) {
                     throw new IllegalArgumentException("Method should end with 
parenthesis, was " + methodName);
                 }
                 // and there must be an even number of parenthesis in the 
syntax
                 // (we can use betweenOuterPair as it return null if the 
syntax is invalid)
-                if (ObjectHelper.betweenOuterPair(methodName, '(', ')') == 
null) {
+                if (StringHelper.betweenOuterPair(methodName, '(', ')') == 
null) {
                     throw new IllegalArgumentException("Method should have 
even pair of parenthesis, was " + methodName);
                 }
             }
@@ -284,8 +284,8 @@ public class BeanInfo {
             }
         }
 
-        if (methodInfo == null) {
-            // no name or type
+        if (methodInfo == null && methodMap.size() >= 2) {
+            // only try to choose if there is at least 2 methods
             methodInfo = chooseMethod(pojo, exchange, null);
         }
         if (methodInfo == null) {

http://git-wip-us.apache.org/repos/asf/camel/blob/e5cbba04/camel-core/src/test/java/org/apache/camel/component/bean/BeanInvokeSingleMethodNoBodyTest.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/test/java/org/apache/camel/component/bean/BeanInvokeSingleMethodNoBodyTest.java
 
b/camel-core/src/test/java/org/apache/camel/component/bean/BeanInvokeSingleMethodNoBodyTest.java
new file mode 100644
index 0000000..3762914
--- /dev/null
+++ 
b/camel-core/src/test/java/org/apache/camel/component/bean/BeanInvokeSingleMethodNoBodyTest.java
@@ -0,0 +1,43 @@
+/**
+ * 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 org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+public class BeanInvokeSingleMethodNoBodyTest extends ContextTestSupport {
+
+    public void testBeanInvokeSingleMethodNoBody() throws Exception {
+        getMockEndpoint("mock:result").expectedBodiesReceived("Hello");
+
+        template.sendBody("direct:start", "Hi");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                    .bean(MySingleMethodNoBodyBean.class)
+                    .to("mock:result");
+            }
+        };
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/e5cbba04/camel-core/src/test/java/org/apache/camel/component/bean/MySingleMethodNoBodyBean.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/test/java/org/apache/camel/component/bean/MySingleMethodNoBodyBean.java
 
b/camel-core/src/test/java/org/apache/camel/component/bean/MySingleMethodNoBodyBean.java
new file mode 100644
index 0000000..e77b525
--- /dev/null
+++ 
b/camel-core/src/test/java/org/apache/camel/component/bean/MySingleMethodNoBodyBean.java
@@ -0,0 +1,24 @@
+/**
+ * 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;
+
+public class MySingleMethodNoBodyBean {
+
+    public String saySomething() {
+        return "Hello";
+    }
+}

Reply via email to