From 2b0fe78fac8041b4a2673c6bb8f5ddbb7e6e9cf3 Mon Sep 17 00:00:00 2001 From: stephb9959 Date: Fri, 10 Dec 2021 14:24:29 -0800 Subject: [PATCH] Framework update --- CMakeLists.txt | 2 +- build | 2 +- .../RESTAPI_Servers.cpp} | 12 +- src/RESTAPI/RESTAPI_configurations_handler.h | 3 +- .../RESTAPI_configurations_list_handler.h | 3 +- src/RESTAPI/RESTAPI_contact_handler.h | 3 +- src/RESTAPI/RESTAPI_contact_list_handler.h | 3 +- src/RESTAPI/RESTAPI_entity_handler.h | 3 +- src/RESTAPI/RESTAPI_entity_list_handler.h | 3 +- src/RESTAPI/RESTAPI_inventory_handler.h | 3 +- src/RESTAPI/RESTAPI_inventory_list_handler.h | 3 +- src/RESTAPI/RESTAPI_location_handler.h | 3 +- src/RESTAPI/RESTAPI_location_list_handler.h | 3 +- .../RESTAPI_managementPolicy_handler.h | 3 +- .../RESTAPI_managementPolicy_list_handler.h | 3 +- src/RESTAPI/RESTAPI_managementRole_handler.h | 3 +- .../RESTAPI_managementRole_list_handler.h | 3 +- src/RESTAPI/RESTAPI_map_handler.h | 3 +- src/RESTAPI/RESTAPI_map_list_handler.h | 3 +- src/RESTAPI/RESTAPI_venue_handler.h | 3 +- src/RESTAPI/RESTAPI_venue_list_handler.h | 3 +- src/RESTAPI/RESTAPI_webSocketServer.h | 4 +- src/framework/API_Proxy.h | 10 +- src/framework/MicroService.h | 113 ++++++++++-------- 24 files changed, 113 insertions(+), 84 deletions(-) rename src/{APIServers.cpp => RESTAPI/RESTAPI_Servers.cpp} (83%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8852ec2..e8bbd3d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,7 +82,7 @@ add_executable(owprov src/RESTObjects/RESTAPI_ProvObjects.cpp src/RESTObjects/RESTAPI_ProvObjects.h src/RESTObjects/RESTAPI_GWobjects.h src/RESTObjects/RESTAPI_GWobjects.cpp src/RESTObjects/RESTAPI_FMSObjects.h src/RESTObjects/RESTAPI_FMSObjects.cpp - src/APIServers.cpp + src/RESTAPI/RESTAPI_Servers.cpp src/Daemon.cpp src/Daemon.h src/Dashboard.h src/Dashboard.cpp src/StorageService.cpp src/StorageService.h diff --git a/build b/build index 9d1ce53..615be70 100644 --- a/build +++ b/build @@ -1 +1 @@ -82 \ No newline at end of file +85 \ No newline at end of file diff --git a/src/APIServers.cpp b/src/RESTAPI/RESTAPI_Servers.cpp similarity index 83% rename from src/APIServers.cpp rename to src/RESTAPI/RESTAPI_Servers.cpp index 8c0b541..fefc2ec 100644 --- a/src/APIServers.cpp +++ b/src/RESTAPI/RESTAPI_Servers.cpp @@ -25,8 +25,8 @@ namespace OpenWifi { - Poco::Net::HTTPRequestHandler * RESTAPI_external_server(const char *Path, RESTAPIHandler::BindingMap &Bindings, - Poco::Logger & L, RESTAPI_GenericServer & S) { + Poco::Net::HTTPRequestHandler * RESTAPI_ExtRouter(const char *Path, RESTAPIHandler::BindingMap &Bindings, + Poco::Logger & L, RESTAPI_GenericServer & S, uint64_t TransactionId) { return RESTAPI_Router< RESTAPI_system_command, RESTAPI_entity_handler, @@ -47,16 +47,16 @@ namespace OpenWifi { RESTAPI_map_handler, RESTAPI_map_list_handler, RESTAPI_webSocketServer - >(Path,Bindings,L, S); + >(Path,Bindings,L, S, TransactionId); } - Poco::Net::HTTPRequestHandler * RESTAPI_internal_server(const char *Path, RESTAPIHandler::BindingMap &Bindings, - Poco::Logger & L, RESTAPI_GenericServer & S) { + Poco::Net::HTTPRequestHandler * RESTAPI_IntRouter(const char *Path, RESTAPIHandler::BindingMap &Bindings, + Poco::Logger & L, RESTAPI_GenericServer & S, uint64_t TransactionId) { return RESTAPI_Router_I< RESTAPI_system_command , RESTAPI_inventory_handler, RESTAPI_configurations_handler, RESTAPI_configurations_list_handler - >(Path, Bindings, L, S); + >(Path, Bindings, L, S, TransactionId); } } \ No newline at end of file diff --git a/src/RESTAPI/RESTAPI_configurations_handler.h b/src/RESTAPI/RESTAPI_configurations_handler.h index 2854154..a12e540 100644 --- a/src/RESTAPI/RESTAPI_configurations_handler.h +++ b/src/RESTAPI/RESTAPI_configurations_handler.h @@ -14,13 +14,14 @@ namespace OpenWifi { class RESTAPI_configurations_handler : public RESTAPIHandler { public: - RESTAPI_configurations_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, bool Internal) + RESTAPI_configurations_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, uint64_t TransactionId, bool Internal) : RESTAPIHandler(bindings, L, std::vector{ Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_POST, Poco::Net::HTTPRequest::HTTP_PUT, Poco::Net::HTTPRequest::HTTP_DELETE, Poco::Net::HTTPRequest::HTTP_OPTIONS}, Server, + TransactionId, Internal), DB_(StorageService()->ConfigurationDB()){} diff --git a/src/RESTAPI/RESTAPI_configurations_list_handler.h b/src/RESTAPI/RESTAPI_configurations_list_handler.h index e7a7191..f6c32ea 100644 --- a/src/RESTAPI/RESTAPI_configurations_list_handler.h +++ b/src/RESTAPI/RESTAPI_configurations_list_handler.h @@ -10,12 +10,13 @@ namespace OpenWifi { class RESTAPI_configurations_list_handler : public RESTAPIHandler { public: - RESTAPI_configurations_list_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, bool Internal) + RESTAPI_configurations_list_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, uint64_t TransactionId, bool Internal) : RESTAPIHandler(bindings, L, std::vector{ Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_OPTIONS}, Server, + TransactionId, Internal) {} static const std::list PathName() { return std::list{"/api/v1/configurations"}; }; diff --git a/src/RESTAPI/RESTAPI_contact_handler.h b/src/RESTAPI/RESTAPI_contact_handler.h index 50144e1..4fa39d6 100644 --- a/src/RESTAPI/RESTAPI_contact_handler.h +++ b/src/RESTAPI/RESTAPI_contact_handler.h @@ -14,13 +14,14 @@ namespace OpenWifi { class RESTAPI_contact_handler : public RESTAPIHandler { public: - RESTAPI_contact_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, bool Internal) + RESTAPI_contact_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, uint64_t TransactionId, bool Internal) : RESTAPIHandler(bindings, L, std::vector{ Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_POST, Poco::Net::HTTPRequest::HTTP_PUT, Poco::Net::HTTPRequest::HTTP_DELETE, Poco::Net::HTTPRequest::HTTP_OPTIONS}, Server, + TransactionId, Internal), DB_(StorageService()->ContactDB()){} static const std::list PathName() { return std::list{"/api/v1/contact/{uuid}"}; }; diff --git a/src/RESTAPI/RESTAPI_contact_list_handler.h b/src/RESTAPI/RESTAPI_contact_list_handler.h index 7f21258..822cdc5 100644 --- a/src/RESTAPI/RESTAPI_contact_list_handler.h +++ b/src/RESTAPI/RESTAPI_contact_list_handler.h @@ -11,12 +11,13 @@ namespace OpenWifi { class RESTAPI_contact_list_handler : public RESTAPIHandler { public: - RESTAPI_contact_list_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, bool Internal) + RESTAPI_contact_list_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, uint64_t TransactionId, bool Internal) : RESTAPIHandler(bindings, L, std::vector{ Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_OPTIONS}, Server, + TransactionId, Internal) {} static const std::list PathName() { return std::list{"/api/v1/contact"}; }; diff --git a/src/RESTAPI/RESTAPI_entity_handler.h b/src/RESTAPI/RESTAPI_entity_handler.h index e059e5b..e3cc7ea 100644 --- a/src/RESTAPI/RESTAPI_entity_handler.h +++ b/src/RESTAPI/RESTAPI_entity_handler.h @@ -14,7 +14,7 @@ namespace OpenWifi { class RESTAPI_entity_handler : public RESTAPIHandler { public: - RESTAPI_entity_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, bool Internal) + RESTAPI_entity_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, uint64_t TransactionId, bool Internal) : RESTAPIHandler(bindings, L, std::vector{ Poco::Net::HTTPRequest::HTTP_GET, @@ -23,6 +23,7 @@ namespace OpenWifi { Poco::Net::HTTPRequest::HTTP_DELETE, Poco::Net::HTTPRequest::HTTP_OPTIONS}, Server, + TransactionId, Internal), DB_(StorageService()->EntityDB()){} static const std::list PathName() { return std::list{"/api/v1/entity/{uuid}"}; }; diff --git a/src/RESTAPI/RESTAPI_entity_list_handler.h b/src/RESTAPI/RESTAPI_entity_list_handler.h index f8cad36..2f556d1 100644 --- a/src/RESTAPI/RESTAPI_entity_list_handler.h +++ b/src/RESTAPI/RESTAPI_entity_list_handler.h @@ -14,13 +14,14 @@ namespace OpenWifi { class RESTAPI_entity_list_handler : public RESTAPIHandler { public: - RESTAPI_entity_list_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, bool Internal) + RESTAPI_entity_list_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, uint64_t TransactionId, bool Internal) : RESTAPIHandler(bindings, L, std::vector{ Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_POST, Poco::Net::HTTPRequest::HTTP_OPTIONS}, Server, + TransactionId, Internal) {} static const std::list PathName() { return std::list{"/api/v1/entity"}; }; diff --git a/src/RESTAPI/RESTAPI_inventory_handler.h b/src/RESTAPI/RESTAPI_inventory_handler.h index 70ab16a..bec3d8f 100644 --- a/src/RESTAPI/RESTAPI_inventory_handler.h +++ b/src/RESTAPI/RESTAPI_inventory_handler.h @@ -14,13 +14,14 @@ namespace OpenWifi { class RESTAPI_inventory_handler : public RESTAPIHandler { public: - RESTAPI_inventory_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, bool Internal) + RESTAPI_inventory_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, uint64_t TransactionId, bool Internal) : RESTAPIHandler(bindings, L, std::vector{ Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_POST, Poco::Net::HTTPRequest::HTTP_PUT, Poco::Net::HTTPRequest::HTTP_DELETE, Poco::Net::HTTPRequest::HTTP_OPTIONS}, Server, + TransactionId, Internal), DB_(StorageService()->InventoryDB()){} static const std::list PathName() { return std::list{"/api/v1/inventory/{serialNumber}"}; }; diff --git a/src/RESTAPI/RESTAPI_inventory_list_handler.h b/src/RESTAPI/RESTAPI_inventory_list_handler.h index 424bad1..5ae5a01 100644 --- a/src/RESTAPI/RESTAPI_inventory_list_handler.h +++ b/src/RESTAPI/RESTAPI_inventory_list_handler.h @@ -15,12 +15,13 @@ namespace OpenWifi { class RESTAPI_inventory_list_handler : public RESTAPIHandler { public: - RESTAPI_inventory_list_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, bool Internal) + RESTAPI_inventory_list_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, uint64_t TransactionId, bool Internal) : RESTAPIHandler(bindings, L, std::vector{ Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_OPTIONS}, Server, + TransactionId, Internal) {} static const std::list PathName() { return std::list{"/api/v1/inventory"}; }; diff --git a/src/RESTAPI/RESTAPI_location_handler.h b/src/RESTAPI/RESTAPI_location_handler.h index e9c237b..ba07133 100644 --- a/src/RESTAPI/RESTAPI_location_handler.h +++ b/src/RESTAPI/RESTAPI_location_handler.h @@ -14,13 +14,14 @@ namespace OpenWifi { class RESTAPI_location_handler : public RESTAPIHandler { public: - RESTAPI_location_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, bool Internal) + RESTAPI_location_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, uint64_t TransactionId, bool Internal) : RESTAPIHandler(bindings, L, std::vector{ Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_POST, Poco::Net::HTTPRequest::HTTP_PUT, Poco::Net::HTTPRequest::HTTP_DELETE, Poco::Net::HTTPRequest::HTTP_OPTIONS}, Server, + TransactionId, Internal), DB_(StorageService()->LocationDB()){} static const std::list PathName() { return std::list{"/api/v1/location/{uuid}"}; }; diff --git a/src/RESTAPI/RESTAPI_location_list_handler.h b/src/RESTAPI/RESTAPI_location_list_handler.h index 3ac5300..bea623a 100644 --- a/src/RESTAPI/RESTAPI_location_list_handler.h +++ b/src/RESTAPI/RESTAPI_location_list_handler.h @@ -10,12 +10,13 @@ namespace OpenWifi { class RESTAPI_location_list_handler : public RESTAPIHandler { public: - RESTAPI_location_list_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, bool Internal) + RESTAPI_location_list_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, uint64_t TransactionId, bool Internal) : RESTAPIHandler(bindings, L, std::vector{ Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_OPTIONS}, Server, + TransactionId, Internal) {} static const std::list PathName() { return std::list{"/api/v1/location"}; }; diff --git a/src/RESTAPI/RESTAPI_managementPolicy_handler.h b/src/RESTAPI/RESTAPI_managementPolicy_handler.h index 84fb55f..8c6ed3a 100644 --- a/src/RESTAPI/RESTAPI_managementPolicy_handler.h +++ b/src/RESTAPI/RESTAPI_managementPolicy_handler.h @@ -13,13 +13,14 @@ namespace OpenWifi { class RESTAPI_managementPolicy_handler : public RESTAPIHandler { public: - RESTAPI_managementPolicy_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, bool Internal) + RESTAPI_managementPolicy_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, uint64_t TransactionId, bool Internal) : RESTAPIHandler(bindings, L, std::vector{ Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_POST, Poco::Net::HTTPRequest::HTTP_PUT, Poco::Net::HTTPRequest::HTTP_DELETE, Poco::Net::HTTPRequest::HTTP_OPTIONS}, Server, + TransactionId, Internal), DB_(StorageService()->PolicyDB()){} static const std::list PathName() { return std::list{"/api/v1/managementPolicy/{uuid}"}; }; diff --git a/src/RESTAPI/RESTAPI_managementPolicy_list_handler.h b/src/RESTAPI/RESTAPI_managementPolicy_list_handler.h index 55ee4f2..5f39155 100644 --- a/src/RESTAPI/RESTAPI_managementPolicy_list_handler.h +++ b/src/RESTAPI/RESTAPI_managementPolicy_list_handler.h @@ -8,12 +8,13 @@ namespace OpenWifi { class RESTAPI_managementPolicy_list_handler : public RESTAPIHandler { public: - RESTAPI_managementPolicy_list_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, bool Internal) + RESTAPI_managementPolicy_list_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, uint64_t TransactionId, bool Internal) : RESTAPIHandler(bindings, L, std::vector{ Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_OPTIONS}, Server, + TransactionId, Internal) {} static const std::list PathName() { return std::list{"/api/v1/managementPolicy"}; }; diff --git a/src/RESTAPI/RESTAPI_managementRole_handler.h b/src/RESTAPI/RESTAPI_managementRole_handler.h index c7090f0..c407369 100644 --- a/src/RESTAPI/RESTAPI_managementRole_handler.h +++ b/src/RESTAPI/RESTAPI_managementRole_handler.h @@ -8,13 +8,14 @@ namespace OpenWifi { class RESTAPI_managementRole_handler : public RESTAPIHandler { public: - RESTAPI_managementRole_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, bool Internal) + RESTAPI_managementRole_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, uint64_t TransactionId, bool Internal) : RESTAPIHandler(bindings, L, std::vector{ Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_POST, Poco::Net::HTTPRequest::HTTP_PUT, Poco::Net::HTTPRequest::HTTP_DELETE, Poco::Net::HTTPRequest::HTTP_OPTIONS}, Server, + TransactionId, Internal), DB_(StorageService()->RolesDB()){} static const std::list PathName() { return std::list{"/api/v1/managementRole/{uuid}"}; }; diff --git a/src/RESTAPI/RESTAPI_managementRole_list_handler.h b/src/RESTAPI/RESTAPI_managementRole_list_handler.h index 6dda5cc..56f0fec 100644 --- a/src/RESTAPI/RESTAPI_managementRole_list_handler.h +++ b/src/RESTAPI/RESTAPI_managementRole_list_handler.h @@ -9,12 +9,13 @@ namespace OpenWifi { class RESTAPI_managementRole_list_handler : public RESTAPIHandler { public: - RESTAPI_managementRole_list_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, bool Internal) + RESTAPI_managementRole_list_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, uint64_t TransactionId, bool Internal) : RESTAPIHandler(bindings, L, std::vector{ Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_OPTIONS}, Server, + TransactionId, Internal) {} static const std::list PathName() { return std::list{"/api/v1/managementRole"}; }; diff --git a/src/RESTAPI/RESTAPI_map_handler.h b/src/RESTAPI/RESTAPI_map_handler.h index 2f5c09a..acaa9e6 100644 --- a/src/RESTAPI/RESTAPI_map_handler.h +++ b/src/RESTAPI/RESTAPI_map_handler.h @@ -9,13 +9,14 @@ namespace OpenWifi { class RESTAPI_map_handler : public RESTAPIHandler { public: - RESTAPI_map_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, bool Internal) + RESTAPI_map_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, uint64_t TransactionId, bool Internal) : RESTAPIHandler(bindings, L, std::vector{ Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_POST, Poco::Net::HTTPRequest::HTTP_PUT, Poco::Net::HTTPRequest::HTTP_DELETE, Poco::Net::HTTPRequest::HTTP_OPTIONS}, Server, + TransactionId, Internal), DB_(StorageService()->MapDB()){} static const std::list PathName() { return std::list{"/api/v1/map/{uuid}"}; }; diff --git a/src/RESTAPI/RESTAPI_map_list_handler.h b/src/RESTAPI/RESTAPI_map_list_handler.h index 71f0e34..0bc1db2 100644 --- a/src/RESTAPI/RESTAPI_map_list_handler.h +++ b/src/RESTAPI/RESTAPI_map_list_handler.h @@ -9,12 +9,13 @@ namespace OpenWifi { class RESTAPI_map_list_handler : public RESTAPIHandler { public: - RESTAPI_map_list_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, bool Internal) + RESTAPI_map_list_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, uint64_t TransactionId, bool Internal) : RESTAPIHandler(bindings, L, std::vector{ Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_OPTIONS}, Server, + TransactionId, Internal) {} static const std::list PathName() { return std::list{"/api/v1/map"}; }; diff --git a/src/RESTAPI/RESTAPI_venue_handler.h b/src/RESTAPI/RESTAPI_venue_handler.h index 63f6834..2e755c9 100644 --- a/src/RESTAPI/RESTAPI_venue_handler.h +++ b/src/RESTAPI/RESTAPI_venue_handler.h @@ -14,13 +14,14 @@ namespace OpenWifi { class RESTAPI_venue_handler : public RESTAPIHandler { public: - RESTAPI_venue_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, bool Internal) + RESTAPI_venue_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, uint64_t TransactionId, bool Internal) : RESTAPIHandler(bindings, L, std::vector{ Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_POST, Poco::Net::HTTPRequest::HTTP_PUT, Poco::Net::HTTPRequest::HTTP_DELETE, Poco::Net::HTTPRequest::HTTP_OPTIONS}, Server, + TransactionId, Internal), DB_(StorageService()->VenueDB()) {} static const std::list PathName() { return std::list{"/api/v1/venue/{uuid}"}; }; private: diff --git a/src/RESTAPI/RESTAPI_venue_list_handler.h b/src/RESTAPI/RESTAPI_venue_list_handler.h index 917eceb..9b801c3 100644 --- a/src/RESTAPI/RESTAPI_venue_list_handler.h +++ b/src/RESTAPI/RESTAPI_venue_list_handler.h @@ -10,12 +10,13 @@ namespace OpenWifi { class RESTAPI_venue_list_handler : public RESTAPIHandler { public: - RESTAPI_venue_list_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, bool Internal) + RESTAPI_venue_list_handler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, uint64_t TransactionId, bool Internal) : RESTAPIHandler(bindings, L, std::vector{ Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_OPTIONS}, Server, + TransactionId, Internal) {} static const std::list PathName() { return std::list{"/api/v1/venue"}; }; diff --git a/src/RESTAPI/RESTAPI_webSocketServer.h b/src/RESTAPI/RESTAPI_webSocketServer.h index 2c2067f..23ccda0 100644 --- a/src/RESTAPI/RESTAPI_webSocketServer.h +++ b/src/RESTAPI/RESTAPI_webSocketServer.h @@ -9,11 +9,11 @@ namespace OpenWifi { class RESTAPI_webSocketServer : public RESTAPIHandler { public: - RESTAPI_webSocketServer(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, bool Internal) + RESTAPI_webSocketServer(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer &Server, uint64_t TransactionId, bool Internal) : RESTAPIHandler(bindings, L, std::vector{ Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_OPTIONS}, - Server, Internal,false) {} + Server, TransactionId, Internal,false) {} static const std::list PathName() { return std::list{"/api/v1/ws"};} void DoGet() final; void DoDelete() final {}; diff --git a/src/framework/API_Proxy.h b/src/framework/API_Proxy.h index 4716d8b..82fd2e6 100644 --- a/src/framework/API_Proxy.h +++ b/src/framework/API_Proxy.h @@ -21,7 +21,9 @@ namespace OpenWifi { Poco::URI DestinationURI(Svc.PrivateEndPoint); DestinationURI.setPath(PathRewrite); DestinationURI.setQuery(SourceURI.getQuery()); - // std::cout << DestinationURI.getHost() << ":" << DestinationURI.getPort() << "/" << DestinationURI.getPathAndQuery() << std::endl; + + // std::cout << " Source: " << SourceURI.toString() << std::endl; + // std::cout << "Destination: " << DestinationURI.toString() << std::endl; Poco::Net::HTTPSClientSession Session(DestinationURI.getHost(), DestinationURI.getPort()); Session.setKeepAlive(true); @@ -48,8 +50,10 @@ namespace OpenWifi { std::stringstream SS; try { auto Body = P.parse(Request->stream()).extract(); - Poco::JSON::Stringifier::stringify(Body,SS); - } catch(...) { + Poco::JSON::Stringifier::condense(Body,SS); + SS << "\r\n\r\n"; + } catch(const Poco::Exception &E) { + Logger.log(E); } if(SS.str().empty()) { diff --git a/src/framework/MicroService.h b/src/framework/MicroService.h index 5557bdf..f4f7ca7 100644 --- a/src/framework/MicroService.h +++ b/src/framework/MicroService.h @@ -1522,6 +1522,7 @@ namespace OpenWifi { Poco::Logger &l, std::vector Methods, RESTAPI_GenericServer & Server, + uint64_t TransactionId, bool Internal=false, bool AlwaysAuthorize=true, bool RateLimited=false, @@ -1531,11 +1532,13 @@ namespace OpenWifi { Logger_(l), Methods_(std::move(Methods)), Server_(Server), + TransactionId_(TransactionId), Internal_(Internal), AlwaysAuthorize_(AlwaysAuthorize), RateLimited_(RateLimited), MyRates_(Profile), - SubOnlyService_(SubscriberOnly){ + SubOnlyService_(SubscriberOnly) + { } inline bool RoleIsAuthorized(const std::string & Path, const std::string & Method, std::string & Reason) { @@ -1992,12 +1995,13 @@ namespace OpenWifi { Poco::JSON::Parser IncomingParser_; RESTAPI_GenericServer & Server_; RateLimit MyRates_; + uint64_t TransactionId_; }; class RESTAPI_UnknownRequestHandler : public RESTAPIHandler { public: - RESTAPI_UnknownRequestHandler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server) - : RESTAPIHandler(bindings, L, std::vector{}, Server) {} + RESTAPI_UnknownRequestHandler(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, uint64_t TransactionId) + : RESTAPIHandler(bindings, L, std::vector{}, Server, TransactionId) {} inline void DoGet() override {}; inline void DoPost() override {}; inline void DoPut() override {}; @@ -2016,30 +2020,30 @@ namespace OpenWifi { } template - RESTAPIHandler * RESTAPI_Router(const std::string & RequestedPath, RESTAPIHandler::BindingMap &Bindings, Poco::Logger & Logger, RESTAPI_GenericServer & Server) { + RESTAPIHandler * RESTAPI_Router(const std::string & RequestedPath, RESTAPIHandler::BindingMap &Bindings, Poco::Logger & Logger, RESTAPI_GenericServer & Server, uint64_t TransactionId) { static_assert(test_has_PathName_method((T*)nullptr), "Class must have a static PathName() method."); if(RESTAPIHandler::ParseBindings(RequestedPath,T::PathName(),Bindings)) { - return new T(Bindings, Logger, Server, false); + return new T(Bindings, Logger, Server, false, TransactionId); } if constexpr (sizeof...(Args) == 0) { - return new RESTAPI_UnknownRequestHandler(Bindings,Logger, Server); + return new RESTAPI_UnknownRequestHandler(Bindings,Logger, Server, TransactionId); } else { - return RESTAPI_Router(RequestedPath, Bindings, Logger, Server); + return RESTAPI_Router(RequestedPath, Bindings, Logger, Server, TransactionId); } } template - RESTAPIHandler * RESTAPI_Router_I(const std::string & RequestedPath, RESTAPIHandler::BindingMap &Bindings, Poco::Logger & Logger, RESTAPI_GenericServer & Server) { + RESTAPIHandler * RESTAPI_Router_I(const std::string & RequestedPath, RESTAPIHandler::BindingMap &Bindings, Poco::Logger & Logger, RESTAPI_GenericServer & Server, uint64_t TransactionId) { static_assert(test_has_PathName_method((T*)nullptr), "Class must have a static PathName() method."); if(RESTAPIHandler::ParseBindings(RequestedPath,T::PathName(),Bindings)) { - return new T(Bindings, Logger, Server, true); + return new T(Bindings, Logger, Server, true, TransactionId); } if constexpr (sizeof...(Args) == 0) { - return new RESTAPI_UnknownRequestHandler(Bindings,Logger, Server); + return new RESTAPI_UnknownRequestHandler(Bindings,Logger, Server, TransactionId); } else { - return RESTAPI_Router_I(RequestedPath, Bindings, Logger, Server); + return RESTAPI_Router_I(RequestedPath, Bindings, Logger, Server, TransactionId); } } @@ -2410,17 +2414,17 @@ namespace OpenWifi { inline ALBHealthCheckServer * ALBHealthCheckServer() { return ALBHealthCheckServer::instance(); } - Poco::Net::HTTPRequestHandler * RESTAPI_external_server(const char *Path, RESTAPIHandler::BindingMap &Bindings, - Poco::Logger & L, RESTAPI_GenericServer & S); + Poco::Net::HTTPRequestHandler * RESTAPI_ExtRouter(const char *Path, RESTAPIHandler::BindingMap &Bindings, + Poco::Logger & L, RESTAPI_GenericServer & S, uint64_t Id); - Poco::Net::HTTPRequestHandler * RESTAPI_internal_server(const char *Path, RESTAPIHandler::BindingMap &Bindings, - Poco::Logger & L, RESTAPI_GenericServer & S); + Poco::Net::HTTPRequestHandler * RESTAPI_IntRouter(const char *Path, RESTAPIHandler::BindingMap &Bindings, + Poco::Logger & L, RESTAPI_GenericServer & S, uint64_t Id); - class RESTAPI_server : public SubSystemServer { + class RESTAPI_ExtServer : public SubSystemServer { public: - static RESTAPI_server *instance() { - static RESTAPI_server *instance_ = new RESTAPI_server; + static RESTAPI_ExtServer *instance() { + static RESTAPI_ExtServer *instance_ = new RESTAPI_ExtServer; return instance_; } int Start() override; @@ -2434,9 +2438,9 @@ namespace OpenWifi { inline void reinitialize(Poco::Util::Application &self) override; - inline Poco::Net::HTTPRequestHandler *CallServer(const char *Path) { + inline Poco::Net::HTTPRequestHandler *CallServer(const char *Path, uint64_t Id) { RESTAPIHandler::BindingMap Bindings; - return RESTAPI_external_server(Path, Bindings, Logger_, Server_); + return RESTAPI_ExtRouter(Path, Bindings, Logger_, Server_, Id); } private: @@ -2444,18 +2448,18 @@ namespace OpenWifi { Poco::ThreadPool Pool_; RESTAPI_GenericServer Server_; - RESTAPI_server() noexcept: - SubSystemServer("RESTAPIServer", "RESTAPIServer", "openwifi.restapi") + RESTAPI_ExtServer() noexcept: + SubSystemServer("RESTAPI_ExtServer", "RESTAPIServer", "openwifi.restapi") { } }; - inline RESTAPI_server * RESTAPI_server() { return RESTAPI_server::instance(); }; + inline RESTAPI_ExtServer * RESTAPI_ExtServer() { return RESTAPI_ExtServer::instance(); }; - class RequestHandlerFactory : public Poco::Net::HTTPRequestHandlerFactory { + class ExtRequestHandlerFactory : public Poco::Net::HTTPRequestHandlerFactory { public: - RequestHandlerFactory(RESTAPI_GenericServer & Server) : - Logger_(RESTAPI_server::instance()->Logger()), + explicit ExtRequestHandlerFactory(RESTAPI_GenericServer & Server) : + Logger_(RESTAPI_ExtServer::instance()->Logger()), Server_(Server) { @@ -2464,15 +2468,16 @@ namespace OpenWifi { inline Poco::Net::HTTPRequestHandler *createRequestHandler(const Poco::Net::HTTPServerRequest &Request) override { Poco::URI uri(Request.getURI()); auto *Path = uri.getPath().c_str(); - return RESTAPI_server()->CallServer(Path); + return RESTAPI_ExtServer()->CallServer(Path, TransactionId_++); } private: - Poco::Logger &Logger_; - RESTAPI_GenericServer &Server_; + static inline std::atomic_uint64_t TransactionId_ = 1; + Poco::Logger &Logger_; + RESTAPI_GenericServer &Server_; }; - inline int RESTAPI_server::Start() { + inline int RESTAPI_ExtServer::Start() { Logger_.information("Starting."); Server_.InitLogging(); @@ -2491,7 +2496,7 @@ namespace OpenWifi { Params->setMaxQueued(200); Params->setKeepAlive(true); - auto NewServer = std::make_unique(new RequestHandlerFactory(Server_), Pool_, Sock, Params); + auto NewServer = std::make_unique(new ExtRequestHandlerFactory(Server_), Pool_, Sock, Params); NewServer->start(); RESTServers_.push_back(std::move(NewServer)); } @@ -2499,11 +2504,11 @@ namespace OpenWifi { return 0; } - class RESTAPI_InternalServer : public SubSystemServer { + class RESTAPI_IntServer : public SubSystemServer { public: - static RESTAPI_InternalServer *instance() { - static RESTAPI_InternalServer *instance_ = new RESTAPI_InternalServer; + static RESTAPI_IntServer *instance() { + static RESTAPI_IntServer *instance_ = new RESTAPI_IntServer; return instance_; } @@ -2517,39 +2522,40 @@ namespace OpenWifi { inline void reinitialize(Poco::Util::Application &self) override; - inline Poco::Net::HTTPRequestHandler *CallServer(const char *Path) { + inline Poco::Net::HTTPRequestHandler *CallServer(const char *Path, uint64_t Id) { RESTAPIHandler::BindingMap Bindings; - return RESTAPI_internal_server(Path, Bindings, Logger_, Server_); + return RESTAPI_IntRouter(Path, Bindings, Logger_, Server_, Id); } private: std::vector> RESTServers_; Poco::ThreadPool Pool_; RESTAPI_GenericServer Server_; - RESTAPI_InternalServer() noexcept: SubSystemServer("RESTAPIInternalServer", "REST-ISRV", "openwifi.internal.restapi") + RESTAPI_IntServer() noexcept: SubSystemServer("RESTAPI_IntServer", "REST-ISRV", "openwifi.internal.restapi") { } }; - inline RESTAPI_InternalServer * RESTAPI_InternalServer() { return RESTAPI_InternalServer::instance(); }; + inline RESTAPI_IntServer * RESTAPI_IntServer() { return RESTAPI_IntServer::instance(); }; - class InternalRequestHandlerFactory : public Poco::Net::HTTPRequestHandlerFactory { + class IntRequestHandlerFactory : public Poco::Net::HTTPRequestHandlerFactory { public: - InternalRequestHandlerFactory(RESTAPI_GenericServer & Server) : - Logger_(RESTAPI_InternalServer()->Logger()), + explicit IntRequestHandlerFactory(RESTAPI_GenericServer & Server) : + Logger_(RESTAPI_IntServer()->Logger()), Server_(Server){} inline Poco::Net::HTTPRequestHandler *createRequestHandler(const Poco::Net::HTTPServerRequest &Request) override { Poco::URI uri(Request.getURI()); auto *Path = uri.getPath().c_str(); - return RESTAPI_InternalServer()->CallServer(Path); + return RESTAPI_IntServer()->CallServer(Path, TransactionId_); } private: - Poco::Logger & Logger_; - RESTAPI_GenericServer & Server_; + static inline std::atomic_uint64_t TransactionId_ = 1; + Poco::Logger &Logger_; + RESTAPI_GenericServer &Server_; }; - inline int RESTAPI_InternalServer::Start() { + inline int RESTAPI_IntServer::Start() { Logger_.information("Starting."); Server_.InitLogging(); @@ -2567,7 +2573,7 @@ namespace OpenWifi { Params->setMaxQueued(200); Params->setKeepAlive(true); - auto NewServer = std::make_unique(new InternalRequestHandlerFactory(Server_), Pool_, Sock, Params); + auto NewServer = std::make_unique(new IntRequestHandlerFactory(Server_), Pool_, Sock, Params); NewServer->start(); RESTServers_.push_back(std::move(NewServer)); } @@ -2848,8 +2854,8 @@ namespace OpenWifi { // add the default services SubSystems_.push_back(KafkaManager()); SubSystems_.push_back(ALBHealthCheckServer()); - SubSystems_.push_back(RESTAPI_server()); - SubSystems_.push_back(RESTAPI_InternalServer()); + SubSystems_.push_back(RESTAPI_ExtServer()); + SubSystems_.push_back(RESTAPI_IntServer()); Poco::Net::initializeSSL(); Poco::Net::HTTPStreamFactory::registerFactory(); @@ -3419,14 +3425,14 @@ namespace OpenWifi { Consumer.unsubscribe(); } - inline void RESTAPI_server::reinitialize(Poco::Util::Application &self) { + inline void RESTAPI_ExtServer::reinitialize(Poco::Util::Application &self) { MicroService::instance().LoadConfigurationFile(); Logger_.information("Reinitializing."); Stop(); Start(); } - void RESTAPI_InternalServer::reinitialize(Poco::Util::Application &self) { + void RESTAPI_IntServer::reinitialize(Poco::Util::Application &self) { MicroService::instance().LoadConfigurationFile(); Logger_.information("Reinitializing."); Stop(); @@ -3435,12 +3441,13 @@ namespace OpenWifi { class RESTAPI_system_command : public RESTAPIHandler { public: - RESTAPI_system_command(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, bool Internal) + RESTAPI_system_command(const RESTAPIHandler::BindingMap &bindings, Poco::Logger &L, RESTAPI_GenericServer & Server, uint64_t TransactionId, bool Internal) : RESTAPIHandler(bindings, L, std::vector{Poco::Net::HTTPRequest::HTTP_POST, Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_OPTIONS}, Server, + TransactionId, Internal) {} static const std::list PathName() { return std::list{"/api/v1/system"};} @@ -3750,7 +3757,7 @@ namespace OpenWifi { if (AuthClient()->IsAuthorized( SessionToken_, UserInfo_, Expired, Sub)) { #endif if(Server_.LogIt(Request->getMethod(),true)) { - Logger_.debug(Poco::format("X-REQ-ALLOWED(%s): User='%s@%s' Method='%s' Path='%s", + Logger_.debug(Poco::format("X-REQ-ALLOWED(%s): User='%s@%s' Method='%s' Path='%s'", UserInfo_.userinfo.email, Utils::FormatIPv6(Request->clientAddress().toString()), Request->clientAddress().toString(), @@ -3760,7 +3767,7 @@ namespace OpenWifi { return true; } else { if(Server_.LogBadTokens(true)) { - Logger_.debug(Poco::format("X-REQ-DENIED(%s): Method='%s' Path='%s", + Logger_.debug(Poco::format("X-REQ-DENIED(%s): Method='%s' Path='%s'", Utils::FormatIPv6(Request->clientAddress().toString()), Request->getMethod(), Request->getURI())); }