Author: klystr
(2009/12/04 11:06) About 2 years ago
Send to Q3 done
21
System.out.println("[" + this.getqName() + "] Item was added");
22
this.queue.add(input);
23
}
24
25
public void deleteFromQueue(String queuedObject) {
26
this.queue.remove(queuedObject);
27
28
public String getqName() {
29
return qName;
30
try {
while (true) {
this.readAndProcessFTP();
Thread.sleep(3000);
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
serverSocket = new ServerSocket(this.getChannelPort());
new Thread(new HTTPConnection(serverSocket.accept(), this)).start();
new Thread(new HTTPPostConnection(serverSocket.accept(), this)).start();
} catch (IOException e) {
16
private Socket socket;
17
private PrintWriter outPutWriter;
18
private BufferedReader inputReader;
19
private String inputMessage;
20
private HTTPQ2AppChannel httpObject;
public HTTPGetConnection(Socket accept, HTTPQ2AppChannel httpq2AppChannel) {
...
32
31
33
private String getQueueName(String header) {
34
// "GET /<<QueueNaam>> HTTP/1.1"
if (header.indexOf("?") > 0) { // Has ID
35
return header.substring(5, header.indexOf("?ID="));
36
37
return header.substring(5, header.indexOf(" HTTP/1.1"));
38
39
40
private void reply(String queryType) {
41
if (queryType.indexOf("?ID") > 0) { // Specifiek ID
42
if (queryType.indexOf("?ID=") > 0) { // Specifiek ID
this.replyId(this.getId(queryType));
43
} else { // Overzicht
44
this.replyList();
45
63
66
64
// Luister naar input van gebruiker
67
65
68
String inputLine = inputReader.readLine().trim();
69
String inputLine = inputReader.readLine();
while (inputLine != null) {
70
if (inputLine.startsWith("GET /")) {
71
String queryType = this.getHttpQueueName();
72
if (queryType.equals(this.getQueueName(inputLine))) {
73
String qName = this.getQueueName(inputLine);
this.reply(queryType);
74
if (queryType.equals(qName)) {
75
this.reply(inputLine);
break;
76
} else {
77
System.err.println("Queue niet gevonden");
78
System.err.println("Queue " + qName + " niet gevonden");
outPutWriter.println("HTTP/1.1 404 Not Found");
79
80
81
85
outPutWriter.close();
89
86
inputReader.close();
90
87
91
88
// Print op scherm
// System.out.println();
} catch (Exception e) {
92
// do nothing
93
System.err.println("Fout in connectie");
94
134
LinkedList<String> queued = this.httpObject.getSourceQueue().peekEntireQueue();
135
if (queued.size() > 0) {
136
for (String inQueue : queued) {
137
if (queryId == this.findId(inQueue)) {
138
if (queryId.equals(this.findId(inQueue))) {
outPutWriter.write("HTTP/1.1 200 OK\n");
139
outPutWriter.write("Content-Length=" + inQueue.length() + "\n");
140
outPutWriter.write(inQueue);
141
142
143
// Verwijder
144
this.httpObject.getSourceQueue().deleteFromQueue(inQueue);
145
return;
146
147
148
1
Naar FTP:
2
-----------------------------------------
POST /StudentPortalToIBGQueue HTTP/1.1
3
Content-Length=121
4
<message>
5
6
<payload>
8
7
Hier staat dan tekst
9
</payload>
10
</message>
11
12
13
14
Naar Socket:
15
SEND StudentPortalToLocatorQueue/121
<message><queue-name>StudentPortalToIBGQueue</queue-name><id>2</id><payload>Hier staat dan tekst</payload></message>
package hanze.ga.wt3.main;
import hanze.ga.wt3.channels.App2Q;
import hanze.ga.wt3.channels.Channel;
import hanze.ga.wt3.channels.ESBQueue;
import hanze.ga.wt3.channels.Q2App;
import hanze.ga.wt3.xml.ESBDOMParser;
import java.util.HashMap;
new ESBServer("C:/Users/Martijn/workspace/ESB/src/hanze/ga/wt3/xml/configuration.xml");
private HashMap<String, Channel> esbChannels;
public static HashMap<String, Channel> esbChannels;
private HashMap<String, ESBQueue> esbQueues;
@SuppressWarnings("static-access")
public ESBServer(String configFilePath) {
// Bouw ESB aan de hand van config
System.out.println(this.esbQueues.size() + " Queues");
System.out.println("------------------------------------");
// Zorgt dat Channels de juiste Queue's hebben
this.linkQueueToChannel();
// Start threads van channels
this.initChannels();
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);
} else if (receiver instanceof Q2App) {
((Q2App) receiver).setSourceQueue(esbQueue);
// Link sender
Channel sender = esbQueue.getqSenderChannel();
if (sender instanceof App2Q) {
((App2Q) sender).setDestinationQueue(esbQueue);
} else if (sender instanceof Q2App) {
((Q2App) sender).setSourceQueue(esbQueue);
49
<channel-def>
<name>LocatorIn</name>
<adapter>
<direction>Q2APP</direction> <!-- FOUT -->
<direction>APP2Q</direction> <!-- FOUT -->
<protocol>SOCKET</protocol>
<address>145.33.160.234</address>
<port>9091</port>
<name>LocatorOut</name>
<direction>APP2Q</direction>
<direction>Q2APP</direction>
package hanze.ga.wt3.xml;
import hanze.ga.wt3.ftp.FTPApp2QChannel;
import hanze.ga.wt3.ftp.FTPQ2AppChannel;
import hanze.ga.wt3.helper.Security;
this.buildFTPApp2Q(channelDef);
for (ESBQueue esbQueue : this.queues.values()) {
private void buildFTPApp2Q(Xml channel) {
FTPApp2QChannel ftp = new FTPApp2QChannel();
Xml root = new Xml(filePath, "esb-configuration");
this.buildChannels(root);
this.buildQueues(root);
95
96
97
98
System.out.println("[" + this.getqName() + "] Item was added");System.out.println("[" + this.getqName() + "] Item was added");public void deleteFromQueue(String queuedObject) {public String getqName() {public String getqName() {try {try {while (true) {while (true) {Thread.sleep(3000);Thread.sleep(10000);} catch (InterruptedException e) {} catch (InterruptedException e) {while (true) {while (true) {new Thread(new HTTPPostConnection(serverSocket.accept(), this)).start();} catch (IOException e) {} catch (IOException e) {private String inputMessage;public HTTPGetConnection(Socket accept, HTTPQ2AppChannel httpq2AppChannel) {public HTTPGetConnection(Socket accept, HTTPQ2AppChannel httpq2AppChannel) {private String getQueueName(String header) {private String getQueueName(String header) {if (header.indexOf("?") > 0) { // Has IDreturn header.substring(5, header.indexOf("?ID="));return header.substring(5, header.indexOf(" HTTP/1.1"));return header.substring(5, header.indexOf(" HTTP/1.1"));private void reply(String queryType) {private void reply(String queryType) {if (queryType.indexOf("?ID") > 0) { // Specifiek IDif (queryType.indexOf("?ID=") > 0) { // Specifiek ID} else { // Overzicht} else { // Overzichttry {try {String inputLine = inputReader.readLine().trim();while (inputLine != null) {while (inputLine != null) {if (inputLine.startsWith("GET /")) {if (inputLine.startsWith("GET /")) {if (queryType.equals(this.getQueueName(inputLine))) {String qName = this.getQueueName(inputLine);this.reply(queryType);if (queryType.equals(qName)) {this.reply(inputLine);} else {} else {System.err.println("Queue niet gevonden");System.err.println("Queue " + qName + " niet gevonden");outPutWriter.println("HTTP/1.1 404 Not Found");outPutWriter.println("HTTP/1.1 404 Not Found");// Print op scherm// System.out.println();} catch (Exception e) {} catch (Exception e) {System.err.println("Fout in connectie");System.err.println("Fout in connectie");if (queued.size() > 0) {if (queued.size() > 0) {for (String inQueue : queued) {for (String inQueue : queued) {if (queryId == this.findId(inQueue)) {if (queryId.equals(this.findId(inQueue))) {outPutWriter.write("HTTP/1.1 200 OK\n");outPutWriter.write("HTTP/1.1 200 OK\n");outPutWriter.write("Content-Length=" + inQueue.length() + "\n");outPutWriter.write("Content-Length=" + inQueue.length() + "\n");Naar Socket:-----------------------------------------SEND StudentPortalToLocatorQueue/121<message><queue-name>StudentPortalToIBGQueue</queue-name><id>2</id><payload>Hier staat dan tekst</payload></message>import hanze.ga.wt3.channels.App2Q;import hanze.ga.wt3.channels.Q2App;new ESBServer("C:/Users/Martijn/workspace/ESB/src/hanze/ga/wt3/xml/configuration.xml");new ESBServer("C:/Users/Martijn/workspace/ESB/src/hanze/ga/wt3/xml/configuration.xml");private HashMap<String, Channel> esbChannels;public static HashMap<String, Channel> esbChannels;@SuppressWarnings("static-access")public ESBServer(String configFilePath) {public ESBServer(String configFilePath) {System.out.println("------------------------------------");System.out.println("------------------------------------");// Zorgt dat Channels de juiste Queue's hebbenthis.linkQueueToChannel();/*** Zorgt ervoor dat een Channel de juiste bron- en bestemmingsQueue heeft.*/private void linkQueueToChannel() {for (ESBQueue esbQueue : esbQueues.values()) {// Link receiverChannel receiver = esbQueue.getqReceiverChannel();if (receiver instanceof App2Q) {((App2Q) receiver).setDestinationQueue(esbQueue);} else if (receiver instanceof Q2App) {((Q2App) receiver).setSourceQueue(esbQueue);}// Link senderChannel sender = esbQueue.getqSenderChannel();if (sender instanceof App2Q) {((App2Q) sender).setDestinationQueue(esbQueue);} else if (sender instanceof Q2App) {((Q2App) sender).setSourceQueue(esbQueue);}}}<direction>Q2APP</direction> <!-- FOUT --><direction>APP2Q</direction> <!-- FOUT --><direction>APP2Q</direction><direction>Q2APP</direction>private void linkQueueToChannel() {for (ESBQueue esbQueue : this.queues.values()) {if (receiver instanceof App2Q) {} else if (receiver instanceof Q2App) {if (sender instanceof App2Q) {} else if (sender instanceof Q2App) {private void buildFTPApp2Q(Xml channel) {private void buildFTPApp2Q(Xml channel) {