camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/2] camel git commit: CAMEL-8476: doTry should break out if fault message was set. Make setting fault message same as setting regular message on either IN or OUT. Do not force OUT anymore.
Date Sat, 14 Mar 2015 13:29:01 GMT
CAMEL-8476: doTry should break out if fault message was set. Make setting fault message same
as setting regular message on either IN or OUT. Do not force OUT anymore.


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

Branch: refs/heads/camel-2.15.x
Commit: 23a642f6a8db1c2d3b8ecb36b365a31ef4173cd8
Parents: b668a89
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sat Mar 14 08:49:55 2015 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sat Mar 14 14:30:31 2015 +0100

----------------------------------------------------------------------
 .../apache/camel/builder/ExpressionBuilder.java |  6 +-
 .../apache/camel/builder/ProcessorBuilder.java  | 22 +++++--
 .../org/apache/camel/impl/DefaultExchange.java  |  5 +-
 .../camel/impl/DefaultExchangeHolder.java       |  6 ++
 .../camel/impl/InterceptSendToEndpoint.java     |  2 -
 .../camel/processor/OnCompletionProcessor.java  | 13 +++++
 .../apache/camel/processor/PipelineHelper.java  | 10 ++--
 .../org/apache/camel/processor/RoutingSlip.java |  5 --
 .../apache/camel/processor/TryProcessor.java    |  2 +
 .../interceptor/HandleFaultInterceptor.java     | 12 +++-
 .../org/apache/camel/util/ExchangeHelper.java   |  7 ++-
 .../apache/camel/processor/TrySetFaultTest.java | 61 ++++++++++++++++++++
 .../apache/camel/component/cxf/CxfConsumer.java |  8 ++-
 .../component/jms/EndpointMessageListener.java  | 11 ++--
 .../restlet/DefaultRestletBinding.java          |  5 +-
 .../integration/adapter/CamelTargetAdapter.java |  3 +-
 .../processor/SpringSetFaultBodyTest.java       |  7 +--
 17 files changed, 147 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/23a642f6/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java b/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
