Repository: camel
Updated Branches:
  refs/heads/camel-2.15.x f2fedc76a -> a554780c3
  refs/heads/master e104f9f7b -> 598a214a5


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/598a214a
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/598a214a
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/598a214a

Branch: refs/heads/master
Commit: 598a214a5723eedc1ac03e6b7e3baa1facae30a8
Parents: e104f9f
Author: Claus Ibsen <davscl...@apache.org>
Authored: Mon Jun 15 10:44:20 2015 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Mon Jun 15 10:44:20 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/598a214a/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 ef098be..109a2d8 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
@@ -48,6 +48,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();
 
@@ -67,7 +73,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/598a214a/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 fd1e378..b5d9854 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
@@ -48,6 +48,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/598a214a/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 48eb206..1276108 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
@@ -46,6 +46,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/598a214a/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 a0b0662..fe82780 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
@@ -49,6 +49,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();
 
@@ -73,7 +79,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/598a214a/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");
+    }
+}

Reply via email to