Changeset 366

User picture

Author: klystr

(2009/12/04 11:06) About 2 years ago

Send to Q3 done

Affected files

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

365366
21
		System.out.println("[" + this.getqName() + "] Item was added");
21
		System.out.println("[" + this.getqName() + "] Item was added");
22
		this.queue.add(input);
22
		this.queue.add(input);
23
	}
23
	}
24
	
25
	public void deleteFromQueue(String queuedObject) {
26
		this.queue.remove(queuedObject);
27
	}
24
28
25
	public String getqName() {
29
	public String getqName() {
26
		return qName;
30
		return qName;

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

365366
21
		try {
21
		try {
22
			while (true) {
22
			while (true) {
23
				this.readAndProcessFTP();
23
				this.readAndProcessFTP();
24
				Thread.sleep(3000);
24
				Thread.sleep(10000);
25
			}
25
			}
26
		} catch (InterruptedException e) {
26
		} catch (InterruptedException e) {
27
			e.printStackTrace();
27
			e.printStackTrace();

Updated Weektaken2/Weektaak3/ESB/src/hanze/ga/wt3/http/HTTPApp2QChannel.java Download diff

365366
23
23
24
			serverSocket = new ServerSocket(this.getChannelPort());
24
			serverSocket = new ServerSocket(this.getChannelPort());
25
			while (true) {
25
			while (true) {
26
				new Thread(new HTTPConnection(serverSocket.accept(), this)).start();
26
				new Thread(new HTTPPostConnection(serverSocket.accept(), this)).start();
27
			}
27
			}
28
		} catch (IOException e) {
28
		} catch (IOException e) {
29
			e.printStackTrace();
29
			e.printStackTrace();

Updated Weektaken2/Weektaak3/ESB/src/hanze/ga/wt3/http/HTTPGetConnection.java Download diff

365366
16
	private Socket socket;
16
	private Socket socket;
17
	private PrintWriter outPutWriter;
17
	private PrintWriter outPutWriter;
18
	private BufferedReader inputReader;
18
	private BufferedReader inputReader;
19
	private String inputMessage;
20
	private HTTPQ2AppChannel httpObject;
19
	private HTTPQ2AppChannel httpObject;
21
20
22
	public HTTPGetConnection(Socket accept, HTTPQ2AppChannel httpq2AppChannel) {
21
	public HTTPGetConnection(Socket accept, HTTPQ2AppChannel httpq2AppChannel) {
...
...
32
31
33
	private String getQueueName(String header) {
32
	private String getQueueName(String header) {
34
		// "GET /<<QueueNaam>> HTTP/1.1"
33
		// "GET /<<QueueNaam>> HTTP/1.1"
34
		if (header.indexOf("?") > 0) { // Has ID
35
			return header.substring(5, header.indexOf("?ID="));
36
		}
37
		// "GET /<<QueueNaam>> HTTP/1.1"
35
		return header.substring(5, header.indexOf(" HTTP/1.1"));
38
		return header.substring(5, header.indexOf(" HTTP/1.1"));
36
	}
39
	}
37
40
38
	private void reply(String queryType) {
41
	private void reply(String queryType) {
39
		if (queryType.indexOf("?ID") > 0) { // Specifiek ID
42
		if (queryType.indexOf("?ID=") > 0) { // Specifiek ID
40
			this.replyId(this.getId(queryType));
43
			this.replyId(this.getId(queryType));
41
		} else { // Overzicht
44
		} else { // Overzicht
42
			this.replyList();
45
			this.replyList();
...
...
63
66
64
		// Luister naar input van gebruiker
67
		// Luister naar input van gebruiker
65
		try {
68
		try {
66
			String inputLine = inputReader.readLine().trim();
69
			String inputLine = inputReader.readLine();
67
			while (inputLine != null) {
70
			while (inputLine != null) {
68
				if (inputLine.startsWith("GET /")) {
71
				if (inputLine.startsWith("GET /")) {
69
					String queryType = this.getHttpQueueName();
72
					String queryType = this.getHttpQueueName();
70
					if (queryType.equals(this.getQueueName(inputLine))) {
73
					String qName = this.getQueueName(inputLine);
71
						this.reply(queryType);
74
					if (queryType.equals(qName)) {
75
						this.reply(inputLine);
72
						break;
76
						break;
73
					} else {
77
					} else {
74
						System.err.println("Queue niet gevonden");
78
						System.err.println("Queue " + qName + " niet gevonden");
75
						outPutWriter.println("HTTP/1.1 404 Not Found");
79
						outPutWriter.println("HTTP/1.1 404 Not Found");
76
						break;
80
						break;
77
					}
81
					}
...
...
85
			outPutWriter.close();
89
			outPutWriter.close();
86
			inputReader.close();
90
			inputReader.close();
87
91
88
			// Print op scherm
89
			// System.out.println();
90
91
		} catch (Exception e) {
92
		} catch (Exception e) {
92
			// do nothing
93
			// do nothing
93
			System.err.println("Fout in connectie");
94
			System.err.println("Fout in connectie");
...
...
134
		LinkedList<String> queued = this.httpObject.getSourceQueue().peekEntireQueue();
135
		LinkedList<String> queued = this.httpObject.getSourceQueue().peekEntireQueue();
135
		if (queued.size() > 0) {
136
		if (queued.size() > 0) {
136
			for (String inQueue : queued) {
137
			for (String inQueue : queued) {
137
				if (queryId == this.findId(inQueue)) {
138
				if (queryId.equals(this.findId(inQueue))) {
138
					outPutWriter.write("HTTP/1.1 200 OK\n");
139
					outPutWriter.write("HTTP/1.1 200 OK\n");
139
					outPutWriter.write("Content-Length=" + inQueue.length() + "\n");
140
					outPutWriter.write("Content-Length=" + inQueue.length() + "\n");
140
					outPutWriter.write(inQueue);
141
					outPutWriter.write(inQueue);
142
143
					// Verwijder
144
					this.httpObject.getSourceQueue().deleteFromQueue(inQueue);
145
141
					return;
146
					return;
142
				}
147
				}
143
			}
148
			}

Updated Weektaken2/Weektaak3/ESB/src/hanze/ga/wt3/http/post-example.txt Download diff

365366
1
Naar FTP:
2
-----------------------------------------
1
POST /StudentPortalToIBGQueue HTTP/1.1
3
POST /StudentPortalToIBGQueue HTTP/1.1
2
Content-Length=121
4
Content-Length=121
3
<message>
5
<message>
...
...
6
	<payload>
8
	<payload>
7
		Hier staat dan tekst
9
		Hier staat dan tekst
8
	</payload>
10
	</payload>
9
</message>
11
</message>
12
13
14
Naar Socket:
15
-----------------------------------------
16
SEND StudentPortalToLocatorQueue/121
17
<message><queue-name>StudentPortalToIBGQueue</queue-name><id>2</id><payload>Hier staat dan tekst</payload></message>

Updated Weektaken2/Weektaak3/ESB/src/hanze/ga/wt3/main/ESBServer.java Download diff

365366
1
package hanze.ga.wt3.main;
1
package hanze.ga.wt3.main;
2
2
3
import hanze.ga.wt3.channels.App2Q;
4
import hanze.ga.wt3.channels.Channel;
3
import hanze.ga.wt3.channels.Channel;
5
import hanze.ga.wt3.channels.ESBQueue;
4
import hanze.ga.wt3.channels.ESBQueue;
6
import hanze.ga.wt3.channels.Q2App;
7
import hanze.ga.wt3.xml.ESBDOMParser;
5
import hanze.ga.wt3.xml.ESBDOMParser;
8
6
9
import java.util.HashMap;
7
import java.util.HashMap;
...
...
14
		new ESBServer("C:/Users/Martijn/workspace/ESB/src/hanze/ga/wt3/xml/configuration.xml");
12
		new ESBServer("C:/Users/Martijn/workspace/ESB/src/hanze/ga/wt3/xml/configuration.xml");
15
	}
13
	}
16
14
17
	private HashMap<String, Channel> esbChannels;
15
	public static HashMap<String, Channel> esbChannels;
18
16
19
	private HashMap<String, ESBQueue> esbQueues;
17
	private HashMap<String, ESBQueue> esbQueues;
20
18
19
	@SuppressWarnings("static-access")
21
	public ESBServer(String configFilePath) {
20
	public ESBServer(String configFilePath) {
22
21
23
		// Bouw ESB aan de hand van config
22
		// Bouw ESB aan de hand van config
...
...
34
		System.out.println(this.esbQueues.size() + " Queues");
33
		System.out.println(this.esbQueues.size() + " Queues");
35
		System.out.println("------------------------------------");
34
		System.out.println("------------------------------------");
36
35
37
		// Zorgt dat Channels de juiste Queue's hebben
38
		this.linkQueueToChannel();
39
40
		// Start threads van channels
36
		// Start threads van channels
41
		this.initChannels();
37
		this.initChannels();
42
	}
38
	}
...
...
50
		}
46
		}
51
	}
47
	}
52
48
53
	/**
54
	 * Zorgt ervoor dat een Channel de juiste bron- en bestemmingsQueue heeft.
55
	 */
56
	private void linkQueueToChannel() {
57
		for (ESBQueue esbQueue : esbQueues.values()) {
58
59
			// Link receiver
60
			Channel receiver = esbQueue.getqReceiverChannel();
61
			if (receiver instanceof App2Q) {
62
				((App2Q) receiver).setDestinationQueue(esbQueue);
63
			} else if (receiver instanceof Q2App) {
64
				((Q2App) receiver).setSourceQueue(esbQueue);
65
			}
66
67
			// Link sender
68
			Channel sender = esbQueue.getqSenderChannel();
69
			if (sender instanceof App2Q) {
70
				((App2Q) sender).setDestinationQueue(esbQueue);
71
			} else if (sender instanceof Q2App) {
72
				((Q2App) sender).setSourceQueue(esbQueue);
73
			}
74
		}
75
	}
76
}
49
}

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

365366
61
	<channel-def> 
61
	<channel-def> 
62
		<name>LocatorIn</name> 
62
		<name>LocatorIn</name> 
63
		<adapter> 
63
		<adapter> 
64
			<direction>Q2APP</direction> <!-- FOUT -->
64
			<direction>APP2Q</direction> <!-- FOUT -->
65
			<protocol>SOCKET</protocol>
65
			<protocol>SOCKET</protocol>
66
			<address>145.33.160.234</address> 
66
			<address>145.33.160.234</address> 
67
			<port>9091</port>
67
			<port>9091</port>
...
...
72
	<channel-def> 
72
	<channel-def> 
73
		<name>LocatorOut</name> 
73
		<name>LocatorOut</name> 
74
		<adapter> 
74
		<adapter> 
75
			<direction>APP2Q</direction> 
75
			<direction>Q2APP</direction> 
76
			<protocol>SOCKET</protocol> 
76
			<protocol>SOCKET</protocol> 
77
			<address>145.33.160.234</address> 
77
			<address>145.33.160.234</address> 
78
			<port>9091</port>
78
			<port>9091</port>

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

365366
1
package hanze.ga.wt3.xml;
1
package hanze.ga.wt3.xml;
2
2
3
import hanze.ga.wt3.channels.App2Q;
3
import hanze.ga.wt3.channels.Channel;
4
import hanze.ga.wt3.channels.Channel;
4
import hanze.ga.wt3.channels.ESBQueue;
5
import hanze.ga.wt3.channels.ESBQueue;
6
import hanze.ga.wt3.channels.Q2App;
5
import hanze.ga.wt3.ftp.FTPApp2QChannel;
7
import hanze.ga.wt3.ftp.FTPApp2QChannel;
6
import hanze.ga.wt3.ftp.FTPQ2AppChannel;
8
import hanze.ga.wt3.ftp.FTPQ2AppChannel;
7
import hanze.ga.wt3.helper.Security;
9
import hanze.ga.wt3.helper.Security;
...
...
37
			this.buildFTPApp2Q(channelDef);
39
			this.buildFTPApp2Q(channelDef);
38
		}
40
		}
39
	}
41
	}
42
	
43
	/**
44
	 * Zorgt ervoor dat een Channel de juiste bron- en bestemmingsQueue heeft.
45
	 */
46
	private void linkQueueToChannel() {
47
		for (ESBQueue esbQueue : this.queues.values()) {
40
48
49
			// Link receiver
50
			Channel receiver = esbQueue.getqReceiverChannel();
51
			if (receiver instanceof App2Q) {
52
				((App2Q) receiver).setDestinationQueue(esbQueue);
53
			} else if (receiver instanceof Q2App) {
54
				((Q2App) receiver).setSourceQueue(esbQueue);
55
			}
56
57
			// Link sender
58
			Channel sender = esbQueue.getqSenderChannel();
59
			if (sender instanceof App2Q) {
60
				((App2Q) sender).setDestinationQueue(esbQueue);
61
			} else if (sender instanceof Q2App) {
62
				((Q2App) sender).setSourceQueue(esbQueue);
63
			}
64
		}
65
	}
66
41
	private void buildFTPApp2Q(Xml channel) {
67
	private void buildFTPApp2Q(Xml channel) {
42
		FTPApp2QChannel ftp = new FTPApp2QChannel();
68
		FTPApp2QChannel ftp = new FTPApp2QChannel();
43
69
...
...
66
		Xml root = new Xml(filePath, "esb-configuration");
92
		Xml root = new Xml(filePath, "esb-configuration");
67
		this.buildChannels(root);
93
		this.buildChannels(root);
68
		this.buildQueues(root);
94
		this.buildQueues(root);
95
		this.linkQueueToChannel();
69
	}
96
	}
70
97
71
	/**
98
	/**