camel-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Claus Ibsen (JIRA)" <j...@apache.org>
Subject [jira] [Resolved] (CAMEL-11787) Try/catch on fault, not on exceptions
Date Tue, 19 Sep 2017 11:35:01 GMT

     [ https://issues.apache.org/jira/browse/CAMEL-11787?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Claus Ibsen resolved CAMEL-11787.
---------------------------------
    Resolution: Won't Fix

A fault is not an exception. When a message has a fault body, its stopped from continued being
routed.

See this unit test sample
https://github.com/apache/camel/blob/master/camel-core/src/test/java/org/apache/camel/processor/TrySetFaultTest.java

> 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)

Mime
View raw message