camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bvah...@apache.org
Subject camel git commit: CAMEL-8160: Don't take the Java bridge methods into account which leads to problems when using POJO binding annotations with class inheritance (in Java 8)
Date Sun, 21 Dec 2014 13:09:39 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.14.x e61688cd0 -> 5c6720713


CAMEL-8160: Don't take the Java bridge methods into account which leads to problems when using
POJO binding annotations with class inheritance (in Java 8)


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

Branch: refs/heads/camel-2.14.x
Commit: 5c67207135c4024c993d59d3902ce5d5ad93a36d
Parents: e61688c
Author: Babak Vahdat <bvahdat@apache.org>
Authored: Sun Dec 21 14:07:19 2014 +0100
Committer: Babak Vahdat <bvahdat@apache.org>
Committed: Sun Dec 21 14:09:26 2014 +0100

----------------------------------------------------------------------
 .../org/apache/camel/util/ReflectionHelper.java |  8 ++++
 .../spring/produce/generics/MyService.java      | 23 ++++++++++
 .../spring/produce/generics/MyServiceImpl.java  | 36 +++++++++++++++
 .../produce/generics/MyServiceInvoker.java      | 36 +++++++++++++++
 .../produce/generics/MyServiceSupport.java      | 30 +++++++++++++
 .../spring/produce/generics/MyServiceTest.java  | 46 ++++++++++++++++++++
 .../produce/generics/MyServiceTest-context.xml  | 30 +++++++++++++
 7 files changed, 209 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/5c672071/camel-core/src/main/java/org/apache/camel/util/ReflectionHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/ReflectionHelper.java b/camel-core/src/main/java/org/apache/camel/util/ReflectionHelper.java
