You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by ourdatguy <ou...@gmail.com> on 2016/02/11 06:41:38 UTC

Headers set from custom component are lost on exception

Actually, in line with the above answer, the only way I found to set and preserve headers in a catch block is to set the headers on the original message acquired through the unit of work (which can be accessed through the exchange).

For example:

try{
	//doing something awseome with my component
} catch(SomeException se) {
	exchange
		.getUnitOfWork()
		.getOriginalInMessage()
		.getHeaders()
		.put(“MySpecialHeader”,”MySpecialValue"); 

	exchange.setException(se) //or throw
}


/dcb

David C. Bauer 
email:  ourdatguy@gmail.com <ma...@gmail.com>
skype:  tucsonalama
mobile: 801-995-0516


Re: Headers set from custom component are lost on exception

Posted by Claus Ibsen <cl...@gmail.com>.
Yes its by design the failed operation "rollback" so you can perform
redeliveries and whatnot, without having the exchange tangled with
side-effects and left overs from previous attempt.

The intent is that the data on exchange only changes if the operation
is success.

On Thu, Feb 11, 2016 at 6:41 AM, ourdatguy <ou...@gmail.com> wrote:
> Actually, in line with the above answer, the only way I found to set and preserve headers in a catch block is to set the headers on the original message acquired through the unit of work (which can be accessed through the exchange).
>
> For example:
>
> try{
>         //doing something awseome with my component
> } catch(SomeException se) {
>         exchange
>                 .getUnitOfWork()
>                 .getOriginalInMessage()
>                 .getHeaders()
>                 .put(“MySpecialHeader”,”MySpecialValue");
>
>         exchange.setException(se) //or throw
> }
>
>
> /dcb
>
> David C. Bauer
> email:  ourdatguy@gmail.com <ma...@gmail.com>
> skype:  tucsonalama
> mobile: 801-995-0516
>



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2