2

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

Justin Miller
  • 757
  • 2
  • 8
  • 19

1 Answers1

2

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

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • Will that work even with an inbound-channel-adapter? A channel adapter doesn't inherently generate a reply -- an http one will only because the protocol requires it. So how would I do this? I've seen others reference a header-enricher, but again, due to the nature of an inbound channel adapter, that doesn't seem possible. – Justin Miller Jun 13 '14 at 18:27
  • Sorry - misread your question - you would have to use the gateway to return a custom response. If you want to send it immediately and not wait for the downstream process to complete, use a pub-sub channel with task executor - the main flow will run async and the second subscriber to the pub-sub channel can be a simple header-enricher. I will edit my answer with details. – Gary Russell Jun 13 '14 at 19:04
  • Got it. Thanks for the response! For the sake of conversation, that's about the same amount of config/lines of code as if I had just written a controller and used a MessagingGateway. Do you think there's any advantage to the XML vs Java in this instance? It would be a nice feature to be able to specify the response code as an attribute of the inbound-channel-adapter rather than the above config. – Justin Miller Jun 14 '14 at 18:39
  • The controller route is probably simpler for folks who don't mind writing a bit of Java. That said, having a `status-code-expression` on the inbound adapter is not a bad idea; feel free to open a [New Feature JIRA Issue](https://jira.spring.io/browse/INT). – Gary Russell Jun 14 '14 at 18:55