我在流程中有一个进行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支持.