Spring Integration HTTP出站网关java dsl与ChannelInterceptorAdapter

时间:2017-01-24 05:23:56

标签: spring web-services spring-integration

我正在尝试使用Spring Integration HTTP Outbound网关的java dsl配置。我可以连接外部休息服务的地方。但我想拦截请求&响应有效载荷信息到审计表中。

通过Spring集成XML配置,我能够实现。

<int:channel id="channel.ext.request">
    <int:interceptors>
        <ref bean="customInterceptor" />
    </int:interceptors>
</int:channel>

customIntercepter正在扩展ChannelInterceptorAdapter。这里我只是重写postSend方法并将通道信息保存到db表。

public Message<?> postSend(Message<?> message, MessageChannel channel) {
        return message;
}

这是按预期工作的。

我想拦截请求&amp;通过java dsl响应通道信息。 我无法得到任何消息来源。这是我的java dsl config。

@Bean
public IntegrationFlow httpOut() {
        logger.info("IntegrationFlow enabled");

        return IntegrationFlows.from("channel.ext.request")
                .enrichHeaders(getHeaders())
                .handle(Http.outboundGateway("http://hostname/rest/invoke").charset("UTF-8")
                        .httpMethod(HttpMethod.POST).requestFactory(requestFactory()).expectedResponseType(String.class))
                .channel("channel.ext.response").get();
}

请建议。

1 个答案:

答案 0 :(得分:1)

.channel(MessageChannels.direct("channel.ext.request").interceptor(myInterceptor()))
.handle(...)
.channel(MessageChannels.direct("channel.ext.response").interceptor(myInterceptor()))