You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Vero Kato <ve...@gmail.com> on 2015/12/06 11:05:58 UTC

Exception handling with Apache Camel

hi, I use Camel Rest and currently when I need to suppress exception in my
code and show on a screen nice message, I do like this:

onException(Exception.class).handled(true).setBody(constant("Parsing Error,
please check your input")).log("error sent back to client");

The only problem is that "error sent back to client" is not logged in our
log file, how to wire up my own logger into this? I also want to log
original exception message, how to reference original exception object
instance in this code?

Thanks,
Vero

Re: Exception handling with Apache Camel

Posted by Joakim Bjørnstad <jo...@gmail.com>.
Hello,

Set up your own logger, for example with slf4j and logback loggers/appenders.

private static final Logger LOGGER = LoggerFactory.getLogger(MyRoute.class);

onException(Exception.class)
  .handled(true)
  .setBody(constant("Parsing Error, please check your input"))
  .log(LoggingLevel.ERROR, LOGGER, "error sent back to client");

To log exception message, use the simple language:

.log(LoggingLevel.ERROR, LOGGER, "error sent back to client.
originalExceptionMessage=${exception.message}");

If you want to do custom processing on the exception object. It can be
found in exchangeProperty(Exchange.EXCEPTION_CAUGHT)

Please also see: http://camel.apache.org/logeip.html

On Sun, Dec 6, 2015 at 11:05 AM, Vero Kato <ve...@gmail.com> wrote:
> hi, I use Camel Rest and currently when I need to suppress exception in my
> code and show on a screen nice message, I do like this:
>
> onException(Exception.class).handled(true).setBody(constant("Parsing Error,
> please check your input")).log("error sent back to client");
>
> The only problem is that "error sent back to client" is not logged in our
> log file, how to wire up my own logger into this? I also want to log
> original exception message, how to reference original exception object
> instance in this code?
>
> Thanks,
> Vero



-- 
Kind regards
Joakim Bjørnstad