On Tue, May 29, 2012 at 2:00 PM, Plug Gulp <[email protected]> wrote:
> @Nagaev
>
>> I changed your code to work as expected:
>
> No, it does not work. Are you trying the example with the wthttp
> server that comes with Wt or are you trying this with FCGI connector?
I used with wthttp.

$ md5sum 1.cpp
af1ee4b949a63e8071a20e393077ee92  1.cpp

Compilation:
$ g++ 1.cpp -o 1 -lwt -lwthttp

Run:
$ ./1 --http-port 8000 --http-address 0.0.0.0 --docroot .

Access:
$ curl http://0.0.0.0:8000/hello
Hello World!

It should work.

For static resources, no extra requests are performed: you just get
(through HTTP) output of handleRequest.

It should work as well with any type of connector (fcgi or isapi) or
when wthttp is used through reverse proxy (like nginx or apache
http_proxy).

But it is not how RESTful API should be implemented for Wt.
imho, you should use normal WApplication and connect
internalPathChanged() signal to handler function, that would create
WText("Hello");

In this case you'll get additional requests (application
initialization, javascript, etc).
And "Hello" would not be raw HTTP contents (as in 1.cpp), but a part of HTML.

Full example see attached file 2.cpp

When I click the anchor, URL is changed to http://0.0.0.0:8000/#/hello/
I other browsers (and Wt versions) it could be
http://0.0.0.0:8000?_=/hello/ or http://0.0.0.0:8000/hello/
It should also work through fcgi or http proxy (some configuration may
be needed).


> I am using Apache+fcgid and it does not work for me. If you try to
> access the example "hello" RESTful API mentioned in my original post,
> you will get an html page back (refer the output file attached with
> the original post). If you want to understand what actually happens
> when that RESTful API is invoked, try accessing it via Firefox instead
> of cURL. When you access the API via Firefox, there are actually 6
> requests sent to the server (5 GET and 1 POST). These extra request
> are injected by Wt. Also the URL is modified by Wt to include
> sessionID and other parameters. The WResource is not created and
> registered until after the first few GET requests that Wt generates.
> Even after that the handleRequest method of the resource is never
> called because the EntryPoint deduced by Wt for any of the 6 requests
> is never of type StaticResource. So I am missing something here. Its
> not just the code, it is also about how to invoke the RESTful API for
> Wt service. It will be helpful if someone can point me to a simple
> "hello world" RESTful service example that works under FCGI connector.
>
>
>> 1. remove #if macros
>
> Well if you do not define WITH_APP then you get essentially what you
> suggest in following two points.

Ok, I did not notice that :)

>
>> 2. remove call of Wt::WRun, which used to prevent the program to enter 
>> try-catch.
>> 3. remove RestApplication class (which is not needed for this example)
>
> Just don't define WITH_APP and it should be okay.
>
>
>> 4. add beingDeleted(); to ~RestGetHello() (as as stated in documentation)
>
> Yep, missed that. Thanks!
>
> Kind regards,
>
> ~Plug
>
> ------------------------------------------------------------------------------
> 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/
> _______________________________________________
> witty-interest mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/witty-interest
#include <Wt/WApplication>
#include <Wt/WText>
#include <Wt/WAnchor>
#include <Wt/WContainerWidget>
#include <iostream>

using namespace Wt;

class RestApplication : public WApplication {
   public:
       RestApplication(const WEnvironment& env)
           : WApplication(env)
       {
           WAnchor* a = new WAnchor();
           a->setRefInternalPath("/hello/");
           a->setText("anchor");
           root()->addWidget(a);
           internalPathChanged().connect(this,
				&RestApplication::path_changed_handler);
           path_changed_handler(); // if it is already openned
       }

   private:
       void path_changed_handler() {
		   			   std::cout << "111" << std::endl;

		   if (internalPathMatches("/hello/")) {
			   root()->clear();
			   root()->addWidget(new WText("Hello"));
		   }
	   }
};

WApplication *createApplication(const WEnvironment& env)
{
   return new RestApplication(env);
}

int main(int argc, char **argv)
{
   return Wt::WRun(argc, argv, &createApplication);
}
------------------------------------------------------------------------------
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/
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest

Reply via email to