You need to sign in or sign up before continuing.
Commit 3d0492dc authored by Pavel Vainerman's avatar Pavel Vainerman

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

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