Camel SFTP,quartz2组件给出:无法检索文件:由GenericFileOperationFailedException引起,当从sftp轮询多个文件时

时间:2016-04-22 19:38:01

标签: apache-camel camel-ftp

我正在尝试使用下面的驼峰路径和使用quartz2调度程序从sftp位置轮询文件,在轮询了几个文件之后我得到了GenricFileOperationFailedException caused by java.io.IOException: Pipe closed

JaxbDataFormat dataFormat = new JaxbDataFormat();
dataFormat.setContext(JAXBContext.newInstance(MyBean.class));

    from(sftphost + sourcedirpath + 
                          "?password=" + password  
                        + "&username=" + userName  
                        + "&include=" + filePattern
                        + "&localWorkDirectory=" + localWorkingDirectory
                        + "&flatten=true"
                        + "&delete=true"
                        + "&scheduler=quartz2"
                        + "&scheduler.cron=0/45 * * * * ?" 
                        + "&stepwise=false"
                        + "&disconnect=true")
                .onException(Exception.class)
                    .to(sftphost + errdirpath + "?password=" + password + "&username=" + userName+"&disconnect=true")
                    .handled(true)
                    .end()
                .log(LoggingLevel.INFO, "Processing File : ${file:onlyname}").log(LoggingLevel.INFO, "Before Unmarshalling XML").unmarshal(dataFormat)
                .log(LoggingLevel.INFO, "after UnMarshalling the XML").beanRef("service", "processData(${body}, ${file:name})")
                .to(sftphost + processedDirPAth + "?password=" + password + "&username=" + userName+ "&disconnect=true");

只有在使用quartz2 Scheduler时才会遇到此问题。上面的骆驼路线 当我在驼峰路线中使用'& delay = 10000'参数时,它完全正常。

错误Stacktrace:

2016-04-22 10:33:15,634 | WARN  | terface_Worker-1 | SftpConsumer                    ]
    | ?                                     ? | 264 - 1.0.0.SNAPSHOT | Error processing file RemoteFile[/home/source/file_one.XML
    ] due to Cannot retrieve file: /home/source/file_one.XML. Caused by: [org.apache.camel.component.file.GenericFileOperat
    ionFailedException - Cannot retrieve file: /home/source/file_one.XML]
    org.apache.camel.component.file.GenericFileOperationFailedException: Cannot retrieve file: /home/source/file_one.XML
            at org.apache.camel.component.file.remote.SftpOperations.retrieveFileToFileInLocalWorkDirectory(SftpOperations.java:735)[264:myBundle:1.0.0.SNAPSHOT]
            at org.apache.camel.component.file.remote.SftpOperations.retrieveFile(SftpOperations.java:591)[264:myBundle:1.0.0.SNAPSHOT]
            at org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:396)[264:myBundle:1.0.0.SNAPSHOT]
            at org.apache.camel.component.file.remote.RemoteFileConsumer.processExchange(RemoteFileConsumer.java:137)[264:myBundle:1.0.0.SNAPSHOT]
            at org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:211)[264:myBundle:1.0.0.SNAPSHOT]
            at org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:175)[264:myBundle:1.0.0.SNAPSHOT]
            at org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:174)[264:myBundle:1.0.0.SNAPSHOT]
            at org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:101)[264:myBundle:1.0.0.SNAPSHOT]
            at org.apache.camel.pollconsumer.quartz2.QuartzScheduledPollConsumerJob.execute(QuartzScheduledPollConsumerJob.java:59)[264:myBundle:1.0.0.SNAPSHOT]
            at org.quartz.core.JobRunShell.run(JobRunShell.java:202)[264:myBundle
    :1.0.0.SNAPSHOT]
            at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)[264:myBundle:1.0.0.SNAPSHOT]
    Caused by: 4:
            at com.jcraft.jsch.ChannelSftp._get(ChannelSftp.java:1160)[264:myBundle:1.0.0.SNAPSHOT]
            at com.jcraft.jsch.ChannelSftp.get(ChannelSftp.java:1006)[264:myBundle:1.0.0.SNAPSHOT]
            at com.jcraft.jsch.ChannelSftp.get(ChannelSftp.java:984)[264:myBundle
    :1.0.0.SNAPSHOT]
            at org.apache.camel.component.file.remote.SftpOperations.retrieveFileToFileInLocalWorkDirectory(SftpOperations.java:724)[264:myBundle:1.0.0.SNAPSHOT]
            ... 10 more
    Caused by: java.io.IOException: Pipe closed
            at java.io.PipedInputStream.read(PipedInputStream.java:307)[:1.8.0_45]
            at java.io.PipedInputStream.read(PipedInputStream.java:377)[:1.8.0_45]
            at com.jcraft.jsch.ChannelSftp.fill(ChannelSftp.java:2882)[264:myBundle:1.0.0.SNAPSHOT]
            at com.jcraft.jsch.ChannelSftp.header(ChannelSftp.java:2908)[264:myBundle:1.0.0.SNAPSHOT]
            at com.jcraft.jsch.ChannelSftp._get(ChannelSftp.java:1025)[264:myBundle:1.0.0.SNAPSHOT]
            ... 13 more

我没有使用任何其他在骆驼路线中关闭的IO流。

1 个答案:

答案 0 :(得分:0)

这看起来像是目标计算机上SFTP用户的权限问题。有关详细信息,请查看https://winscp.net/eng/docs/sftp_codes#code_4

由于SSL上下文未立即在Camel FTP2组件中配置/初始化,因此可能只会出现延迟,因此您需要在启动前延迟一小段时间才能实现轮询。