Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring Integration to Iterate through a list of files or records
    text
    copied!<p>I am using spring integration to download files and to process them.</p> <pre><code>&lt;int-sftp:inbound-channel-adapter channel="FileDownloadChannel" session-factory="SftpSessionFactory" remote-directory="/home/sshaji/from_disney/files" filter = "modifiedFileListFilter" local-directory="/home/sshaji/to_disney/downloads" auto-create-local-directory="true" &gt; &lt;integration:poller cron="*/10 * * * * *" default="true"/&gt; &lt;/int-sftp:inbound-channel-adapter&gt; &lt;integration:transformer input-channel="FileDownloadChannel" ref="ErrorTransformer" output-channel="EndChannel"/&gt; &lt;integration:router input-channel="FileErrorProcessingChannel" expression="payload.getErrorCode() &gt; 0"&gt; &lt;integration:mapping value="true" channel="ReportErrorChannel"/&gt; &lt;integration:mapping value="false" channel="FilesBackupChannel"/&gt; &lt;/integration:router&gt; </code></pre> <p>The int-sftp:inbound-channel-adapter is used to download files from sftp server. It downloads about 6 files. all xml files.</p> <p>The transformer iterates all the 6 files and check whether they have an error tag. If there is an error tag then it will set its errorcode as 1. else it will be set a 0.</p> <p>When it comes out of the transformer and goes to the router, i want to send the files whose errorcode is set to 1 to move to a specific folder (Error) and those which has errorcode set to 0 to move to another folder (NoError).</p> <p>Currently the transformer returns a " list fileNames " which contains the errorcode and fileNames of all the 6 files.</p> <p>How can i check the error code for each file using the router? and then map that particular file to a router.</p> <p>Common C Logic for my problem</p> <pre><code>for (int i =0; i&lt;fileNames.lenght();i++) { if(fileNames[i].getErrorCode == 1) { moveToErrorFolder(fileNames[i].getName()); } else { moveToNoErrors(fileNames[i].getName()); } } </code></pre> <p>How can i achieve this using spring integration?. If its not possible, is there any workaround for it?. I hope now its clear. I am sorry for not providing enough details last time.</p> <p>Also in the int-sftp:inbound-channel-adapter i have hard coded the "remote-directory" and "local-directory" fields to a specific folder in the system. can i refer these from a bean property or from a constant value?. I need to configure these values based on config.xml file, is that possible?.</p> <p>I am new to Spring Integration. Please help me. Thanks in Advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload