use of org.apache.camel.CamelExchangeException in project camel by apache.
the class ExceptionBuilderTest method createRouteBuilder.
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@SuppressWarnings("unchecked")
public void configure() throws Exception {
errorHandler(deadLetterChannel("mock:error").redeliveryDelay(0).maximumRedeliveries(3));
// START SNIPPET: exceptionBuilder1
onException(NullPointerException.class).maximumRedeliveries(0).setHeader(MESSAGE_INFO, constant("Damm a NPE")).to(ERROR_QUEUE);
onException(IOException.class).redeliveryDelay(100L).maximumRedeliveries(3).maximumRedeliveryDelay(30 * 1000L).backOffMultiplier(1.0).useExponentialBackOff().setHeader(MESSAGE_INFO, constant("Damm somekind of IO exception")).to(ERROR_QUEUE);
onException(Exception.class).redeliveryDelay(100L).maximumRedeliveries(2).setHeader(MESSAGE_INFO, constant("Damm just exception")).to(ERROR_QUEUE);
onException(MyBaseBusinessException.class).redeliveryDelay(100L).maximumRedeliveries(3).setHeader(MESSAGE_INFO, constant("Damm my business is not going to well")).to(BUSINESS_ERROR_QUEUE);
onException(GeneralSecurityException.class, KeyException.class).maximumRedeliveries(1).setHeader(MESSAGE_INFO, constant("Damm some security error")).to(SECURITY_ERROR_QUEUE);
onException(InstantiationException.class, IllegalAccessException.class, ClassNotFoundException.class).maximumRedeliveries(0).setHeader(MESSAGE_INFO, constant("Damm some access error")).to(ERROR_QUEUE);
// END SNIPPET: exceptionBuilder1
from("direct:a").process(new Processor() {
public void process(Exchange exchange) throws Exception {
String s = exchange.getIn().getBody(String.class);
if ("Hello NPE".equals(s)) {
throw new NullPointerException();
} else if ("Hello IO".equals(s)) {
throw new ConnectException("Forced for testing - cannot connect to remote server");
} else if ("Hello Exception".equals(s)) {
throw new CamelExchangeException("Forced for testing", exchange);
} else if ("Hello business".equals(s)) {
throw new MyBusinessException();
} else if ("I am not allowed to do this".equals(s)) {
throw new KeyManagementException();
} else if ("I am not allowed to access this".equals(s)) {
throw new IllegalAccessException();
}
exchange.getOut().setBody("Hello World");
}
}).to("mock:result");
}
};
}
use of org.apache.camel.CamelExchangeException in project camel by apache.
the class SplitterParallelStopOnExceptionTest method testSplitParallelStopOnExceptionStop.
public void testSplitParallelStopOnExceptionStop() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:split");
mock.expectedMinimumMessageCount(0);
mock.allMessages().body().isNotEqualTo("Kaboom");
try {
template.sendBody("direct:start", "Hello World,Goodday World,Kaboom,Bye World");
fail("Should thrown an exception");
} catch (CamelExecutionException e) {
CamelExchangeException cause = assertIsInstanceOf(CamelExchangeException.class, e.getCause());
assertTrue(cause.getMessage().startsWith("Parallel processing failed for number "));
assertEquals("Forced", cause.getCause().getMessage());
String body = cause.getExchange().getIn().getBody(String.class);
assertTrue(body.contains("Kaboom"));
}
assertMockEndpointsSatisfied();
}
use of org.apache.camel.CamelExchangeException in project camel by apache.
the class SplitterStopOnExceptionTest method testSplitStopOnExceptionStop.
public void testSplitStopOnExceptionStop() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:split");
// we do stop so we stop splitting when the exception occurs and thus we only receive 1 message
mock.expectedBodiesReceived("Hello World");
try {
template.sendBody("direct:start", "Hello World,Kaboom,Bye World");
fail("Should thrown an exception");
} catch (CamelExecutionException e) {
CamelExchangeException cause = assertIsInstanceOf(CamelExchangeException.class, e.getCause());
assertTrue(cause.getMessage().startsWith("Sequential processing failed for number 1."));
assertEquals("Forced", cause.getCause().getMessage());
}
assertMockEndpointsSatisfied();
}
use of org.apache.camel.CamelExchangeException in project camel by apache.
the class EnricherAsyncUnhandledExceptionTest method testInOutWithRequestBody.
@Test
public void testInOutWithRequestBody() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:pickedUp");
mock.expectedMessageCount(1);
// this direct endpoint should receive an exception
try {
Future<Object> obj = template.asyncRequestBody("direct:in", "Hello World");
// wait five seconds at most; else, let's assume something went wrong
obj.get(5000, TimeUnit.MILLISECONDS);
} catch (Exception e) {
// if we receive an exception, the async routing engine is working correctly
// before the Enricher was fixed for cases where routing was async and the AggregationStrategy
// threw an exception, the call to requestBody would stall indefinitely
// unwrap the exception chain
assertTrue(e instanceof ExecutionException);
assertTrue(e.getCause() instanceof CamelExecutionException);
assertTrue(e.getCause().getCause() instanceof CamelExchangeException);
assertTrue(e.getCause().getCause().getCause() instanceof RuntimeException);
assertTrue(e.getCause().getCause().getCause().getMessage().equals("Bang! Unhandled exception"));
mock.assertIsSatisfied();
return;
}
fail("Expected an RuntimeException");
}
use of org.apache.camel.CamelExchangeException in project camel by apache.
the class DefaultExceptionPolicyStrategyTest method testDirectMatch1.
public void testDirectMatch1() {
setupPolicies();
OnExceptionDefinition result = strategy.getExceptionPolicy(policies, null, new CamelExchangeException("", null));
assertEquals(type1, result);
}
Aggregations