Commit 2856dcf6 authored by Mosaical's avatar Mosaical

20200903

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