You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Martin Krasser <de...@martin-krasser.de> on 2009/11/20 10:20:54 UTC

Unexpected behaviour of TransactionErrorHandler?

I'm using the TransactionErrorHandler of Camel 2.0.0 and observe an 
unexpected transaction-outcome for handled errors. Using the 
TransactionErrorHandler with the route

onException(Exception.class).handled(true).process(...);
from("direct:test").transacted().processRef('myFailureProcessor');

does actually a *commit* on the transaction manager (... the 
mayFailureProcessor bean simply throws an Exception). Here I'd definitly 
expect a rollback. I also tried to make an explicit rollback in the 
exception handler:

onException(Exception.class).handled(true).process(...).rollback();
from("direct:test").transacted().processRef('myFailureProcessor');

This rolls back the transaction but a new exception is thrown 
(TransactedRuntimeCamelException). This is somewhat unexpected too 
because handled(true) is used.

Is this really the intended behaviour of the TransactionErrorHandler or 
is it a bug?

Thanks,
Martin

Re: Unexpected behaviour of TransactionErrorHandler?

Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Nov 20, 2009 at 11:13 AM, Martin Krasser <de...@martin-krasser.de> wrote:
> Using
>
> setProperty(Exchange.ROLLBACK_ONLY, Boolean.TRUE)
>
> isn't enough for 2.0.0. This causes the TransactionErrorHandler in this
> version to throw an exception too. In 2-1.SNAPSHOT everything works as
> expected because of additional logic added to the TransactionErrorHandler.
>
> For getting it running with Camel 2.0.0 a custom transaction error handler
> needs likely to be provided. I'll try this approach (it is needed for a
> customer that uses Camel 2.0.0).
>

Ah damn. Yeah its a pity. Well at least its covered in 2.1 which we
should get out in a couple of weeks.

Writing your own error handler seems like the only option.


> Thanks for your help.
> Martin
>
> Claus Ibsen schrieb:
>>
>> On Fri, Nov 20, 2009 at 10:38 AM, Claus Ibsen <cl...@gmail.com>
>> wrote:
>>
>>>
>>> On Fri, Nov 20, 2009 at 10:36 AM, Claus Ibsen <cl...@gmail.com>
>>> wrote:
>>>
>>>>
>>>> On Fri, Nov 20, 2009 at 10:35 AM, Martin Krasser <de...@martin-krasser.de>
>>>> wrote:
>>>>
>>>>>
>>>>> I know that when I don't declare the local exception handler a rollback
>>>>> will
>>>>> occur. But how can I handle the exception for returning a custom
>>>>> response to
>>>>> the sender AND rollback the transaction? Maybe I'm missing something
>>>>> obvious
>>>>> (?).
>>>>>
>>>>
>>>> Use markRollbackOnly()
>>>>
>>>>
>>>
>>> In fact the DSL have javadoc you know so try looking there also :)
>>>
>>>
>>
>> Ah markRollbackOnly() is for Camel 2.1
>> Just look at how its implemented and do that same in 2.0.
>>
>> eg. just set this header
>> exchange.setProperty(Exchange.ROLLBACK_ONLY, Boolean.TRUE);
>>
>>
>>
>>>
>>> But this use case will definitely also be in my book, as I currently
>>> write on chapter 9 about transactions.
>>>
>>>
>>>
>>>>
>>>>
>>>>>
>>>>> Claus Ibsen schrieb:
>>>>>
>>>>>>
>>>>>> On Fri, Nov 20, 2009 at 10:20 AM, Martin Krasser
>>>>>> <de...@martin-krasser.de>
>>>>>> wrote:
>>>>>>
>>>>>>
>>>>>>>
>>>>>>> I'm using the TransactionErrorHandler of Camel 2.0.0 and observe an
>>>>>>> unexpected transaction-outcome for handled errors. Using the
>>>>>>> TransactionErrorHandler with the route
>>>>>>>
>>>>>>> onException(Exception.class).handled(true).process(...);
>>>>>>> from("direct:test").transacted().processRef('myFailureProcessor');
>>>>>>>
>>>>>>> does actually a *commit* on the transaction manager (... the
>>>>>>> mayFailureProcessor bean simply throws an Exception). Here I'd
>>>>>>> definitly
>>>>>>> expect a rollback. I also tried to make an explicit rollback in the
>>>>>>> exception handler:
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>> Yes of course it will commit because you have the local
>>>>>> onException(Exception.class).handled(true) which intercepts the
>>>>>> exception and handle it.
>>>>>> Remove it all together and the transaction will rollback.
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>>
>>>>>>> onException(Exception.class).handled(true).process(...).rollback();
>>>>>>> from("direct:test").transacted().processRef('myFailureProcessor');
>>>>>>>
>>>>>>> This rolls back the transaction but a new exception is thrown
>>>>>>> (TransactedRuntimeCamelException). This is somewhat unexpected too
>>>>>>> because
>>>>>>> handled(true) is used.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>> No it not because you add the rollback() in the end which causes a new
>>>>>> exception to be set and rollback the transaction anyway.
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>>
>>>>>>> Is this really the intended behaviour of the TransactionErrorHandler
>>>>>>> or
>>>>>>> is
>>>>>>> it a bug?
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>> No its not a bug. You can mix and match transacted routes with the
>>>>>> error handling in Camel using the onException clauses.
>>>>>>
>>>>>> However in most cases with transacted routes you would normally not
>>>>>> use onException() but they are at your disposal if you need fine
>>>>>> grained control.
>>>>>> Or even want local retry in a transacted route, e.g. try uploading to
>>>>>> FTP server 3 times etc.
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>>
>>>>>>> Thanks,
>>>>>>> Martin
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>>> --
>>>> 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
>>>>
>>>>
>>>
>>> --
>>> 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
>>>
>>>
>>
>>
>>
>>
>
>



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

