我有发送传真的全球api,如下面的代码所示,目前我只能将单个文件作为附件发送传真,但我有另一种情况是在一个传真请求中发送多个文件,文件名按此顺序排列在数据库中可用
以下是发送传真的完整代码
package oracle.apps.print;
import com.softlinx.replixfax.*;
import javax.xml.ws.*;
import org.apache.commons.codec.binary.Base64;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.Path;
import java.io.File;
public class Fax {
public String Fax(String Filepath,String faxno,String flg) {
try {
ReplixFaxService service = new ReplixFaxService();
ReplixFaxPort port = service.getReplixFaxPort();
((BindingProvider) port).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "user");
if (flg.toString().equals("N")) {
((BindingProvider) port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,"https://api.rpxfax.com/softlinx/replixfax/wsapi");
} else {
((BindingProvider) port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,"https://api.rpxtest.com:8083/softlinx/replixfax/wsapi");
}
Authentication auth = new Authentication();
auth.setLogin("user");
String password="pwd";
auth.setPassword(org.apache.commons.codec.binary.Base64.encodeBase64String(password.getBytes()));
auth.setRealm("MTBC");
auth.setPasswordSecurity("base64");
SendFaxInput sendFaxInput = new SendFaxInput();
sendFaxInput.setAuthentication(auth);
FaxRecipient recipient = new FaxRecipient();
recipient.setFaxNumber(faxno.toString());
Attachment attachment = new Attachment();
File f = new File(Filepath.toString());
attachment.setFileName(f.getName());
Path path = Paths.get(Filepath.toString());
byte[] data = Files.readAllBytes(path);
attachment.setAttachmentContent(data);
sendFaxInput.getFaxRecipient().add(recipient);
sendFaxInput.getAttachment().add(attachment);
SendFaxOutput result = port.sendFax(sendFaxInput);
System.out.println("Status Code= " + result.getRequestStatus().getStatusCode());
if(result.getFaxInfo() != null){
System.out.println("Fax ID = " + result.getFaxInfo().get(0).getFaxId());
}
return result.getRequestStatus().getStatusCode();
//return "a";
} catch (Exception ex) {
System.out.println("Exception: " + ex.getMessage());
return ex.getMessage();
}
}
}
我在
附上档案Attachment attachment = new Attachment();
File f = new File(Filepath.toString());
attachment.setFileName(f.getName());
Path path = Paths.get(Filepath.toString());
byte[] data = Files.readAllBytes(path);
attachment.setAttachmentContent(data);
sendFaxInput.getFaxRecipient().add(recipient);
sendFaxInput.getAttachment().add(attachment);
我可以将我的Above Files字符串解析为多个附件方式, 需要帮助将所有文件视为附件
答案 0 :(得分:0)
我已经通过自己添加代码来解决这个问题
String[] f_paths = Filepath.split("///");
for (int i = 0; i < f_paths.length; i++) {
Attachment attachment = new Attachment();
File f = new File(f_paths[i].toString());
attachment.setFileName(f.getName());
Path path = Paths.get(f_paths[i].toString());
byte[] data = Files.readAllBytes(path);
attachment.setAttachmentContent(data);
sendFaxInput.getAttachment().add(attachment);
}
只需按分隔符拆分文件字符串,然后通过循环
进行迭代