Annavi
Annavi

Reputation: 151

errorChannel not recognised After Throwing Exception form ChannelInterceptor

I tried to Throw some Exception from ChennelInterceptor.But it's not sending the message to ErrrorChannel i have defined.

Below the snippet.

 <int-file:inbound-channel-adapter id="fileInBound" 
            channel="fileProcessingChannel"
            directory="${file.processing.folder}" 
            prevent-duplicates="true"
            filename-pattern="*.txt">
</int-file:inbound-channel-adapter>
<int:channel id="fileProcessingChannel">
    <int:queue/>
</int:channel>
<!--Setting the Error Channel -->
 <int:header-enricher input-channel="inputchannel" output-channel="testChannel">
    <int:error-channel ref="myErrorChannel" overwrite="true"></int:error-channel>
</int:header-enricher>

<!-- Accepts only the File data Type -->
<int:channel id="testChannel" >
    <int:interceptors>
        <bean class="com.abc.SomeValidationInterceptor"></bean>
    </int:interceptors> 
</int:channel>

<int:channel id="myErrorChannel">
</int:channel>

<int:service-activator input-channel="myErrorChannel" output-channel="nullChannel">
        <bean class="com.abc.MyErrorHandlerEndpoint"></bean>    
</int:service-activator>

Am throwing exception i.e MessagingException from com.abc.SomeValidationInterceptor.And i expect to reach myErrorChannel but it snot reaching myErrorChannel.

Any idea why its not working.Thanks in advance.

Upvotes: 0

Views: 329

Answers (1)

Gary Russell
Gary Russell

Reputation: 174769

It doesn't work that way. You generally should not manipulate the errorChannel header yourself, except in very specialized circumstances.

How are you getting messages into inputChannel.

In general, you should use a gateway of some kind and declare an error-channel on that; letting the framework handle the headers; the exception is caught by the gateway and the ErrorMessage routed appropriately.

Similarly, an error-channel can be defined on the poller for polled endpoints.

Upvotes: 1

Related Questions