2

我在使用 Camel 的 FTP 组件时遇到了很多问题。我正在使用 Apache Camel 2.14.1 和 Apache ServiceMix 5.2.0

问题是每当我尝试进行 FTP/SFTP 传输时都会收到此错误:

org.apache.camel.ResolveEndpointFailedException: 
Failed to resolve endpoint: sftp://user@sftp_url/test?binary=true&fileName=destinationFile.txt 
due to: No component found with scheme: sftp

我确保在 ServiceMix 中正确安装了所需的组件

karaf@pos-interfaces> list | grep camel-
[ 124] [Active     ] [            ] [       ] [   50] camel-core (2.14.1)
[ 125] [Active     ] [Created     ] [       ] [   50] camel-karaf-commands (2.14.1)
[ 126] [Active     ] [            ] [       ] [   50] camel-jms (2.14.1)
[ 132] [Active     ] [            ] [       ] [   50] camel-spring (2.14.1)
[ 133] [Active     ] [Created     ] [       ] [   50] camel-blueprint (2.14.1)
[ 213] [Active     ] [            ] [       ] [   50] camel-http (2.14.1)
[ 214] [Active     ] [            ] [       ] [   50] camel-jetty (2.14.1)
[ 271] [Active     ] [            ] [       ] [   50] camel-exec (2.14.1)
[ 285] [Active     ] [            ] [       ] [   50] camel-quartz2 (2.14.1)
[ 287] [Active     ] [            ] [       ] [   90] camel-jaxb (2.14.1)
[ 572] [Active     ] [            ] [       ] [   50] camel-ftp (2.14.1)
[ 573] [Active     ] [            ] [       ] [   50] camel-jsch (2.14.1)

我什至添加了一些代码来检查“ftp/sftp”组件是否已经在上下文中并且它是否已启动(如果没有,我会强制启动它)。这是日志中打印的内容:

| DEBUG | xtenderThread-56 | RouteBuilder      | ? | sftp component already there...
| DEBUG | xtenderThread-56 | RouteBuilder      | ? | sftp original status...Stopped
| DEBUG | xtenderThread-56 | RouteBuilder      | ? | sftp starting manually...
| DEBUG | xtenderThread-56 | RouteBuilder      | ? | final sftp status...Started

但是,我仍然收到错误...

我发现这篇文章与我有骆驼在注册表中找不到“sftp”组件并关闭的文章有类似的问题,他们说使用OsgiDefaultCamelContext解决了问题,但我认为我们不能使用它,因为我们正在使用SpringCamelContext…或者至少我还没有找到任何文档/示例来更改 spring-context.xml 中的 CamelContext 类

你能请教吗?提前致谢。

[更新] 终于成功了!问题是我这样声明模板:

producerTemplate = getContext().createProducerTemplate();

这样,OSGI 就没有被设置,错误就发生了。但是后来,我用这个更新了我的 camel-context.xml:

<camelContext trace="false" id="camelContext"
    xmlns="http://camel.apache.org/schema/spring">
    <template id="producerTemplate"/>
    <routeBuilder ref="routeBuilder" />
</camelContext>

我的路线构建器是这样的:

@BeanInject("producerTemplate")
private transient ProducerTemplate producerTemplate;

瞧!有效!

希望这对某人有帮助!

4

1 回答 1

0

终于完成了这项工作!问题是我这样声明模板:

producerTemplate = getContext().createProducerTemplate();

这样,OSGI 就没有被设置,错误就发生了。但是后来,我用这个更新了我的 camel-context.xml:

<camelContext trace="false" id="camelContext"
    xmlns="http://camel.apache.org/schema/spring">
    <template id="producerTemplate"/>
    <routeBuilder ref="routeBuilder" />
</camelContext>

我的路线构建器是这样的:

@BeanInject("producerTemplate")
private transient ProducerTemplate producerTemplate;

瞧!有效!

希望这对某人有帮助!

于 2016-08-23T14:36:39.930 回答