Changeset 361

User picture

Author: klystr

(2009/12/03 15:02) About 2 years ago

IBG > Q2 ready, IBG-app moet nog

Affected files

Updated Weektaken2/Weektaak3/ESB/src/hanze/ga/wt3/channels/App2Q.java Download diff

360361
1
package hanze.ga.wt3.channels;
1
package hanze.ga.wt3.channels;
2
2
3
/**
4
 * Applicatie naar Queue
5
 */
3
public abstract class App2Q extends Channel {
6
public abstract class App2Q extends Channel {
4
7
5
	private ESBQueue destinationQueue;
8
	private ESBQueue destinationQueue;

Updated Weektaken2/Weektaak3/ESB/src/hanze/ga/wt3/channels/ESBQueue.java Download diff

360361
11
	private Channel qReceiverChannel;
11
	private Channel qReceiverChannel;
12
	private Queue<String> queue = new LinkedList<String>();
12
	private Queue<String> queue = new LinkedList<String>();
13
13
14
	/**
15
	 * Adds a String with file contents to the Queue
16
	 * 
17
	 * @param input
18
	 *            String with contents of file
19
	 */
14
	public void addToQueue(String input) {
20
	public void addToQueue(String input) {
15
		System.out.println("[" + this.getqName() + "] Item was added");
21
		System.out.println("[" + this.getqName() + "] Item was added");
16
		this.queue.add(input);
22
		this.queue.add(input);
...
...
36
		return this.queue.size();
42
		return this.queue.size();
37
	}
43
	}
38
44
45
	/**
46
	 * Removes latest item from the Queue and removes it from the Queue.
47
	 * 
48
	 * @return File contents
49
	 */
39
	public String pollFromQueue() {
50
	public String pollFromQueue() {
40
		System.out.println("[" + this.getqName() + "] Item was polled");
51
		System.out.println("[" + this.getqName() + "] Item was polled");
41
		return this.queue.poll();
52
		return this.queue.poll();

Updated Weektaken2/Weektaak3/ESB/src/hanze/ga/wt3/ftp/ESBFTP.java Download diff

360361
1
package hanze.ga.wt3.ftp;
1
package hanze.ga.wt3.ftp;
2
2
3
import java.io.ByteArrayOutputStream;
3
import java.io.IOException;
4
import java.io.IOException;
4
import java.io.InputStream;
5
import java.io.InputStream;
5
import java.net.SocketException;
6
import java.net.SocketException;
6
7
7
import org.apache.commons.net.ftp.FTPClient;
8
import org.apache.commons.net.ftp.FTPClient;
9
import org.apache.commons.net.ftp.FTPFile;
8
10
9
public class ESBFTP {
11
public class ESBFTP {
10
12
11
	private String ftpAddress, ftpUserName, ftpPassword;
13
	private String ftpAddress, ftpUserName, ftpPassword;
12
	int ftpPort;
14
	int ftpPort;
15
	private FTPClient ftpClient;
13
16
17
	/**
18
	 * Klasse maakt FTP-handelingen mogelijk
19
	 * 
20
	 * @param ftpAddress
21
	 *            IP-adres of hostnaam van FTP-server
22
	 * @param ftpUserName
23
	 *            FTP-username
24
	 * @param ftpPassword
25
	 *            FTP-password
26
	 * @param ftpPort
27
	 *            FTP-poort (standaard 21)
28
	 */
14
	public ESBFTP(String ftpAddress, String ftpUserName, String ftpPassword, int ftpPort) {
29
	public ESBFTP(String ftpAddress, String ftpUserName, String ftpPassword, int ftpPort) {
15
		this.ftpAddress = ftpAddress;
30
		this.ftpAddress = ftpAddress;
16
		this.ftpUserName = ftpUserName;
31
		this.ftpUserName = ftpUserName;
...
...
18
		this.ftpPort = ftpPort;
33
		this.ftpPort = ftpPort;
19
	}
34
	}
20
35
21
	public void store(InputStream file, String destination) {
36
	/**
22
		FTPClient ftpClient = new FTPClient();
37
	 * Maakt verbinding met de FTP-server en slaat deze verbinding op in de
38
	 * lokale variabele ftpClient
39
	 */
40
	private void makeConnection() {
23
		try {
41
		try {
24
			// Naar FTP
42
			ftpClient = new FTPClient();
25
			ftpClient.connect(this.ftpAddress, this.ftpPort);
43
			ftpClient.connect(this.ftpAddress, this.ftpPort);
26
			ftpClient.login(this.ftpUserName, this.ftpPassword);
44
			ftpClient.login(this.ftpUserName, this.ftpPassword);
27
			ftpClient.storeFile(destination, file);
28
			ftpClient.disconnect();
29
		} catch (SocketException e) {
45
		} catch (SocketException e) {
30
			e.printStackTrace();
46
			e.printStackTrace();
31
		} catch (IOException e) {
47
		} catch (IOException e) {
...
...
33
		}
49
		}
34
	}
50
	}
35
51
52
	/**
53
	 * Sluit connectie met server die nu in lokale variabele ftpClient staat
54
	 */
55
	private void terminateConnection() {
56
		try {
57
			this.ftpClient.disconnect();
58
		} catch (IOException e) {
59
			e.printStackTrace();
60
		}
61
		this.ftpClient = null;
62
	}
63
64
	/**
65
	 * Transporteert bestand naar de server
66
	 * 
67
	 * @param file
68
	 *            Stream van het bestand
69
	 * @param destination
70
	 *            Pad + bestandsnaam
71
	 */
72
	public void store(InputStream file, String destination) {
73
		try {
74
			this.makeConnection();
75
			this.ftpClient.storeFile(destination, file);
76
			this.terminateConnection();
77
		} catch (SocketException e) {
78
			e.printStackTrace();
79
		} catch (IOException e) {
80
			e.printStackTrace();
81
		}
82
	}
83
84
	/**
85
	 * Haalt bestanden uit directory
86
	 * 
87
	 * @param directory
88
	 *            doeldirectory
89
	 * @return Array van FTPFiles
90
	 */
91
	public FTPFile[] getFilesFromDir(String directory) {
92
		this.makeConnection();
93
		FTPFile[] output = null;
94
		try {
95
			output = this.ftpClient.listFiles(directory);
96
		} catch (IOException e) {
97
			e.printStackTrace();
98
		}
99
		this.terminateConnection();
100
		return output;
101
	}
102
103
	/**
104
	 * Haalt opgegeven bestand van de server er verwijderd deze.
105
	 * 
106
	 * @param filePath
107
	 *            Pad + bestandsnaam
108
	 * @return Bestandsinhoud
109
	 */
110
	public String pollFile(String filePath) {
111
		this.makeConnection();
112
		ByteArrayOutputStream outputStream = null;
113
		try {
114
			outputStream = new ByteArrayOutputStream();
115
			this.ftpClient.retrieveFile(filePath, outputStream);
116
			this.ftpClient.dele(filePath);
117
		} catch (IOException e) {
118
			e.printStackTrace();
119
		}
120
121
		this.terminateConnection();
122
		return outputStream.toString();
123
	}
36
}
124
}

Added Weektaken2/Weektaak3/ESB/src/hanze/ga/wt3/ftp/FTPApp2QChannel.java

Show contents

Updated Weektaken2/Weektaak3/ESB/src/hanze/ga/wt3/ftp/FTPQ2AppChannel.java Download diff

360361
13
public class FTPQ2AppChannel extends Q2App {
13
public class FTPQ2AppChannel extends Q2App {
14
14
15
	private String ftpAddress;
15
	private String ftpAddress;
16
17
	private String ftpInitDir;
16
	private String ftpInitDir;
18
	private String ftpUserName;
17
	private String ftpUserName;
19
	private String ftpPassword;
18
	private String ftpPassword;

Updated Weektaken2/Weektaak3/ESB/src/hanze/ga/wt3/xml/configuration.xml Download diff

360361
47
	<channel-def> 
47
	<channel-def> 
48
		<name>OutboxIBGQ2APP</name> 
48
		<name>OutboxIBGQ2APP</name> 
49
		<adapter> 
49
		<adapter> 
50
			<direction>Q2APP</direction> 
50
			<direction>APP2Q</direction> 
51
			<protocol>FTP</protocol> 
51
			<protocol>FTP</protocol> 
52
			<address>145.33.160.234</address> 
52
			<address>145.33.160.234</address> 
53
			<port>9090</port> 
53
			<port>9090</port> 

Updated Weektaken2/Weektaak3/ESB/src/hanze/ga/wt3/xml/ESBDOMParser.java Download diff

360361
2
2
3
import hanze.ga.wt3.channels.Channel;
3
import hanze.ga.wt3.channels.Channel;
4
import hanze.ga.wt3.channels.ESBQueue;
4
import hanze.ga.wt3.channels.ESBQueue;
5
import hanze.ga.wt3.ftp.FTPApp2QChannel;
5
import hanze.ga.wt3.ftp.FTPQ2AppChannel;
6
import hanze.ga.wt3.ftp.FTPQ2AppChannel;
6
import hanze.ga.wt3.helper.Security;
7
import hanze.ga.wt3.helper.Security;
7
import hanze.ga.wt3.http.HTTPApp2QChannel;
8
import hanze.ga.wt3.http.HTTPApp2QChannel;
...
...
32
			this.buildHttpApp2Q(channelDef);
33
			this.buildHttpApp2Q(channelDef);
33
		} else if (protocol.equals("SOCKET")) {
34
		} else if (protocol.equals("SOCKET")) {
34
			this.buildSocketApp2Q(channelDef);
35
			this.buildSocketApp2Q(channelDef);
36
		} else if (protocol.equals("FTP")) {
37
			this.buildFTPApp2Q(channelDef);
35
		}
38
		}
36
	}
39
	}
37
40
41
	private void buildFTPApp2Q(Xml channel) {
42
		FTPApp2QChannel ftp = new FTPApp2QChannel();
43
44
		// Globale settings
45
		ftp.setChannelName(channel.child("name").content());
46
47
		// FTP Adapter waarden
48
		Xml adapterNode = channel.child("adapter");
49
		ftp.setFtpAddress(adapterNode.child("address").content());
50
		ftp.setFtpInitDir(adapterNode.child("init-dir").content());
51
		ftp.setFtpPassword(adapterNode.child("password").content());
52
		ftp.setFtpUserName(adapterNode.child("username").content());
53
		ftp.setChannelPort(adapterNode.child("port").content());
54
55
		// Zet in lijst
56
		this.channels.put(channel.child("name").content(), ftp);
57
	}
58
38
	/**
59
	/**
39
	 * Bouwen van ESB aan de hand van XML-bestand.
60
	 * Bouwen van ESB aan de hand van XML-bestand.
40
	 * 
61
	 *