SFTP delegation example
BHARATHCK opened this issue · comments
I understand there is a sample of dynamic FTP.
But would be helpful to have a SFTP delegation sample for outbound adapter as well , using SFTP session caching and factory methods.
Thanks
Please, elaborate what is "SFTP delegation"?
By the way, if you have something in mind already, it is OK to raise a PR and we will review it shortly.
Thanks
Hi ,
By SFTP Delegation I mean invoking different session factories at runtime as mentioned in docs :
https://docs.spring.io/spring-integration/reference/html/sftp.html#sftp-dsf
I don't completely follow the docs, but I am working on the above scenario.
Thanks
OK. Got it! Yeah.. we indeed may consider to add some simple sample on the matter.
Meanwhile I don't think the "Dynamic FTP" is relevant somehow to the DelegatingSessionFactory
.
On the other hand let's see first of all what is your struggle because I think the sample we can come up may not be so helpful for you.
As you see the DelegatingSessionFactory
is based on the ThreadLocal
. So, before using its current state in the flow, you should populate a key for desired delegate. The setThreadKey()
and clearThreadKey()
API is there for you.
You can look into https://github.com/spring-projects/spring-integration/blob/master/spring-integration-file/src/test/java/org/springframework/integration/file/remote/session/DelegatingSessionFactoryTests.java and its XML config: https://github.com/spring-projects/spring-integration/blob/master/spring-integration-file/src/test/java/org/springframework/integration/file/remote/session/delegating-session-factory-context.xml to see how it is used.
This is definitely gonna help me , thank u for the explanation , I see things more clearly now by going throught those links.
Will see what I can come up with.
Thanks.
Hi,
I currently have a working code for 2 SFTP configs but i am using 2 SFTP Outbound adapter and calling the appropriate channel based on the header, which I'm guessing is not the best practice...
But below is the XML config that i came up with using DelegatingSessionFactory
but i do have 2 questions which I'm not able to figure out, would be really helpful if u could take a look at it.
Added Intent and Questions in the Comments in the gist below :
let me know if this isn't the right place to ask the question :) !!
Thanks
Sure!
Here is what I see in your code:
org.springframework.messaging.MessageHandlingException: Expression evaluation failed: @dsf.setThreadKey('ONE'); nested exception is org.springframework.expression.AccessException: Could not resolve bean reference against BeanFactory
That @dsf
is a reference to a bean, but your one is this:
<bean id="delegatingSessionFactory" class="org.springframework.integration.file.remote.session.DelegatingSessionFactory">
So, or rename this bean to dsf
or use delegatingSessionFactory
in those expressions instead.
See more info in Docs: https://docs.spring.io/spring-integration/reference/html/spel.html#spel
headers['factoryToUse']
- you need to be sure that you really set this header in advance - to one or another delegate key.
Great!
Closing as nothing to discuss any more