You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Victor (JIRA)" <ji...@apache.org> on 2017/09/19 11:38:00 UTC
[jira] [Commented] (CAMEL-11787) Try/catch on fault, not on
exceptions
[ https://issues.apache.org/jira/browse/CAMEL-11787?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16171556#comment-16171556 ]
Victor commented on CAMEL-11787:
--------------------------------
Ok, but there is a missing feature: how can you write anything to process that fault, instead of stopping the routing?
That's the subject of my request: I'm not asking that fault be considered an exception, I'm asking for a feature to be able to process faults.
The examples I put are using the try/catch paradigm because camel does not have anything else for me to express it, hence this issue.
Could we reopen this and take the time to discuss the need? Thanks :)
> Try/catch on fault, not on exceptions
> -------------------------------------
>
> Key: CAMEL-11787
> URL: https://issues.apache.org/jira/browse/CAMEL-11787
> Project: Camel
> Issue Type: New Feature
> Components: camel-core
> Reporter: Victor
>
> Hi,
> I would like to be able to catch exchange that are faults in a try/catch.
> Something like this should work:
> {code:java}
> public class TrySetFaultTest extends CamelTestSupport {
> @Test
> public void testSetFault() throws Exception {
> getMockEndpoint("mock:a").expectedMessageCount(0);
> getMockEndpoint("mock:catch-a").expectedMessageCount(1);
> template.requestBody("direct:start", "Hello World");
> assertMockEndpointsSatisfied(1, TimeUnit.SECONDS);
> }
> @Override
> protected RouteBuilder createRouteBuilder() throws Exception {
> return new RouteBuilder() {
> @Override
> public void configure() throws Exception {
> context.setTracing(true);
> from("direct:start")
> .doTry()
> .setFaultBody(constant("Failed at A"))
> .to("mock:a")
> .doCatch(Exception.class) // of course, this does not!
> .to("mock:catch-a")
> .end();
> }
> };
> }
> }
> {code}
> The following existing test: https://github.com/apache/camel/blob/master/camel-core/src/test/java/org/apache/camel/processor/TrySetFaultTest.java is incorrect in my opinion: it lets people think that it should work, but the exchange never reach "mock:catch-a"!
> There seems to be no way to express what I want (without going through complex stuffs), hence this feature request.
> An alternative to this would be to be able to tell camel not to stop processing when there is a fault, so that I can simply handle it at the level of "mock:a":
> {code:java}
> public class TrySetFaultTest extends CamelTestSupport {
> @Test
> public void testSetFault() throws Exception {
> getMockEndpoint("mock:a").expectedMessageCount(1);
> template.requestBody("direct:start", "Hello World");
> assertMockEndpointsSatisfied(1, TimeUnit.SECONDS);
> }
> @Override
> protected RouteBuilder createRouteBuilder() throws Exception {
> return new RouteBuilder() {
> @Override
> public void configure() throws Exception {
> context.setTracing(true);
> from("direct:start")
> // here something to tell camel not to stop on faults!
> .setFaultBody(constant("Failed at A"))
> .to("mock:a");
> }
> };
> }
> }
> {code}
> Thanks!
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)