Thank you! This worked for me:

onException(BadHeaderException.class)
 .handled(true)
* .transform(simple("Bad API request:  ${exception.message}"))*
 .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(400))


2018-02-02 11:33 GMT+02:00 Claus Ibsen <claus.ib...@gmail.com>:

> Hi
>
> The configure method in the RouteBuilder is only invoked once to setup
> the routes.
> And constant is creating a constant message.
>
> So what you need to do is to use simple instead to tell Camel to build
> a dynamic message with the exception message
>
> See the docs at: http://camel.apache.org/simple
>
>
>
> On Thu, Feb 1, 2018 at 8:43 PM, Yacov Schondorf
> <yacov.schond...@gmail.com> wrote:
> > I have the following global onException clause in my RouteBuilder
> configure
> > method:
> >
> > onException(BadHeaderException.class)
> > .handled(true)
> > .transform(constant("Bad API request: " + exceptionMessage()))
> > .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(400))
> >
> > The route is as follows:
> >
> > from(String.format("jetty://http://0.0.0.0:%d%s",port, KEEP_ALIVE_URI))
> > .process(new MyRequiredHeaderProcessor())
> > .log("My API called")
> > .setBody(simple(KEEP_ALIVE_SUCCESS_MESSAGE));
> >
> > and  MyRequiredHeaderProcessor may throw BadHeaderException:
> >
> > class MyRequiredHeaderProcessor implements Processor {
> > @Override
> > public void process(Exchange exchange) throws Exception {
> > final Object myHeader = exchange.getIn().getHeader("MyRequiredHeader");
> > if (myHeader == null) {
> > throw new BadHeaderException ("Missing header");
> > }
> > if (!myHeader .equals(someValue)) {
> > throw new BadHeaderException("Incorrect  header value");
> > }
> > }
> > }
> >
> > When I call the jetty URL without the required header, the request is
> > rejected with error code 400 - as expected - BUT the error message is:
> >  
> > Bad API request: simple{${exception.message}}
> >
> > Shouldn't exceptionMessage() return the text I set in
> > MyRequiredHeaderProcessor?
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2
>



-- 
יעקב שיינדורף
מנכ"ל ומנהל פיתוח,
מילות מפתח לאתרים
054-5750201
http://keywords-4-websites.com <http://keywords-4-websites.com/home.jsp>

יעקב שיינדורף
מנהל מוסיקלי StyleBrass
054-5750201
http://www.stylebrass.co.il

Reply via email to