camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r566911 - in /activemq/camel/trunk/camel-core/src: main/java/org/apache/camel/component/bean/ main/java/org/apache/camel/model/ test/java/org/apache/camel/ test/java/org/apache/camel/processor/
Date Fri, 17 Aug 2007 04:21:50 GMT
Author: jstrachan
Date: Thu Aug 16 21:21:41 2007
New Revision: 566911

URL: http://svn.apache.org/viewvc?view=rev&rev=566911
Log:
added a test case and fix for CAMEL-111. Also noticed that methods of the form: cheese(String
body, @Header(name="foo") String foo) were not correctly being mapped by default by the BeanProcessor,
so fixed that too

Added:
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/BeanWithExceptionTest.java
      - copied, changed from r566791, activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ValidationTest.java
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/BeanRef.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java?view=diff&rev=566911&r1=566910&r2=566911
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
Thu Aug 16 21:21:41 2007
@@ -126,7 +126,7 @@
             Expression expression = createParameterUnmarshalExpression(clazz, method, parameterType,
                                                                        parameterAnnotations);
             if (expression == null) {
-                if (parameterTypes.length == 1 && bodyParameters.isEmpty()) {
+                if (bodyParameters.isEmpty()) {
                     // lets assume its the body
                     expression = ExpressionBuilder.bodyExpression(parameterType);
                 } else {

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java?view=diff&rev=566911&r1=566910&r2=566911
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanProcessor.java
Thu Aug 16 21:21:41 2007
@@ -16,18 +16,18 @@
  */
 package org.apache.camel.component.bean;
 
-import java.lang.reflect.Method;
-
 import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
 import org.apache.camel.Processor;
 import org.apache.camel.spi.Registry;
 import org.apache.camel.util.ObjectHelper;
+import static org.apache.camel.util.ObjectHelper.isNullOrBlank;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import static org.apache.camel.util.ObjectHelper.isNullOrBlank;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 
 /**
  * A {@link Processor} which converts the inbound exchange to a method
@@ -96,12 +96,22 @@
             invocation = beanInfo.createInvocation(pojo, exchange);
         }
         if (invocation == null) {
-            throw new IllegalStateException("No method invocation could be created");
+            throw new IllegalStateException("No method invocation could be created, no maching
method could be found on: " + pojo);
         }
         try {
             Object value = invocation.proceed();
             if (value != null) {
                 exchange.getIn().setBody(value);
+            }
+        } catch (InvocationTargetException e) {
+            // lets unwrap the exception
+            Throwable cause = e.getTargetException();
+            if (cause instanceof Exception) {
+                throw (Exception) cause;
+            }
+            else {
+                // TODO deal with errors!
+                throw e;
             }
         } catch (Exception e) {
             throw e;

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/BeanRef.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/BeanRef.java?view=diff&rev=566911&r1=566910&r2=566911
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/BeanRef.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/BeanRef.java Thu
Aug 16 21:21:41 2007
@@ -42,8 +42,8 @@
     public BeanRef() {
     }
 
-    public BeanRef(Object bean) {
-        this.bean = bean;
+    public BeanRef(String ref) {
+        this.ref = ref;
     }
 
     public BeanRef(String ref, String method) {

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java?view=diff&rev=566911&r1=566910&r2=566911
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java
Thu Aug 16 21:21:41 2007
@@ -22,6 +22,8 @@
 import org.apache.camel.spi.Language;
 import org.apache.camel.util.jndi.JndiTest;
 
+import javax.naming.Context;
+
 /**
  * A useful base class which creates a {@link CamelContext} with some routes
  * along with a {@link CamelTemplate} for use in the test case
@@ -89,7 +91,15 @@
     }
 
     protected CamelContext createCamelContext() throws Exception {
-        return new DefaultCamelContext(new JndiRegistry(JndiTest.createInitialContext()));
+        return new DefaultCamelContext(createRegistry());
+    }
+
+    protected JndiRegistry createRegistry() throws Exception {
+        return new JndiRegistry(createJndiContext());
+    }
+
+    protected Context createJndiContext() throws Exception {
+        return JndiTest.createInitialContext();
     }
 
     protected RouteBuilder createRouteBuilder() throws Exception {

Copied: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/BeanWithExceptionTest.java
(from r566791, activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ValidationTest.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/BeanWithExceptionTest.java?view=diff&rev=566911&p1=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ValidationTest.java&r1=566791&p2=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/BeanWithExceptionTest.java&r2=566911
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ValidationTest.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/BeanWithExceptionTest.java
Thu Aug 16 21:21:41 2007
@@ -17,15 +17,21 @@
 package org.apache.camel.processor;
 
 import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Header;
 import org.apache.camel.Processor;
 import org.apache.camel.ValidationException;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.util.jndi.JndiContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.naming.Context;
 
 /**
  * @version $Revision: 1.1 $
  */
-public class ValidationTest extends ContextTestSupport {
+public class BeanWithExceptionTest extends ContextTestSupport {
     protected Processor validator = new MyValidator();
     protected MockEndpoint validEndpoint;
     protected MockEndpoint invalidEndpoint;
@@ -54,15 +60,34 @@
         invalidEndpoint = resolveMandatoryEndpoint("mock:invalid", MockEndpoint.class);
     }
 
+    @Override
+    protected Context createJndiContext() throws Exception {
+        JndiContext answer = new JndiContext();
+        answer.bind("myBean", new ValidationBean());
+        return answer;
+    }
+
     protected RouteBuilder createRouteBuilder() {
         return new RouteBuilder() {
             public void configure() {
+                exception(ValidationException.class).to("mock:invalid");
+
                 from("direct:start").
-                        tryBlock().
-                            process(validator).
-                            to("mock:valid").
-                        handle(ValidationException.class).to("mock:invalid");
-            }
+                        beanRef("myBean").
+                        to("mock:valid");            }
         };
     }
-}
+
+    public static class ValidationBean {
+        private static final transient Log LOG = LogFactory.getLog(ValidationBean.class);
+
+        public void someMethod(String body, @Header(name = "foo") String header) throws ValidationException
{
+            if ("bar".equals(header)) {
+                LOG.info("someMethod() called with valid header and body: " + body);
+            }
+            else {
+                throw new ValidationException(null, "Invalid header foo: " + header);
+            }
+        }
+    }
+}
\ No newline at end of file



Mime
View raw message