TestDebugMsg.java
3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package th.co.ais.ssbsrfc.control;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileReader;
import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.xpath.XPathExpressionException;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import ec02.exception.MessageParserException;
import ec02.server.EC02Handler;
import ec02.server.EC02Server;
public class TestDebugMsg {
public static void main(String[] args) throws IOException,
TransformerException, XPathExpressionException,
ParserConfigurationException, SAXException, MessageParserException {
BufferedReader in = new BufferedReader(new FileReader(
"./example.msg/" +
// "debug.html-text-plain.xml"
// "debug.html-text-xml.xml"
// "debug.html-text-xml-header.xml"
// "debug.ldap.xml"
// "debug.diameter.xml"
"debug.xml"
));
String str, reqMessage = "";
String conf = "";
String temp = "";
while ((str = in.readLine()) != null) {
reqMessage += str;
}
in.close();
in = new BufferedReader(new FileReader("./conf/WS1.EC02.SERV.0"));
while ((temp = in.readLine()) != null) {
conf += temp;
}
in.close();
String[] a = { "WS1", "SERV", "0", conf };
EC02Server.main(a);
EC02Handler handler = new EC02Handler();
System.out.println(handler.verifyAFConfig(conf));
System.out.println(TestDebugMsg.formatXml(handler.handle(reqMessage,
100000)));
// int max=100;
// for(int i=0; i<=max; i++)
// {
// ProcessingThread pt = new ProcessingThread(conf, reqMessage);
// Thread t = new Thread(pt, "t"+String.valueOf(i));
// t.start();
// }
}
public static String formatXml(String xml) {
try {
Transformer serializer = TransformerFactory.newInstance()
.newTransformer();
serializer.setOutputProperty(OutputKeys.INDENT, "yes");
serializer.setOutputProperty(
"{http://xml.apache.org/xslt}indent-amount", "4");
Source xmlSource = new SAXSource(new InputSource(
new ByteArrayInputStream(xml.getBytes())));
StreamResult res = new StreamResult(new ByteArrayOutputStream());
serializer.transform(xmlSource, res);
return new String(
((ByteArrayOutputStream) res.getOutputStream())
.toByteArray());
} catch (Exception e) {
return xml;
}
}
}
class ProcessingThread1 implements Runnable {
private String conf;
private String reqMessage;
public ProcessingThread1(String _conf, String _msg) {
this.conf = _conf;
this.reqMessage = _msg;
}
@Override
public void run() {
EC02Handler handler = new EC02Handler();
System.out.println(handler.verifyAFConfig(conf));
System.out.println(TestDebugMsg.formatXml(handler.handle(reqMessage,
100000)));
}
}