0

I am looking for an way to pass InputStream to service class method by using service-activator, with below configuration tested and seems the service-activator was not called. can any point where am doing wrong?

<bean id="sftpSessionFactory" ... />

<int:channel id="inboundGetStream">
    <int:queue />
</int:channel>

<int-sftp:outbound-gateway session-factory="sftpSessionFactory"
              request-channel="inboundGetStream"
              command="get"
              command-options="-stream"
              expression="payload"
              remote-directory="ftpTarget"
              reply-channel="streamHandler" />

<int:service-activator input-channel="inboundGetStream" ref="streamHandler" method="handleMessage"/>

where in service class an method with InputStream parameter created :

@Service("streamHandler")
public class StreamHandler {

    public void handleMessage(InputStream file, @Headers['file_remoteSession']DefaultSftpSessionFactory session) throws FileNotFoundException, IOException{
        log.debug("############# handleMessage(file) ###########");     
        log.debug(IOUtils.toString(new FileInputStream(file)));
        session.close();
    }
}
Abhishek Nayak
  • 3,732
  • 3
  • 33
  • 64

1 Answers1

1

Remove the chain - the <file:splitter/> reads the file from the inputStream and emits each line as a Message<String>.

Since you want to consume the inputStream yourself, you don't want that. Your service method is then correct.

Simply change the reply-channel to outboundGetStream and change the service activator's input channel to that.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • questions updated, getting an exception " java.lang.IllegalStateException: Cannot convert value of type StreamHandler" to required type [org.springframework.messaging.MessageChannel] for property 'outputChannel': no matching editors or conversion strategy found – Abhishek Nayak Mar 14 '16 at 20:37
  • The gateway's `reply-channel` needs to be wired to the service activator's `input-channel`. I didn't notice before that you had both bound to `inboundGetStream`. – Gary Russell Mar 14 '16 at 20:57