root/Weektaken2/Weektaak3/ESB/src/hanze/ga/wt3/ftp/FTPQ2AppChannel.java

356357
1
package hanze.ga.wt3.ftp;
1
package hanze.ga.wt3.ftp;
2
2
3
import java.io.*;
4
5
import hanze.ga.wt3.channels.Q2App;
3
import hanze.ga.wt3.channels.Q2App;
6
import hanze.ga.wt3.filters.ToIBGFilter;
4
import hanze.ga.wt3.filters.ToIBGFilter;
7
import hanze.ga.wt3.xml.Xml;
5
import hanze.ga.wt3.xml.Xml;
8
6
7
import java.io.ByteArrayInputStream;
8
import java.io.File;
9
import java.io.FileWriter;
10
import java.io.StringReader;
11
import java.io.StringWriter;
12
9
public class FTPQ2AppChannel extends Q2App {
13
public class FTPQ2AppChannel extends Q2App {
10
14
11
	private String ftpAddress;
15
	private String ftpAddress;
...
...
30
		return ftpUserName;
34
		return ftpUserName;
31
	}
35
	}
32
36
33
	@Override
34
	public void run() {
35
		try {
36
			while (true) {
37
				this.readQueue();
38
				Thread.sleep(1000);
39
			}
40
		} catch (InterruptedException e) {
41
			e.printStackTrace();
42
		}
43
	}
44
45
	private void readQueue() {
46
		while (this.getSourceQueue().getSize() > 0) {
47
			this.processItem(this.getSourceQueue().pollFromQueue());
48
		}
49
	}
50
51
	private void processItem(String pollItem) {
37
	private void processItem(String pollItem) {
52
38
53
		StringWriter stringWriter = new StringWriter();
39
		StringWriter stringWriter = new StringWriter();
...
...
62
			Xml xmlParser = new Xml("C:/esb.tmp", "message");
48
			Xml xmlParser = new Xml("C:/esb.tmp", "message");
63
			String reqId = xmlParser.child("id").content();
49
			String reqId = xmlParser.child("id").content();
64
			tmpFile.delete();
50
			tmpFile.delete();
65
			
51
66
			// Filter item
52
			// Filter item
67
			ToIBGFilter toFilter = new ToIBGFilter();
53
			ToIBGFilter toFilter = new ToIBGFilter();
68
			toFilter.doFilter(new StringReader(pollItem), stringWriter);
54
			toFilter.doFilter(new StringReader(pollItem), stringWriter);
69
			String fileContents = stringWriter.toString();
55
			String fileContents = stringWriter.toString();
70
			
56
71
			// Maak FTP-verbinding klaar
57
			// Maak FTP-verbinding klaar
72
			ESBFTP ftpClient = new ESBFTP(this.getFtpAddress(), this.getFtpUserName(), this
58
			ESBFTP ftpClient = new ESBFTP(this.getFtpAddress(), this.getFtpUserName(), this
73
					.getFtpPassword(), this.getChannelPort());
59
					.getFtpPassword(), this.getChannelPort());
...
...
88
74
89
	}
75
	}
90
76
77
	private void readQueue() {
78
		while (this.getSourceQueue().getSize() > 0) {
79
			this.processItem(this.getSourceQueue().pollFromQueue());
80
		}
81
	}
82
83
	@Override
84
	public void run() {
85
		try {
86
			while (true) {
87
				this.readQueue();
88
				Thread.sleep(1000);
89
			}
90
		} catch (InterruptedException e) {
91
			e.printStackTrace();
92
		}
93
	}
94
91
	public void setFtpAddress(String ftpAddress) {
95
	public void setFtpAddress(String ftpAddress) {
92
		this.ftpAddress = ftpAddress;
96
		this.ftpAddress = ftpAddress;
93
		super.setChannelIp(ftpAddress);
97
		super.setChannelIp(ftpAddress);