[英]camel spring-ws: handling exception
有没有办法在骆驼+ spring-ws中返回自定义主体(例如,自定义bean)和http状态为500?
我尝试过
onException(RuntimeException.class).handled(true).process(new
ExceptionProcessor()).marshal(jaxb);
然后在处理器公共类ExceptionProcessor中实现Processor {
@Override
public void process(Exchange exchange) throws Exception {
RuntimeException e = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, RuntimeException.class);
ExceptionHandler handler = ExceptionHandlerFactory.fromException(e);
ExceptionType response = handler.handleException();
if (exchange.hasOut()) {
exchange.getOut().setBody(response);
} else {
exchange.getIn().getHeaders();
exchange.getIn().setFault(true);
exchange.getIn().setBody(response);
}
}
}
但是即使身体是我想要的,http状态始终为200。
你能帮助我吗?
一些更多的信息:我正在使用骆驼版本2.20.2
exchange.setProperty(Exchange.HTTP_RESPONSE_CODE, 500);
exchange.getOut().setFault(true);
应该为您工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.