forked from waterscar/docker-soapui
-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathserver.py
More file actions
executable file
·104 lines (82 loc) · 3.21 KB
/
server.py
File metadata and controls
executable file
·104 lines (82 loc) · 3.21 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
#!/usr/bin/env python
from __future__ import print_function
import cgi
import urlparse
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
from subprocess import Popen, PIPE
class S(BaseHTTPRequestHandler):
def _set_headers(self):
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
def do_GET(self):
self._set_headers()
with open('server_index.html', 'r') as server_index:
self.wfile.write(server_index.read().replace('\n', ''))
def do_POST(self):
# self._set_headers()
ctype, pdict = cgi.parse_header(self.headers.getheader('content-type'))
if ctype == 'multipart/form-data':
postvars = cgi.parse_multipart(self.rfile, pdict)
elif ctype == 'application/x-www-form-urlencoded':
length = int(self.headers.getheader('content-length'))
postvars = urlparse.parse_qs(self.rfile.read(length), keep_blank_values=1)
elif ctype == 'text/xml':
length = int(self.headers.getheader('content-length'))
postvars = urlparse.parse_qs(self.rfile.read(length), keep_blank_values=1)
else:
postvars = {}
suite = postvars.get('suite')
xml = postvars.get('project')
properties = postvars.get('properties')
option = postvars.get('option')
if not xml:
self.send_response(552, message='No SoapUI Project')
self.end_headers()
self.wfile.write('you need to specify the SoapUI project!')
return
else:
xml = xml[0]
f = open('/tmp/soapui-project.xml', 'w')
print(xml, file=f)
f.close()
arguments = ['/opt/SoapUI/bin/testrunner.sh']
if suite:
arguments.append('-r -s"%s"' % suite[0])
if option:
for op in option:
for line in op.splitlines():
arguments.append('%s' % line)
if properties:
properties = properties[0]
f = open('/tmp/global.properties', 'w')
print(properties, file=f)
f.close()
arguments.append('-Dsoapui.properties=/tmp/global.properties')
arguments.append('/tmp/soapui-project.xml')
p = Popen(arguments, stdin=PIPE, stdout=PIPE, stderr=PIPE, bufsize=-1)
try:
output, error = p.communicate()
if p.returncode >= 1:
self.send_response(550, message='Test Failure(s)')
self.end_headers()
self.wfile.write(output)
self.wfile.write(error)
else:
self.send_response(200)
self.end_headers()
self.wfile.write(output)
except Exception as e:
self.send_response(500)
self.wfile.write(e)
def run(server_class=HTTPServer, handler_class=S, port=3000):
server_address = ('', port)
httpd = server_class(server_address, handler_class)
print('SoapUI Test Runner Started on port %s...' % port)
httpd.serve_forever()
if __name__ == "__main__":
from sys import argv
if len(argv) == 2:
run(port=int(argv[1]))
else:
run()