IMF_Sender.java
2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package com.tianbo.imf;
import com.caac.imf.api.IMFClient;
import com.tianbo.Main;
import com.tianbo.util.Date.DateUtil;
import com.tianbo.util.IO.FileTool;
import com.tianbo.util.XML.MakeImfMeta;
import org.apache.commons.io.FileUtils;
import org.apache.log4j.Logger;
import java.io.File;
import java.util.List;
public class IMF_Sender extends Thread{
protected static final Logger logger = Logger.getLogger(IMF_Sender.class);
public static boolean isrunning;
private IMFClient client;
private String content;
public IMF_Sender(IMFClient client) {
this.client = client;
}
public IMF_Sender(IMFClient client, String content) {
this.client = client;
this.content = content;
}
public void run(){
try {
String sendDir = FileTool.readProperties("readDirectory");
String SNDR = FileTool.readProperties("loginname");
String TYPE = FileTool.readProperties("TYPE");
String STYP = FileTool.readProperties("STYP");
String RCVR = FileTool.readProperties("RCVR");
String DDTM = DateUtil.getDDTM();
String SEQN = DDTM;
if (this.client == null) {
logger.info("IMFClient has been closed");
return;
}
isrunning=true;
if(Main.isSuc){
// logger.info("<<<<<<<<<<<主线程初始化成功>>>>>>>>>>>>");
if(Main.LOGIN_OK){
while (true){
//发送报文
List<File> files = FileTool.readDirectoryFiles(new File(sendDir));
for (File file:files) {
String fileContent = FileTool.readfile(file);
String sendMsg = MakeImfMeta.makeImfDocument(SNDR,RCVR,TYPE,STYP,DDTM,SEQN,fileContent);
String returnMsg = this.client.sendMSG(sendMsg);
//发送成功处理,删除已发送成功的目录下的文件
if(returnMsg.indexOf("<CODE>9</CODE>")>=0){
FileUtils.forceDelete(file);
}
}
try {
Thread.sleep(500L);
} catch (InterruptedException var3) {
var3.printStackTrace();
}
}
}else{
logger.info("<<<<<<<<<<<登陆中>>>>>>>>>>>>");
}
}
}catch (Exception var14) {
var14.printStackTrace();
logger.info(var14.getMessage());
}
isrunning=false;
logger.info("<<<<<<<<<<<发送线程结束>>>>>>>>>>>>");
}
}