在Spring-Integration中处理“204 no content”

时间:2017-02-24 13:20:08

标签: spring-integration

我的int-http:outbound-gateway正在返回“204无内容”。结果我的UI层失败了,因为它期望一个非空的有效载荷。有没有办法在Spring-Integration中处理这种情况?

1 个答案:

答案 0 :(得分:0)

HttpRequestExecutingMessageHandler执行此操作:

if (this.expectReply) {
    ...
    AbstractIntegrationMessageBuilder<?> replyBuilder = null;
    if (httpResponse.hasBody()) {
        Object responseBody = httpResponse.getBody();
        replyBuilder = (responseBody instanceof Message<?>) ?
                            this.getMessageBuilderFactory().fromMessage((Message<?>) responseBody) : this.getMessageBuilderFactory().withPayload(responseBody);

    }
    else {
        replyBuilder = this.getMessageBuilderFactory().withPayload(httpResponse);
    }
                replyBuilder.setHeader(org.springframework.integration.http.HttpHeaders.STATUS_CODE, httpResponse.getStatusCode());
    return replyBuilder.copyHeaders(headers).build();
    }
return null;

因此,如果您不使用<int-http:outbound-channel-adapter>,您肯定会得到一些回复,HttpHeaders.STATUS_CODE标题会以HttpStatus.NO_CONTENT作为值。

正如您所看到的,payload消息取决于httpResponse.hasBody(),我想如果HttpStatus.NO_CONTENT,则确实没有body。因此,有效负载是一个完整的ResponseEntity

现在,请分享更多信息,它对您有何帮助?您如何获得null payload