Author: klystr
(2009/12/03 15:02) About 2 years ago
IBG > Q2 ready, IBG-app moet nog
1
package hanze.ga.wt3.channels;
2
3
/**
4
* Applicatie naar Queue
5
*/
public abstract class App2Q extends Channel {
6
7
private ESBQueue destinationQueue;
8
11
private Channel qReceiverChannel;
12
private Queue<String> queue = new LinkedList<String>();
13
14
15
* Adds a String with file contents to the Queue
16
*
17
* @param input
18
* String with contents of file
19
public void addToQueue(String input) {
20
System.out.println("[" + this.getqName() + "] Item was added");
21
this.queue.add(input);
22
...
36
return this.queue.size();
42
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
40
System.out.println("[" + this.getqName() + "] Item was polled");
51
41
return this.queue.poll();
52
package hanze.ga.wt3.ftp;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.SocketException;
import org.apache.commons.net.ftp.FTPClient;
9
import org.apache.commons.net.ftp.FTPFile;
10
public class ESBFTP {
private String ftpAddress, ftpUserName, ftpPassword;
int ftpPort;
private FTPClient ftpClient;
* Klasse maakt FTP-handelingen mogelijk
* @param ftpAddress
* IP-adres of hostnaam van FTP-server
* @param ftpUserName
23
* FTP-username
24
* @param ftpPassword
25
* FTP-password
26
* @param ftpPort
27
* FTP-poort (standaard 21)
28
public ESBFTP(String ftpAddress, String ftpUserName, String ftpPassword, int ftpPort) {
29
this.ftpAddress = ftpAddress;
30
this.ftpUserName = ftpUserName;
31
this.ftpPort = ftpPort;
33
34
35
public void store(InputStream file, String destination) {
FTPClient ftpClient = new FTPClient();
* Maakt verbinding met de FTP-server en slaat deze verbinding op in de
* lokale variabele ftpClient
private void makeConnection() {
try {
// Naar FTP
ftpClient = new FTPClient();
ftpClient.connect(this.ftpAddress, this.ftpPort);
ftpClient.login(this.ftpUserName, this.ftpPassword);
ftpClient.storeFile(destination, file);
ftpClient.disconnect();
} catch (SocketException e) {
e.printStackTrace();
} catch (IOException e) {
53
* Sluit connectie met server die nu in lokale variabele ftpClient staat
54
55
private void terminateConnection() {
56
57
this.ftpClient.disconnect();
58
59
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
73
74
this.makeConnection();
75
this.ftpClient.storeFile(destination, file);
76
this.terminateConnection();
77
78
79
80
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
93
FTPFile[] output = null;
94
95
output = this.ftpClient.listFiles(directory);
96
97
98
99
100
return output;
101
102
103
104
* Haalt opgegeven bestand van de server er verwijderd deze.
105
106
* @param filePath
107
108
* @return Bestandsinhoud
109
110
public String pollFile(String filePath) {
111
112
ByteArrayOutputStream outputStream = null;
113
114
outputStream = new ByteArrayOutputStream();
115
this.ftpClient.retrieveFile(filePath, outputStream);
116
this.ftpClient.dele(filePath);
117
118
119
120
121
122
return outputStream.toString();
123
124
public class FTPQ2AppChannel extends Q2App {
private String ftpAddress;
private String ftpInitDir;
private String ftpUserName;
private String ftpPassword;
<channel-def>
<name>OutboxIBGQ2APP</name>
<adapter>
<direction>Q2APP</direction>
<direction>APP2Q</direction>
<protocol>FTP</protocol>
<address>145.33.160.234</address>
<port>9090</port>
import hanze.ga.wt3.channels.Channel;
import hanze.ga.wt3.channels.ESBQueue;
import hanze.ga.wt3.ftp.FTPApp2QChannel;
import hanze.ga.wt3.ftp.FTPQ2AppChannel;
import hanze.ga.wt3.helper.Security;
import hanze.ga.wt3.http.HTTPApp2QChannel;
32
this.buildHttpApp2Q(channelDef);
} else if (protocol.equals("SOCKET")) {
this.buildSocketApp2Q(channelDef);
} else if (protocol.equals("FTP")) {
this.buildFTPApp2Q(channelDef);
private void buildFTPApp2Q(Xml channel) {
FTPApp2QChannel ftp = new FTPApp2QChannel();
// Globale settings
ftp.setChannelName(channel.child("name").content());
// FTP Adapter waarden
Xml adapterNode = channel.child("adapter");
ftp.setFtpAddress(adapterNode.child("address").content());
ftp.setFtpInitDir(adapterNode.child("init-dir").content());
ftp.setFtpPassword(adapterNode.child("password").content());
ftp.setFtpUserName(adapterNode.child("username").content());
ftp.setChannelPort(adapterNode.child("port").content());
// Zet in lijst
this.channels.put(channel.child("name").content(), ftp);
* Bouwen van ESB aan de hand van XML-bestand.
public abstract class App2Q extends Channel {public abstract class App2Q extends Channel {public void addToQueue(String input) {public void addToQueue(String input) {System.out.println("[" + this.getqName() + "] Item was added");System.out.println("[" + this.getqName() + "] Item was added");public String pollFromQueue() {public String pollFromQueue() {System.out.println("[" + this.getqName() + "] Item was polled");System.out.println("[" + this.getqName() + "] Item was polled");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) {public void store(InputStream file, String destination) {/**FTPClient ftpClient = new FTPClient();* Maakt verbinding met de FTP-server en slaat deze verbinding op in de* lokale variabele ftpClient*/private void makeConnection() {try {try {// Naar FTPftpClient = new FTPClient();ftpClient.storeFile(destination, file);ftpClient.disconnect();} catch (SocketException e) {} catch (SocketException e) {} catch (IOException e) {} catch (IOException e) {private void terminateConnection() {try {} catch (IOException e) {public void store(InputStream file, String destination) {try {} catch (SocketException e) {} catch (IOException e) {public FTPFile[] getFilesFromDir(String directory) {try {} catch (IOException e) {public String pollFile(String filePath) {try {} catch (IOException e) {public class FTPQ2AppChannel extends Q2App {public class FTPQ2AppChannel extends Q2App {<direction>Q2APP</direction><direction>APP2Q</direction>} else if (protocol.equals("SOCKET")) {} else if (protocol.equals("SOCKET")) {} else if (protocol.equals("FTP")) {private void buildFTPApp2Q(Xml channel) {ftp.setChannelName(channel.child("name").content());Xml adapterNode = channel.child("adapter");ftp.setFtpAddress(adapterNode.child("address").content());ftp.setFtpInitDir(adapterNode.child("init-dir").content());ftp.setFtpPassword(adapterNode.child("password").content());ftp.setFtpUserName(adapterNode.child("username").content());ftp.setChannelPort(adapterNode.child("port").content());this.channels.put(channel.child("name").content(), ftp);