如何在Spring Integration中声明outputChannel并处理HttpRequestExecutingMessageHandler的http响应

时间:2018-07-09 17:14:56

标签: spring spring-boot spring-integration spring-integration-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一起使用。

1 个答案:

答案 0 :(得分:0)

这不是httpResponseChannel的责任。您需要考虑为此ExpressionEvaluatingRequestHandlerAdvice添加一个HttpRequestExecutingMessageHandlerhttps://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 { };