Making SFTP outbound gate way pollable for mput operation

爷,独闯天下 提交于 2019-12-08 07:35:26

问题


I am using spring integration for SFTP operation. I need to poll the files with directory structure from a certain location of SFTP and also put files with directory structure from local directory to certain SFTP location. I have added faking inbound channel adapter fro mget & mput opeation. While running Junit , some junk message files are generated in target SFTP location of mput operation. And ,after war is deployed no file is getting transferred to mget local directory. The mput and mget operation will started once war is deployed in server Please advice the configuration. This queston is in refrence to SFTP inbound adapter configuration for multiple remote directory using single adapter and single channel

Sftp-outboundgatewaycontext.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-sftp="http://www.springframework.org/schema/integration/sftp"
    xmlns:int="http://www.springframework.org/schema/integration"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/integration/sftp
     http://www.springframework.org/schema/integration/sftp/spring-integration-sftp-4.1.xsd
        http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-4.1.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
         http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-4.1.xsd">


    <context:property-placeholder order="0"
        location="classpath:/sftpuser.properties" ignore-unresolvable="true" />
    <context:property-placeholder order="1"
        location="classpath:/sftpfile.properties" ignore-unresolvable="true" />
    <bean id="sftpServerConfig" class="com.iux.ieg.sftp.SftpConfigurator" />




    <bean id="sftpSessionFactory"
        class="org.springframework.integration.file.remote.session.CachingSessionFactory">
        <constructor-arg ref="defaultSftpSessionFactory" />
    </bean>

    <bean id="defaultSftpSessionFactory"
        class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory">
        <property name="host" value="${sftp.host}" />
        <property name="port" value="${sftp.port}" />
        <property name="user" value="${sftp.username}" />
        <property name="privateKey" value="${private.keyfile}" />
        <property name="privateKeyPassphrase" value="${passphrase}" />
    </bean>

    <int:channel id="outputmget">
        <int:queue />

    </int:channel>

    <int:channel id="outputmput">
        <int:queue />

    </int:channel>

<int:inbound-channel-adapter channel="inboundMGetRecursive"
    expression="''">
    <int:poller fixed-rate="1000" max-messages-per-poll="10" /> 
</int:inbound-channel-adapter>

<int:inbound-channel-adapter channel="inboundMPutRecursive" expression="''">
    <int:poller fixed-rate="1000" max-messages-per-poll="10" /> 
</int:inbound-channel-adapter>  





    <int:channel id="inboundMGetRecursive" />

    <int-sftp:outbound-gateway session-factory="sftpSessionFactory"
        request-channel="inboundMGetRecursive" command="mget" expression="payload"
        mode="REPLACE" command-options="-R"

        local-directory-expression="@sftpServerConfig.targetLocalDirectory+ #remoteDirectory"

        reply-channel="outputmget">
<!-- local-filename-generator-expression="#remoteFileName.replaceFirst('sftpSource', 'localTarget')" -->

    </int-sftp:outbound-gateway>




    <int:channel id="inboundMPutRecursive" />

    <int-sftp:outbound-gateway session-factory="sftpSessionFactory"
        request-channel="inboundMPutRecursive" command="mput" command-options="-R"
        auto-create-directory="true" filename-pattern="*.txt" expression="payload"
        local-directory="@SftpServerConfig.mPutLocalDir+'/'"
        remote-directory="sftpTarget" reply-channel="outputmput">

    </int-sftp:outbound-gateway>




</beans>

**Javafile:SftpConfigurator.java**

package com.iux.ieg.sftp;



import java.io.File;

/**

 */
public class SftpConfigurator  {





    private volatile File targetSftpDirectory;

    private volatile File sourceLocalDirectory;

    private volatile File targetLocalDirectory;
    private volatile File mPutLocalDir;

    public File getmPutLocalDir() {
        return mPutLocalDir;
    }



    public void setmPutLocalDir(File mPutLocalDir) {
        this.mPutLocalDir = mPutLocalDir;
    }



    public File getTargetLocalDirectory() {
        return targetLocalDirectory;
    }



    public void setTargetLocalDirectory(File targetLocalDirectory) {
        this.targetLocalDirectory = targetLocalDirectory;
    }



    public File getTargetSftpDirectory() {
        return targetSftpDirectory;
    }



    public void setTargetSftpDirectory(File targetSftpDirectory) {
        this.targetSftpDirectory = targetSftpDirectory;
    }



    public File getSourceLocalDirectory() {
        return sourceLocalDirectory;
    }



    public void setSourceLocalDirectory(File sourceLocalDirectory) {
        this.sourceLocalDirectory = sourceLocalDirectory;
    }







    public SftpConfigurator() {
        this.targetSftpDirectory = new File("/u01/IIP/iipuser/Java/test1") ;
        this.sourceLocalDirectory = new File("D:\\sourceforsftp");
        this.targetLocalDirectory = new File("D:\\sftplocalfolder");
        this.mPutLocalDir=new File("D:\\sourceforsftp");
    }


}

回答1:


It is not at all clear what you are asking. Phrases like "some junk" are useless. You should be able to debug this application by turning on DEBUG logging and track the messages through the flow.




回答2:


MPUT is end-user operation. What is the reason of inbound-channel-adapter for such an operation? You should send local directory as a message payload to PUT all files to the SFTP. Right now your config does not make sence.



来源:https://stackoverflow.com/questions/28128049/making-sftp-outbound-gate-way-pollable-for-mput-operation

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