Commit 9477c7e6 authored by Fang-WANG's avatar Fang-WANG

sdmSubscription test ok.

parent 427aa67f
......@@ -12,6 +12,12 @@
*/
#include "SubscriptionCreationApiImpl.h"
#include "udm_config.hpp"
#include "logger.hpp"
#include "curl.hpp"
using namespace config;
extern config::udm_config udm_cfg;
namespace oai {
namespace udm {
......@@ -26,7 +32,48 @@ SubscriptionCreationApiImpl::SubscriptionCreationApiImpl(
void SubscriptionCreationApiImpl::subscribe(
const std::string &supi, const SdmSubscription &sdmSubscription,
Pistache::Http::ResponseWriter &response) {
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
std::string udr_ip =
std::string(inet_ntoa(*((struct in_addr *)&udm_cfg.nudr.addr4)));
std::string udr_port = std::to_string(udm_cfg.nudr.port);
std::string remoteUri;
std::string Method;
std::string msgBody;
std::string Response;
nlohmann::json j_ProblemDetails;
ProblemDetails m_ProblemDetails;
// UDR GET interface ----- get 3gpp_registration related info--------------------
remoteUri = udr_ip + ":" + udr_port + "/nudr-dr/v2/subscription-data/" + supi + "/context-data/sdm-subscriptions";
Logger::udm_uecm().debug("POST Request:" + remoteUri);
Method = "POST";
nlohmann::json sdmSubscription_j;
to_json(sdmSubscription_j, sdmSubscription);
long http_code;
http_code = Curl::curl_http_client(remoteUri, Method, sdmSubscription_j.dump(), Response);
nlohmann::json response_data = {};
try {
Logger::udm_uecm().debug("POST Reponse:" + Response);
response_data = nlohmann::json::parse(Response.c_str());
} catch (nlohmann::json::exception &e) { // error handling
Logger::udm_uecm().info("Could not get Json content from UDR response");
m_ProblemDetails.setCause("USER_NOT_FOUND");
m_ProblemDetails.setStatus(404);
m_ProblemDetails.setDetail("User " + supi + " not found in Database");
to_json(j_ProblemDetails, m_ProblemDetails);
Logger::udm_uecm().error("User " + supi + " not found in Database");
Logger::udm_uecm().info("Send 404 Not_Found response to client");
response.send(Pistache::Http::Code::Not_Found, j_ProblemDetails.dump());
return;
}
Logger::udm_uecm().debug("http reponse code %d. \n",http_code);
response.send(static_cast<Pistache::Http::Code>(http_code), sdmSubscription_j.dump());
}
} // namespace api
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment