gpt4 book ai didi

java - 是否可以从 Spring Integration http 入站 channel 适配器返回 204?

转载 作者:可可西里 更新时间:2023-11-01 16:33:41 26 4
gpt4 key购买 nike

我有一个入站 channel 适配器,它转发到一个返回 null 的 bean 方法,但由于 http 必须返回响应,因此返回 200。在某些情况下,我想指定返回值是什么,例如一个 204,我已经尝试了很多东西,但似乎没有任何效果。

我正在使用 spring-integration 3.0.2。

谢谢,贾斯汀

最佳答案

是的,将回复消息中的 http_statusCode header 设置为 204。

编辑:(见下面的评论)

<int-http:inbound-gateway request-channel="receiveChannel"
path="/receiveGateway"
supported-methods="POST"/>

<int:publish-subscribe-channel id="receiveChannel" task-executor="exec" />

<int:service-activator input-channel="receiveChannel" expression="payload + ' from the other side'" output-channel="next"/>

<int:chain input-channel="receiveChannel">
<int:header-enricher>
<int:header name="http_statusCode" value="204"/>
</int:header-enricher>
<int:transformer expression="''"/>
</int:chain>

假设主流程不返回结果。

如果您想等到流程完成,请删除任务执行器。

您可能还需要一个转换器,将负载转换为 ""

关于java - 是否可以从 Spring Integration http 入站 channel 适配器返回 204?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24147573/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com