Re: Unexpected behaviour of TransactionErrorHandler?

Posted by Martin Krasser <de...@martin-krasser.de>.
Using

setProperty(Exchange.ROLLBACK_ONLY, Boolean.TRUE)

isn't enough for 2.0.0. This causes the TransactionErrorHandler in this 
version to throw an exception too. In 2-1.SNAPSHOT everything works as 
expected because of additional logic added to the TransactionErrorHandler.

For getting it running with Camel 2.0.0 a custom transaction error 
handler needs likely to be provided. I'll try this approach (it is 
needed for a customer that uses Camel 2.0.0).

Thanks for your help.
Martin

Claus Ibsen schrieb:
> On Fri, Nov 20, 2009 at 10:38 AM, Claus Ibsen <cl...@gmail.com> wrote:
>   
>> On Fri, Nov 20, 2009 at 10:36 AM, Claus Ibsen <cl...@gmail.com> wrote:
>>     
>>> On Fri, Nov 20, 2009 at 10:35 AM, Martin Krasser <de...@martin-krasser.de> wrote:
>>>       
>>>> I know that when I don't declare the local exception handler a rollback will
>>>> occur. But how can I handle the exception for returning a custom response to
>>>> the sender AND rollback the transaction? Maybe I'm missing something obvious
>>>> (?).
>>>>         
>>> Use markRollbackOnly()
>>>
>>>       
>> In fact the DSL have javadoc you know so try looking there also :)
>>
>>     
>
> Ah markRollbackOnly() is for Camel 2.1
> Just look at how its implemented and do that same in 2.0.
>
> eg. just set this header
> exchange.setProperty(Exchange.ROLLBACK_ONLY, Boolean.TRUE);
>
>
>   
>> But this use case will definitely also be in my book, as I currently
>> write on chapter 9 about transactions.
>>
>>
>>     
>>>       
>>>> Claus Ibsen schrieb:
>>>>         
>>>>> On Fri, Nov 20, 2009 at 10:20 AM, Martin Krasser <de...@martin-krasser.de>
>>>>> wrote:
>>>>>
>>>>>           
>>>>>> I'm using the TransactionErrorHandler of Camel 2.0.0 and observe an
>>>>>> unexpected transaction-outcome for handled errors. Using the
>>>>>> TransactionErrorHandler with the route
>>>>>>
>>>>>> onException(Exception.class).handled(true).process(...);
>>>>>> from("direct:test").transacted().processRef('myFailureProcessor');
>>>>>>
>>>>>> does actually a *commit* on the transaction manager (... the
>>>>>> mayFailureProcessor bean simply throws an Exception). Here I'd definitly
>>>>>> expect a rollback. I also tried to make an explicit rollback in the
>>>>>> exception handler:
>>>>>>
>>>>>>
>>>>>>             
>>>>> Yes of course it will commit because you have the local
>>>>> onException(Exception.class).handled(true) which intercepts the
>>>>> exception and handle it.
>>>>> Remove it all together and the transaction will rollback.
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>           
>>>>>> onException(Exception.class).handled(true).process(...).rollback();
>>>>>> from("direct:test").transacted().processRef('myFailureProcessor');
>>>>>>
>>>>>> This rolls back the transaction but a new exception is thrown
>>>>>> (TransactedRuntimeCamelException). This is somewhat unexpected too
>>>>>> because
>>>>>> handled(true) is used.
>>>>>>
>>>>>>
>>>>>>             
>>>>> No it not because you add the rollback() in the end which causes a new
>>>>> exception to be set and rollback the transaction anyway.
>>>>>
>>>>>
>>>>>
>>>>>           
>>>>>> Is this really the intended behaviour of the TransactionErrorHandler or
>>>>>> is
>>>>>> it a bug?
>>>>>>
>>>>>>
>>>>>>             
>>>>> No its not a bug. You can mix and match transacted routes with the
>>>>> error handling in Camel using the onException clauses.
>>>>>
>>>>> However in most cases with transacted routes you would normally not
>>>>> use onException() but they are at your disposal if you need fine
>>>>> grained control.
>>>>> Or even want local retry in a transacted route, e.g. try uploading to
>>>>> FTP server 3 times etc.
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>           
>>>>>> Thanks,
>>>>>> Martin
>>>>>>
>>>>>>
>>>>>>             
>>>>>
>>>>>
>>>>>           
>>>>         
>>>
>>> --
>>> 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
>>>
>>>       
>>
>> --
>> 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
>>
>>     
>
>
>
>   


