![](/img/trans.png)
[英]How can I create http outbound-gateway with JAVA config in Spring integration?
[英]Spring Integration Java DSL - How to invoke int-http:outbound-gateway?
我在流程中有一个进行ReST API调用的部分:
<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复制它,但找不到足够的文档。 任何帮助将非常感激。
是的,Spring Integration Java DSL还没有提供HTTP的命名空间工厂。
无论如何,我们可以继续使用其通用组件来做到这一点:
@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();
}
从另一方面来看,所提到的文档完全展示了HttpRequestHandlingMessagingGateway
的样本......
UPDATE
顺便说一下:随意提出一个JIRA票据,为Java DSL添加HTTP支持。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.