This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit 4a2cfbd8bf8bac6cb42b9f0833b28d51abbcabb4 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Wed Aug 7 05:32:12 2019 +0200 CAMEL-13561: camel-hystrix - HystrixBadRequestException is swallowed --- .../component/hystrix/processor/HystrixProcessorCommand.java | 8 +++++++- .../hystrix/processor/HystrixBadRequestExceptionTest.java | 11 +++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorCommand.java b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorCommand.java index f9fb8ec..dced5c4 100644 --- a/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorCommand.java +++ b/components/camel-hystrix/src/main/java/org/apache/camel/component/hystrix/processor/HystrixProcessorCommand.java @@ -52,6 +52,11 @@ public class HystrixProcessorCommand extends HystrixCommand { @Override protected Message getFallback() { + // if bad request then break-out + if (exchange.getException() instanceof HystrixBadRequestException) { + return null; + } + // guard by lock as the run command can be running concurrently in case hystrix caused a timeout which // can cause the fallback timer to trigger this fallback at the same time the run command may be running // after its processor.process method which could cause both threads to mutate the state on the exchange @@ -154,7 +159,8 @@ public class HystrixProcessorCommand extends HystrixCommand { // special for HystrixBadRequestException which should not trigger fallback if (camelExchangeException instanceof HystrixBadRequestException) { LOG.debug("Running processor: {} with exchange: {} done as bad request", processor, exchange); - return exchange.getMessage(); + exchange.setException(camelExchangeException); + throw camelExchangeException; } // copy the result before its regarded as success diff --git a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixBadRequestExceptionTest.java b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixBadRequestExceptionTest.java index df0e13e..786df98 100644 --- a/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixBadRequestExceptionTest.java +++ b/components/camel-hystrix/src/test/java/org/apache/camel/component/hystrix/processor/HystrixBadRequestExceptionTest.java @@ -17,6 +17,7 @@ package org.apache.camel.component.hystrix.processor; import com.netflix.hystrix.exception.HystrixBadRequestException; +import org.apache.camel.Exchange; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.test.junit4.CamelTestSupport; import org.junit.Test; @@ -26,11 +27,13 @@ public class HystrixBadRequestExceptionTest extends CamelTestSupport { @Test public void testHystrix() throws Exception { getMockEndpoint("mock:fallback").expectedMessageCount(0); - getMockEndpoint("mock:result").expectedBodiesReceived("Hello World"); - getMockEndpoint("mock:result").expectedPropertyReceived(HystrixConstants.HYSTRIX_RESPONSE_SUCCESSFUL_EXECUTION, true); - getMockEndpoint("mock:result").expectedPropertyReceived(HystrixConstants.HYSTRIX_RESPONSE_FROM_FALLBACK, false); + getMockEndpoint("mock:result").expectedMessageCount(0); - template.sendBody("direct:start", "Hello World"); + Exchange out = template.send("direct:start", e -> e.getMessage().setBody("Hello World")); + assertTrue(out.isFailed()); + assertFalse(out.getProperty(HystrixConstants.HYSTRIX_RESPONSE_SUCCESSFUL_EXECUTION, boolean.class)); + assertFalse(out.getProperty(HystrixConstants.HYSTRIX_RESPONSE_FROM_FALLBACK, boolean.class)); + assertTrue(out.getException() instanceof HystrixBadRequestException); assertMockEndpointsSatisfied(); }