Apache Camel - How to set a private key in a dinamic sftp endpoint

◇◆丶佛笑我妖孽 提交于 2019-12-13 03:34:56

问题


Using Java DSL, I have a route in which I poll a file in an SFTP server using the file name set in the message headers

from("direct:download")
        .pollEnrich()
        .simple("sftp://my.host:22/folder/?username=foo&fileName=${header.CamelFileName}")
        .to("file://state/downloaded");

The sftp endpoint needs to have set a private key. Usually something like this suffices:

        endpoint("sftp://my.host:22/folder/?username=foo&fileName=my_file_explicitly_written_here", SftpEndpoint.class).getConfiguration().setPrivateKey(getSshPrivateKey());

However, I see no way to "mix" dynamic fields in the URI (${header.CamelFileName}) in the pollEnrich().simple()) with endpoint configuration.

Any suggestion on this?


回答1:


You can reference privateKey as bean from registry.

.pollEnrich()
    .simple("sftp://my.host:22/folder/?username=foo&privateKey=#myKeyInRegistry&fileName=${header.CamelFileName}")

Binding bean to registry depends on platform and Camel version you are using.



来源:https://stackoverflow.com/questions/57396184/apache-camel-how-to-set-a-private-key-in-a-dinamic-sftp-endpoint

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!