Re: Unexpected behaviour of TransactionErrorHandler?

Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Nov 20, 2009 at 10:38 AM, Claus Ibsen <cl...@gmail.com> wrote:
> On Fri, Nov 20, 2009 at 10:36 AM, Claus Ibsen <cl...@gmail.com> wrote:
>> On Fri, Nov 20, 2009 at 10:35 AM, Martin Krasser <de...@martin-krasser.de> wrote:
>>> I know that when I don't declare the local exception handler a rollback will
>>> occur. But how can I handle the exception for returning a custom response to
>>> the sender AND rollback the transaction? Maybe I'm missing something obvious
>>> (?).
>>
>> Use markRollbackOnly()
>>
>
> In fact the DSL have javadoc you know so try looking there also :)
>

Ah markRollbackOnly() is for Camel 2.1
Just look at how its implemented and do that same in 2.0.

eg. just set this header
exchange.setProperty(Exchange.ROLLBACK_ONLY, Boolean.TRUE);


> But this use case will definitely also be in my book, as I currently
> write on chapter 9 about transactions.
>
>
>>
>>
>>>
>>> Claus Ibsen schrieb:
>>>>
>>>> On Fri, Nov 20, 2009 at 10:20 AM, Martin Krasser <de...@martin-krasser.de>
>>>> wrote:
>>>>
>>>>>
>>>>> I'm using the TransactionErrorHandler of Camel 2.0.0 and observe an
>>>>> unexpected transaction-outcome for handled errors. Using the
>>>>> TransactionErrorHandler with the route
>>>>>
>>>>> onException(Exception.class).handled(true).process(...);
>>>>> from("direct:test").transacted().processRef('myFailureProcessor');
>>>>>
>>>>> does actually a *commit* on the transaction manager (... the
>>>>> mayFailureProcessor bean simply throws an Exception). Here I'd definitly
>>>>> expect a rollback. I also tried to make an explicit rollback in the
>>>>> exception handler:
>>>>>
>>>>>
>>>>
>>>> Yes of course it will commit because you have the local
>>>> onException(Exception.class).handled(true) which intercepts the
>>>> exception and handle it.
>>>> Remove it all together and the transaction will rollback.
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>>
>>>>> onException(Exception.class).handled(true).process(...).rollback();
>>>>> from("direct:test").transacted().processRef('myFailureProcessor');
>>>>>
>>>>> This rolls back the transaction but a new exception is thrown
>>>>> (TransactedRuntimeCamelException). This is somewhat unexpected too
>>>>> because
>>>>> handled(true) is used.
>>>>>
>>>>>
>>>>
>>>> No it not because you add the rollback() in the end which causes a new
>>>> exception to be set and rollback the transaction anyway.
>>>>
>>>>
>>>>
>>>>>
>>>>> Is this really the intended behaviour of the TransactionErrorHandler or
>>>>> is
>>>>> it a bug?
>>>>>
>>>>>
>>>>
>>>> No its not a bug. You can mix and match transacted routes with the
>>>> error handling in Camel using the onException clauses.
>>>>
>>>> However in most cases with transacted routes you would normally not
>>>> use onException() but they are at your disposal if you need fine
>>>> grained control.
>>>> Or even want local retry in a transacted route, e.g. try uploading to
>>>> FTP server 3 times etc.
>>>>
>>>>
>>>>
>>>>
>>>>>
>>>>> Thanks,
>>>>> Martin
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>>
>> --
>> 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
>>
>
>
>
> --
> 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
>



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

