You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by al...@apache.org on 2019/02/20 13:47:19 UTC

[nifi-minifi-cpp] 01/02: MINIFICPP-739: Resolve json checks for c2 responses

This is an automated email from the ASF dual-hosted git repository.

aldrin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git

commit 0f3ee67746386ca8a92a0875b955108b85ea2cce
Author: Marc Parisi <ph...@apache.org>
AuthorDate: Tue Feb 19 13:34:53 2019 -0500

    MINIFICPP-739: Resolve json checks for c2 responses
---
 libminifi/src/c2/protocols/RESTProtocol.cpp | 33 ++++++++++++++++++++++-------
 1 file changed, 25 insertions(+), 8 deletions(-)

diff --git a/libminifi/src/c2/protocols/RESTProtocol.cpp b/libminifi/src/c2/protocols/RESTProtocol.cpp
index d081510..3463407 100644
--- a/libminifi/src/c2/protocols/RESTProtocol.cpp
+++ b/libminifi/src/c2/protocols/RESTProtocol.cpp
@@ -33,16 +33,21 @@ namespace nifi {
 namespace minifi {
 namespace c2 {
 
+#ifdef WIN32
+#pragma push_macro("GetObject")
+#undef GetObject
+#endif
 const C2Payload RESTProtocol::parseJsonResponse(const C2Payload &payload, const std::vector<char> &response) {
-#ifndef WIN32
   rapidjson::Document root;
 
   try {
     rapidjson::ParseResult ok = root.Parse(response.data(), response.size());
     if (ok) {
+
       std::string requested_operation = getOperation(payload);
 
       std::string identifier;
+
       if (root.HasMember("operationid")) {
         identifier = root["operationid"].GetString();
       } else if (root.HasMember("operationId")) {
@@ -50,16 +55,25 @@ const C2Payload RESTProtocol::parseJsonResponse(const C2Payload &payload, const
       } else if (root.HasMember("identifier")) {
         identifier = root["identifier"].GetString();
       }
-      if (root["requested_operations"].Size() == 0 && root["requestedOperations"].Size() == 0)
+
+      int size = 0;
+      if (root.HasMember("requested_operations")) {
+        size = root["requested_operations"].Size();
+      }
+      if (root.HasMember("requestedOperations")) {
+        size = root["requestedOperations"].Size();
+      }
+
+      // neither must be there. We don't want assign array yet and cause an assertion error
+      if (size == 0)
         return C2Payload(payload.getOperation(), state::UpdateState::READ_COMPLETE, true);
 
       C2Payload new_payload(payload.getOperation(), state::UpdateState::NESTED, true);
-
       if (!identifier.empty())
         new_payload.setIdentifier(identifier);
-      auto array = root["requested_operations"].GetArray();
-      if (root["requested_operations"].Size() == 0)
-        array = root["requestedOperations"].GetArray();
+
+      auto array = root.HasMember("requested_operations") ? root["requested_operations"].GetArray() : root["requestedOperations"].GetArray();
+
       for (const rapidjson::Value& request : array) {
         Operation newOp = stringToOperation(request["operation"].GetString());
         C2Payload nested_payload(newOp, state::UpdateState::READ_COMPLETE, true);
@@ -126,9 +140,10 @@ const C2Payload RESTProtocol::parseJsonResponse(const C2Payload &payload, const
       return new_payload;
       // }
     }
+  } catch (const std::exception &e) {
+
   } catch (...) {
   }
-#endif
   return C2Payload(payload.getOperation(), state::UpdateState::READ_COMPLETE, true);
 }
 
@@ -387,7 +402,9 @@ Operation RESTProtocol::stringToOperation(const std::string str) {
   }
   return Operation::HEARTBEAT;
 }
-
+#ifdef WIN32
+#pragma pop_macro("GetObject")
+#endif
 } /* namespace c2 */
 } /* namespace minifi */
 } /* namespace nifi */