将MarshallingWebServiceOutboundGateway与基于消息头的动态URI一起使用



我有以下配置,用于作为集成流的一部分发送SOAP请求,其中uriDefinedInApplicationProperties是一个固定的uri,在"application.properties"文件中定义:

@Bean
public MarshallingWebServiceOutboundGateway outboundSOAPGateway()
{
    final MarshallingWebServiceOutboundGateway outboundGateway = new MarshallingWebServiceOutboundGateway(
            uriDefinedInApplicationProperties,
            requestMarshaller,
            responseMarshaller);
    outboundGateway.setAdviceChain(Collections.singletonList(retryOutboundGatewayAdvice));
    if (soapActionCallback!= null) {
        outboundGateway.setRequestCallback(soapActionCallback);
    }
    return outboundGateway;
}

现在我需要动态生成远程SOAP服务器的URI(我计划使用消息头来存储URI(。

我想做一些类似的事情,但MarshallingWebServiceOutboundGateway似乎不支持它,而且我还没能找到如何使用spring集成dsl:做类似的事情

@Bean
public MarshallingWebServiceOutboundGateway outboundSOAPGateway()
{
    final MarshallingWebServiceOutboundGateway outboundGateway = new MarshallingWebServiceOutboundGateway(
            message -> (message -> message.getHeaders().get("remote.uri.header"),
            requestMarshaller,
            responseMarshaller);
    outboundGateway.setAdviceChain(Collections.singletonList(retryOutboundGatewayAdvice));
    if (soapActionCallback!= null) {
        outboundGateway.setRequestCallback(soapActionCallback);
    }
    return outboundGateway;
}

我注意到MarshallingWebServiceOutboundGateway有一个setUriVariableExpressions(Map<String, Expression> uriVariableExpressions)方法,但我没有找到任何关于它应该做什么以及如何工作的明确文档。

此外,我还尝试执行以下操作来创建出站网关,但它似乎不支持requestCallbacks或建议链。

Http.outboundGateway(message -> message.getHeaders().get("remote.uri.header"))
            .messageConverters(new MarshallingHttpMessageConverter(
                    remoteRequestMarshaller,
                    remoteResponseMarshaller));

创建具有重试建议和动态生成uri的SOAP出站网关的最佳方法是什么?

advice配置不是MessageHandler的职责。如果您使用JavaDSL,请参阅用于MarshallingWebServiceOutboundGateway:的handle()的第二个参数(GenericEndpointSpec lambda(

/**
 * Configure a list of {@link Advice} objects to be applied, in nested order, to the
 * endpoint's handler. The advice objects are applied only to the handler.
 * @param advice the advice chain.
 * @return the endpoint spec.
 */
public S advice(Advice... advice) {

是的,我同意MarshallingWebServiceOutboundGateway(及其超类(目前不支持针对消息的URI解析。请随意提出GH问题,以修复与SpEL配置的差距,就像我们为提到的Http.outboundGateway所做的那样。

同时,作为一种变通方法,您可以考虑实现一个从TheadLocal存储读取URI的DestinationProvider。在调用此网关之前,您应该查阅消息,并将构建的URI存储到ThreadLocal变量中。

最新更新