Re: Unexpected behaviour of TransactionErrorHandler?

Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Nov 20, 2009 at 10:41 AM, Martin Krasser <de...@martin-krasser.de> wrote:
> ... not part of the Camel 2.0.0 Javadocs ...
>

Ah my bad. I missed your obvious statement about using 2.0.0. And the
new markRollbackOnly() was added in 2.1. And hence its of course not
mentioned in the javadoc.
Sorry for sounding rudy or anything. Just wanted a generic hint that
the DSL method do actually have javadoc which is a good way to check
as there are links to other methods.
Which should lead you to markRollbackOnly() <--> rollback().

And if those javadocs are unclear whats the difference or what they
do, then please help improve them. Having links to the Camel wiki site
for more info is also something we try to add.



> Claus Ibsen schrieb:
>>
>> On Fri, Nov 20, 2009 at 10:36 AM, Claus Ibsen <cl...@gmail.com>
>> wrote:
>>
>>>
>>> On Fri, Nov 20, 2009 at 10:35 AM, Martin Krasser <de...@martin-krasser.de>
>>> wrote:
>>>
>>>>
>>>> I know that when I don't declare the local exception handler a rollback
>>>> will
>>>> occur. But how can I handle the exception for returning a custom
>>>> response to
>>>> the sender AND rollback the transaction? Maybe I'm missing something
>>>> obvious
>>>> (?).
>>>>
>>>
>>> Use markRollbackOnly()
>>>
>>>
>>
>> In fact the DSL have javadoc you know so try looking there also :)
>>
>> But this use case will definitely also be in my book, as I currently
>> write on chapter 9 about transactions.
>>
>>
>>
>>>
>>>
>>>>
>>>> Claus Ibsen schrieb:
>>>>
>>>>>
>>>>> On Fri, Nov 20, 2009 at 10:20 AM, Martin Krasser
>>>>> <de...@martin-krasser.de>
>>>>> wrote:
>>>>>
>>>>>
>>>>>>
>>>>>> I'm using the TransactionErrorHandler of Camel 2.0.0 and observe an
>>>>>> unexpected transaction-outcome for handled errors. Using the
>>>>>> TransactionErrorHandler with the route
>>>>>>
>>>>>> onException(Exception.class).handled(true).process(...);
>>>>>> from("direct:test").transacted().processRef('myFailureProcessor');
>>>>>>
>>>>>> does actually a *commit* on the transaction manager (... the
>>>>>> mayFailureProcessor bean simply throws an Exception). Here I'd
>>>>>> definitly
>>>>>> expect a rollback. I also tried to make an explicit rollback in the
>>>>>> exception handler:
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>> Yes of course it will commit because you have the local
>>>>> onException(Exception.class).handled(true) which intercepts the
>>>>> exception and handle it.
>>>>> Remove it all together and the transaction will rollback.
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>>
>>>>>> onException(Exception.class).handled(true).process(...).rollback();
>>>>>> from("direct:test").transacted().processRef('myFailureProcessor');
>>>>>>
>>>>>> This rolls back the transaction but a new exception is thrown
>>>>>> (TransactedRuntimeCamelException). This is somewhat unexpected too
>>>>>> because
>>>>>> handled(true) is used.
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>> No it not because you add the rollback() in the end which causes a new
>>>>> exception to be set and rollback the transaction anyway.
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>>
>>>>>> Is this really the intended behaviour of the TransactionErrorHandler
>>>>>> or
>>>>>> is
>>>>>> it a bug?
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>> No its not a bug. You can mix and match transacted routes with the
>>>>> error handling in Camel using the onException clauses.
>>>>>
>>>>> However in most cases with transacted routes you would normally not
>>>>> use onException() but they are at your disposal if you need fine
>>>>> grained control.
>>>>> Or even want local retry in a transacted route, e.g. try uploading to
>>>>> FTP server 3 times etc.
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>>
>>>>>> Thanks,
>>>>>> Martin
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>> --
>>> 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
>>>
>>>
>>
>>
>>
>>
>
>



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

