camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1151059 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/component/bean/MethodInfo.java test/java/org/apache/camel/component/bean/BeanParameterNoBeanBindingTest.java
Date Tue, 26 Jul 2011 10:45:13 GMT
Author: davsclaus
Date: Tue Jul 26 10:45:12 2011
New Revision: 1151059

URL: http://svn.apache.org/viewvc?rev=1151059&view=rev
Log:
CAMEL-3961: Improved error message if invalid arguments when invoking bean using bean component.

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanParameterNoBeanBindingTest.java
      - copied, changed from r1151048, camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanParameterInvalidValueTest.java
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfo.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfo.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfo.java?rev=1151059&r1=1151058&r2=1151059&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfo.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/MethodInfo.java Tue
Jul 26 10:45:12 2011
@@ -37,6 +37,7 @@ import org.apache.camel.ExpressionEvalua
 import org.apache.camel.NoTypeConversionAvailableException;
 import org.apache.camel.Pattern;
 import org.apache.camel.Processor;
+import org.apache.camel.RuntimeExchangeException;
 import org.apache.camel.impl.ExpressionAdapter;
 import org.apache.camel.processor.DynamicRouter;
 import org.apache.camel.processor.RecipientList;
@@ -329,7 +330,11 @@ public class MethodInfo {
     }
 
     protected Object invoke(Method mth, Object pojo, Object[] arguments, Exchange exchange)
throws IllegalAccessException, InvocationTargetException {
-        return mth.invoke(pojo, arguments);
+        try {
+            return mth.invoke(pojo, arguments);
+        } catch (IllegalArgumentException e) {
+            throw new RuntimeExchangeException("IllegalArgumentException occurred invoking
method: " + mth + " using arguments: " + Arrays.asList(arguments), exchange, e);
+        }
     }
 
     protected Expression createParametersExpression() {

Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanParameterNoBeanBindingTest.java
(from r1151048, camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanParameterInvalidValueTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanParameterNoBeanBindingTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanParameterNoBeanBindingTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanParameterInvalidValueTest.java&r1=1151048&r2=1151059&rev=1151059&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanParameterInvalidValueTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanParameterNoBeanBindingTest.java
Tue Jul 26 10:45:12 2011
@@ -16,19 +16,16 @@
  */
 package org.apache.camel.component.bean;
 
-import java.util.Map;
-
 import org.apache.camel.CamelExecutionException;
 import org.apache.camel.ContextTestSupport;
-import org.apache.camel.ExpressionEvaluationException;
-import org.apache.camel.NoTypeConversionAvailableException;
+import org.apache.camel.RuntimeExchangeException;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.impl.JndiRegistry;
 
 /**
  *
  */
-public class BeanParameterInvalidValueTest extends ContextTestSupport {
+public class BeanParameterNoBeanBindingTest extends ContextTestSupport {
 
     public void testBeanParameterInvalidValueA() throws Exception {
         getMockEndpoint("mock:result").expectedMessageCount(0);
@@ -37,49 +34,10 @@ public class BeanParameterInvalidValueTe
             template.sendBody("direct:a", "World");
             fail("Should have thrown exception");
         } catch (CamelExecutionException e) {
-            NoTypeConversionAvailableException cause = assertIsInstanceOf(NoTypeConversionAvailableException.class,
e.getCause());
-            assertEquals(String.class, cause.getFromType());
-            assertEquals(int.class, cause.getToType());
-            assertEquals("A", cause.getValue());
-        }
-
-        assertMockEndpointsSatisfied();
-    }
-
-    public void testBeanParameterInvalidValueB() throws Exception {
-        getMockEndpoint("mock:result").expectedMessageCount(0);
-
-        try {
-            template.sendBody("direct:b", "World");
-            fail("Should have thrown exception");
-        } catch (CamelExecutionException e) {
-            NoTypeConversionAvailableException cause = assertIsInstanceOf(NoTypeConversionAvailableException.class,
e.getCause());
-            assertEquals(String.class, cause.getFromType());
-            assertEquals(int.class, cause.getToType());
-            assertEquals("true", cause.getValue());
-        }
-
-        assertMockEndpointsSatisfied();
-    }
-
-    public void testBeanParameterNullC() throws Exception {
-        // should be an empty string
-        getMockEndpoint("mock:result").expectedBodiesReceived("");
-
-        template.sendBody("direct:c", "World");
-
-        assertMockEndpointsSatisfied();
-    }
-
-    public void testBeanParameterInvalidValueD() throws Exception {
-        getMockEndpoint("mock:result").expectedMessageCount(0);
-
-        try {
-            template.sendBody("direct:d", "World");
-            fail("Should have thrown exception");
-        } catch (CamelExecutionException e) {
-            ExpressionEvaluationException cause = assertIsInstanceOf(ExpressionEvaluationException.class,
e.getCause());
-            assertEquals("Illegal syntax: xxx", cause.getCause().getMessage());
+            RuntimeExchangeException cause = assertIsInstanceOf(RuntimeExchangeException.class,
e.getCause());
+            assertTrue(cause.getMessage().contains("echo(java.lang.String,int)"));
+            assertTrue(cause.getMessage().contains("[World, null]"));
+            assertIsInstanceOf(IllegalArgumentException.class, cause.getCause());
         }
 
         assertMockEndpointsSatisfied();
@@ -98,19 +56,7 @@ public class BeanParameterInvalidValueTe
             @Override
             public void configure() throws Exception {
                 from("direct:a")
-                    .to("bean:foo?method=echo(*, 'A')")
-                    .to("mock:result");
-
-                from("direct:b")
-                    .to("bean:foo?method=echo(*, true)")
-                    .to("mock:result");
-
-                from("direct:c")
-                    .to("bean:foo?method=echo(null, 2)")
-                    .to("mock:result");
-
-                from("direct:d")
-                    .to("bean:foo?method=echo(${xxx}, 2)")
+                    .to("bean:foo?method=echo")
                     .to("mock:result");
             }
         };
@@ -135,9 +81,5 @@ public class BeanParameterInvalidValueTe
             return body;
         }
 
-        public String heads(String body, Map headers) {
-            return headers.get("hello") + " " + body;
-        }
-
     }
 }



Mime
View raw message