我正在使用Apache Camel使用sftp从服务器中提取文件。我的代码是从
接收的SFTP://示例.com:22 / DEV139 /上传/白杨用户名=管理员&安培;密码=管理员&安培;二进制=真安培;断开=真安培;删除=真
它可以成功从这个目录中获取文件,因为我可以在日志中看到文件内容,但它会抛出以下异常。
2017-11-06 16:18:42,498 |错误| || FromAlamoSFTP => [msgtyp:AlamoCSV msgdst:CDX] || java.lang.IllegalStateException:无效的BundleContext。 在org.apache.felix.framework.BundleContextImpl.checkValidity(BundleContextImpl.java:514) 在org.apache.felix.framework.BundleContextImpl.getBundle(BundleContextImpl.java:112) 在org.apache.camel.core.osgi.OsgiClassResolver.resolveClass(OsgiClassResolver.java:58) at org.apache.camel.component.bean.BeanHelper.isAssignableToExpectedType(BeanHelper.java:121) 在org.apache.camel.component.bean.BeanInfo.matchMethod(BeanInfo.java:1074) at org.apache.camel.component.bean.BeanInfo.removeNonMatchingMethods(BeanInfo.java:999) 在org.apache.camel.component.bean.BeanInfo.chooseMethod(BeanInfo.java:566) at org.apache.camel.component.bean.BeanInfo.createInvocation(BeanInfo.java:254) 在org.apache.camel.component.bean.BeanInfo.createInvocation(BeanInfo.java:185) 在org.apache.camel.component.bean.BeanProcessor.process(BeanProcessor.java:159) 在org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77) at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:468) at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:196) 在org.apache.camel.processor.Pipeline.process(Pipeline.java:121) 在org.apache.camel.processor.Pipeline.process(Pipeline.java:83) 在org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:109) 在org.apache.camel.processor.Pipeline.process(Pipeline.java:63) at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:171) 在org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:454) 在org.apache.camel.component.file.remote.RemoteFileConsumer.processExchange(RemoteFileConsumer.java:137) 在org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:226) 在org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:190) 在org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:175) 在org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:102) at java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) at java.util.concurrent.ScheduledThreadPoolExecutor $ ScheduledFutureTask.access $ 301(ScheduledThreadPoolExecutor.java:180) at java.util.concurrent.ScheduledThreadPoolExecutor $ ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) 在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:624) 在java.lang.Thread.run(Thread.java:748)
我的守则如下。
public class FromAlamoRouteBuilder extends RouteBuilder implements
InitializingBean, DisposableBean {
@EnforceInitialization
private String DEAD_LETTER_MQ = "";
@EnforceInitialization
private String ALAMO_SFTP_SOURCE;
@EnforceInitialization
private String DESTINATION_QUEUE;
@EnforceInitialization(preventZero = false)
private int exceptionMaximumRedeliveries;
@EnforceInitialization(preventZero = false)
private int exceptionMaximumRedeliveriesDelay;
public void configure() throws Exception {
onException(Exception.class)
.handled(true)
.retriesExhaustedLogLevel(LoggingLevel.ERROR)
.retryAttemptedLogLevel(LoggingLevel.WARN)
.maximumRedeliveries((int) exceptionMaximumRedeliveries)
.redeliveryDelay((int) exceptionMaximumRedeliveriesDelay)
.bean("logging", "error(*, '${exception.stacktrace}')")
.to(DEAD_LETTER_MQ)
.stop();
/*
* The exchange body is expected to be an Alamo CSV file
*/
from(ALAMO_SFTP_SOURCE)
.routeId("FromAlamoSFTP")
.setExchangePattern(ExchangePattern.InOnly)
.bean("logging", "info(*, 'Received message " + ALAMO_SFTP_SOURCE + "[${body}]')")
.setHeader(MsgHdr.MESSAGE_TYPE, constant("AlamoCSV"))
.setHeader(MsgHdr.MESSAGE_DESTINATION, constant("CDX"))
.bean("logging", "info(*, 'Attempting to place Alamo msg on DESTINATION QUEUE " + DESTINATION_QUEUE + "')")
.to(DESTINATION_QUEUE)
.bean("logging", "info(*, 'Successfully placed Alamo msg on " + DESTINATION_QUEUE + "')");
}
public void setDeadLetterQueue(String dEAD_LETTER_MQ) {
DEAD_LETTER_MQ = dEAD_LETTER_MQ;
}
public void setExceptionMaximumRedeliveries(int exceptionMaximumRedeliveries) {
this.exceptionMaximumRedeliveries = exceptionMaximumRedeliveries;
}
public void setExceptionMaximumRedeliveriesDelay(
int exceptionMaximumRedeliveriesDelay) {
this.exceptionMaximumRedeliveriesDelay = exceptionMaximumRedeliveriesDelay;
}
public void setDestinationQueue(String queue){
this.DESTINATION_QUEUE = queue;
}
public void setAlamoSftpSource(String bcRelease){
this.ALAMO_SFTP_SOURCE = bcRelease;
}
public void afterPropertiesSet() throws Exception {
System.out.println("FromAlamoRouteBuilder is starting up");
FieldInitialization.checkAllFields(this);
}
public void destroy() throws Exception {
System.out.println("FromAlmoRouteBuilder is shutting down");
}
}
答案 0 :(得分:0)
我找到了解决这个问题的方法。服务器配置中的错误不是与我的代码相关的错误。感谢大家的帮助