Re: Unexpected behaviour of TransactionErrorHandler?

Posted by Martin Krasser <de...@martin-krasser.de>.
... not part of the Camel 2.0.0 Javadocs ...

Claus Ibsen schrieb:
> On Fri, Nov 20, 2009 at 10:36 AM, Claus Ibsen <cl...@gmail.com> wrote:
>   
>> On Fri, Nov 20, 2009 at 10:35 AM, Martin Krasser <de...@martin-krasser.de> wrote:
>>     
>>> I know that when I don't declare the local exception handler a rollback will
>>> occur. But how can I handle the exception for returning a custom response to
>>> the sender AND rollback the transaction? Maybe I'm missing something obvious
>>> (?).
>>>       
>> Use markRollbackOnly()
>>
>>     
>
> In fact the DSL have javadoc you know so try looking there also :)
>
> But this use case will definitely also be in my book, as I currently
> write on chapter 9 about transactions.
>
>
>   
>>     
>>> Claus Ibsen schrieb:
>>>       
>>>> On Fri, Nov 20, 2009 at 10:20 AM, Martin Krasser <de...@martin-krasser.de>
>>>> wrote:
>>>>
>>>>         
>>>>> I'm using the TransactionErrorHandler of Camel 2.0.0 and observe an
>>>>> unexpected transaction-outcome for handled errors. Using the
>>>>> TransactionErrorHandler with the route
>>>>>
>>>>> onException(Exception.class).handled(true).process(...);
>>>>> from("direct:test").transacted().processRef('myFailureProcessor');
>>>>>
>>>>> does actually a *commit* on the transaction manager (... the
>>>>> mayFailureProcessor bean simply throws an Exception). Here I'd definitly
>>>>> expect a rollback. I also tried to make an explicit rollback in the
>>>>> exception handler:
>>>>>
>>>>>
>>>>>           
>>>> Yes of course it will commit because you have the local
>>>> onException(Exception.class).handled(true) which intercepts the
>>>> exception and handle it.
>>>> Remove it all together and the transaction will rollback.
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>         
>>>>> onException(Exception.class).handled(true).process(...).rollback();
>>>>> from("direct:test").transacted().processRef('myFailureProcessor');
>>>>>
>>>>> This rolls back the transaction but a new exception is thrown
>>>>> (TransactedRuntimeCamelException). This is somewhat unexpected too
>>>>> because
>>>>> handled(true) is used.
>>>>>
>>>>>
>>>>>           
>>>> No it not because you add the rollback() in the end which causes a new
>>>> exception to be set and rollback the transaction anyway.
>>>>
>>>>
>>>>
>>>>         
>>>>> Is this really the intended behaviour of the TransactionErrorHandler or
>>>>> is
>>>>> it a bug?
>>>>>
>>>>>
>>>>>           
>>>> No its not a bug. You can mix and match transacted routes with the
>>>> error handling in Camel using the onException clauses.
>>>>
>>>> However in most cases with transacted routes you would normally not
>>>> use onException() but they are at your disposal if you need fine
>>>> grained control.
>>>> Or even want local retry in a transacted route, e.g. try uploading to
>>>> FTP server 3 times etc.
>>>>
>>>>
>>>>
>>>>
>>>>         
>>>>> Thanks,
>>>>> Martin
>>>>>
>>>>>
>>>>>           
>>>>
>>>>
>>>>         
>>>       
>>
>> --
>> 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
>>
>>     
>
>
>
>   


Re: Unexpected behaviour of TransactionErrorHandler?

Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Nov 20, 2009 at 10:36 AM, Claus Ibsen <cl...@gmail.com> wrote:
> On Fri, Nov 20, 2009 at 10:35 AM, Martin Krasser <de...@martin-krasser.de> wrote:
>> I know that when I don't declare the local exception handler a rollback will
>> occur. But how can I handle the exception for returning a custom response to
>> the sender AND rollback the transaction? Maybe I'm missing something obvious
>> (?).
>
> Use markRollbackOnly()
>

In fact the DSL have javadoc you know so try looking there also :)

