Thread: [Cppcms-users] cppcms::rpc::json_rpc_server usage.
Brought to you by:
artyom-beilis
From: le ba <hma...@gm...> - 2012-05-21 08:39:42
|
Hi, Instead derived from cppcms::application, my application is derived from cppcms::rpc::json_rpc_server . I would like to populate the dynamic page with data from a request using ajax and json. My Questions are: - Is it a normal usage of cppcms framework because I don't find an example like this within the example that you have provided? - If yes, are there some conditions or some style of code for this kind of usage? Thank you very much. hmaminirina. |
From: le ba <hma...@gm...> - 2012-05-21 10:29:16
|
Hi , I would like explain my questions. For example I create my dynamic page (like template or templates_inheritance in the example) with ajax using json_rpc inside: 1. Will I do a derivation from cppcms::appliaction and make a json call inside or 2. Will I do a derivation from cppcms::rpc::json_rpc_server for all application and children. I'd like to know if the context is shared by url dispather and json_rpc_call or they have two different context? Thank you Artyom. ---------- Forwarded message ---------- From: le ba <hma...@gm...> Date: 2012/5/21 Subject: cppcms::rpc::json_rpc_server usage. To: cpp...@li... Cc: art...@ya... Hi, Instead derived from cppcms::application, my application is derived from cppcms::rpc::json_rpc_server . I would like to populate the dynamic page with data from a request using ajax and json. My Questions are: - Is it a normal usage of cppcms framework because I don't find an example like this within the example that you have provided? - If yes, are there some conditions or some style of code for this kind of usage? Thank you very much. hmaminirina. |
From: Artyom B. <art...@ya...> - 2012-05-21 12:51:43
|
> > >I would like explain my questions. For example I create my dynamic page > (like template or templates_inheritance in the example) with ajax using json_rpc inside: > 1. Will I do a derivation from cppcms::appliaction and make a json call inside or > 2. Will I do a derivation from cppcms::rpc::json_rpc_server for all application and children. See json_rcp_server is derived from cppcms::application, so everything you have in application you have in the RPC server. So if you use mostly AJAX and JSON-RPC API it makes sence to use json_rpc_server for your code >I'd like to know if the context is shared by url dispather and json_rpc_call or they have two different context? > No, but dispatching member functions would not work AFAIR as it dispatches function calls in main() that is overriden If you want more specific answers be more specific Artyom > |
From: le ba <hma...@gm...> - 2012-05-22 07:39:17
|
Hi Artyom, this is the main overriden that I used: class numbers : public cppcms::rpc::json_rpc_server { public: numbers(cppcms::service &srv) : cppcms::rpc::json_rpc_server (srv) { dispatcher().assign("",&numbers::all,this); mapper().assign(""); } void main(std:string url) { if(!dispatcher().dispatch(url)) { response().make_error_response(http::response::not_found); } cppcms::rpc::json_rpc_server::main(url); } }; 2012/5/21 Artyom Beilis <art...@ya...> > > > > > > >I would like explain my questions. For example I create my dynamic page > > > (like template or templates_inheritance in the example) with ajax using > json_rpc inside: > > 1. Will I do a derivation from cppcms::appliaction and make a json > call inside or > > 2. Will I do a derivation from cppcms::rpc::json_rpc_server for all > application and children. > > See json_rcp_server is derived from cppcms::application, so everything you > have in application > you have in the RPC server. > > So if you use mostly AJAX and JSON-RPC API it makes sence to use > json_rpc_server for your code > > > >I'd like to know if the context is shared by url dispather and > json_rpc_call or they have two different context? > > > > No, but dispatching member functions would not work AFAIR as it dispatches > function calls in main() that > is overriden > > > If you want more specific answers be more specific > > > Artyom > > > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > > |
From: Artyom B. <art...@ya...> - 2012-05-22 17:07:07
|
> > > void main(std:string url) > { > if(!dispatcher().dispatch(url)) { >response().make_error_response(http::response::not_found); > } > cppcms::rpc::json_rpc_server::main(url); > } >}; > You really mixing stuff incorrectly because you will never be able to execute cppcms::rpc::json_rpc_server::main(url); properly as you already have an output Artyom |
From: le ba <hma...@gm...> - 2012-05-23 12:24:21
|
Hi, What is the wrong in my code?: This is my code. class master : public cppcms::rpc::json_rpc_server { public: master(cppcms::service &s); ~master(); void init(); void clear(); void ini(content::master &c); cppdb::session sql; std::string connection; }; master::master(cppcms::service &s) : cppcms::rpc::json_rpc_server(s) { connection="odbc:dsn=ajaxex;user=root;password=root"; } master::~master(){ } void master::init() { sql.open(connection); if (sql.is_open()) { std::cout << "Data Base ouverte" << std::endl; } else { std::cout << "Data Base non ouverte" << std::endl; } } void master::clear() { sql.close(); } void master::ini(content::master &c) { c.title = "My Web Site"; c.image = settings().get<std::string>("myjsonappli.image"); c.media = settings().get<std::string>("myjsonappli.media"); c.scrpt = settings().get<std::string>("myjsonappli.scrpt"); } class pages : public master { public: pages(cppcms::service &s) : master(s) { bind("softwares",cppcms::rpc::json_method(&pages::softwares,this),method_role);//methode that I would to call with ajax dispatcher().assign("/page",&pages::page,this); mapper().assign("page","/page"); } void softwares(int id) { cppdb::result r; cppcms::json::value val; cppcms::json::array softs; std::cout << id << std::endl; r = sql<< "SELECT id,name,idEditor " "FROM ajax_example_softwares WHERE idEditor=?" "ORDER BY id" << id; int i=0; while(r.next()) { cppcms::json::value soft; soft["id"] = r.get<int>("id"); soft["name"] = r.get<std::string>("name"); soft["ideditor"] = r.get<int>("idEditor"); softs.push_back(soft); std::cout << soft << std::endl; i++; } std::cout << "Nombre de ligne " << i << std::endl; val.array(softs); return_result(val); } void page() { content::page c; ini(c); c.page_title = "Multiflex-3 Update-7 / Header-1"; c.page_content = "<p>A page about this web site</p>"; render("page",c); } void main(std::string url) { cppcms::http::content_type ct = request().content_type_parsed(); if(!dispatcher().dispatch(url)){ response().make_error_response(cppcms::http::response::not_found); } cppcms::rpc::json_rpc_server::main(url); std::string type = ct.type(); std::cout<<type<<std::endl; std::string subtype = ct.subtype(); std::cout<<subtype<<std::endl; std::cout<<request().request_method()<<std::endl; } }; Thank in advance for your help Artyom. 2012/5/22 Artyom Beilis <art...@ya...> > > > > > > > void main(std:string url) > > { > > if(!dispatcher().dispatch(url)) { > >response().make_error_response(http::response::not_found); > > } > > cppcms::rpc::json_rpc_server::main(url); > > } > >}; > > > > > You really mixing stuff incorrectly because you will never > > be able to execute cppcms::rpc::json_rpc_server::main(url); properly > as you already have an output > Artyom > > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > |
From: le ba <hma...@gm...> - 2012-05-23 12:49:40
|
By default cppcms::rpc::json_rpc_server don't dispatches Url by default like cppcms::application. My problem is how to dispatch a dynamic page and activate the json_rpc call after. ---------- Forwarded message ---------- From: le ba <hma...@gm...> Date: 2012/5/23 Subject: Re: [Cppcms-users] Fwd: cppcms::rpc::json_rpc_server usage. To: Artyom Beilis <art...@ya...>, cpp...@li... Hi, What is the wrong in my code?: This is my code. class master : public cppcms::rpc::json_rpc_server { public: master(cppcms::service &s); ~master(); void init(); void clear(); void ini(content::master &c); cppdb::session sql; std::string connection; }; master::master(cppcms::service &s) : cppcms::rpc::json_rpc_server(s) { connection="odbc:dsn=ajaxex;user=root;password=root"; } master::~master(){ } void master::init() { sql.open(connection); if (sql.is_open()) { std::cout << "Data Base ouverte" << std::endl; } else { std::cout << "Data Base non ouverte" << std::endl; } } void master::clear() { sql.close(); } void master::ini(content::master &c) { c.title = "My Web Site"; c.image = settings().get<std::string>("myjsonappli.image"); c.media = settings().get<std::string>("myjsonappli.media"); c.scrpt = settings().get<std::string>("myjsonappli.scrpt"); } class pages : public master { public: pages(cppcms::service &s) : master(s) { bind("softwares",cppcms::rpc::json_method(&pages::softwares,this),method_role);//methode that I would to call with ajax dispatcher().assign("/page",&pages::page,this); mapper().assign("page","/page"); } void softwares(int id) { cppdb::result r; cppcms::json::value val; cppcms::json::array softs; std::cout << id << std::endl; r = sql<< "SELECT id,name,idEditor " "FROM ajax_example_softwares WHERE idEditor=?" "ORDER BY id" << id; int i=0; while(r.next()) { cppcms::json::value soft; soft["id"] = r.get<int>("id"); soft["name"] = r.get<std::string>("name"); soft["ideditor"] = r.get<int>("idEditor"); softs.push_back(soft); std::cout << soft << std::endl; i++; } std::cout << "Nombre de ligne " << i << std::endl; val.array(softs); return_result(val); } void page() { content::page c; ini(c); c.page_title = "Multiflex-3 Update-7 / Header-1"; c.page_content = "<p>A page about this web site</p>"; render("page",c); } void main(std::string url) { cppcms::http::content_type ct = request().content_type_parsed(); if(!dispatcher().dispatch(url)){ response().make_error_response(cppcms::http::response::not_found); } cppcms::rpc::json_rpc_server::main(url); std::string type = ct.type(); std::cout<<type<<std::endl; std::string subtype = ct.subtype(); std::cout<<subtype<<std::endl; std::cout<<request().request_method()<<std::endl; } }; Thank in advance for your help Artyom. 2012/5/22 Artyom Beilis <art...@ya...> > > > > > > > void main(std:string url) > > { > > if(!dispatcher().dispatch(url)) { > >response().make_error_response(http::response::not_found); > > } > > cppcms::rpc::json_rpc_server::main(url); > > } > >}; > > > > > You really mixing stuff incorrectly because you will never > > be able to execute cppcms::rpc::json_rpc_server::main(url); properly > as you already have an output > Artyom > > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > |
From: Artyom B. <art...@ya...> - 2012-05-23 14:08:59
|
>________________________________ > From: le ba <hma...@gm...> > > >By default cppcms::rpc::json_rpc_server don't dispatches Url by default like cppcms::application. >My problem is how to dispatch a dynamic page and activate the json_rpc call after. > > JSON-RPC protocol returns JSON object in output and receives JSON object as input... Dynamic page returns HTML output to the client and optionally receives some POST data as input... Decide what do you want to do. If you want some pages return HTML and others use JSON-RPC protocol read the documentation about application hierarchy http://cppcms.com/wikipp/en/page/cppcms_1x_tut_hierarchy Applications that should handle JSON-RPC should be derived from cppcms::rpc::json_rpc_server others should behave as normal applications. Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.com/ CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/ |
From: le ba <hma...@gm...> - 2012-05-29 14:33:04
|
Hi Artyom, Thanks for your help, it works fine now . An other article that are very important in cppcms document : "context is a central class that holds all specific connection related information. It encapsulates CGI request and response, cache, session and locale information *Instance of this class is created upon client requests, it provides access to all connection related interfaces*.* This class is unique per each applications hierarchy and destroyed when HTTP request/response is completed *". Thank you very much. 2012/5/23 Artyom Beilis <art...@ya...> > > > > > > >________________________________ > > From: le ba <hma...@gm...> > > > > > >By default cppcms::rpc::json_rpc_server don't dispatches Url by default > like cppcms::application. > >My problem is how to dispatch a dynamic page and activate the json_rpc > call after. > > > > > > JSON-RPC protocol returns JSON object in output and receives JSON object > as input... > Dynamic page returns HTML output to the client and optionally receives > some POST data as input... > > Decide what do you want to do. If you want some pages return HTML and > others use JSON-RPC protocol > read the documentation about application hierarchy > > > http://cppcms.com/wikipp/en/page/cppcms_1x_tut_hierarchy > > Applications that should handle JSON-RPC should be derived from > cppcms::rpc::json_rpc_server > > others should behave as normal applications. > > Artyom Beilis > -------------- > CppCMS - C++ Web Framework: http://cppcms.com/ > CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/ > > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > |