Spring-Camel.How 从 sftp 读取文件(org.apache.camel.ResolveEndpointFailedException:无法解析端点:)

Spring-Camel.How to read files from sftp (org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint:)

首先,我在本地安装了 sftp 服务器,我可以使用按位 ssh 客户端连接到它:

我的凭据:

登录:tester
密码:password

sftp 文件夹如下所示:

然后我写了下面的代码:

 @PostConstruct
    public void init() {
        from("sftp://tester@localhost:22/myFolder?password=password&username=tester")
                .log("msg: ${body}")
                .process(exchange -> {
                    System.out.println(exchange.getIn().getBody());
                });
    }

但是当我尝试启动应用程序时,我在日志中看到:

org.apache.camel.RuntimeCamelException: org.apache.camel.FailedToCreateRouteException: Failed to create route route1: Route(route1)[[From[sftp://tester@localhost:22/myFolder?pass... because of Failed to resolve endpoint: sftp://tester@localhost:22/myFolder?password=password&username=tester due to: No component found with scheme: sftp
    at org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1831) ~[camel-core-2.20.0.jar:2.20.0]
    at org.apache.camel.spring.SpringCamelContext.start(SpringCamelContext.java:136) ~[camel-spring-2.20.0.jar:2.20.0]
    at org.apache.camel.spring.SpringCamelContext.onApplicationEvent(SpringCamelContext.java:174) ~[camel-spring-2.20.0.jar:2.20.0]
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:383) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:337) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:882) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:144) ~[spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:545) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
    at SpringBootCamelIntegrationApplication.main(SpringBootCamelIntegrationApplication.java:9) [classes/:na]
Caused by: org.apache.camel.FailedToCreateRouteException: Failed to create route route1: Route(route1)[[From[sftp://tester@localhost:22/myFolder?pass... because of Failed to resolve endpoint: sftp://tester@localhost:22/myFolder?password=password&username=tester due to: No component found with scheme: sftp
    at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:209) ~[camel-core-2.20.0.jar:2.20.0]
    at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:1135) ~[camel-core-2.20.0.jar:2.20.0]
    at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:3714) ~[camel-core-2.20.0.jar:2.20.0]
    at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:3428) ~[camel-core-2.20.0.jar:2.20.0]
    at org.apache.camel.impl.DefaultCamelContext.access[=14=]0(DefaultCamelContext.java:208) ~[camel-core-2.20.0.jar:2.20.0]
    at org.apache.camel.impl.DefaultCamelContext.call(DefaultCamelContext.java:3236) ~[camel-core-2.20.0.jar:2.20.0]
    at org.apache.camel.impl.DefaultCamelContext.call(DefaultCamelContext.java:3232) ~[camel-core-2.20.0.jar:2.20.0]
    at org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:3255) ~[camel-core-2.20.0.jar:2.20.0]
    at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:3232) ~[camel-core-2.20.0.jar:2.20.0]
    at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61) ~[camel-core-2.20.0.jar:2.20.0]
    at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:3155) ~[camel-core-2.20.0.jar:2.20.0]
    at org.apache.camel.spring.SpringCamelContext.start(SpringCamelContext.java:133) ~[camel-spring-2.20.0.jar:2.20.0]
    ... 15 common frames omitted
Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: sftp://tester@localhost:22/myFolder?password=password&username=tester due to: No component found with scheme: sftp
    at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:756) ~[camel-core-2.20.0.jar:2.20.0]
    at org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:80) ~[camel-core-2.20.0.jar:2.20.0]
    at org.apache.camel.model.RouteDefinition.resolveEndpoint(RouteDefinition.java:219) ~[camel-core-2.20.0.jar:2.20.0]
    at org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:115) ~[camel-core-2.20.0.jar:2.20.0]
    at org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:121) ~[camel-core-2.20.0.jar:2.20.0]
    at org.apache.camel.model.FromDefinition.resolveEndpoint(FromDefinition.java:69) ~[camel-core-2.20.0.jar:2.20.0]
    at org.apache.camel.impl.DefaultRouteContext.getEndpoint(DefaultRouteContext.java:97) ~[camel-core-2.20.0.jar:2.20.0]
    at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1278) ~[camel-core-2.20.0.jar:2.20.0]
    at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:204) ~[camel-core-2.20.0.jar:2.20.0]
    ... 26 common frames omitted

我做错了什么?

P.S. 我正在阅读 this doc

我也尝试禁用防火墙 - 没有帮助

我添加后它正在运行

compile group: 'org.apache.camel', name: 'camel-ftp-starter', version: '2.20.0'

build.gradle 文件

您日志中的错误消息指出了根本原因:缺少 (s)ftp-组件的 jar 文件。
您需要将 camel-ftp-2.20.jar (对于 ftp-stuff)和 jsch-0.1.54.jar (对于 ssh-stuff)添加到类路径 -或者让一些构建工具为您完成。

添加依赖到项目后成功

compile group: 'org.apache.camel', name: 'camel-ftp', version: camelVersion