But this use case will definitely also be in my book, as I currently
write on chapter 9 about transactions.


>
>
>>
>> Claus Ibsen schrieb:
>>>
>>> On Fri, Nov 20, 2009 at 10:20 AM, Martin Krasser <de...@martin-krasser.de>
>>> wrote:
>>>
>>>>
>>>> I'm using the TransactionErrorHandler of Camel 2.0.0 and observe an
>>>> unexpected transaction-outcome for handled errors. Using the
>>>> TransactionErrorHandler with the route
>>>>
>>>> onException(Exception.class).handled(true).process(...);
>>>> from("direct:test").transacted().processRef('myFailureProcessor');
>>>>
>>>> does actually a *commit* on the transaction manager (... the
>>>> mayFailureProcessor bean simply throws an Exception). Here I'd definitly
>>>> expect a rollback. I also tried to make an explicit rollback in the
>>>> exception handler:
>>>>
>>>>
>>>
>>> Yes of course it will commit because you have the local
>>> onException(Exception.class).handled(true) which intercepts the
>>> exception and handle it.
>>> Remove it all together and the transaction will rollback.
>>>
>>>
>>>
>>>
>>>
>>>>
>>>> onException(Exception.class).handled(true).process(...).rollback();
>>>> from("direct:test").transacted().processRef('myFailureProcessor');
>>>>
>>>> This rolls back the transaction but a new exception is thrown
>>>> (TransactedRuntimeCamelException). This is somewhat unexpected too
>>>> because
>>>> handled(true) is used.
>>>>
>>>>
>>>
>>> No it not because you add the rollback() in the end which causes a new
>>> exception to be set and rollback the transaction anyway.
>>>
>>>
>>>
>>>>
>>>> Is this really the intended behaviour of the TransactionErrorHandler or
>>>> is
>>>> it a bug?
>>>>
>>>>
>>>
>>> No its not a bug. You can mix and match transacted routes with the
>>> error handling in Camel using the onException clauses.
>>>
>>> However in most cases with transacted routes you would normally not
>>> use onException() but they are at your disposal if you need fine
>>> grained control.
>>> Or even want local retry in a transacted route, e.g. try uploading to
>>> FTP server 3 times etc.
>>>
>>>
>>>
>>>
>>>>
>>>> Thanks,
>>>> Martin
>>>>
>>>>
>>>
>>>
>>>
>>>
>>
>>
>
>
>
> --
> 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
>



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

Re: Unexpected behaviour of TransactionErrorHandler?

Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Nov 20, 2009 at 10:35 AM, Martin Krasser <de...@martin-krasser.de> wrote:
> I know that when I don't declare the local exception handler a rollback will
> occur. But how can I handle the exception for returning a custom response to
> the sender AND rollback the transaction? Maybe I'm missing something obvious
> (?).

Use markRollbackOnly()



>
> Claus Ibsen schrieb:
>>
>> On Fri, Nov 20, 2009 at 10:20 AM, Martin Krasser <de...@martin-krasser.de>
>> wrote:
>>
>>>
>>> I'm using the TransactionErrorHandler of Camel 2.0.0 and observe an
>>> unexpected transaction-outcome for handled errors. Using the
>>> TransactionErrorHandler with the route
>>>
>>> onException(Exception.class).handled(true).process(...);
>>> from("direct:test").transacted().processRef('myFailureProcessor');
>>>
>>> does actually a *commit* on the transaction manager (... the
>>> mayFailureProcessor bean simply throws an Exception). Here I'd definitly
>>> expect a rollback. I also tried to make an explicit rollback in the
>>> exception handler:
>>>
>>>
>>
>> Yes of course it will commit because you have the local
>> onException(Exception.class).handled(true) which intercepts the
>> exception and handle it.
>> Remove it all together and the transaction will rollback.
>>
>>
>>
>>
>>
>>>
>>> onException(Exception.class).handled(true).process(...).rollback();
>>> from("direct:test").transacted().processRef('myFailureProcessor');
>>>
>>> This rolls back the transaction but a new exception is thrown
>>> (TransactedRuntimeCamelException). This is somewhat unexpected too
>>> because
>>> handled(true) is used.
>>>
>>>
>>
>> No it not because you add the rollback() in the end which causes a new
>> exception to be set and rollback the transaction anyway.
>>
>>
>>
>>>
>>> Is this really the intended behaviour of the TransactionErrorHandler or
>>> is
>>> it a bug?
>>>
>>>
>>
>> No its not a bug. You can mix and match transacted routes with the
>> error handling in Camel using the onException clauses.
>>
>> However in most cases with transacted routes you would normally not
>> use onException() but they are at your disposal if you need fine
>> grained control.
>> Or even want local retry in a transacted route, e.g. try uploading to
>> FTP server 3 times etc.
>>
>>
>>
>>
>>>
>>> Thanks,
>>> Martin
>>>
>>>
>>
>>
>>
>>
>
>



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

