Skip to content

How to get the file from service-activator Message object in listener class

I need to pass the file to service layer which i am receiving in SFTP path. below is configuration and i am seeing the message receiving in my service-activator like

GenericMessage [payload=com.jcraft.jsch.ChannelSftp$2@322906a2, 
id=704c58e7-1d93-3bef-0330-233c0f9af55c, file_remoteDirectory=/tmp/charge/, 
file_remoteFile=Charge.txt, timestamp=1594158522576}]

<bean id="sftpSessionFactory" 
    <property name="host" value="hostname"/>
    <property name="port" value="22"/>
    <property name="user" value="vkp"/>
    <property name="password" value="1234"/>
    <property name="allowUnknownKeys" value="true"/>
<int-sftp:inbound-streaming-channel-adapter id="sftpAdapterAutoCreate"

<int:poller fixed-rate="25000" max-messages-per-poll="1" id="shippingChargePoller" default="true"/>

<int:channel id="receiveChannel">

<int:stream-transformer id="withCharset" charset="UTF-8"    input- 
channel="receiveChannel" />

<int:service-activator id="FeedListener" input-channel="receiveChannel"  method="onMessage">
    <bean class="com.listener.ChargeFeedListener"/>

   public void onMessage(Message<?> message){
    System.out.println( " Received File is  "+message.getPayload());

But i am not receiving the file in my java class . What i need to do to get the file ?



Please, read documentation: The <int-sftp:inbound-streaming-channel-adapter> is not about files. It does open an InputStream for a remote entry (probably file on SFTP) and let you to do with this stream whatever you want. For example (also according that docs), there is a StreamTransformer which let’s you to read that stream into a byte[] or string if you provide a charset. If you really want to deal with files, then you need to consider to switch to the <int-sftp:inbound-channel-adapter>. That one pull the remote entry and store its content into a local file. Then that is sent to the channel for your consideration.

I think we had a chat with you on the matter in other your question: Spring SFTP Integration is not polling the file.

Please, let us know what is wrong with our docs that confuses you so you have to raise questions like this over here.

6 People found this is helpful