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 2017/06/02 08:49:20 UTC
[1/2] camel git commit: 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.
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 <da...@apache.org>
Authored: Fri Jun 2 10:10:05 2017 +0200
Committer: Claus Ibsen <da...@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";
+ }
+}
[2/2] camel git commit: Polished
Posted by da...@apache.org.
Polished
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/09eb1511
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/09eb1511
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/09eb1511
Branch: refs/heads/master
Commit: 09eb1511aaedef6cfdbd07e4331405eea2ab1815
Parents: eb69733
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Jun 2 09:48:35 2017 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Jun 2 10:10:11 2017 +0200
----------------------------------------------------------------------
.../apache/camel/component/bean/BeanInfo.java | 38 +++++---------------
1 file changed, 9 insertions(+), 29 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/09eb1511/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 018ed9b..3448ff8 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
@@ -507,8 +507,8 @@ public class BeanInfo {
return new MethodInfo(camelContext, clazz, method, parameters, bodyParameters, hasCustomAnnotation, hasHandlerAnnotation);
}
+ @SuppressWarnings("unchecked")
protected List<Annotation>[] collectParameterAnnotations(Class<?> c, Method m) {
- @SuppressWarnings("unchecked")
List<Annotation>[] annotations = new List[m.getParameterCount()];
for (int i = 0; i < annotations.length; i++) {
annotations[i] = new ArrayList<Annotation>();
@@ -883,7 +883,7 @@ public class BeanInfo {
return answer;
}
// try to choose among multiple methods with annotations
- MethodInfo chosen = chooseMethodWithCustomAnnotations(exchange, possibles);
+ MethodInfo chosen = chooseMethodWithCustomAnnotations(possibles);
if (chosen != null) {
return chosen;
}
@@ -953,8 +953,7 @@ public class BeanInfo {
return null;
}
- private MethodInfo chooseMethodWithCustomAnnotations(Exchange exchange, Collection<MethodInfo> possibles)
- throws AmbiguousMethodCallException {
+ private MethodInfo chooseMethodWithCustomAnnotations(Collection<MethodInfo> possibles) {
// if we have only one method with custom annotations let's choose that
MethodInfo chosen = null;
for (MethodInfo possible : possibles) {
@@ -1043,9 +1042,7 @@ public class BeanInfo {
while (clazz != null && !clazz.equals(Object.class)) {
for (Class<?> interfaceClazz : clazz.getInterfaces()) {
- for (Method interfaceMethod : interfaceClazz.getDeclaredMethods()) {
- answer.add(interfaceMethod);
- }
+ Collections.addAll(answer, interfaceClazz.getDeclaredMethods());
}
clazz = clazz.getSuperclass();
}
@@ -1068,14 +1065,8 @@ public class BeanInfo {
}
private void removeNonMatchingMethods(List<MethodInfo> methods, String name) {
- Iterator<MethodInfo> it = methods.iterator();
- while (it.hasNext()) {
- MethodInfo info = it.next();
- if (!matchMethod(info.getMethod(), name)) {
- // method does not match so remove it
- it.remove();
- }
- }
+ // method does not match so remove it
+ methods.removeIf(info -> !matchMethod(info.getMethod(), name));
}
private void removeAllAbstractMethods(List<MethodInfo> methods) {
@@ -1103,7 +1094,7 @@ public class BeanInfo {
// do not use qualifier for name matching
String name = methodName;
if (name.contains("(")) {
- name = ObjectHelper.before(name, "(");
+ name = StringHelper.before(name, "(");
}
// must match name
@@ -1118,7 +1109,7 @@ public class BeanInfo {
}
// match qualifier types which is used to select among overloaded methods
- String types = ObjectHelper.between(methodName, "(", ")");
+ String types = StringHelper.between(methodName, "(", ")");
if (ObjectHelper.isNotEmpty(types)) {
// we must qualify based on types to match method
String[] parameters = StringQuoteHelper.splitSafeQuote(types, ',');
@@ -1226,11 +1217,10 @@ public class BeanInfo {
}
/**
- * Gets the list of methods (unsorted)
+ * Gets the list of methods sorted by A..Z method name.
*
* @return the methods.
*/
- @Deprecated
public List<MethodInfo> getMethods() {
if (operations.isEmpty()) {
return Collections.emptyList();
@@ -1240,17 +1230,7 @@ public class BeanInfo {
for (Collection<MethodInfo> col : operations.values()) {
methods.addAll(col);
}
- return methods;
- }
- /**
- * Gets the list of methods sorted by A..Z method name.
- *
- * @return the methods.
- */
- @Deprecated
- public List<MethodInfo> getSortedMethods() {
- List<MethodInfo> methods = getMethods();
if (methods.size() > 1) {
// sort the methods by name A..Z
methods.sort(Comparator.comparing(o -> o.getMethod().getName()));