有没有办法在camel + 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
答案 0 :(得分:0)
exchange.setProperty(Exchange.HTTP_RESPONSE_CODE, 500);
exchange.getOut().setFault(true);
应该适合你。