Spring Integration Java DSL-如何调用int-http:outbound-gateway? [英] Spring Integration Java DSL - How to invoke int-http:outbound-gateway?

查看:182
本文介绍了Spring Integration Java DSL-如何调用int-http:outbound-gateway?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在流程中进行了一次ReST API调用:

I have a piece in the flow where a ReST API call is made:

<int:channel id="requestChannel"/>

<int-http:outbound-gateway request-channel="requestChannel"
                           reply-channel="logger"
                           url="${api.base.uri}/data"
                           http-method="PUT"
                           expected-response-type="java.lang.String"/>

<int:logging-channel-adapter id="logger"
                             logger-name="logger"
                             expression="payload"
                             level="INFO"/>

我正在尝试使用Java DSL复制此文件,但找不到足够的文档。任何帮助将不胜感激。

I'm trying to replicate this using Java DSL but could not find adequate documentation. Any help would be much appreciated.

推荐答案

Spring Integration Java DSL尚未提供HTTP的命名空间工厂。

Right, Spring Integration Java DSL doesn't provide the Namespace Factory for HTTP, yet.

无论如何,我们都可以使用其通用组件进行操作:

Anyway we can go ahead and do that using its generic components:

    @Bean
    public MessageHandler logger() {
        LoggingHandler loggingHandler = new LoggingHandler("INFO");
        loggingHandler.setLoggerName("logger");
        // This is redundant because the default expression is exactly "payload"
        // loggingHandler.setExpression("payload");
        return loggingHandler;
    }

    @Bean
    public MessageHandler httpGateway(@Value("${api.base.uri}/data") URI uri) {
        HttpRequestExecutingMessageHandler httpHandler = new HttpRequestExecutingMessageHandler(uri);
        httpHandler.setExpectedResponseType(String.class);
        httpHandler.setHttpMethod(HttpMethod.PUT);
        return httpHandler;
    }

    @Bean
    public IntegrationFlow httpFlow(MessageHandler httpGateway) {
        return IntegrationFlows.from("requestChannel")
                .handle(httpGateway)
                .handle(logger())
                .get();
    }

从另一面提到的文档演示了<$ c $的示例c> HttpRequestHandlingMessagingGateway ...

From other side the mentioned documentation demonstrate the sample exactly for the HttpRequestHandlingMessagingGateway...

更新

顺便说一句:随意提出 JIRA 票证,以向Java DSL添加HTTP支持。

By the way: feel free to raise a JIRA ticket for adding HTTP support to the Java DSL.

这篇关于Spring Integration Java DSL-如何调用int-http:outbound-gateway?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