index a31e895..c22ad80 100644
--- a/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
+++ b/camel-core/src/main/java/org/apache/camel/builder/ExpressionBuilder.java
@@ -1110,7 +1110,8 @@ public final class ExpressionBuilder {
     public static Expression faultBodyExpression() {
         return new ExpressionAdapter() {
             public Object evaluate(Exchange exchange) {
-                return exchange.getOut().isFault() ? exchange.getOut().getBody() : null;
+                Message msg = exchange.hasOut() ? exchange.getOut() : exchange.getIn();
+                return msg.isFault() ? msg.getBody() : null;
             }
 
             @Override
@@ -1127,7 +1128,8 @@ public final class ExpressionBuilder {
     public static <T> Expression faultBodyExpression(final Class<T> type) {
         return new ExpressionAdapter() {
             public Object evaluate(Exchange exchange) {
-                return exchange.getOut().isFault() ? exchange.getOut().getBody(type) : null;
+                Message msg = exchange.hasOut() ? exchange.getOut() : exchange.getIn();
+                return msg.isFault() ? msg.getBody(type) : null;
             }
 
             @Override

http://git-wip-us.apache.org/repos/asf/camel/blob/23a642f6/camel-core/src/main/java/org/apache/camel/builder/ProcessorBuilder.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/builder/ProcessorBuilder.java b/camel-core/src/main/java/org/apache/camel/builder/ProcessorBuilder.java
index e2c88b4..25a6f9f 100644
--- a/camel-core/src/main/java/org/apache/camel/builder/ProcessorBuilder.java
+++ b/camel-core/src/main/java/org/apache/camel/builder/ProcessorBuilder.java
@@ -77,14 +77,19 @@ public final class ProcessorBuilder {
     }
 
     /**
-     * Creates a processor which sets the body of the FAULT message (FAULT must be OUT) to
the value of the expression
+     * Creates a processor which sets the body of the FAULT message to the value of the expression
      */
     public static Processor setFaultBody(final Expression expression) {
         return new Processor() {
             public void process(Exchange exchange) {
                 Object newBody = expression.evaluate(exchange, Object.class);
-                exchange.getOut().setFault(true);
-                exchange.getOut().setBody(newBody);
+                if (exchange.hasOut()) {
+                    exchange.getOut().setFault(true);
+                    exchange.getOut().setBody(newBody);
+                } else {
+                    exchange.getIn().setFault(true);
+                    exchange.getIn().setBody(newBody);
+                }
             }
 
             @Override
@@ -136,14 +141,19 @@ public final class ProcessorBuilder {
     }
 
     /**
-     * Sets the header on the FAULT message (FAULT must be OUT)
+     * Sets the header on the FAULT message
      */
     public static Processor setFaultHeader(final String name, final Expression expression)
{
         return new Processor() {
             public void process(Exchange exchange) {
                 Object value = expression.evaluate(exchange, Object.class);
-                exchange.getOut().setFault(true);
-                exchange.getOut().setHeader(name, value);
+                if (exchange.hasOut()) {
+                    exchange.getOut().setFault(true);
+                    exchange.getOut().setHeader(name, value);
+                } else {
+                    exchange.getIn().setFault(true);
+                    exchange.getIn().setHeader(name, value);
+                }
             }
 
             @Override

http://git-wip-us.apache.org/repos/asf/camel/blob/23a642f6/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java
index 3045838..eb6db98 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java
@@ -345,7 +345,10 @@ public final class DefaultExchange implements Exchange {
     }
 
     public boolean isFailed() {
-        return (hasOut() && getOut().isFault()) || getException() != null;
+        if (exception != null) {
+            return true;
+        }
+        return hasOut() ? getOut().isFault() : getIn().isFault();
     }
 
     public boolean isTransacted() {

http://git-wip-us.apache.org/repos/asf/camel/blob/23a642f6/camel-core/src/main/java/org/apache/camel/impl/DefaultExchangeHolder.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultExchangeHolder.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultExchangeHolder.java
index 20bb42d..e6a277b 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultExchangeHolder.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultExchangeHolder.java
@@ -61,6 +61,7 @@ public class DefaultExchangeHolder implements Serializable {
     private String exchangeId;
     private Object inBody;
     private Object outBody;
+    private Boolean inFaultFlag = Boolean.FALSE;
     private Boolean outFaultFlag = Boolean.FALSE;
     private Map<String, Object> inHeaders;
     private Map<String, Object> outHeaders;
@@ -102,6 +103,8 @@ public class DefaultExchangeHolder implements Serializable {
             payload.outBody = checkSerializableBody("out body", exchange, exchange.getOut().getBody());
             payload.outFaultFlag = exchange.getOut().isFault();
             payload.safeSetOutHeaders(exchange);
+        } else {
+            payload.inFaultFlag = exchange.getIn().isFault();
         }
         if (includeProperties) {
             payload.safeSetProperties(exchange);
@@ -126,6 +129,9 @@ public class DefaultExchangeHolder implements Serializable {
         if (payload.inHeaders != null) {
             exchange.getIn().setHeaders(payload.inHeaders);
         }
+        if (payload.inFaultFlag != null) {
+            exchange.getIn().setFault(payload.inFaultFlag);
+        }
         if (payload.outBody != null) {
             exchange.getOut().setBody(payload.outBody);
             if (payload.outHeaders != null) {

http://git-wip-us.apache.org/repos/asf/camel/blob/23a642f6/camel-core/src/main/java/org/apache/camel/impl/InterceptSendToEndpoint.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/InterceptSendToEndpoint.java b/camel-core/src/main/java/org/apache/camel/impl/InterceptSendToEndpoint.java
index 2a333af..9c73ed2 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/InterceptSendToEndpoint.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/InterceptSendToEndpoint.java
@@ -132,8 +132,6 @@ public class InterceptSendToEndpoint implements Endpoint {
                     detour.process(exchange);
                 } catch (Exception e) {
                     exchange.setException(e);
-                    callback.done(true);
-                    return true;
                 }
 
                 // Decide whether to continue or not; similar logic to the Pipeline

http://git-wip-us.apache.org/repos/asf/camel/blob/23a642f6/camel-core/src/main/java/org/apache/camel/processor/OnCompletionProcessor.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/OnCompletionProcessor.java
b/camel-core/src/main/java/org/apache/camel/processor/OnCompletionProcessor.java
index 6575cb2..e420772 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/OnCompletionProcessor.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/OnCompletionProcessor.java
@@ -256,9 +256,16 @@ public class OnCompletionProcessor extends ServiceSupport implements
AsyncProces
             // must use a copy as we dont want it to cause side effects of the original exchange
             final Exchange copy = prepareExchange(exchange);
             final Exception original = copy.getException();
+            final boolean originalFault = copy.hasOut() ? copy.getOut().isFault() : copy.getIn().isFault();
             // must remove exception otherwise onFailure routing will fail as well
             // the caused exception is stored as a property (Exchange.EXCEPTION_CAUGHT) on
the exchange
             copy.setException(null);
+            // must clear fault otherwise onFailure routing will fail as well
+            if (copy.hasOut()) {
+                copy.getOut().setFault(false);
+            } else {
+                copy.getIn().setFault(false);
+            }
 
             if (executorService != null) {
                 executorService.submit(new Callable<Exchange>() {
@@ -276,6 +283,12 @@ public class OnCompletionProcessor extends ServiceSupport implements
AsyncProces
                 doProcess(processor, copy);
                 // restore exception after processing
                 copy.setException(original);
+                // restore fault after processing
+                if (copy.hasOut()) {
+                    copy.getOut().setFault(originalFault);
+                } else {
+                    copy.getIn().setFault(originalFault);
+                }
             }
         }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/23a642f6/camel-core/src/main/java/org/apache/camel/processor/PipelineHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/PipelineHelper.java b/camel-core/src/main/java/org/apache/camel/processor/PipelineHelper.java
index ebc5398..6c111e8 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/PipelineHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/PipelineHelper.java
@@ -17,6 +17,7 @@
 package org.apache.camel.processor;
 
 import org.apache.camel.Exchange;
+import org.apache.camel.Message;
 import org.slf4j.Logger;
 
 import static org.apache.camel.util.ExchangeHelper.hasExceptionBeenHandledByErrorHandler;
@@ -45,12 +46,13 @@ public final class PipelineHelper {
         boolean exceptionHandled = hasExceptionBeenHandledByErrorHandler(exchange);
         if (exchange.isFailed() || exchange.isRollbackOnly() || exceptionHandled) {
             // We need to write a warning message when the exception and fault message be
set at the same time
-            if (exchange.hasOut() && exchange.getOut().isFault() && exchange.getException()
!= null) {
+            Message msg = exchange.hasOut() ? exchange.getOut() : exchange.getIn();
+            if (msg.isFault() && exchange.getException() != null) {
                 StringBuilder sb = new StringBuilder();
                 sb.append("Message exchange has failed: " + message + " for exchange: ").append(exchange);
                 sb.append(" Warning: Both fault and exception exists on the exchange, its
best practice to only set one of them.");
                 sb.append(" Exception: ").append(exchange.getException());
-                sb.append(" Fault: ").append(exchange.getOut());
+                sb.append(" Fault: ").append(msg);
                 if (exceptionHandled) {
                     sb.append(" Handled by the error handler.");
                 }
@@ -67,8 +69,8 @@ public final class PipelineHelper {
                 if (exchange.getException() != null) {
                     sb.append(" Exception: ").append(exchange.getException());
                 }
-                if (exchange.hasOut() && exchange.getOut().isFault()) {
-                    sb.append(" Fault: ").append(exchange.getOut());
+                if (msg.isFault()) {
+                    sb.append(" Fault: ").append(msg);
                 }
                 if (exceptionHandled) {
                     sb.append(" Handled by the error handler.");

http://git-wip-us.apache.org/repos/asf/camel/blob/23a642f6/camel-core/src/main/java/org/apache/camel/processor/RoutingSlip.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/RoutingSlip.java b/camel-core/src/main/java/org/apache/camel/processor/RoutingSlip.java
index 88e57db..00625d6 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/RoutingSlip.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/RoutingSlip.java
@@ -408,11 +408,6 @@ public class RoutingSlip extends ServiceSupport implements AsyncProcessor,
Trace
      */
     private void copyOutToIn(Exchange result, Exchange source) {
         result.setException(source.getException());
-
-        if (source.hasOut() && source.getOut().isFault()) {
-            result.getOut().copyFrom(source.getOut());
-        }
-
         result.setIn(getResultMessage(source));
 
         result.getProperties().clear();

http://git-wip-us.apache.org/repos/asf/camel/blob/23a642f6/camel-core/src/main/java/org/apache/camel/processor/TryProcessor.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/TryProcessor.java b/camel-core/src/main/java/org/apache/camel/processor/TryProcessor.java
index b53a14e..24cea69 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/TryProcessor.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/TryProcessor.java
@@ -34,6 +34,8 @@ import org.apache.camel.util.ServiceHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static org.apache.camel.processor.PipelineHelper.continueProcessing;
+
 /**
  * Implements try/catch/finally type processing
  *

http://git-wip-us.apache.org/repos/asf/camel/blob/23a642f6/camel-core/src/main/java/org/apache/camel/processor/interceptor/HandleFaultInterceptor.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/interceptor/HandleFaultInterceptor.java
b/camel-core/src/main/java/org/apache/camel/processor/interceptor/HandleFaultInterceptor.java
index 538fe88..06394c4 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/interceptor/HandleFaultInterceptor.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/interceptor/HandleFaultInterceptor.java
@@ -19,6 +19,7 @@ package org.apache.camel.processor.interceptor;
 import org.apache.camel.AsyncCallback;
 import org.apache.camel.CamelException;
 import org.apache.camel.Exchange;
+import org.apache.camel.Message;
 import org.apache.camel.Processor;
 import org.apache.camel.processor.DelegateAsyncProcessor;
 
@@ -56,11 +57,16 @@ public class HandleFaultInterceptor extends DelegateAsyncProcessor {
      */
     protected void handleFault(Exchange exchange) {
         // Take the fault message out before we keep on going
-        if (exchange.hasOut() && exchange.getOut().isFault()) {
-            final Object faultBody = exchange.getOut().getBody();
+        Message msg = exchange.hasOut() ? exchange.getOut() : exchange.getIn();
+        if (msg.isFault()) {
+            final Object faultBody = msg.getBody();
             if (faultBody != null && exchange.getException() == null) {
                 // remove fault as we are converting it to an exception
-                exchange.setOut(null);
+                if (exchange.hasOut()) {
+                    exchange.setOut(null);
+                } else {
+                    exchange.setIn(null);
+                }
                 if (faultBody instanceof Throwable) {
                     exchange.setException((Throwable) faultBody);
                 } else {

http://git-wip-us.apache.org/repos/asf/camel/blob/23a642f6/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java b/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java
index cc6836d..88905d7 100644
--- a/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java
@@ -625,7 +625,9 @@ public final class ExchangeHelper {
 
             // result could have a fault message
             if (hasFaultMessage(exchange)) {
-                return exchange.getOut().getBody();
+                Message msg = exchange.hasOut() ? exchange.getOut() : exchange.getIn();
+                answer = msg.getBody();
+                return answer;
             }
 
             // okay no fault then return the response according to the pattern
@@ -654,7 +656,8 @@ public final class ExchangeHelper {
      * @return <tt>true</tt> if fault message exists
      */
     public static boolean hasFaultMessage(Exchange exchange) {
-        return exchange.hasOut() && exchange.getOut().isFault() && exchange.getOut().getBody()
!= null;
+        Message msg = exchange.hasOut() ? exchange.getOut() : exchange.getIn();
+        return msg.isFault() && msg.getBody() != null;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/camel/blob/23a642f6/camel-core/src/test/java/org/apache/camel/processor/TrySetFaultTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/TrySetFaultTest.java b/camel-core/src/test/java/org/apache/camel/processor/TrySetFaultTest.java
new file mode 100644
index 0000000..637b779
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/processor/TrySetFaultTest.java
@@ -0,0 +1,61 @@
+/**
+ * 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 TrySetFaultTest extends ContextTestSupport {
+
+    public void testSetFault() throws Exception {
+        getMockEndpoint("mock:a").expectedMessageCount(0);
+        getMockEndpoint("mock:b").expectedMessageCount(0);
+
+        template.requestBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                    .to("direct:a")
+                    .to("mock:a")
+                    .to("direct:b")
+                    .to("mock:b");
+
+                from("direct:a")
+                    .doTry()
+                        .setFaultBody(constant("Failed at A"))
+                    .doCatch(Exception.class)
+                        .to("mock:catch-a")
+                    .end();
+
+                from("direct:b")
+                    .doTry()
+                        .setFaultBody(constant("Failed at B"))
+                    .doCatch(Exception.class)
+                        .to("mock:catch-a")
+                    .end()
+                    .to("log:b");
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/23a642f6/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java
b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java
index 4198dfb..fab7267 100644
--- a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java
+++ b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java
@@ -220,8 +220,12 @@ public class CxfConsumer extends DefaultConsumer {
             private void checkFailure(org.apache.camel.Exchange camelExchange, Exchange cxfExchange)
throws Fault {
                 final Throwable t;
                 if (camelExchange.isFailed()) {
-                    t = (camelExchange.hasOut() && camelExchange.getOut().isFault())
? camelExchange.getOut()
-                        .getBody(Throwable.class) : camelExchange.getException();
+                    org.apache.camel.Message camelMsg = camelExchange.hasOut() ? camelExchange.getOut()
: camelExchange.getIn();
+                    if (camelMsg.isFault()) {
+                        t = camelMsg.getBody(Throwable.class);
+                    } else {
+                        t = camelExchange.getException();
+                    }
                     cxfExchange.getInMessage().put(FaultMode.class, FaultMode.UNCHECKED_APPLICATION_FAULT);
                     if (t instanceof Fault) {
                         cxfExchange.getInMessage().put(FaultMode.class, FaultMode.CHECKED_APPLICATION_FAULT);

http://git-wip-us.apache.org/repos/asf/camel/blob/23a642f6/components/camel-jms/src/main/java/org/apache/camel/component/jms/EndpointMessageListener.java
----------------------------------------------------------------------
diff --git a/components/camel-jms/src/main/java/org/apache/camel/component/jms/EndpointMessageListener.java
b/components/camel-jms/src/main/java/org/apache/camel/component/jms/EndpointMessageListener.java
index e1396b1..9f7778a 100644
--- a/components/camel-jms/src/main/java/org/apache/camel/component/jms/EndpointMessageListener.java
+++ b/components/camel-jms/src/main/java/org/apache/camel/component/jms/EndpointMessageListener.java
@@ -185,10 +185,13 @@ public class EndpointMessageListener implements MessageListener {
                         // do not send a reply but wrap and rethrow the exception
                         rce = wrapRuntimeCamelException(exchange.getException());
                     }
-                } else if (exchange.hasOut() && exchange.getOut().isFault()) {
-                    // a fault occurred while processing
-                    body = exchange.getOut();
-                    cause = null;
+                } else {
+                    org.apache.camel.Message msg = exchange.hasOut() ? exchange.getOut()
: exchange.getIn();
+                    if (msg.isFault()) {
+                        // a fault occurred while processing
+                        body = msg;
+                        cause = null;
+                    }
                 }
             } else {
                 // process OK so get the reply body if we are InOut and has a body

http://git-wip-us.apache.org/repos/asf/camel/blob/23a642f6/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
----------------------------------------------------------------------
diff --git a/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
b/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
index dbc949d..35369bf 100644
--- a/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
+++ b/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
@@ -217,8 +217,9 @@ public class DefaultRestletBinding implements RestletBinding, HeaderFilterStrate
         if (exchange.isFailed()) {
             // 500 for internal server error which can be overridden by response code in
header
             response.setStatus(Status.valueOf(500));
-            if (exchange.hasOut() && exchange.getOut().isFault()) {
-                out = exchange.getOut();
+            Message msg = exchange.hasOut() ? exchange.getOut() : exchange.getIn();
+            if (msg.isFault()) {
+                out = msg;
             } else {
                 // print exception as message and stacktrace
                 Exception t = exchange.getException();

http://git-wip-us.apache.org/repos/asf/camel/blob/23a642f6/components/camel-spring-integration/src/main/java/org/apache/camel/component/spring/integration/adapter/CamelTargetAdapter.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-integration/src/main/java/org/apache/camel/component/spring/integration/adapter/CamelTargetAdapter.java
b/components/camel-spring-integration/src/main/java/org/apache/camel/component/spring/integration/adapter/CamelTargetAdapter.java
index 46671fd..50b1434 100644
--- a/components/camel-spring-integration/src/main/java/org/apache/camel/component/spring/integration/adapter/CamelTargetAdapter.java
+++ b/components/camel-spring-integration/src/main/java/org/apache/camel/component/spring/integration/adapter/CamelTargetAdapter.java
@@ -73,7 +73,8 @@ public class CamelTargetAdapter extends AbstractCamelAdapter implements
MessageH
         Exchange inExchange = new DefaultExchange(getCamelContext(), pattern);
         SpringIntegrationBinding.storeToCamelMessage(message, inExchange.getIn());
         Exchange outExchange = getCamelTemplate().send(getCamelEndpointUri(), inExchange);
-        if (outExchange.getOut() != null && outExchange.getOut().isFault()) {
+        org.apache.camel.Message camelMsg = outExchange.hasOut() ? outExchange.getOut() :
outExchange.getIn();
+        if (camelMsg.isFault()) {
             result = true;
         }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/23a642f6/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringSetFaultBodyTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringSetFaultBodyTest.java
b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringSetFaultBodyTest.java
index fa00161..f0b0f25 100644
--- a/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringSetFaultBodyTest.java
+++ b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringSetFaultBodyTest.java
@@ -33,7 +33,7 @@ public class SpringSetFaultBodyTest extends SpringTestSupport {
     }
 
     public void testSetFaultBody() throws Exception {
-        Exchange out = template.send("direct:start", new Processor() {
+        Exchange out = template.request("direct:start", new Processor() {
             @Override
             public void process(Exchange exchange) throws Exception {
                 exchange.getIn().setBody("Hello World");
@@ -41,8 +41,7 @@ public class SpringSetFaultBodyTest extends SpringTestSupport {
         });
 
         assertNotNull(out);
-        assertTrue(out.hasOut());
-        assertEquals("Bye World", out.getOut().getBody());
-        assertTrue("Should be a fault body", out.getOut().isFault());
+        assertEquals("Bye World", out.getIn().getBody());
+        assertTrue("Should be a fault body", out.getIn().isFault());
     }
 }


Mime
View raw message