|
@@ -38,15 +38,23 @@ class VTNService:
|
|
Handle all incoming POST requests.
|
|
Handle all incoming POST requests.
|
|
"""
|
|
"""
|
|
content = await request.read()
|
|
content = await request.read()
|
|
- print(f"Received: {content.decode('utf-8')}")
|
|
|
|
message_type, message_payload = self._parse_message(content)
|
|
message_type, message_payload = self._parse_message(content)
|
|
- print(f"Interpreted message: {message_type}: {message_payload}")
|
|
|
|
|
|
|
|
if message_type in self.handlers:
|
|
if message_type in self.handlers:
|
|
handler = self.handlers[message_type]
|
|
handler = self.handlers[message_type]
|
|
- response_type, response_payload = await handler(message_payload)
|
|
|
|
|
|
+ result = handler(message_payload)
|
|
|
|
+ if iscoroutine(result):
|
|
|
|
+ result = await result
|
|
|
|
+ if result is not None:
|
|
|
|
+ response_type, response_payload = result
|
|
|
|
+ else:
|
|
|
|
+ response_type, response_payload = 'oadrResponse', {}
|
|
response_payload['vtn_id'] = self.vtn_id
|
|
response_payload['vtn_id'] = self.vtn_id
|
|
|
|
|
|
|
|
+ response_payload['response'] = {'request_id': message_payload.get('request_id', None),
|
|
|
|
+ 'response_code': 200,
|
|
|
|
+ 'response_description': 'OK'}
|
|
|
|
+
|
|
# Create the XML response
|
|
# Create the XML response
|
|
msg = self._create_message(response_type, **response_payload)
|
|
msg = self._create_message(response_type, **response_payload)
|
|
response = web.Response(text=msg,
|
|
response = web.Response(text=msg,
|
|
@@ -56,10 +64,9 @@ class VTNService:
|
|
else:
|
|
else:
|
|
msg = self._create_message('oadrResponse',
|
|
msg = self._create_message('oadrResponse',
|
|
status_code=errorcodes.COMPLIANCE_ERROR,
|
|
status_code=errorcodes.COMPLIANCE_ERROR,
|
|
- status_description=f'A message of type {message_type} should not be sent to this endpoint')
|
|
|
|
|
|
+ status_description=f"A message of type {message_type} should not be sent to this endpoint")
|
|
response = web.Response(
|
|
response = web.Response(
|
|
text=msg,
|
|
text=msg,
|
|
status=HTTPStatus.BAD_REQUEST,
|
|
status=HTTPStatus.BAD_REQUEST,
|
|
content_type='application/xml')
|
|
content_type='application/xml')
|
|
- print(f"Sending {response.text}")
|
|
|
|
return response
|
|
return response
|