【问题标题】:camel spring-ws: handling exception骆驼弹簧-ws:处理异常
【发布时间】:2018-04-03 16:02:56
【问题描述】:

有没有办法在 camel + spring-ws 中返回自定义主体(例如自定义 bean)和 http 状态为 500?

我试过了

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

然后在处理器中 公共类 ExceptionProcessor 实现处理器 {

@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);
    }

}

}

但即使body是我想要的,http状态总是200。
你能帮助我吗?

更多信息: 我使用的是骆驼版本 2.20.2

【问题讨论】:

    标签: apache-camel spring-ws spring-camel


    【解决方案1】:
    exchange.setProperty(Exchange.HTTP_RESPONSE_CODE, 500);
    exchange.getOut().setFault(true);
    

    应该适合你。

    【讨论】:

    • 仍然无法正常工作。如果我将故障设置为 true,则信封主体甚至是空白的。在任何情况下,http 状态始终为 200。仅供参考,我使用的是骆驼 2.20.2
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-09
    • 2018-08-15
    • 2023-04-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多