我需要将文件(xml)传输到AS2服务器。我不太擅长这个沟通 channel ,但我需要以编程方式进行。例如发送到 SFTP 我正在使用以下代码:
import com.jcraft.jsch.*;
.......
public void uploadViaSFTP (String fileToUpload, String sftp_host, String sftp_user, String sftp_psw)
{
int SFTPPORT = 22;
Session session = null;
Channel channel = null;
ChannelSftp channelSftp = null;
try{
JSch jsch = new JSch();
session = jsch.getSession(sftp_user,sftp_host,SFTPPORT);
session.setPassword(sftp_psw);
java.util.Properties config = new java.util.Properties();
//this line should be used only for testing, not for production
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect();
channel = session.openChannel("sftp");
channel.connect();
channelSftp = (ChannelSftp)channel;
channelSftp.cd("/");
File f = new File(fileToUpload);
channelSftp.put(new FileInputStream(f), f.getName());
}catch(Exception ex){
ex.printStackTrace();
}
}
但现在我需要对 AS2 做同样的事情。我可以使用什么库(openAS2)?有没有像SFTP那样简单的传输方法?
最佳答案
您应该能够使用标准 HTTPS 组件和 S/MIME 附件,因为 AS2 是 HTTP 或 HTTPS 之上的安全层和使用规范。
我将从 ( https://www.mkyong.com/java/java-https-client-httpsurlconnection-example/ )、AS2 规范 ( http://www.ietf.org/rfc/rfc4130.txt ) 以及来自 github 的这个示例开始:( https://github.com/protocol7/smime-java-example )
关于sftp - 用于传输文件的独立 AS2 客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42758938/