You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by bv...@apache.org on 2014/12/21 14:07:47 UTC
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)
Repository: camel
Updated Branches:
refs/heads/master 0a96a200a -> 15b2d886d
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/15b2d886
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/15b2d886
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/15b2d886
Branch: refs/heads/master
Commit: 15b2d886daca305e113f1df735ff1c8175bcdbfe
Parents: 0a96a20
Author: Babak Vahdat <bv...@apache.org>
Authored: Sun Dec 21 14:07:19 2014 +0100
Committer: Babak Vahdat <bv...@apache.org>
Committed: Sun Dec 21 14:07:19 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/15b2d886/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/15b2d886/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/15b2d886/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/15b2d886/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/15b2d886/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/15b2d886/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/15b2d886/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>