#include #include #include #define DAEMON_NAME "Balau/1.0" using namespace Balau; class TestAction : public HttpServer::Action { public: TestAction() : Action(Regexes::any) { } virtual bool Do(HttpServer * server, Http::Request & req, HttpServer::Action::ActionMatch & match, IO out) throw (GeneralException); }; bool TestAction::Do(HttpServer * server, Http::Request & req, HttpServer::Action::ActionMatch & match, IO out) throw (GeneralException) { HttpServer::Response response(server, req, out); response->writeString( "\n" "\n" " \n" " Test\n" " \n" "\n" " \n" " This is a test document.\n" " \n" "\n"); response.Flush(); return true; } Balau::Regex testFailureURL("^/failure.html$"); class TestFailure : public HttpServer::Action { public: TestFailure() : Action(testFailureURL) { } virtual bool Do(HttpServer * server, Http::Request & req, HttpServer::Action::ActionMatch & match, IO out) throw (GeneralException); }; bool TestFailure::Do(HttpServer * server, Http::Request & req, HttpServer::Action::ActionMatch & match, IO out) throw (GeneralException) { throw GeneralException("Test..."); } #define NTHREADS 4 void MainTask::Do() { Printer::enable(M_DEBUG); Printer::log(M_STATUS, "Test::Http running."); Thread * tms[NTHREADS]; for (int i = 0; i < NTHREADS; i++) tms[i] = TaskMan::createThreadedTaskMan(); HttpServer * s = new HttpServer(); HttpServer::Action * a = new TestAction(); HttpServer::Action * f = new TestFailure(); a->registerMe(s); f->registerMe(s); s->setPort(8080); s->setLocal("localhost"); s->start(); yield(); s->stop(); for (int i = 0; i < NTHREADS; i++) tms[i]->join(); Printer::log(M_STATUS, "Test::Http passed."); }