survivor
survivor

Reputation: 37

Spring Integration filter

in my program, there's request to an API and then message in the incoming channel is stored to a file. My problem is I get some kind of error in my payload for some request. I want to store such error file in another directory. How can I add a filter expression, so that such payload is stored in another directory. My code is:

<int:chain input-channel="abcconnect">
        <int:filter id="errorout" expression="payload.containsKey('errorCode')"/>
        <file:outbound-channel-adapter 
            id="apiResponseWriter" 
            directory="${error.path}"
            filename-generator-expression="'abc-' + T(java.lang.System).currentTimeMillis() + '.json'"
            delete-source-files="false" />
    </int:chain>

The error in the payload file is: {"TwitterApi":{"errorCode":400,"errorMsg":"beginTime or endTime is later than now(1472041145)","success":false,"cost":11,"params":

Upvotes: 2

Views: 4338

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121262

The filter lets the message to pass and go ahead in the flow if its predicate returns true. In your case it looks like messages with the errorCode should go down the flow.

So, I guess you have to negate the expression and also add discard-channel to let the false message to be send to different flow for analyze, processing or storing to a different file like your requirement.

Upvotes: 3

Related Questions