You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Dragisa Krsmanovic <dk...@plos.org> on 2009/12/14 18:30:14 UTC

onException() silently ignored if after transacted()

Here is me with more questions/bug report.

I've noticed that Camel can be very sensitive on order operators are
invoked in route builder.

For example, transacted() has to be after onException(). Otherwise,
onException() is completely ignored and message will just pass through
error handling code like it's the part of regular route. See example:


// Fails
from("direct:fails")
  .transacted()
  .onException(Exception.class)
    .handled(true)
    .useOriginalBody()
    .redeliveryDelay(10)
    .maximumRedeliveries(2)
    .retryAttemptedLogLevel(LoggingLevel.WARN)
    .retriesExhaustedLogLevel(LoggingLevel.ERROR)
    .to("mock:error")
  .end()
  .to("mock:end");

// Ok
from("direct:ok")
  .onException(Exception.class)
    .handled(true)
    .useOriginalBody()
    .redeliveryDelay(10)
    .maximumRedeliveries(2)
    .retryAttemptedLogLevel(LoggingLevel.WARN)
    .retriesExhaustedLogLevel(LoggingLevel.ERROR)
    .to("mock:error")
  .end()
  .transacted()
  .to("mock:end");

....

  // Test fails
  @Test
  @DirtiesContext
  public void testTransactionOnException() throws InterruptedException {

    errorMock.expectedMessageCount(0);
    endpoint.expectedMessageCount(1);

    fails.sendBody("Hello World");

    errorMock.assertIsSatisfied();
    endpoint.assertIsSatisfied();
  }


Ideally, Camel should either allow onException() after transacted() or
throw an error if trying to set onException() after transacted(). To
silently ignore onException() seems to be most undesirable.

Cheers,

-- 
Dragisa Krsmanovic
Java Developer
Public Library of Science 
http://www.plos.org


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
This email is confidential to the intended recipient. If you have received it in error, please notify the sender and delete it from your system. Any unauthorized use, disclosure or copying is not permitted. The views or opinions presented are solely those of the sender and do not necessarily represent those of Public Library of Science unless otherwise specifically stated. Please note that neither Public Library of Science nor any of its agents accept any responsibility for any viruses that may be contained in this e-mail or its attachments and it is your responsibility to scan the e-mail and attachments (if any).


Re: onException() silently ignored if after transacted()

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Yeah we will in the future break up the DSL to have a route setup part
and then the regular part for the route flow.
The former should setup onException, transaction, onCompletion,
interceptors and what not, eg cross function stuff.
And the latter is for the route.

The problem is that its currently in the same level. However we didnt
want to do that just out of the blue as it will cause people having to
rearrange the existing routes.



On Mon, Dec 14, 2009 at 6:30 PM, Dragisa Krsmanovic
<dk...@plos.org> wrote:
> Here is me with more questions/bug report.
>
> I've noticed that Camel can be very sensitive on order operators are
> invoked in route builder.
>
> For example, transacted() has to be after onException(). Otherwise,
> onException() is completely ignored and message will just pass through
> error handling code like it's the part of regular route. See example:
>
>
> // Fails
> from("direct:fails")
>  .transacted()
>  .onException(Exception.class)
>    .handled(true)
>    .useOriginalBody()
>    .redeliveryDelay(10)
>    .maximumRedeliveries(2)
>    .retryAttemptedLogLevel(LoggingLevel.WARN)
>    .retriesExhaustedLogLevel(LoggingLevel.ERROR)
>    .to("mock:error")
>  .end()
>  .to("mock:end");
>
> // Ok
> from("direct:ok")
>  .onException(Exception.class)
>    .handled(true)
>    .useOriginalBody()
>    .redeliveryDelay(10)
>    .maximumRedeliveries(2)
>    .retryAttemptedLogLevel(LoggingLevel.WARN)
>    .retriesExhaustedLogLevel(LoggingLevel.ERROR)
>    .to("mock:error")
>  .end()
>  .transacted()
>  .to("mock:end");
>
> ....
>
>  // Test fails
>  @Test
>  @DirtiesContext
>  public void testTransactionOnException() throws InterruptedException {
>
>    errorMock.expectedMessageCount(0);
>    endpoint.expectedMessageCount(1);
>
>    fails.sendBody("Hello World");
>
>    errorMock.assertIsSatisfied();
>    endpoint.assertIsSatisfied();
>  }
>
>
> Ideally, Camel should either allow onException() after transacted() or
> throw an error if trying to set onException() after transacted(). To
> silently ignore onException() seems to be most undesirable.
>
> Cheers,
>
> --
> Dragisa Krsmanovic
> Java Developer
> Public Library of Science
> http://www.plos.org
>
>
> --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> This email is confidential to the intended recipient. If you have received it in error, please notify the sender and delete it from your system. Any unauthorized use, disclosure or copying is not permitted. The views or opinions presented are solely those of the sender and do not necessarily represent those of Public Library of Science unless otherwise specifically stated. Please note that neither Public Library of Science nor any of its agents accept any responsibility for any viruses that may be contained in this e-mail or its attachments and it is your responsibility to scan the e-mail and attachments (if any).
>
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus