예제 #1
0
  virtual void handleRequest(const Wt::Http::Request &request, Wt::Http::Response &response) {
    response.setMimeType("text/html; charset=utf-8");
    response.addHeader("Server", "Wt");

    DbStruct* db = dbStruct_.get();
    if (!db) {
      db = new DbStruct();
      dbStruct_.reset(db);
    }

    Wt::Dbo::Transaction transaction(db->session);
    Fortunes fortunes = db->session.find<Fortune>();
    VFortunes vFortunes;
    for (Fortunes::const_iterator i = fortunes.begin(); i != fortunes.end(); ++i)
      vFortunes.push_back(*i);
    Fortune* additionalFortune = new Fortune();
    additionalFortune->message = "Additional fortune added at request time.";
    vFortunes.push_back(Wt::Dbo::ptr<Fortune>(additionalFortune));

    std::sort(vFortunes.begin(), vFortunes.end(), fortuneCmp);

    FortuneTemplate tpl(vFortunes);

    response.out() << "<!DOCTYPE html>";
    tpl.renderTemplate(response.out());
  }
예제 #2
0
  virtual void handleRequest(const Wt::Http::Request &request, Wt::Http::Response &response) {
    int n;
    if (const std::string *queries = request.getParameter("queries")) {
      n = atoi(queries->c_str());
      if (n < 1)
        n = 1;
      else if (n > 500)
        n = 500;
    } else {
      n = 1;
    }

    response.setMimeType("application/json");
    response.addHeader("Server", "Wt");

    DbStruct* db = dbStruct_.get();
    if (!db) {
      db = new DbStruct();
      dbStruct_.reset(db);
    }

    Wt::Dbo::Transaction transaction(db->session);
    std::vector<Wt::Dbo::ptr<World> > results;
    results.reserve(n);
    for (int i = 0; i < n; ++i) {
      results.push_back(db->session.load<World>(db->rand()));
    }
    Wt::Dbo::JsonSerializer writer(response.out());
    writer.serialize(results);
  }
예제 #3
0
void PrintResource::handleRequest(const Wt::Http::Request& request,
                                  Wt::Http::Response& response)
{
    //log("info")<<"PrintResource::handleRequest() "<<__LINE__;
    response.addHeader("Cache-Control", "max-age=315360000");
    response.setMimeType("text/html; charset=utf-8");
    std::ostringstream htmlStream;// = std::cout;
    htmlStream << "";

    //log("info")<<m_content->find("order_form");
    if(WContainerWidget *form = dynamic_cast<WContainerWidget*>(m_content->find("order_form")))
    {
        for(int i=0;i < form->count()-1;i++)
        {
            WWidget *item = form->widget(i);
            if(item->id() == "comments")
            {
                item->decorationStyle().setBorder(WBorder());
            }else
                item->setHidden(true);
        }
    }

    response.out() <<"<link href=\"http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css\" type=\"text/css\" rel=\"stylesheet\">"<<std::endl;
    response.out() <<"<link href=\"http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap-theme.min.css\" type=\"text/css\" rel=\"stylesheet\">"<<std::endl;
    response.out() << "<script src=\"/css/ie_console.js\"></script>";

    response.out() << ""
    "<script type=\"text/javascript\">\n"
    "        window.setTimeout(function () {\n"
    "            window.print();\n"
    "        }, 1000);\n"
    "</script>\n"<<std::endl;

    m_content->htmlText(response.out());
    //log("info")<<"PrintResource::handleRequest() "<<__LINE__;

/*
    response.out() << ""
    "<script type=\"text/javascript\">\n"
    "    (function() { \n"
    "        window.setTimeout(function () {\n"
    "            window.print();\n"
    "        }, 1500);\n"
    "    }); \n"
    "</script>\n"<<std::endl;

*/
    //m_content->htmlText(htmlStream);
    //std::string htmlStr= "";
    //htmlStr << htmlStream;
    //std::cout <<htmlStream<<std::endl;
    //renderer.render(WString().fromUTF8(htmlStream.str()));

    response.out() << WString().fromUTF8(htmlStream.str()) << std::endl;
}
예제 #4
0
    virtual void handleRequest(const Wt::Http::Request &request, Wt::Http::Response &response) {
        response.setMimeType("application/json");
        response.addHeader("Server", "Wt");

        MyMessage message;
        message.message = "Hello, World!";

        Wt::Dbo::JsonSerializer writer(response.out());
        writer.serialize(message);
    }
예제 #5
0
  virtual void handleRequest(const Wt::Http::Request &request, Wt::Http::Response &response) {
    response.setMimeType("application/json");
    response.addHeader("Server", "Wt");

    DbStruct* db = dbStruct_.get();
    if (!db) {
      db = new DbStruct();
      dbStruct_.reset(db);
    }

    Wt::Dbo::Transaction transaction(db->session);
    Wt::Dbo::ptr<World> entry = db->session.load<World>(db->rand());
    
    Wt::Dbo::JsonSerializer writer(response.out());
    writer.serialize(entry);
  }
예제 #6
0
  virtual void handleRequest(const Wt::Http::Request &request, Wt::Http::Response &response) {
    int n;
    if (const std::string *queries = request.getParameter("queries")) {
      n = atoi(queries->c_str());
      if (n < 1)
        n = 1;
      else if (n > 500)
        n = 500;
    } else {
      n = 1;
    }

    response.setMimeType("application/json");
    response.addHeader("Server", "Wt");

    DbStruct* db = dbStruct_.get();
    if (!db) {
      db = new DbStruct();
      dbStruct_.reset(db);
    }

    std::vector<Wt::Dbo::ptr<World> > results;

    for (int i = 0; i < n; ++i) {
      bool success = false;
      while (!success) {
        try {
          Wt::Dbo::Transaction transaction(db->session);
          Wt::Dbo::ptr<World> world = db->session.load<World>(db->rand());
          world.modify()->randomNumber = db->rand();
          transaction.commit();
          results.push_back(world);
          success = true;
        } catch (Wt::Dbo::Exception& e) {
          // Retry
        }
      }
    }

    Wt::Dbo::JsonSerializer writer(response.out());
    writer.serialize(results);
  }
예제 #7
0
  virtual void handleRequest(const Wt::Http::Request &request, Wt::Http::Response &response) {
    response.setMimeType("text/plain");
    response.addHeader("Server", "Wt");

    response.out() << "Hello, World!";
  }
예제 #8
0
 void handleRequest (const Wt::Http::Request&, Wt::Http::Response &response) {
      Wt::WApplication::instance()->log("info") << "Handle Request Called";
      response.setStatus(200);
      response.addHeader("Content-type", "text/plain");
      response.out() << "Hello\n";
 }