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 2016/04/23 11:04:37 UTC

[1/4] camel git commit: CAMEL-9896: When using continued with onException then dead letter channel endpooint should not be invoked.

Repository: camel
Updated Branches:
  refs/heads/camel-2.16.x a6b710e8d -> bba477b1a
  refs/heads/camel-2.17.x f72a857c9 -> fc9569588
  refs/heads/master f0b7ae187 -> 15404ced2


CAMEL-9896: When using continued with onException then dead letter channel endpooint should not be invoked.


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

Branch: refs/heads/master
Commit: 7cb35c411b2002239dfd0b287cec3efdf86f58e7
Parents: f0b7ae1
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Apr 23 10:08:07 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Apr 23 10:08:07 2016 +0200

----------------------------------------------------------------------
 .../camel/processor/RedeliveryErrorHandler.java |   9 +-
 .../issues/OnExceptionContinuedIssueTest.java   | 107 +++++++++++++++++++
 ...xceptionContinuedNoFailureProcessorTest.java |   2 +-
 3 files changed, 115 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/7cb35c41/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java b/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
index 4b961f1..4661797 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
@@ -912,8 +912,13 @@ public abstract class RedeliveryErrorHandler extends ErrorHandlerSupport impleme
             decrementRedeliveryCounter(exchange);
         }
 
