You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Echo <ah...@gmail.com> on 2011/07/20 12:56:52 UTC

Set different exception on exchange at the processor

Hello ,
I have on route like that : 


onException(classOf[RuntimeException]).process(runtimeProcessor).process(doSmth).log(LoggingLevel.INFO,
"new", "${exchangeId} --- ${exception.stacktrace} ")


On the processor I do : 

    CustomException customException =new CustomException ()
    exchange.setException(customException )
    exchange.getOut.setBody(doc)


The issue now that after this processor , it doesn't go to other processors
(i.e. in my case , it doesn't go to "doSmth" processor )

I guess that behavior is that I have changed the exception on the exchange
that I have built my "onException" over it .

Is there any way to force to go on my route even after changing the
Exchange's exception !! 




--
View this message in context: http://camel.465427.n5.nabble.com/Set-different-exception-on-exchange-at-the-processor-tp4615500p4615500.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Set different exception on exchange at the processor

Posted by Echo <ah...@gmail.com>.
I was trying to wrap the caught exception that comes into the exchage and
wrap it into another custom exception .

After this wrapping I need to set this exception into a custom exchange .
I have discoverd later from @Claus Ibsen-2  that Camel won't cont. routing
when I use 

    exchange.setException(ex)

I have managed to do some work around by doing the following @ processor : 

    exchange.getOut.setHeader("ex",customException) 

then @Route : 

   
this.onException(classOf[IOException]).process(doSmth).log(LoggingLevel.INFO,
"new", ${in.header.ex} ") 


It prints into my log the following and that what I exactly need from the
beginning : 
CustomException: java.lang.IOException 


Thx for ur assistance

--
View this message in context: http://camel.465427.n5.nabble.com/Set-different-exception-on-exchange-at-the-processor-tp4615500p4619687.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Set different exception on exchange at the processor

Posted by Echo <ah...@gmail.com>.
Actually that's the happy scenario :) 
Um now sucedded to log into a new file rather than karaf.log . 

I need when an exception occurs , throw a CustomException into my new log . 

Um now trying to use these :http://camel.apache.org/simple.html

Trying to use : 

exchange.getOut.setHeader("tot","hi there") 

process(doSmth). 
       log(LoggingLevel.INFO, "new", "${exchangeId} -CUSTOM--
${out.header.tot} 

I got nothing when I try to print : ${out.header.tot} ... any ideaS !! 

Your methodology about continued(true) is nice but um using :
onException(IllegalArgumentException.class)

@ the processor , I need to do smth like that without cutting my route :
exchange.setExceptio(MyCustomException)

continued(true) won't let the next processor to run as I have changed my
exception !!

--
View this message in context: http://camel.465427.n5.nabble.com/Set-different-exception-on-exchange-at-the-processor-tp4615500p4616073.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Set different exception on exchange at the processor

Posted by Ashwin Karpe <ak...@fusesource.com>.
Hi,

If your intention is to handle the exception in your processor and then
continue processing along the original route then you can do the following

public void configure() throws Exception {
    // tell Camel to handle and continue when this exception is thrown
   
onException(IllegalArgumentException.class).*process(doSomething).continued(true);*

    from("direct:start")
        .to("mock:start")
        .throwException(new IllegalArgumentException("Forced"))
        .to("mock:result");
}

Cheers,

Ashwin...

-----
---------------------------------------------------------
Ashwin Karpe
Apache Camel Committer & Sr Principal Consultant
FUSESource (a Progress Software Corporation subsidiary)
http://fusesource.com 

Blog: http://opensourceknowledge.blogspot.com 
---------------------------------------------------------
--
View this message in context: http://camel.465427.n5.nabble.com/Set-different-exception-on-exchange-at-the-processor-tp4615500p4615943.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Set different exception on exchange at the processor

Posted by Echo <ah...@gmail.com>.
As it's not going to continue routing into my route , I have tried to do an
addition :
onException(CustomException).process(dosmth)

I also tried to use doTry/doCatch
I also tried to manipulate with the original stack trace without the need to
use : setException()
Still have the same issue .

I don't need to set into the body or the head , I need to replace the
exchange's exception with customException 

As I use DSL logging into the end of the route to  log into a new log file.
This new log file should have an exception of type CustomException into it . 



--
View this message in context: http://camel.465427.n5.nabble.com/Set-different-exception-on-exchange-at-the-processor-tp4615500p4615711.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Set different exception on exchange at the processor

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Jul 20, 2011 at 12:56 PM, Echo <ah...@gmail.com> wrote:
> Hello ,
> I have on route like that :
>
>
> onException(classOf[RuntimeException]).process(runtimeProcessor).process(doSmth).log(LoggingLevel.INFO,
> "new", "${exchangeId} --- ${exception.stacktrace} ")
>
>
> On the processor I do :
>
>    CustomException customException =new CustomException ()
>    exchange.setException(customException )
>    exchange.getOut.setBody(doc)
>

Camel does not continue routing when an exception has been set on the exchange.

>
> The issue now that after this processor , it doesn't go to other processors
> (i.e. in my case , it doesn't go to "doSmth" processor )
>
> I guess that behavior is that I have changed the exception on the exchange
> that I have built my "onException" over it .
>
> Is there any way to force to go on my route even after changing the
> Exchange's exception !!
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Set-different-exception-on-exchange-at-the-processor-tp4615500p4615500.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/