Add second work package for REST API implementation
[anna.git] / example / diameter / launcher / MyHandler.cpp
index ed49f4f..49205ed 100644 (file)
@@ -114,7 +114,7 @@ throw(anna::RuntimeException) {
     }
     catch(anna::RuntimeException &ex) {
       ex.trace();
-      LOGINFORMATION(anna::Logger::information("XXXXXXXXXXXX EXCEPCION PENDIENTE DE CATCHEAR ABAJO !!! XXXXXXXXXXXXXXXXX", ANNA_FILE_LOCATION));
+      LOGINFORMATION(anna::Logger::information("doPOST exception: TODO control in inner method. Check traces", ANNA_FILE_LOCATION));
     }
   }
 
@@ -252,15 +252,26 @@ bool MyHandler::doPOST(const std::string &uri, const nlohmann::json &j, std::str
 
   // Flow operations
   else if ((opType == "/sendmsg2e")||(opType == "/sendmsg2c")) {
-    auto it = j.find("diameterJson");
-    if (it != j.end())
+    auto itJ = j.find("diameterJson");
+    if (itJ != j.end()) {
       if (opType == "/sendmsg2e")
-        result = eop.sendmsg2e(response, it->dump(4)); // get the object as string (always indentation = 4)
+        result = eop.sendmsg_hex_2e(response, itJ->dump(4), true); // get the object as string (always indentation = 4)
       else
-        result = eop.sendmsg2c(response, it->dump(4)); // get the object as string (always indentation = 4)
+        result = eop.sendmsg_hex_2c(response, itJ->dump(4), true); // get the object as string (always indentation = 4)
+    }
     else
       response += "missing 'diameterJson' object field";
   }
+  else if ((opType == "/sendhex2e")||(opType == "/sendhex2c")) {
+    auto itH = j.find("diameterHex");
+    if (itH != j.end())
+      if (opType == "/sendhex2e")
+        result = eop.sendmsg_hex_2e(response, *itH, false);
+      else
+        result = eop.sendmsg_hex_2c(response, *itH, false);
+    else
+      response += "missing 'diameterHex' string field";
+  }
   else if ((opType == "/answermsg2e")||(opType == "/answermsg2c")) {
     auto itJ = j.find("diameterJson");
     auto itA = j.find("action");
@@ -268,33 +279,20 @@ bool MyHandler::doPOST(const std::string &uri, const nlohmann::json &j, std::str
     bool hasA = (itA != j.end());
 
     if (hasJ != hasA) { // XOR
-
-      if (opType == "/answermsg2e") {
-        if (hasJ)
-          result = eop.answermsg2e(response, itJ->dump(4)); // get the object as string (always indentation = 4)
-        else
-          result = eop.answermsg2e_action(response, *itA);
-      }
-      else {
-        if (hasJ)
-          result = eop.answermsg2c(response, itJ->dump(4)); // get the object as string (always indentation = 4)
-        else
-          result = eop.answermsg2c_action(response, *itA);
+      std::string action;
+      if (hasA) {
+        action = *itA;
+        if (action == "") action = "list"; // default if missing
       }
+
+      if (opType == "/answermsg2e")
+        result = eop.answermsg_action_2e(response, (hasJ ? itJ->dump(4) : action), hasJ); // itJ: get the object as string (always indentation = 4)
+      else
+        result = eop.answermsg_action_2c(response, (hasJ ? itJ->dump(4) : action), hasJ); // itJ: get the object as string (always indentation = 4)
     }
     else
       response += "missing 'diameterJson' object or 'action' string field (only one accepted)";
   }
-  else if ((opType == "/sendhex2e")||(opType == "/sendhex2c")) {
-    auto it = j.find("diameterHex");
-    if (it != j.end())
-      if (opType == "/sendhex2e")
-        result = eop.sendhex2e(response, *it);
-      else
-        result = eop.sendhex2c(response, *it);
-    else
-      response += "missing 'diameterHex' string field";
-  }
 
   // FSM testing
   // test_id__<command>