Re: Unexpected behaviour of TransactionErrorHandler?

Posted by Martin Krasser <de...@martin-krasser.de>.
I know that when I don't declare the local exception handler a rollback 
will occur. But how can I handle the exception for returning a custom 
response to the sender AND rollback the transaction? Maybe I'm missing 
something obvious (?).

Claus Ibsen schrieb:
> On Fri, Nov 20, 2009 at 10:20 AM, Martin Krasser <de...@martin-krasser.de> wrote:
>   
>> I'm using the TransactionErrorHandler of Camel 2.0.0 and observe an
>> unexpected transaction-outcome for handled errors. Using the
>> TransactionErrorHandler with the route
>>
>> onException(Exception.class).handled(true).process(...);
>> from("direct:test").transacted().processRef('myFailureProcessor');
>>
>> does actually a *commit* on the transaction manager (... the
>> mayFailureProcessor bean simply throws an Exception). Here I'd definitly
>> expect a rollback. I also tried to make an explicit rollback in the
>> exception handler:
>>
>>     
>
> Yes of course it will commit because you have the local
> onException(Exception.class).handled(true) which intercepts the
> exception and handle it.
> Remove it all together and the transaction will rollback.
>
>
>
>
>   
>> onException(Exception.class).handled(true).process(...).rollback();
>> from("direct:test").transacted().processRef('myFailureProcessor');
>>
>> This rolls back the transaction but a new exception is thrown
>> (TransactedRuntimeCamelException). This is somewhat unexpected too because
>> handled(true) is used.
>>
>>     
>
> No it not because you add the rollback() in the end which causes a new
> exception to be set and rollback the transaction anyway.
>
>
>   
>> Is this really the intended behaviour of the TransactionErrorHandler or is
>> it a bug?
>>
>>     
>
> No its not a bug. You can mix and match transacted routes with the
> error handling in Camel using the onException clauses.
>
> However in most cases with transacted routes you would normally not
> use onException() but they are at your disposal if you need fine
> grained control.
> Or even want local retry in a transacted route, e.g. try uploading to
> FTP server 3 times etc.
>
>
>
>   
>> Thanks,
>> Martin
>>
>>     
>
>
>
>   


Re: Unexpected behaviour of TransactionErrorHandler?

Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Nov 20, 2009 at 10:20 AM, Martin Krasser <de...@martin-krasser.de> wrote:
> I'm using the TransactionErrorHandler of Camel 2.0.0 and observe an
> unexpected transaction-outcome for handled errors. Using the
> TransactionErrorHandler with the route
>
> onException(Exception.class).handled(true).process(...);
> from("direct:test").transacted().processRef('myFailureProcessor');
>
> does actually a *commit* on the transaction manager (... the
> mayFailureProcessor bean simply throws an Exception). Here I'd definitly
> expect a rollback. I also tried to make an explicit rollback in the
> exception handler:
>

Yes of course it will commit because you have the local
onException(Exception.class).handled(true) which intercepts the
exception and handle it.
Remove it all together and the transaction will rollback.




> onException(Exception.class).handled(true).process(...).rollback();
> from("direct:test").transacted().processRef('myFailureProcessor');
>
> This rolls back the transaction but a new exception is thrown
> (TransactedRuntimeCamelException). This is somewhat unexpected too because
> handled(true) is used.
>

No it not because you add the rollback() in the end which causes a new
exception to be set and rollback the transaction anyway.


> Is this really the intended behaviour of the TransactionErrorHandler or is
> it a bug?
>

No its not a bug. You can mix and match transacted routes with the
error handling in Camel using the onException clauses.

However in most cases with transacted routes you would normally not
use onException() but they are at your disposal if you need fine
grained control.
Or even want local retry in a transacted route, e.g. try uploading to
FTP server 3 times etc.



> Thanks,
> Martin
>



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