如果在DSL的出站网关中引发故障,则路由到错误通道

问题描述 投票:1回答:1

我有以下Spring Integration JAva DSL代码:

    return flow -> flow.channel(INPUT_CHANNEL)
            .transform(customMapper, "mapFrom")
            .enrichHeaders(polarisPreCompSoapActionHeader())
            .route("headers.key",
                    subflowMapping -> subflowMapping
                            .subFlowMapping("value1", subflow -> subflow
                                    .handle(webserviceOutboundGateway,
                                            e -> e.advice(skipAdvice()))
                            )
            )
            .channel(OUTPUT_CHANNEL);

@Bean
public Advice skipAdvice() {
    ExpressionEvaluatingRequestHandlerAdvice advice = new ExpressionEvaluatingRequestHandlerAdvice();
    advice.setFailureChannel(errorChannel());
    return advice;
}

webserviceOutboundGateway被创建为MarshallingWebServiceOutboundGateway的bean。

我试图实现的是在SOAP错误到达时将错误消息路由到错误通道。我以为可以向处理程序添加建议,而该建议应该是可以设置故障通道的ExpressionEvaluatingRequestHandlerAdvice。因此,每当出站网关中出现错误时,错误消息就会转发到错误通道。

然后问题是,现在网关抛出异常,流程停止了

2020-05-20 21:11:55,446 ERROR com.acme.webservice.OrchestrationServiceEndpoint Thread=qtp14486859-17 MDC=16d7cc4c-c9da-449b-8bfa-504e6d81185d Error
org.springframework.ws.client.WebServiceTransportException: Not Found [404]
        at org.springframework.ws.client.core.WebServiceTemplate.handleError(WebServiceTemplate.java:699)
        at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:609)
        at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:555)
        at org.springframework.integration.ws.MarshallingWebServiceOutboundGateway.doHandle(MarshallingWebServiceOutboundGateway.java:87)

任何建议/帮助将不胜感激!谢谢,V]

spring-integration spring-integration-dsl
1个回答
0
投票

请参见ExpressionEvaluatingRequestHandlerAdvice上的此方法:

/**
 * If true, any exception will be caught and null returned.
 * Default false.
 * @param trapException true to trap Exceptions.
 */
public void setTrapException(boolean trapException) {

因此,将其设置为true,以避免重新抛出异常。

[也在文档中查看更多内容:https://docs.spring.io/spring-integration/docs/5.3.0.RELEASE/reference/html/messaging-endpoints.html#expression-advice

© www.soinside.com 2019 - 2024. All rights reserved.