X-Git-Url: https://git.teslayout.com/public/public/public/?p=anna.git;a=blobdiff_plain;f=example%2Fdiameter%2Flauncher%2FMyHandler.cpp;h=9ac1c445d5f2a220db13ba2ff901b34962ca6e41;hp=9f893a75d50e608f5cad1d7d68620e1d94f4ba1a;hb=2f2cc741b21502b2bd37060a1059084a54cb8b6e;hpb=a5d4c4f2e8bd10de42bb5a0bfa20acaceaf2e67a diff --git a/example/diameter/launcher/MyHandler.cpp b/example/diameter/launcher/MyHandler.cpp index 9f893a7..9ac1c44 100644 --- a/example/diameter/launcher/MyHandler.cpp +++ b/example/diameter/launcher/MyHandler.cpp @@ -8,6 +8,8 @@ // Standard #include +#include +#include // Project #include @@ -34,18 +36,20 @@ throw(anna::RuntimeException) { // Operation: std::string response_content; + bool opOk{}; + try { Launcher& my_app = static_cast (anna::app::functions::getApp()); - my_app.eventOperation(body_content, response_content); + opOk = my_app.eventOperation(body_content, response_content); } catch(RuntimeException &ex) { ex.trace(); + opOk = false; } anna::http::Response* response = allocateResponse(); response->setStatusCode(200); // http://en.wikipedia.org/wiki/List_of_HTTP_status_codes - anna::DataBlock db_content(true); - db_content = response_content; - response->setBody(db_content); + +// EXAMPLES TO SET HEADERS: // response->find(anna::http::Header::Type::Date)->setValue("Mon, 30 Jan 2006 14:36:18 GMT"); // anna::http::Header* keepAlive = response->find("Keep-Alive"); // @@ -54,6 +58,20 @@ throw(anna::RuntimeException) { // // keepAlive->setValue("Verificacion del cambio 1.0.7"); + // Content-Type header: + anna::http::Header* contentType = response->find("Content-Type"); + if (contentType == NULL) + contentType = response->createHeader("Content-Type"); + contentType->setValue("application/json"); + + // Json Body for response: + std::stringstream ss; + + ss << R"({ "result":")" << (opOk ? "true":"false") << R"(", "data": )" << std::quoted(response_content) << R"( })"; + anna::DataBlock db_content(true); + db_content = ss.str(); + response->setBody(db_content); + try { clientSocket.send(*response); } catch(Exception& ex) {