Re: [Cppcms-users] Problem with cppcms::application::add() method
Brought to you by:
artyom-beilis
From: Artyom <art...@ya...> - 2010-11-11 20:39:30
|
> >void application::add(application &app,std::string regex,int part) >{ > add(app); > url_dispatcher().mount(regex,app,part); >} > >The code above has an error, the correct code is: >dispatcher().mount(regex,app,part); > add or attach member functions do only one thing - they share the http::context class between all connected applications. Otherwise you'll just have an exception trying to access anything like request() or response() of any class that wasn't added. On the other hand url_dispatching is just a simple way to "split" your main function according to requests between its own member function and other sub applications. There are different tasks and they both required (unless you wan't to do something on your own in main rather then standard URL-dispatching) > Second problem: > > When I attach or add an application B to an application A, > the method "void B::main(std::string url)" is never > called on url dispatch stage. When you mount a sub application you just extract sub expression and pass it to mounted application. I.e. add(users_app) add(uploads) urd_dispatched().mount("/users(/.*)",users_app,1); urd_dispatched().mount("/uploads(/.*)",uploads,1); And then in constructor of users you mount url_dispatcher().attach("/login",&users_class::login,this); when you hit /users/login /users/login is matched against "/users(/.*)" regex and passed to users_app.main() with parameter "/login" then it matched by users_app's url_disptacher against "/login" regex and passed to login member function of users_app instance. So you need both steps and understand how they work. > This behaviour causes problems when adding cppcms::rpc::json_rpc_server > application because the parsing of the request is made in json_rpc_server::main > > method. > The result is that the application does not work. adding application has nothing to do with URL dispatching, url_disptaching just allows you to forward request to other app's main function. > in cppcms::rpc::json_rpc_server application: URL mapping with > dispatcher().assign() method does not work because main method overwriting. When you develop json_rpc server you suppose to rather bind member function by remote procedure functions (i.e. RPC service function = member function) rather then using URL-dispatching method suitable for ordinary web applications. So it is done by design. Artyom |