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 2015/06/15 11:31:23 UTC

[2/2] camel git commit: CAMEL-8871: Fixed null body/header after transform called bean that throws exception. Thanks to Hans Orbaan for reporting.

CAMEL-8871: Fixed null body/header after transform called bean that throws exception. Thanks to Hans Orbaan for reporting.


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

Branch: refs/heads/camel-2.15.x
Commit: a554780c3f93887c295260cf0b3996ae16ef0648
Parents: f2fedc7
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Jun 15 10:44:20 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Jun 15 11:36:12 2015 +0200

----------------------------------------------------------------------
 .../camel/processor/SetBodyProcessor.java       |  8 ++-
 .../camel/processor/SetHeaderProcessor.java     |  6 ++
 .../camel/processor/SetPropertyProcessor.java   |  7 +++
 .../camel/processor/TransformProcessor.java     |  8 ++-
 .../processor/TransformBeanExceptionTest.java   | 64 ++++++++++++++++++++
 5 files changed, 91 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/a554780c/camel-core/src/main/java/org/apache/camel/processor/SetBodyProcessor.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/SetBodyProcessor.java b/camel-core/src/main/java/org/apache/camel/processor/SetBodyProcessor.java
index 8da646a..99cd838 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/SetBodyProcessor.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/SetBodyProcessor.java
@@ -46,6 +46,12 @@ public class SetBodyProcessor extends ServiceSupport implements AsyncProcessor,
         try {
             Object newBody = expression.evaluate(exchange, Object.class);
 
+            if (exchange.getException() != null) {
+                // the expression threw an exception so we should break-out
+                callback.done(true);
+                return true;
+            }
+
             boolean out = exchange.hasOut();
             Message old = out ? exchange.getOut() : exchange.getIn();
 
@@ -65,7 +71,7 @@ public class SetBodyProcessor extends ServiceSupport implements AsyncProcessor,
                 old.setBody(newBody);
             }
 
-        } catch (Exception e) {
+        } catch (Throwable e) {
             exchange.setException(e);
         }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/a554780c/camel-core/src/main/java/org/apache/camel/processor/SetHeaderProcessor.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/SetHeaderProcessor.java b/camel-core/src/main/java/org/apache/camel/processor/SetHeaderProcessor.java
index bfcd3dd..1edecca 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/SetHeaderProcessor.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/SetHeaderProcessor.java
@@ -46,6 +46,12 @@ public class SetHeaderProcessor extends ServiceSupport implements AsyncProcessor
         try {
             Object newHeader = expression.evaluate(exchange, Object.class);
 
+            if (exchange.getException() != null) {
+                // the expression threw an exception so we should break-out
+                callback.done(true);
+                return true;
+            }
+
             boolean out = exchange.hasOut();
             Message old = out ? exchange.getOut() : exchange.getIn();
 

http://git-wip-us.apache.org/repos/asf/camel/blob/a554780c/camel-core/src/main/java/org/apache/camel/processor/SetPropertyProcessor.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/SetPropertyProcessor.java b/camel-core/src/main/java/org/apache/camel/processor/SetPropertyProcessor.java
index d50d07c..d8c1bcb 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/SetPropertyProcessor.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/SetPropertyProcessor.java
@@ -44,6 +44,13 @@ public class SetPropertyProcessor extends ServiceSupport implements AsyncProcess
     public boolean process(Exchange exchange, AsyncCallback callback) {
         try {
             Object newProperty = expression.evaluate(exchange, Object.class);
+
+            if (exchange.getException() != null) {
+                // the expression threw an exception so we should break-out
+                callback.done(true);
+                return true;
+            }
+
             exchange.setProperty(propertyName, newProperty);
         } catch (Exception e) {
             exchange.setException(e);

http://git-wip-us.apache.org/repos/asf/camel/blob/a554780c/camel-core/src/main/java/org/apache/camel/processor/TransformProcessor.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/TransformProcessor.java b/camel-core/src/main/java/org/apache/camel/processor/TransformProcessor.java
index 61db471..1958fe0 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/TransformProcessor.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/TransformProcessor.java
@@ -47,6 +47,12 @@ public class TransformProcessor extends ServiceSupport implements AsyncProcessor
         try {
             Object newBody = expression.evaluate(exchange, Object.class);
 
+            if (exchange.getException() != null) {
+                // the expression threw an exception so we should break-out
+                callback.done(true);
+                return true;
+            }
+
             boolean out = exchange.hasOut();
             Message old = out ? exchange.getOut() : exchange.getIn();
 
@@ -71,7 +77,7 @@ public class TransformProcessor extends ServiceSupport implements AsyncProcessor
                 }
             }
 
-        } catch (Exception e) {
+        } catch (Throwable e) {
             exchange.setException(e);
         }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/a554780c/camel-core/src/test/java/org/apache/camel/processor/TransformBeanExceptionTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/TransformBeanExceptionTest.java b/camel-core/src/test/java/org/apache/camel/processor/TransformBeanExceptionTest.java
new file mode 100644
index 0000000..e45d6c9
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/processor/TransformBeanExceptionTest.java
@@ -0,0 +1,64 @@
+/**
+ * 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.processor;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+public class TransformBeanExceptionTest extends ContextTestSupport {
+
+    public void testTransformBeanException() throws Exception {
+        getMockEndpoint("mock:dead").expectedBodiesReceived("Hello World", "Bye World", "Hi World", "Hi Camel", "Bye Camel");
+
+        template.sendBody("direct:transform", "Hello World");
+        template.sendBody("direct:bean", "Bye World");
+        template.sendBody("direct:setBody", "Hi World");
+        template.sendBody("direct:setHeader", "Hi Camel");
+        template.sendBody("direct:setProperty", "Bye Camel");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                errorHandler(deadLetterChannel("mock:dead"));
+
+                from("direct:transform")
+                    .transform().method(TransformBeanExceptionTest.class, "throwUp");
+
+                from("direct:bean")
+                    .bean(TransformBeanExceptionTest.class, "throwUp");
+
+                from("direct:setBody")
+                    .setBody().method(TransformBeanExceptionTest.class, "throwUp");
+
+                from("direct:setHeader")
+                    .setHeader("hello").method(TransformBeanExceptionTest.class, "throwUp");
+
+                from("direct:setProperty")
+                    .setProperty("bye").method(TransformBeanExceptionTest.class, "throwUp");
+            }
+        };
+    }
+
+    public static String throwUp(String body) {
+        throw new IllegalArgumentException("Forced");
+    }
+}