1
votes

How to use filtering or return from a chain while using enricher pattern

Here is my scenario I am using enricher pattern to retrieve data from a request channel and then use to enrich the payload. The request channel will call multipe webservices to retreive the data. Need to call the second webservice only if the first one has a valid data. If not I need to return to the enricher. When the filter happens I get this exception org.springframework.integration.handler.ReplyRequiredException: No reply produced by handler

Is my message flow correct or need to add something else ?

    <si:enricher id="enricher" input-channel="channelone"
request-channel="retrieveDataChannel" output-channel="outputChannel" >
    <si:property name="amount"    expression="payload.amount"/>

</si:enricher>


<si:chain id="dataChain" input-channel="retrieveDataChannel"  >
    <si:header-enricher >
        <si:header name="Content-Type" value="application/json" />
    </si:header-enricher>   


    <si-http:outbound-gateway id="Gateway1" 
                       url="http://$webservice{host}"                                               
                       http-method="POST" 
                       rest-template="restTemplate"
                       expected-response-type="com.xxx.response.Response1">
    </si-http:outbound-gateway>     

    <si:filter expression="payload.amount lt 30"  />



    <si-http:outbound-gateway id="Gateway2" 
                       url="http://$webservice{host}"                                               
                       http-method="POST" 
                       rest-template="restTemplate"
                       expected-response-type="com.xxx.response.AmountResponse">
    </si-http:outbound-gateway>         


</si:chain> 
1

1 Answers

0
votes

You can't just add a <filter/> in a chain if you are in a request/reply flow; the enricher will wait forever for a reply.

The easiest would be to move the second gateway out of the chain and make the last component of the chain a <router/> and route to the gateway when the data is good and some error-handling service that will return some error result otherwise.