5 from http.server import BaseHTTPRequestHandler
6 from http.server import HTTPServer
8 posted_event_from_prh = b'Empty'
9 received_event_to_get_method = b'Empty'
12 class DmaapSetup(BaseHTTPRequestHandler):
15 if re.search('/set_get_event', self.path):
16 global received_event_to_get_method
17 content_length = int(self.headers['Content-Length'])
18 received_event_to_get_method = self.rfile.read(content_length)
19 _header_200_and_json(self)
24 if re.search('/events/pnfReady', self.path):
25 _header_200_and_json(self)
26 self.wfile.write(posted_event_from_prh)
31 if re.search('/reset', self.path):
32 global posted_event_from_prh
33 global received_event_to_get_method
34 posted_event_from_prh = b'Empty'
35 received_event_to_get_method = b'Empty'
36 _header_200_and_json(self)
41 class DMaaPHandler(BaseHTTPRequestHandler):
44 if re.search('/events/unauthenticated.PNF_READY', self.path):
45 global posted_event_from_prh
46 content_length = int(self.headers['Content-Length'])
47 posted_event_from_prh = self.rfile.read(content_length)
48 _header_200_and_json(self)
53 if re.search('/events/unauthenticated.VES_PNFREG_OUTPUT/OpenDcae-c12/c12', self.path):
54 _header_200_and_json(self)
55 self.wfile.write(received_event_to_get_method)
60 def _header_200_and_json(self):
61 self.send_response(200)
62 self.send_header('Content-Type', 'application/json')
66 def _main_(handler_class=DMaaPHandler, protocol="HTTP/1.0"):
67 handler_class.protocol_version = protocol
68 _thread.start_new_thread(_init_http_endpoints, (2222, DMaaPHandler))
69 _thread.start_new_thread(_init_https_endpoints, (2223, DMaaPHandler))
70 _thread.start_new_thread(_init_http_endpoints, (2224, DmaapSetup))
75 def _init_http_endpoints(port, handler_class, server_class=HTTPServer):
76 server = server_class(('', port), handler_class)
77 sa = server.socket.getsockname()
78 print("Serving HTTP on", sa[0], "port", sa[1], "for", handler_class, "...")
79 server.serve_forever()
82 def _init_https_endpoints(port, handler_class, server_class=HTTPServer):
83 server = server_class(('', port), handler_class)
84 server.socket = ssl.wrap_socket(server.socket,
85 keyfile="certs/server.key", certfile="certs/server.crt",
86 ca_certs="certs/client.crt", server_side=True)
87 sa = server.socket.getsockname()
88 print("Serving HTTPS on", sa[0], "port", sa[1], "for", handler_class, "...")
89 server.serve_forever()
92 if __name__ == '__main__':