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 2011/11/09 11:15:32 UTC

svn commit: r1199683 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/component/bean/ test/java/org/apache/camel/component/bean/

Author: davsclaus
Date: Wed Nov  9 10:15:32 2011
New Revision: 1199683

URL: http://svn.apache.org/viewvc?rev=1199683&view=rev
Log:
CAMEL-4647: Allow toString as method in bean component.

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanInvokeSimpleOgnlToStringMethodTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanInvokeToStringMethodTest.java
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanExcludedMethodTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java?rev=1199683&r1=1199682&r2=1199683&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java Wed Nov  9 10:15:32 2011
@@ -80,6 +80,13 @@ public class BeanInfo {
         EXCLUDED_METHODS.addAll(Arrays.asList(Object.class.getMethods()));
         // exclude all java.lang.reflect.Proxy methods as we dont want to invoke them
         EXCLUDED_METHODS.addAll(Arrays.asList(Proxy.class.getMethods()));
+        try {
+            // but keep toString as this method is okay
+            EXCLUDED_METHODS.remove(Object.class.getMethod("toString"));
+            EXCLUDED_METHODS.remove(Proxy.class.getMethod("toString"));
+        } catch (Throwable e) {
+            // ignore
+        }
     }
 
     public BeanInfo(CamelContext camelContext, Class<?> type) {

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanExcludedMethodTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanExcludedMethodTest.java?rev=1199683&r1=1199682&r2=1199683&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanExcludedMethodTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanExcludedMethodTest.java Wed Nov  9 10:15:32 2011
@@ -57,10 +57,6 @@ public class BeanExcludedMethodTest exte
             return super.hashCode();
         }
 
-        @Override
-        public String toString() {
-            return "dummy";
-        }
     }
 
     public static class MyOtherDummyBean {

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanInvokeSimpleOgnlToStringMethodTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanInvokeSimpleOgnlToStringMethodTest.java?rev=1199683&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanInvokeSimpleOgnlToStringMethodTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanInvokeSimpleOgnlToStringMethodTest.java Wed Nov  9 10:15:32 2011
@@ -0,0 +1,47 @@
+/**
+ * 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 BeanInvokeSimpleOgnlToStringMethodTest extends ContextTestSupport {
+
+    public void testInvokeToString() throws Exception {
+        getMockEndpoint("mock:result").expectedBodiesReceived("MyFooBean");
+
+        MyFooBean foo = new MyFooBean();
+        template.sendBody("direct:start", foo);
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                    .log("${body.toString}")
+                    .to("mock:result");
+            }
+        };
+    }
+}

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanInvokeToStringMethodTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanInvokeToStringMethodTest.java?rev=1199683&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanInvokeToStringMethodTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanInvokeToStringMethodTest.java Wed Nov  9 10:15:32 2011
@@ -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.component.bean;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ *
+ */
+public class BeanInvokeToStringMethodTest extends ContextTestSupport {
+
+    public void testInvokeToString() throws Exception {
+        getMockEndpoint("mock:result").expectedBodiesReceived("MyFooBean");
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                    .bean(MyFooBean.class, "toString")
+                    .to("mock:result");
+            }
+        };
+    }
+}