You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Claus Ibsen <cl...@gmail.com> on 2009/08/04 10:07:30 UTC

Re: Routing with RouteBuilder and onException, missing the Exception instance

On Tue, Aug 4, 2009 at 9:27 AM, juhasiltanen<ju...@gmail.com> wrote:
>
> I have a simple routing configuration of
> onException(MyException.class).to(myEndpoint)
>
> Then I have a simple implementation of a Processor interface reading from
> myEndpoint (that receives an Exchange), let's call it MyProcessor.
>
> How do I get the instance of MyException thrown from the depths of the
> application to MyProcessor?
>
> Exchange.getException returns null, and this is the place I would expect
> MyException to be found.

No its not as when you do routing in the onException then you handle it.
You can get the caused exception from a property

In Camel 2.0
Exception cause = exchange.getProperty(Exchange.EXCEPTION_CAUGHT,
Exception.class);

And its about the same in 1.x the key is different though

See more here:
http://camel.apache.org/exception-clause.html

In the section "using a processor as failure handler"

>
> Thank's in advance!
> --
> View this message in context: http://www.nabble.com/Routing-with-RouteBuilder-and-onException%2C-missing-the-Exception-instance-tp24803541p24803541.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: Routing with RouteBuilder and onException, missing the Exception instance

Posted by juhasiltanen <ju...@gmail.com>.
As it seems, the exchange can not be sent through a queue for processing
after an exception has occured.

Upon exception, the control needs to be passed directly to a processor. As I
am using spring beans with dependency injections, the route definition
needed to be changed from...

onException(...).to(queueEndpoint)

... to ...

onException(...).beanRef("beanName")

... and the CamelExceptionCaught property is available at the Exchange
instance.

thanks for your help!

-J-


juhasiltanen wrote:
> 
> I am trying to get the custom exception at the point when the executions
> hits my processor implementation, not during the route configuration.
> 
> I assume, that by invoking Exchange.getProperties a full Map of properties
> is provided. Is this the case?
> 
> By iterating over the Map, only two properties are available: CamelBinding
> and CamelBeanHolder.
> 
> I am using Camel 2.0 M3
> 
> Any more ideas?
> 
> -J-
> 
> 
> Claus Ibsen-2 wrote:
>> 
>> On Tue, Aug 4, 2009 at 9:27 AM, juhasiltanen<ju...@gmail.com>
>> wrote:
>>>
>>> I have a simple routing configuration of
>>> onException(MyException.class).to(myEndpoint)
>>>
>>> Then I have a simple implementation of a Processor interface reading
>>> from
>>> myEndpoint (that receives an Exchange), let's call it MyProcessor.
>>>
>>> How do I get the instance of MyException thrown from the depths of the
>>> application to MyProcessor?
>>>
>>> Exchange.getException returns null, and this is the place I would expect
>>> MyException to be found.
>> 
>> No its not as when you do routing in the onException then you handle it.
>> You can get the caused exception from a property
>> 
>> In Camel 2.0
>> Exception cause = exchange.getProperty(Exchange.EXCEPTION_CAUGHT,
>> Exception.class);
>> 
>> And its about the same in 1.x the key is different though
>> 
>> See more here:
>> http://camel.apache.org/exception-clause.html
>> 
>> In the section "using a processor as failure handler"
>> 
>>>
>>> Thank's in advance!
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Routing-with-RouteBuilder-and-onException%2C-missing-the-Exception-instance-tp24803541p24803541.html
>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>
>>>
>> 
>> 
>> 
>> -- 
>> Claus Ibsen
>> Apache Camel Committer
>> 
>> Open Source Integration: http://fusesource.com
>> Blog: http://davsclaus.blogspot.com/
>> Twitter: http://twitter.com/davsclaus
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Routing-with-RouteBuilder-and-onException%2C-missing-the-Exception-instance-tp24803541p24805472.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Routing with RouteBuilder and onException, missing the Exception instance

Posted by juhasiltanen <ju...@gmail.com>.
I am trying to get the custom exception at the point when the executions hits
my processor implementation, not during the route configuration.

I assume, that by invoking Exchange.getProperties a full Map of properties
is provided. Is this the case?

By iterating over the Map, only two properties are available: CamelBinding
and CamelBeanHolder.

I am using Camel 2.0 M3

Any more ideas?

-J-


Claus Ibsen-2 wrote:
> 
> On Tue, Aug 4, 2009 at 9:27 AM, juhasiltanen<ju...@gmail.com>
> wrote:
>>
>> I have a simple routing configuration of
>> onException(MyException.class).to(myEndpoint)
>>
>> Then I have a simple implementation of a Processor interface reading from
>> myEndpoint (that receives an Exchange), let's call it MyProcessor.
>>
>> How do I get the instance of MyException thrown from the depths of the
>> application to MyProcessor?
>>
>> Exchange.getException returns null, and this is the place I would expect
>> MyException to be found.
> 
> No its not as when you do routing in the onException then you handle it.
> You can get the caused exception from a property
> 
> In Camel 2.0
> Exception cause = exchange.getProperty(Exchange.EXCEPTION_CAUGHT,
> Exception.class);
> 
> And its about the same in 1.x the key is different though
> 
> See more here:
> http://camel.apache.org/exception-clause.html
> 
> In the section "using a processor as failure handler"
> 
>>
>> Thank's in advance!
>> --
>> View this message in context:
>> http://www.nabble.com/Routing-with-RouteBuilder-and-onException%2C-missing-the-Exception-instance-tp24803541p24803541.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
> 
> 
> 
> -- 
> Claus Ibsen
> Apache Camel Committer
> 
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
> Twitter: http://twitter.com/davsclaus
> 
> 

-- 
View this message in context: http://www.nabble.com/Routing-with-RouteBuilder-and-onException%2C-missing-the-Exception-instance-tp24803541p24804847.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Routing with RouteBuilder and onException, missing the Exception instance

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 on the camel forum 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 


--
View this message in context: http://camel.465427.n5.nabble.com/Routing-with-RouteBuilder-and-onException-missing-the-Exception-instance-tp476479p4619696.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Routing with RouteBuilder and onException, missing the Exception instance

Posted by Echo <ah...@gmail.com>.
Hello , 
I have the same case u were into .

I have declared my CustomException class. 
When the onException() catches it , it goes to the processor I defined : 

onException(classOf[CustomException]).process(doSmth) 

So far so good . 
The issue that I need into the processor to check if the exception is of
type "CustomException" or not 

when I write : 

 def process(exchange: Exchange) = { 
    val exception: CustomException=
exchange.getProperty(Exchange.EXCEPTION_CAUGHT, classOf[CustomException]) 

I got null 

But when I write : 

 def process(exchange: Exchange) = { 
    val exception: Exception =
exchange.getProperty(Exchange.EXCEPTION_CAUGHT, classOf[Exception]) 

I got my exception object 

How could I check which type of exception is thrown into the processor !

The type of exception under CamelExceptionCaught property is
ava.lang.reflect.UndeclaredThrowableException

--
View this message in context: http://camel.465427.n5.nabble.com/Routing-with-RouteBuilder-and-onException-missing-the-Exception-instance-tp476479p4615187.html
Sent from the Camel - Users mailing list archive at Nabble.com.