Kik*_*kou 6 java apache esb onexception
我想从路线中捕捉所有异常.
我添加了这个OnExeption:
onException(Exception.class).process(new MyFunctionFailureHandler()).stop();
Run Code Online (Sandbox Code Playgroud)
然后,我创建了类MyFunctionFailureHandler.
public class MyFunctionFailureHandler implements Processor {
@Override
public void process(Exchange exchange) throws Exception {
Throwable caused;
caused = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Throwable.class);
exchange.getContext().createProducerTemplate().send("mock:myerror", exchange);
}
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,它不起作用,我不知道为什么.
如果有异常,程序必须停止.
我怎么知道为什么这段代码不起作用!!
谢谢.
我在我的路线上使用了这个:
public class MyCamelRoute extends RouteBuilder {
@Override
public void configure() throws Exception {
from("jms:start")
.process(testExcpProcessor)
// -- Handle Exceptions
.onException(Exception.class)
.process(errorProcessor)
.handled(true)
.to("jms:start");
}
}
Run Code Online (Sandbox Code Playgroud)
在我的错误处理器中
public class ErrorProcessor implements Processor {
@Override
public void process(Exchange exchange) throws Exception {
Exception cause = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class);
if(cause != null){
log.error("Error has occurred: ", cause);
// Sending Error message to client
exchange.getOut().setBody("Error");
}else
// Sending response message to client
exchange.getOut().setBody("Good");
}
}
Run Code Online (Sandbox Code Playgroud)
我希望它有帮助
| 归档时间: |
|
| 查看次数: |
17358 次 |
| 最近记录: |