当前位置: 首页>>代码示例>>C++>>正文


C++ WebServer::getHostAddress方法代码示例

本文整理汇总了C++中WebServer::getHostAddress方法的典型用法代码示例。如果您正苦于以下问题:C++ WebServer::getHostAddress方法的具体用法?C++ WebServer::getHostAddress怎么用?C++ WebServer::getHostAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WebServer的用法示例。


在下文中一共展示了WebServer::getHostAddress方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: runWebServerTest

static void runWebServerTest(TestRunner& tr)
{
   const char* path = "/test";
   const char* content = "web server test";
   const char* regexPath = "/test/dumplings/regextest/turkey";
   const char* regexPath2 = "/test/dumplings/regextest2/turkey";
   const char* regexPath3 = "/test/dumplings/regextest3/turkey";
   const char* regexContent = "web server test (regex)";

   // create kernel
   Kernel k;

   // set thread stack size in engine (128k)
   k.getEngine()->getThreadPool()->setThreadStackSize(131072);

   // optional for testing --
   // limit threads to 2: one for accepting, 1 for handling
   //k.getEngine()->getThreadPool()->setPoolSize(2);

   // start engine
   k.getEngine()->start();

   // create server
   Server server;

   WebServer ws;
   Config cfg;
   cfg["host"] = "localhost";
   cfg["port"] = 0;
   cfg["security"] = "off";
   WebServiceContainerRef wsc = new WebServiceContainer();
   ws.setContainer(wsc);
   ws.initialize(cfg);
   WebServiceRef tws = new TestWebService(path, content, regexContent);
   wsc->addService(tws, WebService::Both);
   ws.enable(&server);

   // start server
   assertNoException(server.start(&k));

   // get server port
   int port = ws.getHostAddress()->getPort();

   // check the regular path and data
   tr.test("WebServer - regular path handler");
   {
      Url url;
      url.format("http://%s:%d%s", cfg["host"]->getString(), port, path);
      _checkUrlText(tr, &url, 200, content, strlen(content));
   }
   tr.passIfNoException();

   // check the regex path and data
   tr.test("WebServer - regex path handler");
   {
      Url url;
      url.format("http://%s:%d%s", cfg["host"]->getString(), port, regexPath);
      _checkUrlText(tr, &url, 200, regexContent, strlen(regexContent));
   }
   tr.passIfNoException();

   // check the regex path and data
   tr.test("WebServer - regex path handler matches");
   {
      DynamicObject info;
      info["type"] = "monarch.ws.RestfulHandler";
      DynamicObject& matches = info["matches"];
      matches[0] = "dumplings";
      matches[1] = "turkey";
      string expect = JsonWriter::writeToString(info);

      Url url;
      url.format("http://%s:%d%s", cfg["host"]->getString(), port, regexPath2);
      _checkUrlText(tr, &url, 200, expect.c_str(), expect.length());
   }
   tr.passIfNoException();

   // check the web service authentication exception
   tr.test("WebServer - authentication exception");
   {
      DynamicObject ex;
      ex["message"] = "WebService authentication failed. Access denied.";
      ex["type"] = "monarch.ws.AccessDenied";
      ex["details"]["httpStatusCode"] = 403;
      ex["details"]["path"] = "/test/dumplings/regextest3/turkey";
      ex["details"]["public"] = true;
      DynamicObject& cause = ex["cause"];
      cause["message"] = "Tried to authenticate but failed.";
      cause["type"] = "tests.ws.Exception";
      string expect = JsonWriter::writeToString(ex, true);

      Url url;
      url.format("http://%s:%d%s", cfg["host"]->getString(), port, regexPath3);
      _checkUrlText(tr, &url, 400, expect.c_str(), expect.length());
   }
   tr.passIfNoException();

   server.stop();

   // stop kernel engine
//.........这里部分代码省略.........
开发者ID:bsletten,项目名称:monarch,代码行数:101,代码来源:test-ws.cpp


注:本文中的WebServer::getHostAddress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。