You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Marco Mistroni <mm...@gmail.com> on 2012/04/09 16:56:08 UTC

custom error handler

HI all
 i plan to deploy my apache camel app remotely, and i would like to
configure an error handler so that , when an exception happens,
it sends me an email with the exception details.

I have read camel error handling docs, and i guess the best approach for me
would be to use a deadLetterErrorHandler
with  a deadLetterUri="bean:exceptionHandler?method=handleException"

I have this camel config

<camel:camelContext xmlns="http://camel.apache.org/schema/spring"
        id="camelServer" errorHandlerRef="deadLetterErrorHandler">

        <camel:errorHandler id="deadLetterErrorHandler"
        type="DeadLetterChannel"
deadLetterUri="bean:exceptionHandler?method=handleException"/>

.........

in one of my routes i an explicitly raising a n exception to test the error
handler behaviour..... however it appears that the method handleException
is never
being called....
this is the code of my exceptionHandler Bean

class ExceptionHandler {

    private static final Log LOGGER =
LogFactory.getLog(ExceptionHandler.class);

    public void handleException(Object exception) {
        LOGGER.info("Handling exceptions:" + exception);

    }
}

what am i missing?

or are there any better approaches to configure a custom error handler ? I
am not interested in propagating the exception (as exceptions will happen
only at
endpoints....)


w/kindest regards
 marco

Re: custom error handler

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

When you use XML DSL, then you need to configure the errorHandlerRef
attribute on either <camelContext> and/or <route> to specify which
error handler to use.

eg for example, where you refer the error handler by its id

<camelContext errorHandlerRef ="deadLetterErrorHandler" ...>

Also if you want to get the caused exception, then the type of the
parameter in your bean, should be Exception, and not Object.

If you do

   public void handleException(Object body, Exception cause) {

then you get both the message body from the message being processed
that failed, and the caused exception



On Mon, Apr 9, 2012 at 4:56 PM, Marco Mistroni <mm...@gmail.com> wrote:
> HI all
>  i plan to deploy my apache camel app remotely, and i would like to
> configure an error handler so that , when an exception happens,
> it sends me an email with the exception details.
>
> I have read camel error handling docs, and i guess the best approach for me
> would be to use a deadLetterErrorHandler
> with  a deadLetterUri="bean:exceptionHandler?method=handleException"
>
> I have this camel config
>
> <camel:camelContext xmlns="http://camel.apache.org/schema/spring"
>        id="camelServer" errorHandlerRef="deadLetterErrorHandler">
>
>        <camel:errorHandler id="deadLetterErrorHandler"
>        type="DeadLetterChannel"
> deadLetterUri="bean:exceptionHandler?method=handleException"/>
>
> .........
>
> in one of my routes i an explicitly raising a n exception to test the error
> handler behaviour..... however it appears that the method handleException
> is never
> being called....
> this is the code of my exceptionHandler Bean
>
> class ExceptionHandler {
>
>    private static final Log LOGGER =
> LogFactory.getLog(ExceptionHandler.class);
>
>    public void handleException(Object exception) {
>        LOGGER.info("Handling exceptions:" + exception);
>
>    }
> }
>
> what am i missing?
>
> or are there any better approaches to configure a custom error handler ? I
> am not interested in propagating the exception (as exceptions will happen
> only at
> endpoints....)
>
>
> w/kindest regards
>  marco



-- 
Claus Ibsen
-----------------
CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com
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/