TarasIw
TarasIw

Reputation: 31

Renaming the original file when it's handled successfully by ftp adapter

I have the following Spring Integration configuration:

@Bean
public IntegrationFlow myFlow() {
    return IntegrationFlows.from(Files.inboundAdapter(new File(inputDir))
                    .patternFilter("*.csv"),
            poller -> poller.poller(pm -> pm.cron(cronExpression)))
            .transform(Transformers.fileToByteArray())
            .handleWithAdapter(adapters -> adapters.ftp(ftpSessionFactory())
                    .remoteDirectory(remoteDir))
            .get();
} 

It's working properly but how can I rename the original file to mark it as processed when the ftp adapter has been successful?

Upvotes: 1

Views: 715

Answers (1)

TarasIw
TarasIw

Reputation: 31

This can be done using ExpressionEvaluatingRequestHandlerAdvice. In xml config it looks like:

<int-ftp:outbound-channel-adapter
    channel="inputChannel"
    session-factory="mockSessionFactory"
    remote-directory="foo">
    <int-ftp:request-handler-advice-chain>
        <bean class="org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice">
            <property name="onSuccessExpression" value="payload.delete()" />
            <property name="successChannel" ref="afterSuccessDeleteChannel" />
            <property name="onFailureExpression" value="payload.renameTo(new java.io.File(payload.absolutePath + '.failed.to.send'))" />
            <property name="failureChannel" ref="afterFailRenameChannel" />
        </bean>
    </int-ftp:request-handler-advice-chain>
</int-ftp:outbound-channel-adapter>

Upvotes: 1

Related Questions