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
86 |
package hanze.ga.wt3.ftp;
import hanze.ga.wt3.channels.App2Q;
import hanze.ga.wt3.filters.FromIBGFilter;
import java.io.StringReader;
import java.io.StringWriter;
public class FTPApp2QChannel extends App2Q {
private String ftpAddress;
private String ftpInitDir;
private String ftpUserName;
private String ftpPassword;
private ESBFTP ftpClient;
public String getFtpAddress() {
return ftpAddress;
}
public String getFtpInitDir() {
return ftpInitDir;
}
public String getFtpPassword() {
return ftpPassword;
}
public String getFtpUserName() {
return ftpUserName;
}
private void readAndProcessFTP() {
// Maak FTP-verbinding klaar
this.ftpClient = new ESBFTP(this.getFtpAddress(), this.getFtpUserName(), this
.getFtpPassword(), this.getChannelPort());
FTPFile[] files = this.ftpClient.getFilesFromDir(this.getFtpInitDir());
for (FTPFile ftpFile : files) {
if (!ftpFile.isDirectory()) { // Alleen gewone bestanden
String directory = this.getFtpInitDir() + "/" + ftpFile.getName();
String unFiltered = this.undoFilter(this.ftpClient.pollFile(directory));
this.getDestinationQueue().addToQueue(unFiltered);
System.out.println("[" + this.getChannelName() + "] Got " + ftpFile.getName()
+ " from FTP and put in queue " + this.getDestinationQueue().getqName());
}
}
}
@Override
public void run() {
try {
while (true) {
this.readAndProcessFTP();
Thread.sleep(10000);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void setFtpAddress(String ftpAddress) {
this.ftpAddress = ftpAddress;
}
public void setFtpInitDir(String ftpInitDir) {
this.ftpInitDir = ftpInitDir;
}
public void setFtpPassword(String ftpPassword) {
this.ftpPassword = ftpPassword;
}
public void setFtpUserName(String ftpUserName) {
this.ftpUserName = ftpUserName;
}
private String undoFilter(String fileContents) {
StringWriter stringWriter = new StringWriter();
FromIBGFilter fromFilter = new FromIBGFilter();
fromFilter.doFilter(new StringReader(fileContents), stringWriter);
return stringWriter.toString();
}
} |