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 2015/07/29 11:08:36 UTC

[1/2] camel git commit: CAMEL-9032: Bean component - Should filter out abstract methods

Repository: camel
Updated Branches:
  refs/heads/camel-2.15.x 218bb3d16 -> a9c704b5e


CAMEL-9032: Bean component - Should filter out abstract methods


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

Branch: refs/heads/camel-2.15.x
Commit: 4ac613e80047f59f04ae5e56d0b82aa605463976
Parents: 218bb3d
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Jul 29 10:11:08 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Jul 29 11:14:46 2015 +0200

----------------------------------------------------------------------
 .../apache/camel/component/bean/BeanInfo.java   |  5 +++
 .../bean/issues/BaseFoundationClass.java        | 23 +++++++++++
 .../component/bean/issues/BaseSomething.java    | 22 ++++++++++
 .../issues/BeanAbstractMethodIssueTest.java     | 43 ++++++++++++++++++++
 .../component/bean/issues/RealSomething.java    | 25 ++++++++++++
 5 files changed, 118 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/4ac613e8/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 67a0893..1b34622 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
@@ -831,6 +831,11 @@ public class BeanInfo {
             return false;
         }
 
+        // must not be abstract
+        if (Modifier.isAbstract(method.getModifiers())) {
+            return false;
+        }
+
         // return type must not be an Exchange and it should not be a bridge method
         if ((method.getReturnType() != null && Exchange.class.isAssignableFrom(method.getReturnType())) || method.isBridge()) {
             return false;

http://git-wip-us.apache.org/repos/asf/camel/blob/4ac613e8/camel-core/src/test/java/org/apache/camel/component/bean/issues/BaseFoundationClass.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/bean/issues/BaseFoundationClass.java b/camel-core/src/test/java/org/apache/camel/component/bean/issues/BaseFoundationClass.java
new file mode 100644
index 0000000..a143e54
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/bean/issues/BaseFoundationClass.java
@@ -0,0 +1,23 @@
+/**
+ * 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;
+
+public abstract class BaseFoundationClass {
+
+    public abstract Object doSomething(String name);
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/4ac613e8/camel-core/src/test/java/org/apache/camel/component/bean/issues/BaseSomething.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/bean/issues/BaseSomething.java b/camel-core/src/test/java/org/apache/camel/component/bean/issues/BaseSomething.java
new file mode 100644
index 0000000..545679c
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/bean/issues/BaseSomething.java
@@ -0,0 +1,22 @@
+/**
+ * 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;
+
+public abstract class BaseSomething extends BaseFoundationClass {
+
+    public abstract Long doSomething(String name);
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/4ac613e8/camel-core/src/test/java/org/apache/camel/component/bean/issues/BeanAbstractMethodIssueTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/bean/issues/BeanAbstractMethodIssueTest.java b/camel-core/src/test/java/org/apache/camel/component/bean/issues/BeanAbstractMethodIssueTest.java
new file mode 100644
index 0000000..7c0430c
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/bean/issues/BeanAbstractMethodIssueTest.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.issues;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+public class BeanAbstractMethodIssueTest extends ContextTestSupport {
+
+    public void testAbstractMethod() throws Exception {
+        getMockEndpoint("mock:123").expectedMessageCount(1);
+
+        template.sendBody("direct:start", new RealSomething());
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                        .filter().simple("${body.doSomething} == 123").to("mock:123");
+            }
+        };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/4ac613e8/camel-core/src/test/java/org/apache/camel/component/bean/issues/RealSomething.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/bean/issues/RealSomething.java b/camel-core/src/test/java/org/apache/camel/component/bean/issues/RealSomething.java
new file mode 100644
index 0000000..c89b4f7
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/bean/issues/RealSomething.java
@@ -0,0 +1,25 @@
+/**
+ * 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;
+
+public class RealSomething extends BaseSomething {
+
+    @Override
+    public Long doSomething(String name) {
+        return 123L;
+    }
+}


[2/2] camel git commit: CAMEL-9032: Bean component - Should filter out abstract methods

Posted by da...@apache.org.
CAMEL-9032: Bean component - Should filter out abstract methods


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

Branch: refs/heads/camel-2.15.x
Commit: a9c704b5ebf58fdd3b59314acd7948089ac6aa76
Parents: 4ac613e
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Jul 29 10:35:01 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Jul 29 11:15:48 2015 +0200

----------------------------------------------------------------------
 .../apache/camel/component/bean/BeanInfo.java   | 22 +++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/a9c704b5/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 1b34622..d3c7214 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
@@ -557,6 +557,12 @@ public class BeanInfo {
         final List<MethodInfo> localOperationsWithCustomAnnotation = new ArrayList<MethodInfo>(operationsWithCustomAnnotation);
         final List<MethodInfo> localOperationsWithHandlerAnnotation = new ArrayList<MethodInfo>(operationsWithHandlerAnnotation);
 
+        // remove all abstract methods
+        removeAllAbstractMethods(localOperationsWithBody);
+        removeAllAbstractMethods(localOperationsWithNoBody);
+        removeAllAbstractMethods(localOperationsWithCustomAnnotation);
+        removeAllAbstractMethods(localOperationsWithHandlerAnnotation);
+
         if (name != null) {
             // filter all lists to only include methods with this name
             removeNonMatchingMethods(localOperationsWithHandlerAnnotation, name);
@@ -831,11 +837,6 @@ public class BeanInfo {
             return false;
         }
 
-        // must not be abstract
-        if (Modifier.isAbstract(method.getModifiers())) {
-            return false;
-        }
-
         // return type must not be an Exchange and it should not be a bridge method
         if ((method.getReturnType() != null && Exchange.class.isAssignableFrom(method.getReturnType())) || method.isBridge()) {
             return false;
@@ -982,6 +983,17 @@ public class BeanInfo {
         }
     }
 
+    private void removeAllAbstractMethods(List<MethodInfo> methods) {
+        Iterator<MethodInfo> it = methods.iterator();
+        while (it.hasNext()) {
+            MethodInfo info = it.next();
+            if (Modifier.isAbstract(info.getMethod().getModifiers())) {
+                // we cannot invoke an abstract method
+                it.remove();
+            }
+        }
+    }
+
     private boolean matchMethod(Method method, String methodName) {
         if (methodName == null) {
             return true;