【问题标题】:Spring integration, Setting error-handler on http outbound gatewaySpring集成,在http出站网关上设置错误处理程序
【发布时间】:2016-04-20 13:21:53
【问题描述】:

如果我将自定义错误处理程序添加到 int-http:outbound-gateway,则不会根据预期的响应类型解组响应正文,而是只返回一个 ResponseEntity。我的自定义错误处理程序非常简单:

public class MyResponseErrorHandler extends DefaultResponseErrorHandler {

private static final Logger log = LoggerFactory.getLogger(AlmaGetUserResponseErrorHandler.class);

@Override
public boolean hasError(final ClientHttpResponse response) throws IOException {
    // stop http 400 from returning true to error here.
    log.debug("Request has returned error code {}", response.getStatusCode());
    if (response.getBody() != null) {
        String returnBody = IOUtils.toString(response.getBody(), "UTF-8");
        log.debug("Checking error from response, code {}, body {}", response.getStatusCode(), returnBody);
    }

    return false;
}

}

一旦我删除错误处理程序,它就会正确地将 XML 响应解组到我的 POJO 中。

【问题讨论】:

  • 对不起,我的错。我将正文结果从响应中流出以进行调试,因此正文为空。
  • 嗯,您自己找到了解决方案,真是太好了。因此,请随意删除问题或形成正确的答案以获得一些声誉

标签: spring-integration


【解决方案1】:

上面的问题是 MyResponseErrorHandler 类在将正文内容传递给预期响应类型的编组器之前将其流出。因此,主体为空,并返回了一个普通的 ResponseEntity。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多