Commit 2856dcf6 authored by Mosaical's avatar Mosaical

20200903

parent 549586b8
...@@ -99,27 +99,15 @@ void NFInstanceIDDocumentApi::register_nf_instance_handler(const Pistache::Rest: ...@@ -99,27 +99,15 @@ void NFInstanceIDDocumentApi::register_nf_instance_handler(const Pistache::Rest:
auto acceptEncoding = request.headers().tryGetRaw("Accept-Encoding"); auto acceptEncoding = request.headers().tryGetRaw("Accept-Encoding");
try { try {
//本句有转换错误的问题,故尝试从requestbody先转json再转nFProfile
nlohmann::json::parse(request.body()).get_to(nFProfile); nlohmann::json::parse(request.body()).get_to(nFProfile);
std::string str1 = request.body().c_str(); std::string str1 = request.body().c_str();
//std::cout << str1 << std::endl; request信息已取出 nlohmann::json j1;
Json::Reader Reader; j1 = nlohmann::json::parse(str1);//str1的内容给了j1
Json::Value root;
Reader.parse(str1, root);
std::cout << root << std::endl;//测试是否将消息体取出到json对象root中
// from_json(j1,nFProfile);//将取出的消息体赋值给nFProfile 此处的from_json有bug
//reader.parse(jStr1,devJson);
//from_json(jStr1,nFProfile)
//测试nFProfile内容
nlohmann::json j1 = root;
from_json(j1,nFProfile); from_json(j1,nFProfile);
nlohmann::json j; // nlohmann::json j;
NFProfile *o = &nFProfile; // NFProfile *o = &nFProfile;
j["nfType"] = o->getNfType(); // j["nfType"] = o->getNfType();
std::cout << "NFTYPE为:::" << j << std::endl; // std::cout << "NFTYPE为:::" << j << std::endl;
//测试结束 //测试结束
this->register_nf_instance(nfInstanceID, nFProfile, contentEncoding, acceptEncoding, response); this->register_nf_instance(nfInstanceID, nFProfile, contentEncoding, acceptEncoding, response);
......
{
"nfInstanceId": "AMF",
"nfStatus": "REGISTERED",
"nfType": "AMF"
}
...@@ -1993,6 +1993,8 @@ nlohmann/json.hpp ...@@ -1993,6 +1993,8 @@ nlohmann/json.hpp
/home/root/nrf2/model/NFType.cpp /home/root/nrf2/model/NFType.cpp
NFType.h NFType.h
/home/root/nrf2/model/NFType.h /home/root/nrf2/model/NFType.h
string
-
/home/root/nrf2/model/NFType.h /home/root/nrf2/model/NFType.h
nlohmann/json.hpp nlohmann/json.hpp
......
{
"nfInstanceId": "AMF",
"nfStatus": "REGISTERED",
"nfType": "AMF"
}
No preview for this file type
No preview for this file type
{ {
"nfInstanceId": "AMF", "nfInstanceId": "AMF",
"nfStatus": null, "nfStatus": "REGISTERED",
"nfType": null "nfType": "AMF"
} }
...@@ -51,7 +51,13 @@ void NFInstanceIDDocumentApiImpl::register_nf_instance(const std::string &nfInst ...@@ -51,7 +51,13 @@ void NFInstanceIDDocumentApiImpl::register_nf_instance(const std::string &nfInst
cout << "json信息为" << j << "\r\n"; cout << "json信息为" << j << "\r\n";
//以上为测试内容 //以上为测试内容
//输出json文件 //输出json文件
std::ofstream myfile("myjson.json"); std::string nfInstanceId;
j.at("nfInstanceId").get_to(nfInstanceId);
std::string pointJson = ".json";
std::string value;
value = nfInstanceId + pointJson;
std::ofstream myfile(value);
myfile << std::setw(75) << j << std::endl; myfile << std::setw(75) << j << std::endl;
zookeeperClient zooK; zookeeperClient zooK;
...@@ -60,8 +66,16 @@ void NFInstanceIDDocumentApiImpl::register_nf_instance(const std::string &nfInst ...@@ -60,8 +66,16 @@ void NFInstanceIDDocumentApiImpl::register_nf_instance(const std::string &nfInst
zk = zooK.getZk(); zk = zooK.getZk();
//实例化Register //实例化Register
Register Register; Register Register;
std::string value = "PistachValue"; std::string source = "/";
std::string path = "/PistachPath";
std::string nfType;
j.at("nfType").get_to(nfType);
std::string path;
path = source + nfType;
cout << " path: " << path << endl;
bool b; bool b;
b = Register.registerZK(value, path, zk); b = Register.registerZK(value, path, zk);
response.send(Pistache::Http::Code::Ok, "Do some magic\n"); response.send(Pistache::Http::Code::Ok, "Do some magic\n");
......
...@@ -20,6 +20,9 @@ namespace model { ...@@ -20,6 +20,9 @@ namespace model {
NFProfile::NFProfile() NFProfile::NFProfile()
{ {
//定义没有的变量
Sm_NfType = "";
Sm_NfStatus = "";
m_NfInstanceId = ""; m_NfInstanceId = "";
m_NfInstanceName = ""; m_NfInstanceName = "";
m_NfInstanceNameIsSet = false; m_NfInstanceNameIsSet = false;
...@@ -113,8 +116,10 @@ void to_json(nlohmann::json& j, const NFProfile& o) ...@@ -113,8 +116,10 @@ void to_json(nlohmann::json& j, const NFProfile& o)
j["nfInstanceId"] = o.m_NfInstanceId; j["nfInstanceId"] = o.m_NfInstanceId;
if(o.nfInstanceNameIsSet()) if(o.nfInstanceNameIsSet())
j["nfInstanceName"] = o.m_NfInstanceName; j["nfInstanceName"] = o.m_NfInstanceName;
j["nfType"] = o.m_NfType; //j["nfType"] = o.m_NfType;
j["nfStatus"] = o.m_NfStatus; //j["nfStatus"] = o.m_NfStatus;
j["nfType"] = o.Sm_NfType;
j["nfStatus"] = o.Sm_NfStatus;
if(o.heartBeatTimerIsSet()) if(o.heartBeatTimerIsSet())
j["heartBeatTimer"] = o.m_HeartBeatTimer; j["heartBeatTimer"] = o.m_HeartBeatTimer;
if(o.plmnListIsSet() || !o.m_PlmnList.empty()) if(o.plmnListIsSet() || !o.m_PlmnList.empty())
...@@ -235,14 +240,17 @@ void to_json(nlohmann::json& j, const NFProfile& o) ...@@ -235,14 +240,17 @@ void to_json(nlohmann::json& j, const NFProfile& o)
void from_json(const nlohmann::json& j, NFProfile& o) void from_json(const nlohmann::json& j, NFProfile& o)
{ {
printf("from_json开始! \n");
j.at("nfInstanceId").get_to(o.m_NfInstanceId); j.at("nfInstanceId").get_to(o.m_NfInstanceId);
if(j.find("nfInstanceName") != j.end()) if(j.find("nfInstanceName") != j.end())
{ {
j.at("nfInstanceName").get_to(o.m_NfInstanceName); j.at("nfInstanceName").get_to(o.m_NfInstanceName);
o.m_NfInstanceNameIsSet = true; o.m_NfInstanceNameIsSet = true;
} }
j.at("nfType").get_to(o.m_NfType); //j.at("nfType").get_to(o.m_NfType);
j.at("nfStatus").get_to(o.m_NfStatus); //j.at("nfStatus").get_to(o.m_NfStatus);
j.at("nfType").get_to(o.Sm_NfType);
j.at("nfStatus").get_to(o.Sm_NfStatus);
if(j.find("heartBeatTimer") != j.end()) if(j.find("heartBeatTimer") != j.end())
{ {
j.at("heartBeatTimer").get_to(o.m_HeartBeatTimer); j.at("heartBeatTimer").get_to(o.m_HeartBeatTimer);
......
...@@ -508,7 +508,10 @@ protected: ...@@ -508,7 +508,10 @@ protected:
NFType m_NfType; NFType m_NfType;
NFStatus m_NfStatus; NFStatus m_NfStatus;
//引入自定变量
std::string Sm_NfType;
std::string Sm_NfStatus;
//引入完毕
int32_t m_HeartBeatTimer; int32_t m_HeartBeatTimer;
bool m_HeartBeatTimerIsSet; bool m_HeartBeatTimerIsSet;
std::vector<PlmnId> m_PlmnList; std::vector<PlmnId> m_PlmnList;
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include "NFType.h" #include "NFType.h"
#include <string>
namespace org { namespace org {
namespace openapitools { namespace openapitools {
namespace server { namespace server {
......
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