首页 > 解决方案 > 如何在spring集成中为HttpRequestExecutingMessageHandler声明outputChannel并处理http响应

问题描述

下面是 HttpRequestExecutingMessageHandler 的配置

@Bean
@ServiceActivator(inputChannel = "httpRequestChannel")
    public HttpRequestExecutingMessageHandler httpRequestExecutingMessageHandler() {
    HttpRequestExecutingMessageHandler handler = new HttpRequestExecutingMessageHandler(serviceUrl);
    handler.setCharset(StandardCharsets.UTF_8.displayName());
    handler.setOutputChannel(httpResponseChannel());
    handler.setExpectedResponseType(String.class);

    return handler;
}

我应该如何配置 httpResponseChannel 来处理 httpResponse。如果http状态代码为201,我想将原始文件移动到成功文件夹或错误文件夹以供休息。

我将 spring integration 5 与 spring boot 一起使用。

标签: springspring-bootspring-integrationspring-integration-http

解决方案


这不是httpResponseChannel责任。您需要考虑为此添加一个ExpressionEvaluatingRequestHandlerAdviceHttpRequestExecutingMessageHandlerhttps: //docs.spring.io/spring-integration/docs/5.0.6.RELEASE/reference/html/messaging-endpoints-chapter.html#expression-advice

并且已经在那里,您可以做出成功或失败的决定。

有这个@ServiceActivator选项:

/**
 * Specify a "chain" of {@code Advice} beans that will "wrap" the message handler.
 * Only the handler is advised, not the downstream flow.
 * @return the advice chain.
 */
String[] adviceChain() default { };

推荐阅读