簡體   English   中英

駱駝spring-ws:處理異常

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM