Craig Archer
Craig Archer

Reputation: 71

Spring integration http:inbound-channel-adapter error-channel

I recently update from Spring Integration 4.1.3 to 4.2.6 and noticed that I started getting a 500 response from an http:inbound-gateway. Upon investigation this was due to an empty reply and the gateway interpreting this as a timeout in MessagingGatewaySupport

if (reply == null && this.errorOnTimeout) {

This makes sense so I changed this to an http:inbound-channel-adapter and it solves this problem, but then the error handling doesn't behave as expected.

I previously had and error-channel on the gateway with

<int-http:inbound-gateway id="inboundGateway" request-channel="httpInChannel" reply-channel="httpResponseChannel" path="/**/status*" supported-methods="POST" error-channel="httpErrorChannel"/>
<int:chain input-channel="httpInChannel" output-channel="serviceChannel">
...
</int:chain>
<int:chain input-channel="httpErrorChannel">
    <int:header-enricher>
        <int:header name="http_statusCode" value="500" />
    </int:header-enricher>
    <int:transformer expression="payload.localizedMessage" />
</int:chain>
<int:service-activator input-channel="serviceChannel" ref="someController" method="someVoidMethod"/>

I suspected it may not work but I modified this slightly to

<int-http:inbound-channel-adapter id="inboundAdapter" channel="httpInChannel" path="/**/status*" supported-methods="POST" error-channel="httpErrorChannel"/>
<int:chain input-channel="httpInChannel" output-channel="serviceChannel">
    ...
</int:chain>
<int:chain input-channel="httpErrorChannel">
    <int:header-enricher>
        <int:header name="http_statusCode" value="500" />
    </int:header-enricher>
    <int:transformer expression="payload.localizedMessage" />
</int:chain>
<int:service-activator input-channel="serviceChannel" ref="someController" method="someVoidMethod"/>

Now, it works fine for a normal valid POST request, but if I send an invalid message that errors I get a 500 response with full error stack in response (have tried changing the status code in the header enricher too). The error is

org.springframework.messaging.core.DestinationResolutionException: no output-channel or replyChannel header available

which makes sense as the error-channel does not have an output (although it doesn't in the docs either http://docs.spring.io/spring-integration/docs/4.3.0.RELEASE/reference/htmlsingle/#http-response-statuscode). Is there a way to change the error response for the inbound adapter in a similar way to that of the gateway?

Upvotes: 1

Views: 1268

Answers (1)

Gary Russell
Gary Russell

Reputation: 174554

I think it's a bug, please open a JIRA Issue.

As a work around, in the main flow, just after the adapter, add a mid-flow gateway...

<int:service-activator ref="gw" input-channel="httpInChannel" >

<int:gateway id="gw" error-channel="httpErrorChannel"
     default-request-channel="nextChannelInMainFlow" default-reply-timeout="0" />

The gateway is like a try/catch block around the flow.

The reply timeout is important since you do not expect a reply.

Upvotes: 1

Related Questions