How to get the error message inside Route (cOnException)

Highlighted
Five Stars
Five Stars

How to get the error message inside Route (cOnException)

Hi,

 

I am trying to get the exception message which is caught using cOnException.

I can see the stack trace in the cLog but I want to get the actual value and perform some action. As can be seen in the example below, how can I get the ERROR_MESSAGE of cOnException_1 in cSetBody_1? Below code is not even compiling.

 

 

query.jpg

 

 

Thanks,


Accepted Solutions
Eight Stars

Re: How to get the error message inside Route (cOnException)

In ESB you never ever need to use GlobalMap. Everything is stored within the Camel Exchange message. 

for your need, you can use a cProcessor after cOnException, with some code like 

 

Exception ex = exchange.getProperty(Exchange.EXCEPTION_CAUGHT,Exception.class); 
if ( ex == null) { ex = pExchange.getProperty(Exchange.EXCEPTION_HANDLED,Exception.class); } 
if ( ex != null) { 
      x_error_message = ex.getLocalizedMessage();
      x_error_class = ex.getClass().getCanonicalName();

}

exchange.getIn().setBody(x_error_message+' - '+x_error_class);

View solution in original post


All Replies
Highlighted
Five Stars
Five Stars

Re: How to get the error message inside Route (cOnException)

Suggestions, please  !!

Eight Stars

Re: How to get the error message inside Route (cOnException)

In ESB you never ever need to use GlobalMap. Everything is stored within the Camel Exchange message. 

for your need, you can use a cProcessor after cOnException, with some code like 

 

Exception ex = exchange.getProperty(Exchange.EXCEPTION_CAUGHT,Exception.class); 
if ( ex == null) { ex = pExchange.getProperty(Exchange.EXCEPTION_HANDLED,Exception.class); } 
if ( ex != null) { 
      x_error_message = ex.getLocalizedMessage();
      x_error_class = ex.getClass().getCanonicalName();

}

exchange.getIn().setBody(x_error_message+' - '+x_error_class);

View solution in original post

Highlighted
Five Stars
Five Stars

Re: How to get the error message inside Route (cOnException)

Thanks Loko.

2019 GARTNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

Talend API Designer – Technical Overview

Take a look at this technical overview video of Talend API Designer

Watch Now

Getting Started with APIs

Find out how to get started with APIs

Read