[libjsonrpccpp-devel] No client connection handler found
Brought to you by:
cinemast
|
From: Jason M. <atm...@gm...> - 2016-11-23 20:11:05
|
Hello,
trying to get a basic json-rpc server up and running. Upon testing a
method, i get this error from curl:
No client connection handler found
Here is my code:
#include <jsonrpccpp/server.h>
class AbstractStubServer : public
jsonrpc::AbstractServer<AbstractStubServer>
{
public:
AbstractStubServer(jsonrpc::AbstractServerConnector &conn,
jsonrpc::serverVersion_t type = jsonrpc::JSONRPC_SERVER_V2) :
jsonrpc::AbstractServer<AbstractStubServer>(conn, type)
{
this->bindAndAddMethod(jsonrpc::Procedure("connect",
jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING,
"password",jsonrpc::JSON_STRING,"uri",jsonrpc::JSON_STRING, NULL),
&AbstractStubServer::connectI);
this->bindAndAddMethod(jsonrpc::Procedure("hostGetVersion",
jsonrpc::PARAMS_BY_NAME, jsonrpc::JSON_STRING,
"connID",jsonrpc::JSON_STRING, NULL), &AbstractStubServer::hostGetVersionI);
}
inline virtual void connectI(const Json::Value &request,
Json::Value &response)
{
response = this->connect(request["password"].asString(),
request["uri"].asString());
}
inline virtual void hostGetVersionI(const Json::Value &request,
Json::Value &response)
{
response = this->hostGetVersion(request["connID"].asString());
}
virtual std::string connect(const std::string& password, const
std::string& uri) = 0;
virtual std::string hostGetVersion(const std::string& connID) = 0;
};
using namespace jsonrpc;
using namespace std;
class RpcServer : public AbstractStubServer
{
public:
RpcServer(AbstractServerConnector &connector,
SHRDPTR(Drivers::DriverManager) manager);
virtual std::string connect(const std::string &password, const
std::string &uri);
virtual std::string hostGetVersion(const std::string& connID);
private:
std::map<std::string, SHRDPTR(Drivers::IDriver)> connectionMap_;
SHRDPTR(Drivers::DriverManager)
manager_;
};
RpcServer::RpcServer(AbstractServerConnector &connector,
SHRDPTR(Drivers::DriverManager) manager) :
AbstractStubServer(connector), manager_(manager)
{
}
std::string genConnectionID(std::string uri, std::string password)
{
unsigned char result[MD5_DIGEST_LENGTH];
MD5((unsigned char*)uri.c_str(), uri.size(), result);
std::ostringstream sout;
sout<<std::hex<<std::setfill('0');
for(long long c: result)
{
sout<<std::setw(2)<<(long long)c;
}
return sout.str();
}
std::string RpcServer::connect(const std::string &password, const
std::string &uri)
{
auto conn = MKSHRD(Connection::HypervisorConnection, uri, password);
auto factory = this->manager_->get(conn->getProtocol());
auto driver = factory->create(conn);
auto id = genConnectionID(uri, password);
this->connectionMap_[id] = driver;
return id;
}
std::string RpcServer::hostGetVersion(const std::string& connID)
{
auto driver = this->connectionMap_[connID];
return driver->hostGetVersion();
}
and in main:
HttpServer httpServer(8383);
RpcServer rpcServer(httpServer, manager);
rpcServer.StartListening();
getchar();
rpcServer.StopListening();
What am I missing?
Thanks,
Jason
|