cancel
Showing results for 
Search instead for 
Did you mean: 

Can I use Sender HTTP and Sender SFTP Adapters in a same iFlow?

vkomere
Explorer
0 Kudos
276

Hello,

I have a requirement where I'll get a HTTP get call from vendor, then I need to pull the file from Vendor's SFTP folder to process and send to receiver system. Any Suggestions?

Currently I'm using below added groovy, but not able to pull the file since it is too large (6 MB).
Groovy:

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
 
import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import com.jcraft.jsch.SftpException;
import com.sap.it.api.securestore.SecureStoreService;
import com.sap.it.api.securestore.UserCredential;
import com.sap.it.api.ITApiFactory;
 
import java.util.HashMap;
def Message processData(Message message) {
 
    //Properties
    map = message.getProperties();
 
    def sftp_hostname = "HOST";
    def sftp_port = "PORT"
    def sftp_credential = "CRED";
    def sftp_filename = "/Filepath/Filename";
    String finalString = "";
 
    def secureStorageService =  ITApiFactory.getService(SecureStoreService.class, null);
    def credential = secureStorageService.getUserCredential(sftp_credential);
 
    if (credential == null){
    // TODO
    }
 
    String sftp_username = credential.getUsername();
    String sftp_password =  new String(credential.getPassword());
 
    JSch jsch = new JSch();
    Session session = null;
    try {
        session = jsch.getSession(sftp_username, sftp_hostname, sftp_port as Integer);
        session.setConfig("StrictHostKeyChecking", "no");
        session.setPassword(sftp_password);
        session.connect();
 
        Channel channel = session.openChannel("sftp");
        channel.connect();
        ChannelSftp sftpChannel = (ChannelSftp) channel;
 
        InputStream stream = sftpChannel.get(sftp_filename);
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(stream));
            String line;
            while ((line = br.readLine()) != null) {
            finalString = finalString + line; // You can have your own logic over here
            }
        } catch (IOException io) {
            finalString = io.getMessage();
        } catch (Exception e) {
           finalString = e.getMessage();
        }
        sftpChannel.exit();
        session.disconnect();
        
    } catch (JSchException e) {
        //Exception Handling 
    } catch (SftpException ee) {
       //Exception Handling 
    }
message.setBody(finalString);
return message;
 
}

 

Thanks & Regards,
Venkat Komere

Accepted Solutions (1)

Accepted Solutions (1)

Ryan-Crosby
Active Contributor
0 Kudos

Hi Venkat,

Yes, you can use the poll-enrich step to pull information into your iFlow after an HTTP call.

 

Regards,

Ryan Crosby

Answers (0)