It works in general:
import org.apache.camel.CamelExecutionException;
import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.impl.JndiRegistry;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;
public class CamelGlobalOnExceptionTest extends CamelTestSupport {
@Test
public void test() throws Exception {
MockEndpoint mockErrorHandler = ((MockEndpoint)
context.getEndpoint("mock:errorHandler"));
mockErrorHandler.expectedMessageCount(1);
MockEndpoint mockEnd = ((MockEndpoint)
context.getEndpoint("mock:end"));
mockEnd.setSleepForEmptyTest(2000);
mockEnd.expectedMessageCount(0);
try {
template.sendBody("direct:start", "Camel");
fail("CamelExecutionException expected");
} catch (CamelExecutionException e) {
// expected
}
mockErrorHandler.assertIsSatisfied();
}
@Override
protected JndiRegistry createRegistry() throws Exception {
JndiRegistry registry = super.createRegistry();
registry.bind("bean1", new MyBean(false));
registry.bind("bean2", new MyBean(true));
return registry;
}
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
onException(Exception.class)
.handled(false)
.to("mock:errorHandler")
.logStackTrace(true);
from("direct:start")
.to("bean:bean1")
.to("bean:bean2")
.to("mock:end");
}
};
}
public static class MyBean {
private boolean shouldThrowAnException;
public MyBean(boolean shouldThrowAnException) {
this.shouldThrowAnException = shouldThrowAnException;
}
public void process(Exchange exchange) throws Exception {
if (shouldThrowAnException) {
throw new Exception("exception forced for unit test");
}
}
}
}
Can you try this example with the aws-component?
Best,
Christian
On Tue, Dec 18, 2012 at 6:57 PM, semiosis <[email protected]> wrote:
> Using camel version 2.9.1 on OpenJDK 6 by the way. Thanks again!
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/global-onException-only-works-for-first-to-route-item-but-nothing-after-that-tp5724296p5724298.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
--