Spring Batch - Spring Integration - outbound-channel-adapter issue -
i have below steps. 1. read files sftp 2. process files , copy local folder 3. read processed file local folder , copy sftp out folder
i able first 2 steps successfully, couldn't achieve third step. using outbound-channel-adapter copy files sftp. below codes.
context.xml
<?xml version="1.0" encoding="utf-8"?> <beans xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns="http://www.springframework.org/schema/beans" xmlns:file="http://www.springframework.org/schema/integration/file" xmlns:int="http://www.springframework.org/schema/integration" xmlns:int-ftp="http://www.springframework.org/schema/integration/ftp" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:batch="http://www.springframework.org/schema/batch" xmlns:context="http://www.springframework.org/schema/context" xmlns:util="http://www.springframework.org/schema/util" xmlns:task="http://www.springframework.org/schema/task" xmlns:int-jdbc="http://www.springframework.org/schema/integration/jdbc" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-4.2.xsd http://www.springframework.org/schema/integration/ftp http://www.springframework.org/schema/integration/ftp/spring-integration-ftp-4.2.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd http://www.springframework.org/schema/integration/file http://www.springframework.org/schema/integration/file/spring-integration-file-4.1.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd http://www.springframework.org/schema/integration/jdbc http://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd"> <bean id="dirscanner" class="org.springframework.integration.file.recursiveleafonlydirectoryscanner" /> <context:property-placeholder location="classpath:batch.properties" /> <context:component-scan base-package="src.main" /> <batch:job id="job1"> <batch:step id="step1" next="step2"> <batch:tasklet ref="myftpgetremotefilestasklet" /> </batch:step> <batch:step id="step2" next="step3"> <batch:tasklet ref="generatefiletasklet" /> </batch:step> <batch:step id="step3"> <batch:tasklet ref="filestoftptasklet" /> </batch:step> </batch:job> <!-- step 1 : read files sftp --> <bean id="myftpgetremotefilestasklet" class="com.getremotefiles"></bean> <!-- step 2 : --> <bean id="generatefiletasklet" class="com.service.createfilestasklet"> <property name="sourcefolder" value="file:${local.directory}"></property> <property name="destfolder" value="file:${local.directory.processed}"></property> <property name="outputchannel" ref="outputchannel" /> </bean> <!-- step 3 : --> <bean id="filestoftptasklet" class="com.service.filestoftp"> <property name="sourcefolder" value="file:${local.directory.processed}"></property> <property name="outputsftpchannel" ref="outputsftpchannel" /> </bean> <int-ftp:inbound-channel-adapter id="ftpinbound" auto-startup="false" local-filter="acceptoncefilelistfilter" channel="receivechannel" session-factory="ftpclientfactory" filename-pattern="*.pdf" auto-create-local-directory="true" delete-remote-files="true" temporary-file-suffix=".writing" remote-directory="${remote.directory.in}" local-directory="file:${local.directory}"> <int:poller fixed-rate="10000" max-messages-per-poll="1" /> </int-ftp:inbound-channel-adapter> <!-- copy generated cmod files internal out folder --> <!-- <int-ftp:outbound-channel-adapter channel="outputchannel" session-factory="ftpclientfactory" remote-directory="${local.directory.processed}"/> --> <int-ftp:outbound-channel-adapter id="ftpoutbound" channel="outputsftpchannel" temporary-file-suffix=".writing" remote-directory="${remote.directory.out}" session-factory="ftpclientfactory"> </int-ftp:outbound-channel-adapter> <!-- ftp session factory sftp details --> <bean id="ftpclientfactory" class="org.springframework.integration.ftp.session.defaultftpsessionfactory"> <property name="host" value="${host}" /> <property name="port" value="${availableserverport}"/> <property name="username" value="${username}" /> <property name="password" value="${password}" /> <property name="clientmode" value="0" /> </bean> <bean id="acceptoncefilelistfilter" class="org.springframework.integration.file.filters.acceptoncefilelistfilter" /> <bean id="jobrepository" class="org.springframework.batch.core.repository.support.mapjobrepositoryfactorybean"> <property name="transactionmanager" ref="transactionmanager" /> </bean> <bean id="transactionmanager" class="org.springframework.batch.support.transaction.resourcelesstransactionmanager" /> <bean id="joblauncher" class="org.springframework.batch.core.launch.support.simplejoblauncher"> <property name="jobrepository" ref="jobrepository" /> </bean> <!-- channel declaration --> <int:channel id="receivechannel"> <int:queue capacity="10000" /> </int:channel> <int:channel id="outputchannel"> <int:queue capacity="10000" /> </int:channel> <int:channel id="outputsftpchannel"> <int:queue capacity="10000" /> </int:channel> <int:channel id="errorchannel"> <int:queue capacity="500" /> </int:channel> <bean id="step" class="org.springframework.batch.core.scope.stepscope" /> <int:poller default="true" fixed-delay="10000" /> </beans> filestoftp.java import java.io.file; import java.io.fileinputstream; import java.util.properties; import org.apache.commons.io.fileutils; import org.apache.commons.logging.log; import org.apache.commons.logging.logfactory; import org.springframework.batch.core.stepcontribution; import org.springframework.batch.core.scope.context.chunkcontext; import org.springframework.batch.core.step.tasklet.tasklet; import org.springframework.batch.repeat.repeatstatus; import org.springframework.core.io.resource; import org.springframework.integration.support.messagebuilder; import org.springframework.messaging.message; import org.springframework.messaging.messagechannel; import org.springframework.util.assert; public class cmodfilestoftp implements tasklet { private static log logger = logfactory.getlog(cmodfilestoftp.class); private resource sourcefolder; private messagechannel outputsftpchannel; @override public repeatstatus execute(stepcontribution contribution, chunkcontext chunkcontext) throws exception { // todo auto-generated method stub file dir = sourcefolder.getfile(); assert.state(dir.isdirectory()); file[] files = dir.listfiles(); system.out.println("size of generated files transfer remote location is"+files.length); (int = 0; < files.length; i++) { string tempfilename = files[i].getname(); file tempfile = new file(sourcefolder.geturl().getpath(),tempfilename); if (tempfile.exists()) { message<file> message = messagebuilder.withpayload(tempfile).build(); try { outputsftpchannel.send(message); } catch (exception e) { system.out.println("could not send file per sftp: " + e); } } system.out.println(string.format("successfully transferred '%s' file sftp out folder ", files[i].getname())); } return repeatstatus.finished; } public resource getsourcefolder() { return sourcefolder; } public void setsourcefolder(resource sourcefolder) { this.sourcefolder = sourcefolder; } public messagechannel getoutputsftpchannel() { return outputsftpchannel; } public void setoutputsftpchannel(messagechannel outputsftpchannel) { this.outputsftpchannel = outputsftpchannel; } }
log info:
executing step: [step1] started ftpinbound file has been transfered from: file1.pdf file has been transfered from: file2.pdf file has been transfered from: file3.pdf file has been transfered from: file4.pdf file has been transfered from: file5.pdf executing step: [step2] entering createindex entering createindex exiting createindex exiting createindex entering createindex entering createindex exiting createindex exiting createindex entering createindex entering createindex exiting createindex exiting createindex entering createindex entering createindex exiting createindex exiting createindex entering createindex entering createindex exiting createindex exiting createindex executing step: [step3] job: [flowjob: [name=job1]] completed following parameters: [{}] , following status: [completed] eml file job completed eml file job completed closing org.springframework.context.support.classpathxmlapplicationcontext@6b1701fd: startup date [thu nov 17 11:03:05 est 2016]; root of context hierarchy stopping beans in phase 1073741823 stopped ftpinbound stopped ftpoutbound stopping beans in phase 0 stopping beans in phase -2147483648 shutting down executorservice 'taskscheduler' though step 3 executed, see file file1 extension of .writing in sftp out folder system.out.println prints below messages transferred 'file1' file sftp out folder transferred 'file2' file sftp out folder transferred 'file3' file sftp out folder transferred 'file4' file sftp out folder transferred 'file5' file sftp out folder
could please let me know missing here ?
Comments
Post a Comment