我在流程中有一个进行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复制它,但找不到足够的文档。任何帮助将不胜感激。
答案 0 :(得分:5)
是的,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
...
<强>更新强>
顺便说一句:随意提出JIRA票证,为Java DSL添加HTTP支持。