I've searched the forums and the documentation but could not find any answer to my question there. We're using Spring Integration 2.0.5.RELEASE.
Anywhere an exception occurs in our application, we want the exception to go to the "transform-error-to-response" channel where it is transformed into a proper response message and returned to the user.
To make this possible we set the error-channel on the very first gateway call used for incoming requests, and then never set an error-channel further down the flow like below:
However, when an exception occurs in the flow of "foo-channel", the exception does not go to the "transform-error-to-response" channel defined as error channel in the first error call. Instead the flow goes to some other, unknown error channel (not the default errorChannel either).Code:<chain input-channel="incoming-requestChannel"> <gateway request-channel="service1-channel" error-channel="transform-error-to-response" /> </chain> <chain id="Service1-chain" input-channel="service1-channel" > <gateway request-channel="performValidation-Channel" /> <header-enricher> <header name="request" expression="payload" /> </header-enricher> <recipient-list-router apply-sequence="true" > <recipient channel="call-foo-service" /> <recipient channel="call-bar-service" /> </recipient-list-router> </chain> <chain id="performValidation-chain" input-channel="performValidation-Channel" > <service-activator ref="inputValidator" ></service-activator> </chain> <chain input-channel="call-foo-service" output-channel="handle-foo-result"> <gateway request-channel="foo-channel"> </chain>
To get the error to reach the "transform-error-to-response" channel as intended, we have to add an errorChannel to the gateway call to "foo-channel" which has a call to a service activator which simply re-throws the exception:
Code:<chain input-channel="call-foo-service" output-channel="handle-foo-result"> <gateway request-channel="foo-channel" error-channel="propagate-exception"> </chain> <chain input-channel="propagate-exception"> <service-activator method="propagateErrorMessage"> <beans:bean class="com.example.errorhandling.ErrorPropagator"/> </service-activator> </chain>So my question is: Why is this extra error-channel which re-throws the error needed? My understanding was that since the error-channel is initially set to "transform-error-to-response" and then never overwritten, this would be the channel used when any exception occurs downstream.Code:public class ErrorPropagator { public void propagateErrorMessage(Message<MessagingException> exceptionMsg) throws MessagingException{ MessagingException msgExp = exceptionMsg.getPayload(); throw msgExp; } }


Reply With Quote
