Commit 427aa67f authored by xiangwan's avatar xiangwan

add SessionManagementSubscriptionDataRetrieval, and test ok

parent 081cf4f5
......@@ -15,6 +15,14 @@
#include "SessionManagementSubscriptionData.h"
#include <nlohmann/json.hpp>
#include "udm_config.hpp"
#include "logger.hpp"
#include "curl.hpp"
using namespace config;
extern config::udm_config udm_cfg;
namespace oai {
namespace udm {
namespace api {
......@@ -37,7 +45,7 @@ void SessionManagementSubscriptionDataRetrievalApiImpl::get_sm_data(
const std::string &supi, const Pistache::Optional<Snssai> &singleNssai,
const Pistache::Optional<std::string> &dnn,
Pistache::Http::ResponseWriter &response) {
#if 0
std::cout
<< "Received a SessionManagementSubscriptionDataRetrieval with supi "
<< supi.c_str() << std::endl;
......@@ -94,6 +102,41 @@ void SessionManagementSubscriptionDataRetrievalApiImpl::get_sm_data(
std::string resBody = jsonData.dump();
// httpResponse.headers().add<Pistache::Http::Header::Location>(url);
response.send(Pistache::Http::Code::Ok, resBody);
#endif
// 1. populate remote uri for udp request
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 remote_uri = udr_ip + ":" + udr_port + "/nudr-dr/v2/subscription-data/"+supi+plmnId+"/provisioned-data/am-data";
std::string remote_uri = udr_ip + ":" + udr_port + "/nudr-dr/v2/subscription-data/"+supi+"/456789/provisioned-data/sm-data";
std::string method("GET");
std::string body("");
std::string response_get;
Logger::udm_sdm().debug("UDR: GET Request: "+ remote_uri);
// 2. invoke curl to get response from udr
long http_code = Curl::curl_http_client(remote_uri, method, body, response_get);
// 3. process response
nlohmann::json response_data_json = {};
try {
Logger::udm_sdm().debug("subscription-data: GET Response: "+response_get);
response_data_json = nlohmann::json::parse(response_get.c_str());
} catch (nlohmann::json::exception &e) {
Logger::udm_sdm().info("Could not get json content from UDR response");
ProblemDetails problem_details;
nlohmann::json json_problem_details;
problem_details.setCause("USER_NOT_FOUND");
problem_details.setStatus(404);
problem_details.setDetail("User " + supi + " not found in Database");
to_json(json_problem_details, problem_details);
Logger::udm_sdm().error("User " + supi + " not found in Database");
Logger::udm_sdm().info("Send 404 Not_Found response to client");
response.send(Pistache::Http::Code::Not_Found, json_problem_details.dump());
return;
}
Logger::udm_sdm().debug("http reponse code %d.\n",http_code);
response.send(static_cast<Pistache::Http::Code>(http_code), response_data_json.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