我正在尝试使用camel ftp组件从SFTP服务器提取文件并以自定义方式处理它。我能够成功地连接到SFTP服务器并提取该文件,但是exchange主体包含remote file对象,并且该文件包含com.jcraft.jsch.channelsftp$LSentry对象,当我在调试模式下检查该file对象时,它只包含有关该文件的元数据信息。在将文件强制转换为文件时,我遇到了类型转换异常。如何从exchange对象获取该文件以进行进一步的自定义处理。
当我使用文件而不是SFTP时,一切工作都很好。
<camelContext id="SourceContext" xmlns="http://camel.apache.org/schema/spring">
<routeContextRef ref="SourceTranslatorRouteContext" />
<threadPoolProfile customId="true"
id="SourceSplitThreadProfile" maxPoolSize="100" maxQueueSize="0"
poolSize="20" />
<route id="SourceOutWriteConsumerRoute" streamCache="true">
<from id="SourceEndpoint"
uri="sftp:{{SourceFtpHostname}}:22/{{directoryName}}?siteCommand=NAMEFMT
1&stepwise=false&fileName={{fileName}}&password={{SourceFtpPWD}}&username={{SourceFtpUname}}&useList=false&delete=true" />
<!-- <from id="SourceEndpoint" uri="file:{{directoryName}}?fileName={{fileName}}"/> -->
<removeHeaders id="_removeHeaders1" pattern="Camel*" />
<doTry id="_doTry1">
<setProperty id="_setProperty1" propertyName="policySublobGroup">
<simple>{{policySublobGroup}}</simple>
</setProperty>
<split id="_split1" parallelProcessing="true" streaming="true">
<method bean="customSplitter" method="splitPolicy" />
</split>
<doCatch id="_doCatch1">
<exception>java.lang.Exception</exception>
<handled>
<constant>true</constant>
</handled>
<
</doCatch>
</doTry>
</route>
</camelContext>
用于CSV自定义处理的Java方法。
public static List<List<Policy>> splitPolicy(final Exchange exchange) {
// String line = "";
GenericFile file = exchange.getIn().getBody(GenericFile.class);
InputStream is = null;
BufferedReader br = null;
List<List<Policy>> splitList = new ArrayList<List<Policy>>();
try {
is = new FileInputStream((File) file.getFile());
br = new BufferedReader(new InputStreamReader(is));
br.readLine();
for (String line = br.readLine(); line != null; line = br.readLine()) {
String[] Details = line.split(";");
//logic to add splitList
}
} catch (IOException e) {
LOGGER.error("IOException occured in splitPolicy", e);
} catch (Exception e) {
LOGGER.error("Exception occured in splitPolicy", e);
} finally {
try {
is.close();
br.close();
} catch (IOException e) {
LOGGER.error("Error occured in while closing resource in method splitPolicy ", e);
}
}
return splitList;
}
}
例外情况:
04:00:03,236 ERROR (Camel (SOURCESYSTEMContext) thread #43 - sftp://SOURCESYSTEM.company.parentcompany:22/home/company/SOURCESYSTEM/TEST/OUT/MOAPP) Exception occured in splitPolicy: java.lang.ClassCastException: com.jcraft.jsch.ChannelSftp$LsEntry cannot be cast to java.io.File
at com.company.esb.SOURCESYSTEM.CustomSplitter.splitPolicy(CustomSplitter.java:51) [classes:]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.8.0_151]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [rt.jar:1.8.0_151]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.8.0_151]
at java.lang.reflect.Method.invoke(Method.java:498) [rt.jar:1.8.0_151]
at org.apache.camel.component.bean.MethodInfo.invoke(MethodInfo.java:408) [camel-core-2.17.0.redhat-630283.jar:2.17.0.redhat-630283]
at org.apache.camel.component.bean.MethodInfo$1.doProceed(MethodInfo.java:279) [camel-core-2.17.0.redhat-630283.jar:2.17.0.redhat-630283]
at org.apache.camel.component.bean.MethodInfo$1.proceed(MethodInfo.java:252) [camel-core-2.17.0.redhat-630283.jar:2.17.0.redhat-630283]
at org.apache.camel.component.bean.BeanProcessor.process(BeanProcessor.java:177) [camel-core-2.17.0.redhat-630283.jar:2.17.0.redhat-630283]
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:109) [camel-core-2.17.0.redhat-630283.jar:2.17.0.redhat-630283]
at org.apache.camel.component.bean.BeanProcessor.process(BeanProcessor.java:68) [camel-core-2.17.0.redhat-630283.jar:2.17.0.redhat-630283]
at org.apache.camel.language.bean.BeanExpression$InvokeProcessor.process(BeanExpression.java:211) [camel-core-2.17.0.redhat-630283.jar:2.17.0.redhat-630283]
at org.apache.camel.language.bean.BeanExpression.evaluate(BeanExpression.java:126) [camel-core-2.17.0.redhat-630283.jar:2.17.0.redhat-630283]
at org.apache.camel.language.bean.BeanExpression.evaluate(BeanExpression.java:138) [camel-core-2.17.0.redhat-630283.jar:2.17.0.redhat-630283]
at org.apache.camel.processor.Splitter.createProcessorExchangePairs(Splitter.java:113) [camel-core-2.17.0.redhat-630283.jar:2.17.0.redhat-630283]
at org.apache.camel.processor.MulticastProcessor.process(MulticastProcessor.java:231) [camel-core-2.17.0.redhat-630283.jar:2.17.0.redhat-630283]
at org.apache.camel.processor.Splitter.process(Splitter.java:108) [camel-core-2.17.0.redhat-630283.jar:2.17.0.redhat-630283]
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77) [camel-core-2.17.0.redhat-630283.jar:2.17.0.redhat-630283]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:196) [camel-core-2.17.0.redhat-630283.jar:2.17.0.redhat-630283]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:121) [camel-core-2.17.0.redhat-630283.jar:2.17.0.redhat-630283]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:83) [camel-core-2.17.0.redhat-630283.jar:2.17.0.redhat-630283]
at org.apache.camel.processor.TryProcessor.process(TryProcessor.java:113) [camel-core-2.17.0.redhat-630283.jar:2.17.0.redhat-630283]
at org.apache.camel.processor.TryProcessor.process(TryProcessor.java:84) [camel-core-2.17.0.redhat-630283.jar:2.17.0.redhat-630283]
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77) [camel-core-2.17.0.redhat-630283.jar:2.17.0.redhat-630283]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:196) [camel-core-2.17.0.redhat-630283.jar:2.17.0.redhat-630283]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:121) [camel-core-2.17.0.redhat-630283.jar:2.17.0.redhat-630283]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:83) [camel-core-2.17.0.redhat-630283.jar:2.17.0.redhat-630283]
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:109) [camel-core-2.17.0.redhat-630283.jar:2.17.0.redhat-630283]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:63) [camel-core-2.17.0.redhat-630283.jar:2.17.0.redhat-630283]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:171) [camel-core-2.17.0.redhat-630283.jar:2.17.0.redhat-630283]
at org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:454) [camel-core-2.17.0.redhat-630283.jar:2.17.0.redhat-630283]
at org.apache.camel.component.file.remote.RemoteFileConsumer.processExchange(RemoteFileConsumer.java:137) [camel-ftp-2.17.0.redhat-630262.jar:2.17.0.redhat-630262]
at org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:226) [camel-core-2.17.0.redhat-630283.jar:2.17.0.redhat-630283]
at org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:190) [camel-core-2.17.0.redhat-630283.jar:2.17.0.redhat-630283]
at org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:175) [camel-core-2.17.0.redhat-630283.jar:2.17.0.redhat-630283]
at org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:102) [camel-core-2.17.0.redhat-630283.jar:2.17.0.redhat-630283]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [rt.jar:1.8.0_151]
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [rt.jar:1.8.0_151]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [rt.jar:1.8.0_151]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [rt.jar:1.8.0_151]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [rt.jar:1.8.0_151]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [rt.jar:1.8.0_151]
at java.lang.Thread.run(Thread.java:748) [rt.jar:1.8.0_151]
只需要求Camel将消息正文作为输入流或字符串等
exchange.getIn().getBody(InputStream.class);
python-magic
gulp 暴露了 src() 和 dest() 方法用于处理计算机上存放的文件。 src() 接受 glob 参数,并从文件系统中读取文件然后生成一个 Node 流(stream)。它将所有匹配的文件读取到内存中并通过流(stream)进行处理。 由 src() 产生的流(stream)应当从任务(task)中返回并发出异步完成的信号,就如 创建任务(task) 文档中所述。 const { sr
本文向大家介绍php include类文件超时问题处理,包括了php include类文件超时问题处理的使用技巧和注意事项,需要的朋友参考一下 最近发现,php运行自动加载类函数时总是超时,跟踪php慢查询日志,发现程序卡在了include某个类文件时竟然超时。 初步定位是io响应超时,硬盘读取有问题。 通过几个命令来定位: iostat -d -x -k 1 10 //
我正在处理IDE中制作一个Java处理项目,并希望将其传播到多个PDE(处理源代码)文件中。 我无法使用导入将Java处理源代码文件导入为Java类文件。 <代码>配置。pde <代码>项目。pde 返回导入项目/配置无法解析 分别为。 我必须先编译PDE文件吗?是否可以将处理IDE设置为每次运行都自动执行? 太长,读不下去了 拥有此项目文件夹: 如何使用配置中的函数和变量。项目中的pde。pde
Web开发中对于文本处理是非常重要的一部分,我们往往需要对输出或者输入的内容进行处理,这里的文本包括字符串、数字、Json、XMl等等。Go语言作为一门高性能的语言,对这些文本的处理都有官方的标准库来支持。而且在你使用中你会发现Go标准库的一些设计相当的巧妙,而且对于使用者来说也很方便就能处理这些文本。本章我们将通过四个小节的介绍,让用户对Go语言处理文本有一个很好的认识。 XML是目前很多标准接
本文向大家介绍emacs 文件处理,包括了emacs 文件处理的使用技巧和注意事项,需要的朋友参考一下 示例 用相同的文件名重新保存打开的文件(保存): C-x C-s 写为filename(另存为): C-x C-wfilename 新文件名将在迷你缓冲区中提示。 创建新文件或加载现有文件(新建/加载): C-x C-ffilename 这里的助记符为f表示文件。系统将提示您在迷你缓冲区中输