Is it possible to return a 204 from a Spring Integration http inbound-channel-adapter?

我与影子孤独终老i 提交于 2019-12-24 00:46:59

问题


I have an inbound-channel-adapter that forwards to a bean method that returns null, but since http has to return a response, a 200 is returned. There are cases where I'd like to specify what the return value is, e.g. a 204 and I've tried a bunch of things, but nothing seems to work.

I'm using spring-integration 3.0.2.

Thanks, Justin


回答1:


Yes, set the http_statusCode header in the reply message to 204.

EDIT: (see comments below)

<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>

Assumes the main flow doesn't return a result.

If you want to wait until the flow completes, remove the task executor.

You probably also need a transformer, to transform the payload to "".



来源:https://stackoverflow.com/questions/24147573/is-it-possible-to-return-a-204-from-a-spring-integration-http-inbound-channel-ad

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!