5 from http.server import BaseHTTPRequestHandler
8 ch = logging.StreamHandler(sys.stdout)
12 format='[%(asctime)s] {%(filename)s:%(lineno)d} %(levelname)s - %(message)s',
16 logger = logging.getLogger('DMaaP-simulator-logger')
18 posted_event_from_prh = b'Empty'
19 received_event_to_get_method = b'Empty'
22 class DmaapSetup(BaseHTTPRequestHandler):
25 logger.info('DMaaP SIM Setup Put execution')
26 if re.search('/set_get_event', self.path):
27 global received_event_to_get_method
28 content_length = int(self.headers['Content-Length'])
29 received_event_to_get_method = self.rfile.read(content_length)
30 httpServerLib.header_200_and_json(self)
35 logger.info('DMaaP SIM Setup Get execution')
36 if re.search('/events/pnfReady', self.path):
37 httpServerLib.header_200_and_json(self)
38 self.wfile.write(posted_event_from_prh)
43 logger.info('DMaaP SIM Setup Post execution')
44 if re.search('/reset', self.path):
45 global posted_event_from_prh
46 global received_event_to_get_method
47 posted_event_from_prh = b'Empty'
48 received_event_to_get_method = b'Empty'
49 httpServerLib.header_200_and_json(self)
54 class DMaaPHandler(BaseHTTPRequestHandler):
57 logger.info('DMaaP SIM Post execution')
58 if re.search('/events/unauthenticated.PNF_READY', self.path):
59 global posted_event_from_prh
60 content_length = int(self.headers['Content-Length'])
61 posted_event_from_prh = self.rfile.read(content_length)
62 httpServerLib.header_200_and_json(self)
67 logger.info('DMaaP SIM Get execution')
68 if re.search('/events/unauthenticated.VES_PNFREG_OUTPUT/OpenDcae-c12/c12', self.path):
69 httpServerLib.header_200_and_json(self)
70 self.wfile.write(received_event_to_get_method)
75 def _main_(handler_class=DMaaPHandler, protocol="HTTP/1.0"):
76 handler_class.protocol_version = protocol
77 httpServerLib.start_http_endpoint(2222, DMaaPHandler)
78 httpServerLib.start_https_endpoint(2223, DMaaPHandler, keyfile="certs/org.onap.dmaap-bc.key", certfile="certs/dmaap_bc_topic_mgr_dmaap_bc.onap.org.cer", ca_certs="certs/ca_local_0.cer")
79 httpServerLib.start_http_endpoint(2224, DmaapSetup)
84 if __name__ == '__main__':