Author: klystr
(2009/12/03 13:25) About 2 years ago
16
this.queue.add(input);
17
}
18
19
public String pollFromQueue() {
20
System.out.println("[" + this.getqName() + "] Item was polled");
21
return this.queue.poll();
22
23
24
public String getqName() {
25
return qName;
26
...
37
return qSenderFilter;
32
38
33
39
34
35
public int getSize() {
36
return this.queue.size();
40
41
42
43
public void setqName(String qName) {
44
this.qName = qName;
45
46
53
this.qSenderFilter = qSenderFilter;
57
54
58
55
59
56
60
4
import java.io.InputStream;
5
import java.net.SocketException;
6
7
import org.apache.commons.net.ftp.*;
import org.apache.commons.net.ftp.FTPClient;
8
9
public class ESBFTP {
10
11
private String ftpAddress, ftpUserName, ftpPassword;
12
int ftpPort;
13
14
public ESBFTP(String ftpAddress, String ftpUserName, String ftpPassword, int ftpPort) {
15
this.ftpAddress = ftpAddress;
this.ftpUserName = ftpUserName;
e.printStackTrace();
1
package hanze.ga.wt3.ftp;
2
3
import java.io.*;
import hanze.ga.wt3.channels.Q2App;
import hanze.ga.wt3.filters.ToIBGFilter;
import hanze.ga.wt3.xml.Xml;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileWriter;
import java.io.StringReader;
import java.io.StringWriter;
public class FTPQ2AppChannel extends Q2App {
private String ftpAddress;
30
return ftpUserName;
31
@Override
public void run() {
try {
while (true) {
this.readQueue();
Thread.sleep(1000);
} catch (InterruptedException e) {
private void readQueue() {
while (this.getSourceQueue().getSize() > 0) {
47
this.processItem(this.getSourceQueue().pollFromQueue());
48
49
50
51
private void processItem(String pollItem) {
52
StringWriter stringWriter = new StringWriter();
62
Xml xmlParser = new Xml("C:/esb.tmp", "message");
63
String reqId = xmlParser.child("id").content();
64
tmpFile.delete();
65
66
// Filter item
67
ToIBGFilter toFilter = new ToIBGFilter();
68
toFilter.doFilter(new StringReader(pollItem), stringWriter);
69
String fileContents = stringWriter.toString();
70
71
// Maak FTP-verbinding klaar
72
ESBFTP ftpClient = new ESBFTP(this.getFtpAddress(), this.getFtpUserName(), this
73
.getFtpPassword(), this.getChannelPort());
88
74
89
75
90
76
77
78
79
80
81
82
83
84
85
86
87
91
92
93
94
public void setFtpAddress(String ftpAddress) {
95
96
super.setChannelIp(ftpAddress);
97
package hanze.ga.wt3.http;
import java.net.*;
import hanze.ga.wt3.channels.App2Q;
import hanze.ga.wt3.helper.Security;
import java.io.IOException;
import java.net.ServerSocket;
public class HTTPApp2QChannel extends App2Q {
private Security httpSecurity;
private Socket socket;
private PrintWriter outPutWriter;
private BufferedReader inputReader;
private StringBuilder inputMessage;
private String inputMessage;
private HTTPApp2QChannel httpObject;
public HTTPConnection(Socket accept, HTTPApp2QChannel httpObject) {
this.httpObject = httpObject;
private String getHttpQueueName() {
return this.httpObject.getDestinationQueue().getqName();
private String getQueueName(String header) {
27
// "POST /<<QueueNaam>> HTTP/1.1"
28
return header.substring(6, header.indexOf(" HTTP/1.1"));
29
private void handleValidRequest() {
int contentLength = 0;
String inputLine = inputReader.readLine().trim();
while (inputLine != null) {
if (inputLine.startsWith("Content-Length=")) {
// Content length oplezen
contentLength = Integer.parseInt(inputLine.substring(15));
} catch (Exception e) {
outPutWriter.println("HTTP/1.1 500 Bad Request");
break;
} else {
inputMessage = inputLine;
inputLine = inputReader.readLine().trim();
private void initListen() {
System.out.println("[HTTPApp2QChannel] Connection received from "
+ socket.getInetAddress().getHostName());
100
101
102
this.inputMessage = new StringBuilder();
// Lees input in stringbuilder
char[] tmp = new char[contentLength];
int index = 0;
int read = 0;
while (index < contentLength
&& (read = inputReader.read(tmp, index, contentLength - index)) >= 0) {
index += read;
inputMessage.append("<message>");
inputMessage.append(tmp);
98
99
103
104
105
106
107
108
109
110
111
112
113
114
private void writeToQueue() {
115
this.httpObject.getDestinationQueue().addToQueue(inputMessage.toString());
116
117
118
119
120
// Open connection
121
this.initListen();
122
123
// Input lezen
124
this.listenAndHandle();
125
126
// Schrijf input naar Queue
127
this.writeToQueue();
128
129
this.httpObject.getDestinationQueue().addToQueue(inputMessage);
130
package hanze.ga.wt3.main;
import hanze.ga.wt3.channels.*;
import hanze.ga.wt3.channels.Channel;
import hanze.ga.wt3.channels.ESBQueue;
import hanze.ga.wt3.xml.ESBDOMParser;
import java.util.HashMap;
/**
* Start elke channel in een nieuwe Thread
*/
private void initChannels() {
for (Channel channel : this.esbChannels.values()) {
new Thread(channel).start();
* Zorgt ervoor dat een Channel de juiste bron- en bestemmingsQueue heeft.
private void linkQueueToChannel() {
61
public String pollFromQueue() {System.out.println("[" + this.getqName() + "] Item was polled");return this.queue.poll();}public String getqName() {public String getqName() {public int getSize() {public String pollFromQueue() {System.out.println("[" + this.getqName() + "] Item was polled");public void setqName(String qName) {public void setqName(String qName) {public int getSize() {return this.queue.size();}import org.apache.commons.net.ftp.*;import org.apache.commons.net.ftp.FTPClient;public class ESBFTP {public class ESBFTP {public ESBFTP(String ftpAddress, String ftpUserName, String ftpPassword, int ftpPort) {public ESBFTP(String ftpAddress, String ftpUserName, String ftpPassword, int ftpPort) {import java.io.*;public class FTPQ2AppChannel extends Q2App {public class FTPQ2AppChannel extends Q2App {@Overridepublic void run() {try {while (true) {this.readQueue();Thread.sleep(1000);}} catch (InterruptedException e) {e.printStackTrace();}}private void readQueue() {while (this.getSourceQueue().getSize() > 0) {this.processItem(this.getSourceQueue().pollFromQueue());}}private void processItem(String pollItem) {private void processItem(String pollItem) {Xml xmlParser = new Xml("C:/esb.tmp", "message");Xml xmlParser = new Xml("C:/esb.tmp", "message");String reqId = xmlParser.child("id").content();String reqId = xmlParser.child("id").content();private void readQueue() {while (this.getSourceQueue().getSize() > 0) {public void run() {try {while (true) {} catch (InterruptedException e) {public void setFtpAddress(String ftpAddress) {public void setFtpAddress(String ftpAddress) {import java.io.*;import java.net.*;public class HTTPApp2QChannel extends App2Q {public class HTTPApp2QChannel extends App2Q {private StringBuilder inputMessage;public HTTPConnection(Socket accept, HTTPApp2QChannel httpObject) {public HTTPConnection(Socket accept, HTTPApp2QChannel httpObject) {private String getHttpQueueName() {private String getQueueName(String header) {return header.substring(6, header.indexOf(" HTTP/1.1"));private void handleValidRequest() {try {while (inputLine != null) {if (inputLine.startsWith("Content-Length=")) {try {} catch (Exception e) {outPutWriter.println("HTTP/1.1 500 Bad Request");} else {} catch (Exception e) {outPutWriter.println("HTTP/1.1 500 Bad Request");private void initListen() {private void initListen() {System.out.println("[HTTPApp2QChannel] Connection received from "System.out.println("[HTTPApp2QChannel] Connection received from "private void handleValidRequest() {int contentLength = 0;this.inputMessage = new StringBuilder();try {String inputLine = inputReader.readLine().trim();while (inputLine != null) {if (inputLine.startsWith("Content-Length=")) {// Content length oplezentry {contentLength = Integer.parseInt(inputLine.substring(15));} catch (Exception e) {outPutWriter.println("HTTP/1.1 500 Bad Request");break;}} else {// Lees input in stringbuilderchar[] tmp = new char[contentLength];int index = 0;int read = 0;while (index < contentLength&& (read = inputReader.read(tmp, index, contentLength - index)) >= 0) {index += read;}inputMessage.append("<message>");inputMessage.append(tmp);break;}inputLine = inputReader.readLine().trim();}} catch (Exception e) {outPutWriter.println("HTTP/1.1 500 Bad Request");}}private String getHttpQueueName() {return this.httpObject.getDestinationQueue().getqName();}private String getQueueName(String header) {// "POST /<<QueueNaam>> HTTP/1.1"return header.substring(6, header.indexOf(" HTTP/1.1"));}private void writeToQueue() {this.httpObject.getDestinationQueue().addToQueue(inputMessage.toString());}public void run() {public void run() {private void writeToQueue() {import hanze.ga.wt3.channels.*;import hanze.ga.wt3.channels.App2Q;import hanze.ga.wt3.channels.Channel;import hanze.ga.wt3.channels.ESBQueue;import hanze.ga.wt3.channels.Q2App;private void initChannels() {for (Channel channel : this.esbChannels.values()) {private void linkQueueToChannel() {private void linkQueueToChannel() {/*** Start elke channel in een nieuwe Thread*/private void initChannels() {for (Channel channel : this.esbChannels.values()) {new Thread(channel).start();}}