File Inbound Channel unable to read file

旧巷老猫 提交于 2019-12-06 05:00:18

I remember working on an app similar to this... we had 2 directories...

\in\ was used for the file transfers... every x minutes, it would check if the file was there. Once the file was present, it would rename it and move it in the \process\ directory.

Were were using scp under aix and it did the job processing very large files.

So I ended up using the method given in http://blog.on-x.com/2010/11/spring-integration-implementation-d%E2%80%99un-scenario-35 but with only one custom filter which inherits AcceptOnceFileListFilter, for some reason I can't get the CompositeFileListFilter working...

public class CustomFileListFilter extends AcceptOnceFileListFilter<File> {

    @Override
    public boolean accept(File file) {

        try {
            FileInputStream stream = new FileInputStream(file);
            stream.close();
        }
        catch (IOException e) {
            log.error("File not readable");
            return false;
        }

        return super.accept(file);
    }

}

I'm still interested in other solutions

i also came with this scenario. any how i used the same logic above to make my code work

    <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:integration="http://www.springframework.org/schema/integration"
    xmlns:file="http://www.springframework.org/schema/integration/file"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/integration
            http://www.springframework.org/schema/integration/spring-integration.xsd
            http://www.springframework.org/schema/integration/file
            http://www.springframework.org/schema/integration/file/spring-integration-file.xsd">

    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>

    <file:inbound-channel-adapter id="filesIn"
                                 directory="D:\SpringPoller\Input" prevent-duplicates="false">
        <integration:poller id="poller" fixed-delay="5000"/>
    </file:inbound-channel-adapter>

    <integration:service-activator input-channel="filesIn"
                                   output-channel="filesOut"
                                   ref="handler"/>

    <file:outbound-channel-adapter id="filesOut"
                                   directory="D:\SpringPoller\Output"
                                   delete-source-files="true"/>

    <bean id="handler" class="dummy.Handler"/>

</beans>



    package dummy;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;


public class Handler {



    public File handleFile(File input) {
        System.out.println("Copying file: " + input.getAbsolutePath() + "with length :" + input.length());

        // check the file is fully available (full file was copied and no part files processed ...
        FileInputStream stream = null;
        try {
            stream = new FileInputStream(input);

            System.out.println("***********  Stream available now");

        }
        catch (IOException e) {
            System.out.println("##########  Stream not available now");
        }
        finally { 
            try {

                stream.close();
            }catch(Exception e) {

            }
        }


        return input;
    }



}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!