有没有办法在camel + spring-ws中返回自定义主体(例如自定义bean)和http状态为500?
我试着用
onException(RuntimeException.class).handled(true).process(new
ExceptionProcessor()).marshal(jaxb);然后在processor公共类中,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。
你能帮帮我吗?
更多信息:我使用的是camel版本2.20.2
发布于 2018-04-04 22:04:10
exchange.setProperty(Exchange.HTTP_RESPONSE_CODE, 500);
exchange.getOut().setFault(true);对你来说应该很管用。
https://stackoverflow.com/questions/49634490
复制相似问题