简体   繁体   English

骆驼spring-ws:处理异常

[英]camel spring-ws: handling exception

Is there a way to return a custom body (eg custom bean) and http status as 500 in camel + spring-ws? 有没有办法在骆驼+ spring-ws中返回自定义主体(例如,自定义bean)和http状态为500?

I tried with 我尝试过

onException(RuntimeException.class).handled(true).process(new
     ExceptionProcessor()).marshal(jaxb);

and then in the processor public class ExceptionProcessor implements 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);
    }

}

} }

but even if the body is what I want, the http status is always 200. 但是即使身体是我想要的,http状态始终为200。
Can you help me? 你能帮助我吗?

Some more info: I'm using camel version 2.20.2 一些更多的信息:我正在使用骆驼版本2.20.2

exchange.setProperty(Exchange.HTTP_RESPONSE_CODE, 500);
exchange.getOut().setFault(true);

should work for you. 应该为您工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM