use of org.apache.camel.CamelExchangeException in project camel by apache.
the class CharlesSplitAndTryCatchRollbackIssueTest method testSplitWithTryCatchAndRollbacILEAndException.
public void testSplitWithTryCatchAndRollbacILEAndException() throws Exception {
MockEndpoint split = getMockEndpoint("mock:split");
MockEndpoint ile = getMockEndpoint("mock:ile");
MockEndpoint exception = getMockEndpoint("mock:exception");
split.expectedBodiesReceived("A", "B");
ile.expectedMessageCount(1);
exception.expectedMessageCount(1);
try {
template.sendBody("direct:start", "A,Forced,B,Kaboom,C");
fail("Should thrown an exception");
} catch (CamelExecutionException e) {
CamelExchangeException ee = assertIsInstanceOf(CamelExchangeException.class, e.getCause());
assertTrue(ee.getMessage().startsWith("Sequential processing failed for number 3."));
RollbackExchangeException re = assertIsInstanceOf(RollbackExchangeException.class, ee.getCause());
assertTrue(re.getMessage().startsWith("Intended rollback"));
}
assertMockEndpointsSatisfied();
}
use of org.apache.camel.CamelExchangeException in project camel by apache.
the class FailOverLoadBalanceWrappedExceptionTest method createRouteBuilder.
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
from("direct:start").loadBalance().failover(IOException.class).to("direct:x", "direct:y", "direct:z");
from("direct:x").to("mock:x").process(new Processor() {
public void process(Exchange exchange) throws Exception {
// socket exception is an io exception
throw new CamelExchangeException("foo", exchange, new SocketException("Forced"));
}
});
from("direct:y").to("mock:y").process(new Processor() {
public void process(Exchange exchange) throws Exception {
throw new IOException("Forced");
}
});
from("direct:z").to("mock:z");
}
};
}
use of org.apache.camel.CamelExchangeException in project camel by apache.
the class FailOverLoadBalanceMultipleExceptionTest method createRouteBuilder.
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
from("direct:start").loadBalance().failover(IllegalArgumentException.class, IOException.class, CamelException.class).to("direct:x", "direct:y", "direct:z");
from("direct:x").to("mock:x").process(new Processor() {
public void process(Exchange exchange) throws Exception {
throw new CamelExchangeException("Forced", exchange);
}
});
from("direct:y").to("mock:y").process(new Processor() {
public void process(Exchange exchange) throws Exception {
throw new IOException("Forced");
}
});
from("direct:z").to("mock:z");
}
};
}
use of org.apache.camel.CamelExchangeException in project camel by apache.
the class AggregateIgnoreInvalidCorrelationKeysTest method testAggregateNotIgnoreInvalidCorrelationKeys.
public void testAggregateNotIgnoreInvalidCorrelationKeys() throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").aggregate(header("id"), new BodyInAggregatingStrategy()).completionSize(2).to("mock:result");
}
});
context.start();
getMockEndpoint("mock:result").expectedBodiesReceived("A+C");
template.sendBodyAndHeader("direct:start", "A", "id", 1);
try {
template.sendBodyAndHeader("direct:start", "B", "id", null);
fail("Should throw an exception");
} catch (CamelExecutionException e) {
CamelExchangeException cause = assertIsInstanceOf(CamelExchangeException.class, e.getCause());
assertTrue(cause.getMessage().startsWith("Invalid correlation key"));
}
template.sendBodyAndHeader("direct:start", "C", "id", 1);
assertMockEndpointsSatisfied();
}
use of org.apache.camel.CamelExchangeException in project camel by apache.
the class ThrowExceptionProcessor method process.
public boolean process(Exchange exchange, AsyncCallback callback) {
Exception cause = exception;
try {
if (message != null && type != null) {
// create the message using simple language so it can be dynamic
String text = simple.evaluate(exchange, String.class);
// create a new exception of that type, and provide the message as
Constructor<?> constructor = type.getDeclaredConstructor(String.class);
cause = (Exception) constructor.newInstance(text);
exchange.setException(cause);
} else {
exchange.setException(cause);
}
} catch (Throwable e) {
exchange.setException(new CamelExchangeException("Error creating new instance of " + exception.getClass(), exchange, e));
}
callback.done(true);
return true;
}
Aggregations