【发布时间】:2018-11-26 15:01:32
【问题描述】:
我需要从抛出的异常中返回消息,或者将其放入 outmessage 中。但它不会在前端打印正确的消息。
camel 文档建议使用 .transform(simple?...) .handled(true),但其中大部分已被弃用。
这样做的正确方法是什么?
回应:
<418 I'm a teapot,simple{${exception.message}},{}>
路线
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"));
}
【问题讨论】:
标签: apache spring-boot apache-camel dsl