index e3ad683..c794a72 100644
--- a/camel-core/src/main/java/org/apache/camel/util/ReflectionHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/ReflectionHelper.java
@@ -83,6 +83,9 @@ public final class ReflectionHelper {
     /**
      * Perform the given callback operation on all matching methods of the given
      * class and superclasses (or given interface and super-interfaces).
+     * <p/>
+     * <b>Important:</b> This method does not take the
+     * {@link java.lang.reflect.Method#isBridge() bridge methods} into account.
      *
      * @param clazz class to start looking at
      * @param mc the callback to invoke for each method
@@ -91,6 +94,11 @@ public final class ReflectionHelper {
         // Keep backing up the inheritance hierarchy.
         Method[] methods = clazz.getDeclaredMethods();
         for (Method method : methods) {
+            if (method.isBridge()) {
+                // skip the bridge methods which in Java 8 leads to problems with inheritance
+                // see https://bugs.openjdk.java.net/browse/JDK-6695379
+                continue;
+            }
             try {
                 mc.doWith(method);
             } catch (IllegalAccessException ex) {

http://git-wip-us.apache.org/repos/asf/camel/blob/5c672071/components/camel-spring/src/test/java/org/apache/camel/spring/produce/generics/MyService.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/produce/generics/MyService.java
b/components/camel-spring/src/test/java/org/apache/camel/spring/produce/generics/MyService.java
new file mode 100644
index 0000000..5d084a0
--- /dev/null
+++ b/components/camel-spring/src/test/java/org/apache/camel/spring/produce/generics/MyService.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.spring.produce.generics;
+
+public interface MyService<N extends Number> {
+
+    N sqrt(N number);
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/5c672071/components/camel-spring/src/test/java/org/apache/camel/spring/produce/generics/MyServiceImpl.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/produce/generics/MyServiceImpl.java
b/components/camel-spring/src/test/java/org/apache/camel/spring/produce/generics/MyServiceImpl.java
new file mode 100644
index 0000000..d48e505
--- /dev/null
+++ b/components/camel-spring/src/test/java/org/apache/camel/spring/produce/generics/MyServiceImpl.java
@@ -0,0 +1,36 @@
+/**
+ * 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.spring.produce.generics;
+
+import org.apache.camel.Consume;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.springframework.stereotype.Service;
+
+@Service
+public class MyServiceImpl extends MyServiceSupport<Double> {
+
+    @Consume(uri = "direct:myService")
+    @Override
+    public Double sqrt(Double number) {
+        log(number);
+        return Math.sqrt(number);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/5c672071/components/camel-spring/src/test/java/org/apache/camel/spring/produce/generics/MyServiceInvoker.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/produce/generics/MyServiceInvoker.java
b/components/camel-spring/src/test/java/org/apache/camel/spring/produce/generics/MyServiceInvoker.java
new file mode 100644
index 0000000..87477be
--- /dev/null
+++ b/components/camel-spring/src/test/java/org/apache/camel/spring/produce/generics/MyServiceInvoker.java
@@ -0,0 +1,36 @@
+/**
+ * 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.spring.produce.generics;
+
+import org.apache.camel.Produce;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.springframework.stereotype.Component;
+
+@Component
+public class MyServiceInvoker {
+
+    @Produce(uri = "direct:myService")
+    MyService<Double> myService;
+
+    public Double invokeService(Double number) {
+        return myService.sqrt(number);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/5c672071/components/camel-spring/src/test/java/org/apache/camel/spring/produce/generics/MyServiceSupport.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/produce/generics/MyServiceSupport.java
b/components/camel-spring/src/test/java/org/apache/camel/spring/produce/generics/MyServiceSupport.java
new file mode 100644
index 0000000..101b0c8
--- /dev/null
+++ b/components/camel-spring/src/test/java/org/apache/camel/spring/produce/generics/MyServiceSupport.java
@@ -0,0 +1,30 @@
+/**
+ * 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.spring.produce.generics;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public abstract class MyServiceSupport<N extends Number> implements MyService<N>
{
+
+    private final Logger logger = LoggerFactory.getLogger(getClass());
+
+    protected void log(N number) {
+        logger.info("MyService is called with the value {}", number);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/5c672071/components/camel-spring/src/test/java/org/apache/camel/spring/produce/generics/MyServiceTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/produce/generics/MyServiceTest.java
b/components/camel-spring/src/test/java/org/apache/camel/spring/produce/generics/MyServiceTest.java
new file mode 100644
index 0000000..3e4208d
--- /dev/null
+++ b/components/camel-spring/src/test/java/org/apache/camel/spring/produce/generics/MyServiceTest.java
@@ -0,0 +1,46 @@
+/**
+ * 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.spring.produce.generics;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Produce;
+import org.apache.camel.spring.SpringRunWithTestSupport;
+
+import org.junit.Test;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+
+@ContextConfiguration
+public class MyServiceTest extends SpringRunWithTestSupport {
+
+    @Autowired
+    private MyServiceInvoker invoker;
+
+    @Test
+    public void testInvokeMyService() throws Exception {
+        Double value = 31.7D;
+        Double actual = invoker.invokeService(value);
+        Double expected = Math.sqrt(value);
+
+        assertEquals("The result should be the square root", expected, actual);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/5c672071/components/camel-spring/src/test/resources/org/apache/camel/spring/produce/generics/MyServiceTest-context.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/spring/produce/generics/MyServiceTest-context.xml
b/components/camel-spring/src/test/resources/org/apache/camel/spring/produce/generics/MyServiceTest-context.xml
new file mode 100644
index 0000000..0e4a7f3
--- /dev/null
+++ b/components/camel-spring/src/test/resources/org/apache/camel/spring/produce/generics/MyServiceTest-context.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xmlns:context="http://www.springframework.org/schema/context"
+  xsi:schemaLocation="
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
+       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+    ">
+
+  <context:component-scan base-package="org.apache.camel.spring.produce.generics" />
+
+  <camelContext xmlns="http://camel.apache.org/schema/spring" />
+
+</beans>


Mime
View raw message