-        // is the a failure processor to process the Exchange
-        if (processor != null) {
+        // we should allow using the failure processor if we should not continue
+        // or in case of continue then the failure processor is NOT a dead letter channel
+        // because you can continue and still let the failure processor do some routing
+        // before continue in the main route.
+        boolean allowFailureProcessor = !shouldContinue || !isDeadLetterChannel;
+
+        if (allowFailureProcessor && processor != null) {
 
             // prepare original IN body if it should be moved instead of current body
             if (data.useOriginalInMessage) {

http://git-wip-us.apache.org/repos/asf/camel/blob/7cb35c41/camel-core/src/test/java/org/apache/camel/issues/OnExceptionContinuedIssueTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/issues/OnExceptionContinuedIssueTest.java b/camel-core/src/test/java/org/apache/camel/issues/OnExceptionContinuedIssueTest.java
new file mode 100644
index 0000000..5deca4f
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/issues/OnExceptionContinuedIssueTest.java
@@ -0,0 +1,107 @@
+/**
+ * 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.issues;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.DeadLetterChannelBuilder;
+import org.apache.camel.builder.DefaultErrorHandlerBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+public class OnExceptionContinuedIssueTest extends ContextTestSupport {
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    @Test
+    public void testOnExceptionWrappedMatch() throws Exception {
+        final DefaultErrorHandlerBuilder defaultErrorHandlerBuilder = new DeadLetterChannelBuilder("direct:dead");
+        defaultErrorHandlerBuilder.redeliveryDelay(0); // run fast
+        defaultErrorHandlerBuilder.maximumRedeliveries(2);
+
+        context.setErrorHandlerBuilder(defaultErrorHandlerBuilder);
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                context.setTracing(false);
+
+                onException(OrderFailedException.class)
+                        .maximumRedeliveries(0)
+                        .continued(true);
+
+                from("direct:dead").to("log:dead", "mock:dead");
+
+                from("direct:order")
+                        .to("mock:one")
+                        .process(new Processor() {
+                            @Override
+                            public void process(Exchange exchange) throws Exception {
+                                log.info("First Processor Invoked");
+                                throw new OrderFailedException("First Processor Failure");
+                            }
+                        })
+                        .to("mock:two")
+                        .process(new Processor() {
+                            @Override
+                            public void process(Exchange exchange) throws Exception {
+                                log.info("Second Processor Invoked");
+                            }
+                        })
+                        .to("mock:three")
+                        .process(new Processor() {
+                            @Override
+                            public void process(Exchange exchange) throws Exception {
+                                log.info("Third Processor Invoked");
+                                throw new RuntimeException("Some Runtime Exception");
+                            }
+                        })
+                        .to("mock:four")
+                        .process(new Processor() {
+                            @Override
+                            public void process(Exchange exchange) throws Exception {
+                                log.info("Fourth Processor Invoked");
+                            }
+                        });
+            }
+        });
+        context.start();
+
+        // we should only get 1 to the DLC when we hit the 3rd route that
+        // throws the runtime exception
+        getMockEndpoint("mock:dead").expectedMessageCount(1);
+        getMockEndpoint("mock:one").expectedMessageCount(1);
+        getMockEndpoint("mock:two").expectedMessageCount(1);
+        getMockEndpoint("mock:three").expectedMessageCount(1);
+        getMockEndpoint("mock:four").expectedMessageCount(0);
+
+        template.requestBody("direct:order", "Camel in Action");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public class OrderFailedException extends Exception {
+
+        public OrderFailedException(String s) {
+            super(s);
+        }
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/7cb35c41/camel-core/src/test/java/org/apache/camel/issues/OnExceptionContinuedNoFailureProcessorTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/issues/OnExceptionContinuedNoFailureProcessorTest.java b/camel-core/src/test/java/org/apache/camel/issues/OnExceptionContinuedNoFailureProcessorTest.java
index cad431e..8550425 100644
--- a/camel-core/src/test/java/org/apache/camel/issues/OnExceptionContinuedNoFailureProcessorTest.java
+++ b/camel-core/src/test/java/org/apache/camel/issues/OnExceptionContinuedNoFailureProcessorTest.java
@@ -28,7 +28,7 @@ public class OnExceptionContinuedNoFailureProcessorTest extends ContextTestSuppo
 
     public void testOnException() throws Exception {
         getMockEndpoint("mock:end").expectedMessageCount(1);
-        getMockEndpoint("mock:error").expectedMessageCount(1);
+        getMockEndpoint("mock:error").expectedMessageCount(0);
 
         template.sendBody("direct:start", "Hello World");
 


[3/4] camel git commit: CAMEL-9896: When using continued with onException then dead letter channel endpooint should not be invoked.

Posted by da...@apache.org.
CAMEL-9896: When using continued with onException then dead letter channel endpooint should not be invoked.


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

Branch: refs/heads/camel-2.17.x
Commit: fc9569588abfb09de6c7770cecb95ace81ffe31a
Parents: f72a857
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Apr 23 10:08:07 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Apr 23 11:04:06 2016 +0200

----------------------------------------------------------------------
 .../camel/processor/RedeliveryErrorHandler.java |   9 +-
 .../issues/OnExceptionContinuedIssueTest.java   | 107 +++++++++++++++++++
 ...xceptionContinuedNoFailureProcessorTest.java |   2 +-
 3 files changed, 115 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/fc956958/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java b/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
index 632fb4b..d6250eb 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
@@ -912,8 +912,13 @@ public abstract class RedeliveryErrorHandler extends ErrorHandlerSupport impleme
             decrementRedeliveryCounter(exchange);
         }
 
-        // is the a failure processor to process the Exchange
-        if (processor != null) {
+        // we should allow using the failure processor if we should not continue
+        // or in case of continue then the failure processor is NOT a dead letter channel
+        // because you can continue and still let the failure processor do some routing
+        // before continue in the main route.
+        boolean allowFailureProcessor = !shouldContinue || !isDeadLetterChannel;
+
+        if (allowFailureProcessor && processor != null) {
 
             // prepare original IN body if it should be moved instead of current body
             if (data.useOriginalInMessage) {

http://git-wip-us.apache.org/repos/asf/camel/blob/fc956958/camel-core/src/test/java/org/apache/camel/issues/OnExceptionContinuedIssueTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/issues/OnExceptionContinuedIssueTest.java b/camel-core/src/test/java/org/apache/camel/issues/OnExceptionContinuedIssueTest.java
new file mode 100644
index 0000000..5deca4f
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/issues/OnExceptionContinuedIssueTest.java
@@ -0,0 +1,107 @@
+/**
+ * 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.issues;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.DeadLetterChannelBuilder;
+import org.apache.camel.builder.DefaultErrorHandlerBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+public class OnExceptionContinuedIssueTest extends ContextTestSupport {
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    @Test
+    public void testOnExceptionWrappedMatch() throws Exception {
+        final DefaultErrorHandlerBuilder defaultErrorHandlerBuilder = new DeadLetterChannelBuilder("direct:dead");
+        defaultErrorHandlerBuilder.redeliveryDelay(0); // run fast
+        defaultErrorHandlerBuilder.maximumRedeliveries(2);
+
+        context.setErrorHandlerBuilder(defaultErrorHandlerBuilder);
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                context.setTracing(false);
+
+                onException(OrderFailedException.class)
+                        .maximumRedeliveries(0)
+                        .continued(true);
+
+                from("direct:dead").to("log:dead", "mock:dead");
+
+                from("direct:order")
+                        .to("mock:one")
+                        .process(new Processor() {
+                            @Override
+                            public void process(Exchange exchange) throws Exception {
+                                log.info("First Processor Invoked");
+                                throw new OrderFailedException("First Processor Failure");
+                            }
+                        })
+                        .to("mock:two")
+                        .process(new Processor() {
+                            @Override
+                            public void process(Exchange exchange) throws Exception {
+                                log.info("Second Processor Invoked");
+                            }
+                        })
+                        .to("mock:three")
+                        .process(new Processor() {
+                            @Override
+                            public void process(Exchange exchange) throws Exception {
+                                log.info("Third Processor Invoked");
+                                throw new RuntimeException("Some Runtime Exception");
+                            }
+                        })
+                        .to("mock:four")
+                        .process(new Processor() {
+                            @Override
+                            public void process(Exchange exchange) throws Exception {
+                                log.info("Fourth Processor Invoked");
+                            }
+                        });
+            }
+        });
+        context.start();
+
+        // we should only get 1 to the DLC when we hit the 3rd route that
+        // throws the runtime exception
+        getMockEndpoint("mock:dead").expectedMessageCount(1);
+        getMockEndpoint("mock:one").expectedMessageCount(1);
+        getMockEndpoint("mock:two").expectedMessageCount(1);
+        getMockEndpoint("mock:three").expectedMessageCount(1);
+        getMockEndpoint("mock:four").expectedMessageCount(0);
+
+        template.requestBody("direct:order", "Camel in Action");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public class OrderFailedException extends Exception {
+
+        public OrderFailedException(String s) {
+            super(s);
+        }
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/fc956958/camel-core/src/test/java/org/apache/camel/issues/OnExceptionContinuedNoFailureProcessorTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/issues/OnExceptionContinuedNoFailureProcessorTest.java b/camel-core/src/test/java/org/apache/camel/issues/OnExceptionContinuedNoFailureProcessorTest.java
index cad431e..8550425 100644
--- a/camel-core/src/test/java/org/apache/camel/issues/OnExceptionContinuedNoFailureProcessorTest.java
+++ b/camel-core/src/test/java/org/apache/camel/issues/OnExceptionContinuedNoFailureProcessorTest.java
@@ -28,7 +28,7 @@ public class OnExceptionContinuedNoFailureProcessorTest extends ContextTestSuppo
 
     public void testOnException() throws Exception {
         getMockEndpoint("mock:end").expectedMessageCount(1);
-        getMockEndpoint("mock:error").expectedMessageCount(1);
+        getMockEndpoint("mock:error").expectedMessageCount(0);
 
         template.sendBody("direct:start", "Hello World");
 


[2/4] camel git commit: CAMEL-9879: Circuit Breaker EIP - That is using hystrix.

Posted by da...@apache.org.
CAMEL-9879: Circuit Breaker EIP - That is using hystrix.


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

Branch: refs/heads/master
Commit: 15404ced23ca63a63a2f98796b8ce54d811e304e
Parents: 7cb35c4
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Apr 23 10:48:21 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Apr 23 10:48:21 2016 +0200

----------------------------------------------------------------------
 .../camel/component/hystrix/HystrixConstants.java      |  7 +++++++
 .../component/hystrix/processor/HystrixProcessor.java  | 13 +++++++++++++
 .../processor/BlueprintHystrixRouteFallbackTest.java   |  3 +++
 .../hystrix/processor/BlueprintHystrixRouteOkTest.java |  3 +++
 .../hystrix/processor/HystrixRouteFallbackTest.java    |  3 +++
 .../processor/HystrixRouteFallbackViaNetworkTest.java  |  3 +++
 .../hystrix/processor/HystrixRouteOkTest.java          |  3 +++
 .../processor/SpringHystrixRouteFallbackTest.java      |  3 +++
 .../hystrix/processor/SpringHystrixRouteOkTest.java    |  3 +++
 9 files changed, 41 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/15404ced/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixConstants.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixConstants.java b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixConstants.java
index eeefe09..55f3b9b 100644
--- a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixConstants.java
+++ b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/HystrixConstants.java
@@ -18,6 +18,13 @@ package org.apache.camel.component.hystrix;
 
 public interface HystrixConstants {
 
+    // Hystrix EIP response properties
+    String HYSTRIX_RESPONSE_SUCCESSFUL_EXECUTION = "CamelHystrixSuccessfulExecution";
+    String HYSTRIX_RESPONSE_FROM_FALLBACK = "CamelHystrixResponseFromFallback";
+    String HYSTRIX_RESPONSE_SHORT_CIRCUITED = "CamelHystrixResponseShortCircuited";
+    String HYSTRIX_RESPONSE_TIMED_OUT = "CamelHystrixResponseTimedOut";
+    String HYSTRIX_RESPONSE_REJECTED = "CamelHystrixResponseRejected";
+
     // in message header
     String CAMEL_HYSTRIX_RUN_ENDPOINT = "CamelHystrixRunEndpoint";
     String CAMEL_HYSTRIX_FALLBACK_ENDPOINT = "CamelHystrixFallbackEndpoint";

http://git-wip-us.apache.org/repos/asf/camel/blob/15404ced/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessor.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessor.java b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessor.java
index 15733e7..85f3f10 100644
--- a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessor.java
+++ b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessor.java
@@ -30,6 +30,7 @@ import org.apache.camel.Navigate;
 import org.apache.camel.Processor;
 import org.apache.camel.api.management.ManagedAttribute;
 import org.apache.camel.api.management.ManagedResource;
+import org.apache.camel.component.hystrix.HystrixConstants;
 import org.apache.camel.spi.IdAware;
 import org.apache.camel.support.ServiceSupport;
 import org.apache.camel.util.AsyncProcessorHelper;
@@ -194,6 +195,10 @@ public class HystrixProcessor extends ServiceSupport implements AsyncProcessor,
             }
             HystrixProcessorCommand command = new HystrixProcessorCommand(setter, exchange, processor, fallback, fallbackCommand);
             command.execute();
+
+            // enrich exchange with details from hystrix about the command execution
+            commandResponse(exchange, command);
+
         } catch (Throwable e) {
             exchange.setException(e);
         }
@@ -203,6 +208,14 @@ public class HystrixProcessor extends ServiceSupport implements AsyncProcessor,
         return true;
     }
 
+    private void commandResponse(Exchange exchange, HystrixCommand command) {
+        exchange.setProperty(HystrixConstants.HYSTRIX_RESPONSE_SUCCESSFUL_EXECUTION, command.isSuccessfulExecution());
+        exchange.setProperty(HystrixConstants.HYSTRIX_RESPONSE_FROM_FALLBACK, command.isResponseFromFallback());
+        exchange.setProperty(HystrixConstants.HYSTRIX_RESPONSE_SHORT_CIRCUITED, command.isResponseShortCircuited());
+        exchange.setProperty(HystrixConstants.HYSTRIX_RESPONSE_TIMED_OUT, command.isResponseTimedOut());
+        exchange.setProperty(HystrixConstants.HYSTRIX_RESPONSE_REJECTED, command.isResponseRejected());
+    }
+
     @Override
     protected void doStart() throws Exception {
         // noop

http://git-wip-us.apache.org/repos/asf/camel/blob/15404ced/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/BlueprintHystrixRouteFallbackTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/BlueprintHystrixRouteFallbackTest.java b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/BlueprintHystrixRouteFallbackTest.java
index 5ecb230..861a2ed 100644
--- a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/BlueprintHystrixRouteFallbackTest.java
+++ b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/BlueprintHystrixRouteFallbackTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.hystrix.processor;
 
+import org.apache.camel.component.hystrix.HystrixConstants;
 import org.apache.camel.test.blueprint.CamelBlueprintTestSupport;
 import org.junit.Test;
 
@@ -29,6 +30,8 @@ public class BlueprintHystrixRouteFallbackTest extends CamelBlueprintTestSupport
     @Test
     public void testHystrix() throws Exception {
         getMockEndpoint("mock:result").expectedBodiesReceived("Fallback message");
+        getMockEndpoint("mock:result").expectedPropertyReceived(HystrixConstants.HYSTRIX_RESPONSE_SUCCESSFUL_EXECUTION, false);
+        getMockEndpoint("mock:result").expectedPropertyReceived(HystrixConstants.HYSTRIX_RESPONSE_FROM_FALLBACK, true);
 
         template.sendBody("direct:start", "Hello World");
 

http://git-wip-us.apache.org/repos/asf/camel/blob/15404ced/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/BlueprintHystrixRouteOkTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/BlueprintHystrixRouteOkTest.java b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/BlueprintHystrixRouteOkTest.java
index 044b326..21263fd 100644
--- a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/BlueprintHystrixRouteOkTest.java
+++ b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/BlueprintHystrixRouteOkTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.hystrix.processor;
 
+import org.apache.camel.component.hystrix.HystrixConstants;
 import org.apache.camel.test.blueprint.CamelBlueprintTestSupport;
 import org.junit.Test;
 
@@ -29,6 +30,8 @@ public class BlueprintHystrixRouteOkTest extends CamelBlueprintTestSupport {
     @Test
     public void testHystrix() throws Exception {
         getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
+        getMockEndpoint("mock:result").expectedPropertyReceived(HystrixConstants.HYSTRIX_RESPONSE_SUCCESSFUL_EXECUTION, true);
+        getMockEndpoint("mock:result").expectedPropertyReceived(HystrixConstants.HYSTRIX_RESPONSE_FROM_FALLBACK, false);
 
         template.sendBody("direct:start", "Hello World");
 

http://git-wip-us.apache.org/repos/asf/camel/blob/15404ced/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteFallbackTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteFallbackTest.java b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteFallbackTest.java
index 63f194d..8efe089 100644
--- a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteFallbackTest.java
+++ b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteFallbackTest.java
@@ -17,6 +17,7 @@
 package org.apache.camel.component.hystrix.processor;
 
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.hystrix.HystrixConstants;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
 
@@ -25,6 +26,8 @@ public class HystrixRouteFallbackTest extends CamelTestSupport {
     @Test
     public void testHystrix() throws Exception {
         getMockEndpoint("mock:result").expectedBodiesReceived("Fallback message");
+        getMockEndpoint("mock:result").expectedPropertyReceived(HystrixConstants.HYSTRIX_RESPONSE_SUCCESSFUL_EXECUTION, false);
+        getMockEndpoint("mock:result").expectedPropertyReceived(HystrixConstants.HYSTRIX_RESPONSE_FROM_FALLBACK, true);
 
         template.sendBody("direct:start", "Hello World");
 

http://git-wip-us.apache.org/repos/asf/camel/blob/15404ced/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteFallbackViaNetworkTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteFallbackViaNetworkTest.java b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteFallbackViaNetworkTest.java
index caf7b69..a262813 100644
--- a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteFallbackViaNetworkTest.java
+++ b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteFallbackViaNetworkTest.java
@@ -17,6 +17,7 @@
 package org.apache.camel.component.hystrix.processor;
 
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.hystrix.HystrixConstants;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
 
@@ -25,6 +26,8 @@ public class HystrixRouteFallbackViaNetworkTest extends CamelTestSupport {
     @Test
     public void testHystrix() throws Exception {
         getMockEndpoint("mock:result").expectedBodiesReceived("Fallback message");
+        getMockEndpoint("mock:result").expectedPropertyReceived(HystrixConstants.HYSTRIX_RESPONSE_SUCCESSFUL_EXECUTION, false);
+        getMockEndpoint("mock:result").expectedPropertyReceived(HystrixConstants.HYSTRIX_RESPONSE_FROM_FALLBACK, true);
 
         template.sendBody("direct:start", "Hello World");
 

http://git-wip-us.apache.org/repos/asf/camel/blob/15404ced/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteOkTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteOkTest.java b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteOkTest.java
index 4e03eec..a56c405 100644
--- a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteOkTest.java
+++ b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixRouteOkTest.java
@@ -17,6 +17,7 @@
 package org.apache.camel.component.hystrix.processor;
 
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.hystrix.HystrixConstants;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
 
@@ -25,6 +26,8 @@ public class HystrixRouteOkTest extends CamelTestSupport {
     @Test
     public void testHystrix() throws Exception {
         getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
+        getMockEndpoint("mock:result").expectedPropertyReceived(HystrixConstants.HYSTRIX_RESPONSE_SUCCESSFUL_EXECUTION, true);
+        getMockEndpoint("mock:result").expectedPropertyReceived(HystrixConstants.HYSTRIX_RESPONSE_FROM_FALLBACK, false);
 
         template.sendBody("direct:start", "Hello World");
 

http://git-wip-us.apache.org/repos/asf/camel/blob/15404ced/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/SpringHystrixRouteFallbackTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/SpringHystrixRouteFallbackTest.java b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/SpringHystrixRouteFallbackTest.java
index 5f6064b..4bbff0e 100644
--- a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/SpringHystrixRouteFallbackTest.java
+++ b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/SpringHystrixRouteFallbackTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.hystrix.processor;
 
+import org.apache.camel.component.hystrix.HystrixConstants;
 import org.apache.camel.test.spring.CamelSpringTestSupport;
 import org.junit.Test;
 import org.springframework.context.support.AbstractApplicationContext;
@@ -31,6 +32,8 @@ public class SpringHystrixRouteFallbackTest extends CamelSpringTestSupport {
     @Test
     public void testHystrix() throws Exception {
         getMockEndpoint("mock:result").expectedBodiesReceived("Fallback message");
+        getMockEndpoint("mock:result").expectedPropertyReceived(HystrixConstants.HYSTRIX_RESPONSE_SUCCESSFUL_EXECUTION, false);
+        getMockEndpoint("mock:result").expectedPropertyReceived(HystrixConstants.HYSTRIX_RESPONSE_FROM_FALLBACK, true);
 
         template.sendBody("direct:start", "Hello World");
 

http://git-wip-us.apache.org/repos/asf/camel/blob/15404ced/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/SpringHystrixRouteOkTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/SpringHystrixRouteOkTest.java b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/SpringHystrixRouteOkTest.java
index fcffb27..5f408de 100644
--- a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/SpringHystrixRouteOkTest.java
+++ b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/SpringHystrixRouteOkTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.hystrix.processor;
 
+import org.apache.camel.component.hystrix.HystrixConstants;
 import org.apache.camel.test.spring.CamelSpringTestSupport;
 import org.junit.Test;
 import org.springframework.context.support.AbstractApplicationContext;
@@ -31,6 +32,8 @@ public class SpringHystrixRouteOkTest extends CamelSpringTestSupport {
     @Test
     public void testHystrix() throws Exception {
         getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
+        getMockEndpoint("mock:result").expectedPropertyReceived(HystrixConstants.HYSTRIX_RESPONSE_SUCCESSFUL_EXECUTION, true);
+        getMockEndpoint("mock:result").expectedPropertyReceived(HystrixConstants.HYSTRIX_RESPONSE_FROM_FALLBACK, false);
 
         template.sendBody("direct:start", "Hello World");
 


[4/4] camel git commit: CAMEL-9896: When using continued with onException then dead letter channel endpooint should not be invoked.

Posted by da...@apache.org.
CAMEL-9896: When using continued with onException then dead letter channel endpooint should not be invoked.


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

Branch: refs/heads/camel-2.16.x
Commit: bba477b1a47be05cca08bab2ac9fdb44b5e288ec
Parents: a6b710e
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Apr 23 10:08:07 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Apr 23 11:04:24 2016 +0200

----------------------------------------------------------------------
 .../camel/processor/RedeliveryErrorHandler.java |   9 +-
 .../issues/OnExceptionContinuedIssueTest.java   | 107 +++++++++++++++++++
 ...xceptionContinuedNoFailureProcessorTest.java |   2 +-
 3 files changed, 115 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/bba477b1/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java b/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
index 9697dc6..50d90cb 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
@@ -876,8 +876,13 @@ public abstract class RedeliveryErrorHandler extends ErrorHandlerSupport impleme
             decrementRedeliveryCounter(exchange);
         }
 
-        // is the a failure processor to process the Exchange
-        if (processor != null) {
+        // we should allow using the failure processor if we should not continue
+        // or in case of continue then the failure processor is NOT a dead letter channel
+        // because you can continue and still let the failure processor do some routing
+        // before continue in the main route.
+        boolean allowFailureProcessor = !shouldContinue || !isDeadLetterChannel;
+
+        if (allowFailureProcessor && processor != null) {
 
             // prepare original IN body if it should be moved instead of current body
             if (data.useOriginalInMessage) {

http://git-wip-us.apache.org/repos/asf/camel/blob/bba477b1/camel-core/src/test/java/org/apache/camel/issues/OnExceptionContinuedIssueTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/issues/OnExceptionContinuedIssueTest.java b/camel-core/src/test/java/org/apache/camel/issues/OnExceptionContinuedIssueTest.java
new file mode 100644
index 0000000..5deca4f
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/issues/OnExceptionContinuedIssueTest.java
@@ -0,0 +1,107 @@
+/**
+ * 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.issues;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.DeadLetterChannelBuilder;
+import org.apache.camel.builder.DefaultErrorHandlerBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+public class OnExceptionContinuedIssueTest extends ContextTestSupport {
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    @Test
+    public void testOnExceptionWrappedMatch() throws Exception {
+        final DefaultErrorHandlerBuilder defaultErrorHandlerBuilder = new DeadLetterChannelBuilder("direct:dead");
+        defaultErrorHandlerBuilder.redeliveryDelay(0); // run fast
+        defaultErrorHandlerBuilder.maximumRedeliveries(2);
+
+        context.setErrorHandlerBuilder(defaultErrorHandlerBuilder);
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                context.setTracing(false);
+
+                onException(OrderFailedException.class)
+                        .maximumRedeliveries(0)
+                        .continued(true);
+
+                from("direct:dead").to("log:dead", "mock:dead");
+
+                from("direct:order")
+                        .to("mock:one")
+                        .process(new Processor() {
+                            @Override
+                            public void process(Exchange exchange) throws Exception {
+                                log.info("First Processor Invoked");
+                                throw new OrderFailedException("First Processor Failure");
+                            }
+                        })
+                        .to("mock:two")
+                        .process(new Processor() {
+                            @Override
+                            public void process(Exchange exchange) throws Exception {
+                                log.info("Second Processor Invoked");
+                            }
+                        })
+                        .to("mock:three")
+                        .process(new Processor() {
+                            @Override
+                            public void process(Exchange exchange) throws Exception {
+                                log.info("Third Processor Invoked");
+                                throw new RuntimeException("Some Runtime Exception");
+                            }
+                        })
+                        .to("mock:four")
+                        .process(new Processor() {
+                            @Override
+                            public void process(Exchange exchange) throws Exception {
+                                log.info("Fourth Processor Invoked");
+                            }
+                        });
+            }
+        });
+        context.start();
+
+        // we should only get 1 to the DLC when we hit the 3rd route that
+        // throws the runtime exception
+        getMockEndpoint("mock:dead").expectedMessageCount(1);
+        getMockEndpoint("mock:one").expectedMessageCount(1);
+        getMockEndpoint("mock:two").expectedMessageCount(1);
+        getMockEndpoint("mock:three").expectedMessageCount(1);
+        getMockEndpoint("mock:four").expectedMessageCount(0);
+
+        template.requestBody("direct:order", "Camel in Action");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public class OrderFailedException extends Exception {
+
+        public OrderFailedException(String s) {
+            super(s);
+        }
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/bba477b1/camel-core/src/test/java/org/apache/camel/issues/OnExceptionContinuedNoFailureProcessorTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/issues/OnExceptionContinuedNoFailureProcessorTest.java b/camel-core/src/test/java/org/apache/camel/issues/OnExceptionContinuedNoFailureProcessorTest.java
index cad431e..8550425 100644
--- a/camel-core/src/test/java/org/apache/camel/issues/OnExceptionContinuedNoFailureProcessorTest.java
+++ b/camel-core/src/test/java/org/apache/camel/issues/OnExceptionContinuedNoFailureProcessorTest.java
@@ -28,7 +28,7 @@ public class OnExceptionContinuedNoFailureProcessorTest extends ContextTestSuppo
 
     public void testOnException() throws Exception {
         getMockEndpoint("mock:end").expectedMessageCount(1);
-        getMockEndpoint("mock:error").expectedMessageCount(1);
+        getMockEndpoint("mock:error").expectedMessageCount(0);
 
         template.sendBody("direct:start", "Hello World");