0

インバウンド側を使用しているときに春の統合でFTPを構成しましたリモートパスからファイルを取得できません。常にローカルシステムパスから読み取ります

ftp-inbound-listen-dynamic.xml

<?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:int="http://www.springframework.org/schema/integration"
xmlns:int-file="http://www.springframework.org/schema/integration/file"
xmlns:int-mail="http://www.springframework.org/schema/integration/mail"
xmlns:int-ftp="http://www.springframework.org/schema/integration/ftp"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
    http://www.springframework.org/schema/integration          http://www.springframework.org/schema/integration/spring-integration.xsd
    http://www.springframework.org/schema/integration/mail  http://www.springframework.org/schema/integration/mail/spring-integration-mail.xsd
    http://www.springframework.org/schema/integration/file  http://www.springframework.org/schema/integration/file/spring-integration-file.xsd
    http://www.springframework.org/schema/beans             http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/util              http://www.springframework.org/schema/util/spring-util.xsd
    http://www.springframework.org/schema/context           http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/integration/ftp http://www.springframework.org/schema/integration/ftp/spring-integration-ftp.xsd">

<context:property-placeholder />

<bean id="ftpSessionFactory"
    class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory">
    <property name="host" value="${ftp.host}" />
    <property name="port" value="${ftp.port}" />
    <property name="username" value="${ftp.username}" />
    <property name="password" value="${ftp.password}" />
    <property name="clientMode" value="0" />
    <property name="fileType" value="2" />
    <property name="bufferSize" value="100000" />
</bean>

<int:channel id="inboundChannel" />

<int-ftp:inbound-channel-adapter id="ftpInbound"
    channel="inboundChannel" session-factory="ftpSessionFactory" charset="UTF-8"
    auto-create-local-directory="true" delete-remote-files="true"
    temporary-file-suffix=".writing" remote-directory="${ftp.remote-directory}"
    local-directory="${ftp.local-directory}" filter="compositeFilter"
    local-filter="localCompositeFilter">
    <int:poller fixed-rate="15000" />
</int-ftp:inbound-channel-adapter>


<bean id="compositeFilter"
    class="org.springframework.integration.file.filters.CompositeFileListFilter">
    <constructor-arg>
        <list>
            <bean
                class="org.springframework.integration.file.filters.AcceptAllFileListFilter" />
            <bean
                class="org.springframework.integration.ftp.filters.FtpRegexPatternFileListFilter">
                <constructor-arg name="pattern"
                    value=".+(\.(?i)(pdf|PDF|csv|CSV|xml|XML))$" />
            </bean>
        </list>
    </constructor-arg>
</bean>

<bean id="localCompositeFilter"
    class="org.springframework.integration.file.filters.CompositeFileListFilter">
    <constructor-arg>
        <list>
            <bean
                class="org.springframework.integration.file.filters.AcceptAllFileListFilter" />
        </list>
    </constructor-arg>
</bean>

<int:chain input-channel="inboundChannel">
    <int:header-enricher>
    </int:header-enricher>

    <int:service-activator ref="ftpListenerService"
        method="onDataReceived" />
</int:chain>

FtpInboundChannelResolver.java

@Inject
private ApplicationContext                                          applicationContext;

private final String                                                XML_PATH        = "/META-INF/integration/dynamic/ftp-inbound-listen-dynamic.xml";


@Value( "${local.ftp.storage.path}" )
private String                                                      localStoragePath ;

ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(
                new String[] { XML_PATH }, false );

        ctx.setParent( applicationContext );

        StandardEnvironment env = new StandardEnvironment( );
        Properties props = new Properties( );


        props.setProperty( "ftp.host", "192.168.84.131" );
        props.setProperty( "ftp.port", "21" );
        props.setProperty( "ftp.username", "user" );
        props.setProperty( "ftp.password", "pass" );
        props.setProperty( "ftp.remote-directory", "/home/user/Public/files" );
        props.setProperty( "ftp.local-directory", localStoragePath );

        PropertiesPropertySource pps = new PropertiesPropertySource( "ftpprops", props );
        env.getPropertySources( ).addLast( pps );
        ctx.setEnvironment( env );
        ctx.refresh( );
        channel = ctx.getBean( "inboundChannel", MessageChannel.class );

FTPListnerService.java

@Service("ftpListenerService")
public class FTPListenerService implements IListenerService {

    private static Logger LOGGER = LoggerFactory.getLogger(FTPListenerService.class);

    @Inject
    private ApplicationContext applicationContext;

    public void onDataReceived( File ftpFile) {

        LOGGER.info("FTP: file received for processing " );
        try{
            // read and delete file
            String fileName = ftpFile.getName();
            byte[] fileContents = FileCopyUtils.copyToByteArray(ftpFile);
            ftpFile.delete();

            LOGGER.error("Data Received :", fileContents);


        }catch(Exception ex){
            LOGGER.error("ERROR: while reading ftp transmitted file", ex);
        }

    }
}

これが私の完全なFTP構成ですが、ローカルディレクトリから読み取ったFTPリモートディレクトリから読み取ることができません

助けてください

4

1 に答える 1

0

ファイルはローカル ディレクトリにコピーされ、メッセージ ペイロードはFileローカル ディレクトリ内のオブジェクトです。ファイルがすでにローカルに存在する場合、再取得されません。

于 2016-05-15T14:13:47.020 に答える