Handshake first attempt
This commit is contained in:
@@ -257,13 +257,57 @@ class PingAction(AlpineBitsAction):
|
||||
except Exception as e:
|
||||
return AlpineBitsResponse(f"Error: Invalid XML request - {str(e)}", HttpStatusCode.BAD_REQUEST)
|
||||
|
||||
# compare echo data with capabilities, create a dictionary containing the matching capabilities
|
||||
capabilities_dict = server_capabilities.get_capabilities_dict()
|
||||
matching_capabilities = {"versions": []}
|
||||
|
||||
# Iterate through client's requested versions
|
||||
for client_version in echo_data.get("versions", []):
|
||||
client_version_str = client_version.get("version", "")
|
||||
|
||||
# Find matching server version
|
||||
for server_version in capabilities_dict["versions"]:
|
||||
if server_version["version"] == client_version_str:
|
||||
# Found a matching version, now find common actions
|
||||
matching_version = {
|
||||
"version": client_version_str,
|
||||
"actions": []
|
||||
}
|
||||
|
||||
# Get client's requested actions for this version
|
||||
client_actions = {action.get("action", ""): action for action in client_version.get("actions", [])}
|
||||
server_actions = {action.get("action", ""): action for action in server_version.get("actions", [])}
|
||||
|
||||
# Find common actions
|
||||
for action_name in client_actions:
|
||||
if action_name in server_actions:
|
||||
# Use server's action definition (includes our supports)
|
||||
matching_version["actions"].append(server_actions[action_name])
|
||||
|
||||
# Only add version if there are common actions
|
||||
if matching_version["actions"]:
|
||||
matching_capabilities["versions"].append(matching_version)
|
||||
break
|
||||
|
||||
# Debug print to see what we matched
|
||||
print("🔍 Client requested capabilities:")
|
||||
print(json.dumps(echo_data, indent=2))
|
||||
print("\n🏠 Server capabilities:")
|
||||
print(json.dumps(capabilities_dict, indent=2))
|
||||
print("\n🤝 Matching capabilities:")
|
||||
print(json.dumps(matching_capabilities, indent=2))
|
||||
|
||||
# Create successful ping response with matched capabilities
|
||||
capabilities_json = json.dumps(matching_capabilities, indent=2)
|
||||
|
||||
|
||||
|
||||
|
||||
response_xml = f'''<?xml version="1.0" encoding="UTF-8"?>
|
||||
<OTA_PingRS xmlns="http://www.opentravel.org/OTA/2003/05" Version="8.000">
|
||||
<Success/>
|
||||
<Warnings>
|
||||
<Warning Type="11" Status="AlpineBitsHandshake">{capabilities_json}</Warning>
|
||||
</Warnings>
|
||||
<EchoData>{capabilities_json}</EchoData>
|
||||
</OTA_PingRS>'''
|
||||
|
||||
|
||||
|
||||
@@ -400,7 +444,11 @@ class AlpineBitsServer:
|
||||
|
||||
# Handle the request
|
||||
try:
|
||||
return await action_instance.handle(request_action_name, request_xml, version_enum)
|
||||
# Special case for ping action - pass server capabilities
|
||||
if capability_name == "action_OTA_Ping":
|
||||
return await action_instance.handle(request_action_name, request_xml, version_enum, self.capabilities)
|
||||
else:
|
||||
return await action_instance.handle(request_action_name, request_xml, version_enum)
|
||||
except Exception as e:
|
||||
return AlpineBitsResponse(
|
||||
f"Error: Internal server error while processing {request_action_name}: {str(e)}",
|
||||
@@ -487,7 +535,7 @@ async def main():
|
||||
test_cases = [
|
||||
("OTA_Ping:Handshaking", "2024-10"),
|
||||
("OTA_Read:GuestRequests", "2024-10"),
|
||||
("OTA_Read:GuestRequest", "2022-10"),
|
||||
("OTA_Read:GuestRequests", "2022-10"),
|
||||
("OTA_HotelAvailNotif", "2024-10"),
|
||||
("UnknownAction", "2024-10"),
|
||||
("OTA_Ping:Handshaking", "unsupported-version")
|
||||
|
||||
Reference in New Issue
Block a user