I've written a Camel (2.10) component to do Sftp as I needed a bit more control over the connection than the out of the box component offers.
I have route that looks something like this:
from("direct:start")
.to(startProcessor()) //1. Start processor sets the connection parameters for myCustomSftpComp producer
.to("myCustomSftpComp") //2. Uses Jsch, connects to server, gets the file, add to exchange, closes connection
.to(somePostProcessor()) //3. Does something with the file
.to("file://...."); //4. Write the file
This all works perfectly well.
My problem is at step 2, at the moment my files are quite small and I buffer them into memory, add the byte array to the Exchange body and its passed along and processed until it gets written by the file endpoint.
Of course this wont be sustainable with a large file, I need to add the InputStream reference to the exchange instead. My problem is I close and clean up the connection to the server inside myCustomSftpComp so when the exchange gets to post processor and file endpoint, it can no longer be accessed.
So basically I need some way to keep the connection open until after the file is written and closing the server connection inside the component from the route definition, sounds untidy so I'm open to atlernative ways of doing this.