3

I have an HTTP inbound channel adapter so configured:

<int-http:inbound-channel-adapter id="/api/requests"
    channel="httpRequestsChannel"
    path="/requests"
    supported-methods="POST,OPTIONS">
    <int-http:cross-origin allow-credentials="false" allowed-headers="*" origin="*" />
</int-http:inbound-channel-adapter>

I'd like to make it reply 201 to POST requests and 200 to others (i.e. OPTIONS), but none of:

  • headers.get('http_requestMethod').equals(&quot;POST&quot;) ? 201 : 200
  • :headers[http_requestMethod].equals(&quot;POST&quot;) ? 201 : 200
  • &quot;POST&quot;.equals(:headers['http_requestMethod']) ? 201 : 200

for the status-code-expression attribute worked, most of them end in a failed context initialization with:

IllegalStateException: No node

Am I using the wrong syntax here or those details aren't available at that stage?

I've seen this question where a gateway is suggested, but I'd like to stick with the adapter for now.

watery
  • 5,026
  • 9
  • 52
  • 92

1 Answers1

2

That expression doesn't get access to the requestMessage. However it really may make sense. Feel free to raise a JIRA on the matter.

As a fix for your problem I would suggest to configure it like this expression:

status-code-expression="T(org.springframework.web.context.request.RequestContextHolder).requestAttributes.request.method.equals('POST') ? 201 : 200"
Artem Bilan
  • 113,505
  • 11
  • 91
  • 118