Issue
I am trying to connect to a sftp server in order to store some files. I want to connect via the SSH. My question is almost identical with: Camel SFTP component - SSH private key URI works with privateKeyFile, doesn't work with privateKey and the following answer: Apache Camel - How to set a private key in a dinamic sftp endpoint But I still I didn't manage to connect.
My working route:
from(mytopic)
.to(sftp://[email protected]:22/folder/?privateKeyFile=path/to/privateRsa)
My NON working route:
from(mytopic)
.to(sftp://[email protected]:22/folder/?privateKey=byteArrayRsa)
I debugged the com.jcraft.jsch.KeyPair class -> following method:
public static KeyPair load(JSch jsch, byte[] prvkey, byte[] pubkey) throws JSchException
And seems that instead of having the correct byte[] prvkey, I got its address. How can I send the correct byte array? I tried to create a bean as it is suggested in one of the links, but it didn't worked. (I am using camel 3.1)
Solution
This doesn't work, you cannot simply use a ByteArray reference in a route definition. It works when you use a Registry like org.apache.camel.impl.SimpleRegistry
to store the key reference.
simpleRegistry.put("MySshKey", byteArrayRsa)
camelCtx.setRegistry(simpleRegistry)
Then you can use a reference in the route:
privateKey=#MySshKey
Maybe you could also use Spring Injection.
Answered By - mdo
Answer Checked By - Marilyn (JavaFixing Volunteer)