Commit 3d0492dc authored by Pavel Vainerman's avatar Pavel Vainerman

(UHttp): сделал поддержку передачи параметров

parent dbc31878
......@@ -85,7 +85,7 @@ class UniSetActivator:
return abortScript;
}
virtual nlohmann::json getDataByName( const std::string& name ) override;
virtual nlohmann::json getDataByName( const std::string& name , const Poco::URI::QueryParameters& p ) override;
protected:
......
......@@ -101,7 +101,7 @@ class UniSetObject:
//! поместить сообщение в очередь
virtual void push( const UniSetTypes::TransportMessage& msg ) override;
virtual nlohmann::json getData() override;
virtual nlohmann::json getData( const Poco::URI::QueryParameters& p ) override;
// -------------- вспомогательные --------------
/*! получить ссылку (на себя) */
......
......@@ -15,7 +15,6 @@
*/
// -------------------------------------------------------------------------
#include <ostream>
#include <Poco/URI.h>
#include "UHttpRequestHandler.h"
// -------------------------------------------------------------------------
using namespace std;
......@@ -62,17 +61,13 @@ void UHttpRequestHandler::handleRequest( Poco::Net::HTTPServerRequest& req, Poco
}
const std::string objectName(seg[2]);
// auto qp = uri.getQueryParameters();
// cerr << "params: " << endl;
// for( const auto& p: qp )
// cerr << p.first << "=" << p.second << endl;
auto qp = uri.getQueryParameters();
resp.setStatus(HTTPResponse::HTTP_OK);
resp.setContentType("text/json");
std::ostream& out = resp.send();
auto json = registry->getDataByName(objectName);
auto json = registry->getDataByName(objectName, qp);
out << json.dump();
out.flush();
}
......
......@@ -861,15 +861,15 @@ UniSetActivator::TerminateEvent_Signal UniSetActivator::signal_terminate_event()
return s_term;
}
// ------------------------------------------------------------------------------------------
nlohmann::json UniSetActivator::getDataByName( const string& name )
nlohmann::json UniSetActivator::getDataByName( const string& name, const Poco::URI::QueryParameters& p )
{
auto obj = findObject(name);
if( obj )
return obj->getData();
return obj->getData(p);
auto man = findManager(name);
if( man )
return man->getData();
return man->getData(p);
//! \todo Продумать что возвращать если объект не найден
nlohmann::json j = "";
......
......@@ -379,7 +379,7 @@ void UniSetObject::push( const TransportMessage& tm )
termWaiting();
}
// ------------------------------------------------------------------------------------------
nlohmann::json UniSetObject::getData()
nlohmann::json UniSetObject::getData( const Poco::URI::QueryParameters& p )
{
nlohmann::json jdata;
jdata["name"] = myname;
......
......@@ -12,10 +12,13 @@ class UTestSupplier:
UTestSupplier(){}
virtual ~UTestSupplier(){}
virtual nlohmann::json getData() override
virtual nlohmann::json getData( const Poco::URI::QueryParameters& params ) override
{
nlohmann::json j;
for( const auto& p: params )
j[p.first] = p.second;
j["test"] = 42;
return j;
}
......@@ -29,9 +32,9 @@ class UTestRequestRegistry:
virtual ~UTestRequestRegistry(){}
virtual nlohmann::json getDataByName( const std::string& name ) override
virtual nlohmann::json getDataByName( const std::string& name, const Poco::URI::QueryParameters& p ) override
{
nlohmann::json j = sup.getData();
nlohmann::json j = sup.getData(p);
j["name"] = name;
return j;
}
......@@ -51,6 +54,8 @@ int main(int argc, const char** argv)
auto http = make_shared<UHttp::UHttpServer>(ireg,"localhost", 5555);
http->log()->level(Debug::ANY);
cout << "start http test server localhost:5555" << endl;
http->start();
pause();
http->stop();
......
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