I need to return the message from a thrown exception, or put it in the outmessage. But it does not print the correct message on the frontend.
The camel docs suggest using .transform(simple?...)
.handled(true)
but most of it is deprecated.
What's the correct way of doing this?
Response:
<418 I'm a teapot,simple{${exception.message}},{}>
Route
from("direct:csv")
.doTry()
.process(doSomeThingWithTheFileProcessor)
.doCatch(Exception.class)
.process(e -> {
e.getOut().setBody(new ResponseEntity<String>(exceptionMessage().toString(), HttpStatus.I_AM_A_TEAPOT));
}).stop()
.end()
.process(finalizeTheRouteProcessor);
doSomethingWithFileProcessor
public void process(Exchange exchange) throws Exception {
String filename = exchange.getIn().getHeader("CamelFileName", String.class);
MyFile mf = repo.getFile(filename); //throws exception
exchange.getOut().setBody(exchange.getIn().getBody());
exchange.getOut().setHeader("CamelFileName", exchange.getIn().getHeader("CamelFileName"));
}