Search code examples
spring-integration

how to delete local file in ftp inbound-channel-adapter of Spring integration


I have a integration case that get xml payload from FTP then use http outbound channel to sent the payload to webservice, ftp inbound-channel-adapter has a mandatory attribute named local-directory, remote ftp files will be downloaded here, however when I restart, seems all files in local-directory will be handled again, may I know how to avoid this? One possible way is to delete local file in ftp inbound-channel-adapter, how to do it, can you advise?

thanks

My Spring integration configurations

<ftp:inbound-channel-adapter
        channel="requestChannel"
        session-factory="ftpClientSessionFactory"
        remote-directory="/outbound"
        local-directory="/temp"
        auto-create-local-directory="true"
        delete-remote-files="false"
        filename-pattern="*.xml"
        temporary-file-suffix=".writing">
    <int:poller fixed-delay="5000" max-messages-per-poll="10"/>
</ftp:inbound-channel-adapter>


<int:chain id="inboundChain" input-channel="requestChannel" output-channel="replyChannel">

    <int:transformer ref="xmlToJsonTransformer" />
    <int:transformer ref="jsonToMapTransformer" />
    <int:header-enricher>
        <int:header name="Content-Type" value="application/json" overwrite="true"/>
    </int:header-enricher>
    <http:outbound-gateway  expected-response-type="java.lang.String"
                           url="http://localhost:8080/postService/postupdate"
                           http-method="POST"
                           extract-request-payload="true"
                            request-factory="requestFactory">
    </http:outbound-gateway>
</int:chain>

Solution

  • Add an ExpressionEvaluatingRequestHandlerAdvice to the outbound gateway to remove the file. See the Expression Evaluating Advice Demo in the retry-and-more sample for an example - it removes or renames the file, depending on success or failure.