diff options
author | Kenneth Anthony Giusti <kgiusti@apache.org> | 2010-03-23 19:03:24 +0000 |
---|---|---|
committer | Kenneth Anthony Giusti <kgiusti@apache.org> | 2010-03-23 19:03:24 +0000 |
commit | 4811244f441b02ac10a9137ba71d45928780ed8c (patch) | |
tree | 84623253f3e5e339aa9a29ea35f246933050a107 | |
parent | a2e4f6bf8d5b143450c25f6e4d85cb9816acbfc5 (diff) | |
download | qpid-python-4811244f441b02ac10a9137ba71d45928780ed8c.tar.gz |
add exception msg generation on method call failure
git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/qmf-devel0.7a@926734 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | qpid/cpp/src/qpid/agent/ManagementAgentImpl.cpp | 25 | ||||
-rw-r--r-- | qpid/cpp/src/qpid/management/ManagementAgent.cpp | 33 |
2 files changed, 35 insertions, 23 deletions
diff --git a/qpid/cpp/src/qpid/agent/ManagementAgentImpl.cpp b/qpid/cpp/src/qpid/agent/ManagementAgentImpl.cpp index f160bf004b..845d74d1ea 100644 --- a/qpid/cpp/src/qpid/agent/ManagementAgentImpl.cpp +++ b/qpid/cpp/src/qpid/agent/ManagementAgentImpl.cpp @@ -492,7 +492,8 @@ void ManagementAgentImpl::handleConsoleAddedIndication() void ManagementAgentImpl::invokeMethodRequest(const string& body, const string& cid, const string& replyTo) { - string methodName; + string methodName; + bool failed = false; qpid::messaging::Message inMsg(body); qpid::messaging::MapView inMap(inMsg); qpid::messaging::MapView::const_iterator oid, mid; @@ -502,8 +503,9 @@ void ManagementAgentImpl::invokeMethodRequest(const string& body, const string& if ((oid = inMap.find("_object_id")) == inMap.end() || (mid = inMap.find("_method_name")) == inMap.end()) { - ((outMap["_error"].asMap())["_values"].asMap())["_status"] = Manageable::STATUS_PARAMETER_INVALID; - ((outMap["_error"].asMap())["_values"].asMap())["_status_text"] = Manageable::StatusText(Manageable::STATUS_PARAMETER_INVALID); + (outMap["_values"].asMap())["_status"] = Manageable::STATUS_PARAMETER_INVALID; + (outMap["_values"].asMap())["_status_text"] = Manageable::StatusText(Manageable::STATUS_PARAMETER_INVALID); + failed = true; } else { std::string methodName; ObjectId objId; @@ -521,24 +523,29 @@ void ManagementAgentImpl::invokeMethodRequest(const string& body, const string& ManagementObjectMap::iterator iter = managementObjects.find(objId); if (iter == managementObjects.end() || iter->second->isDeleted()) { - ((outMap["_error"].asMap())["_values"].asMap())["_status"] = Manageable::STATUS_UNKNOWN_OBJECT; - ((outMap["_error"].asMap())["_values"].asMap())["_status_text"] = Manageable::StatusText(Manageable::STATUS_UNKNOWN_OBJECT); + (outMap["_values"].asMap())["_status"] = Manageable::STATUS_UNKNOWN_OBJECT; + (outMap["_values"].asMap())["_status_text"] = Manageable::StatusText(Manageable::STATUS_UNKNOWN_OBJECT); + failed = true; } else { iter->second->doMethod(methodName, inArgs, outMap.asMap()); } } catch(exception& e) { - ((outMap["_error"].asMap())["_values"].asMap())["_status"] = Manageable::STATUS_EXCEPTION; - ((outMap["_error"].asMap())["_values"].asMap())["_status_text"] = e.what(); + outMap.clear(); + (outMap["_values"].asMap())["_status"] = Manageable::STATUS_EXCEPTION; + (outMap["_values"].asMap())["_status_text"] = e.what(); + failed = true; } } qpid::messaging::Variant::Map headers; headers["method"] = "response"; - headers["qmf.opcode"] = "_method_response"; - headers["qmf.content"] = "_data"; headers["qmf.agent"] = name_address; + if (failed) + headers["qmf.opcode"] = "_exception"; + else + headers["qmf.opcode"] = "_method_response"; outMap.encode(); connThreadBody.sendBuffer(outMsg.getContent(), cid, headers, "qmf.default.direct", replyTo); diff --git a/qpid/cpp/src/qpid/management/ManagementAgent.cpp b/qpid/cpp/src/qpid/management/ManagementAgent.cpp index c3cd7e008f..77147b6010 100644 --- a/qpid/cpp/src/qpid/management/ManagementAgent.cpp +++ b/qpid/cpp/src/qpid/management/ManagementAgent.cpp @@ -849,14 +849,14 @@ void ManagementAgent::handleMethodRequestLH (const std::string& body, string rep headers["method"] = "response"; headers["qmf.opcode"] = "_method_response"; - headers["qmf.content"] = "_data"; headers["qmf.agent"] = std::string(agentName); if ((oid = inMap.find("_object_id")) == inMap.end() || (mid = inMap.find("_method_name")) == inMap.end()) { - ((outMap["_error"].asMap())["_values"].asMap())["_status"] = Manageable::STATUS_PARAMETER_INVALID; - ((outMap["_error"].asMap())["_values"].asMap())["_status_text"] = Manageable::StatusText(Manageable::STATUS_PARAMETER_INVALID); + headers["qmf.opcode"] = "_exception"; + (outMap["_values"].asMap())["_status"] = Manageable::STATUS_PARAMETER_INVALID; + (outMap["_values"].asMap())["_status_text"] = Manageable::StatusText(Manageable::STATUS_PARAMETER_INVALID); outMap.encode(); sendBuffer(outMsg.getContent(), cid, headers, dExchange, replyTo); QPID_LOG(trace, "SEND MethodResponse (invalid param) to=" << replyTo << " seq=" << cid); @@ -876,8 +876,9 @@ void ManagementAgent::handleMethodRequestLH (const std::string& body, string rep inArgs = (mid->second).asMap(); } } catch(exception& e) { - ((outMap["_error"].asMap())["_values"].asMap())["_status"] = Manageable::STATUS_EXCEPTION; - ((outMap["_error"].asMap())["_values"].asMap())["_status_text"] = e.what(); + headers["qmf.opcode"] = "_exception"; + (outMap["_values"].asMap())["_status"] = Manageable::STATUS_EXCEPTION; + (outMap["_values"].asMap())["_status_text"] = e.what(); outMap.encode(); sendBuffer(outMsg.getContent(), cid, headers, dExchange, replyTo); QPID_LOG(trace, "SEND MethodResponse (invalid format) to=" << replyTo << " seq=" << cid); @@ -887,8 +888,9 @@ void ManagementAgent::handleMethodRequestLH (const std::string& body, string rep ManagementObjectMap::iterator iter = managementObjects.find(objId); if (iter == managementObjects.end() || iter->second->isDeleted()) { - ((outMap["_error"].asMap())["_values"].asMap())["_status"] = Manageable::STATUS_UNKNOWN_OBJECT; - ((outMap["_error"].asMap())["_values"].asMap())["_status_text"] = Manageable::StatusText(Manageable::STATUS_UNKNOWN_OBJECT); + headers["qmf.opcode"] = "_exception"; + (outMap["_values"].asMap())["_status"] = Manageable::STATUS_UNKNOWN_OBJECT; + (outMap["_values"].asMap())["_status_text"] = Manageable::StatusText(Manageable::STATUS_UNKNOWN_OBJECT); outMap.encode(); sendBuffer(outMsg.getContent(), cid, headers, dExchange, replyTo); QPID_LOG(trace, "SEND MethodResponse (unknown object) to=" << replyTo << " seq=" << cid); @@ -901,8 +903,9 @@ void ManagementAgent::handleMethodRequestLH (const std::string& body, string rep i = disallowed.find(std::make_pair(iter->second->getClassName(), methodName)); if (i != disallowed.end()) { - ((outMap["_error"].asMap())["_values"].asMap())["_status"] = Manageable::STATUS_FORBIDDEN; - ((outMap["_error"].asMap())["_values"].asMap())["_status_text"] = i->second; + headers["qmf.opcode"] = "_exception"; + (outMap["_values"].asMap())["_status"] = Manageable::STATUS_FORBIDDEN; + (outMap["_values"].asMap())["_status_text"] = i->second; outMap.encode(); sendBuffer(outMsg.getContent(), cid, headers, dExchange, replyTo); QPID_LOG(trace, "SEND MethodResponse status=FORBIDDEN text=" << i->second << " seq=" << cid); @@ -916,8 +919,9 @@ void ManagementAgent::handleMethodRequestLH (const std::string& body, string rep params[acl::PROP_SCHEMACLASS] = iter->second->getClassName(); if (!acl->authorise(userId, acl::ACT_ACCESS, acl::OBJ_METHOD, methodName, ¶ms)) { - ((outMap["_error"].asMap())["_values"].asMap())["_status"] = Manageable::STATUS_FORBIDDEN; - ((outMap["_error"].asMap())["_values"].asMap())["_status_text"] = Manageable::StatusText(Manageable::STATUS_FORBIDDEN); + headers["qmf.opcode"] = "_exception"; + (outMap["_values"].asMap())["_status"] = Manageable::STATUS_FORBIDDEN; + (outMap["_values"].asMap())["_status_text"] = Manageable::StatusText(Manageable::STATUS_FORBIDDEN); outMap.encode(); sendBuffer(outMsg.getContent(), cid, headers, dExchange, replyTo); QPID_LOG(trace, "SEND MethodResponse status=FORBIDDEN" << " seq=" << cid); @@ -930,8 +934,10 @@ void ManagementAgent::handleMethodRequestLH (const std::string& body, string rep try { iter->second->doMethod(methodName, inArgs, outMap.asMap()); } catch(exception& e) { - ((outMap["_error"].asMap())["_values"].asMap())["_status"] = Manageable::STATUS_EXCEPTION; - ((outMap["_error"].asMap())["_values"].asMap())["_status_text"] = e.what(); + outMap.clear(); + headers["qmf.opcode"] = "_exception"; + (outMap["_values"].asMap())["_status"] = Manageable::STATUS_EXCEPTION; + (outMap["_values"].asMap())["_status_text"] = e.what(); outMap.encode(); sendBuffer(outMsg.getContent(), cid, headers, dExchange, replyTo); QPID_LOG(trace, "SEND MethodResponse (exception) to=" << replyTo << " seq=" << cid); @@ -1603,7 +1609,6 @@ bool ManagementAgent::authorizeAgentMessageLH(Message& msg) headers["method"] = "response"; headers["qmf.opcode"] = "_method_response"; - headers["qmf.content"] = "_data"; headers["qmf.agent"] = std::string(agentName); ((outMap["_error"].asMap())["_values"].asMap())["_status"] = Manageable::STATUS_FORBIDDEN; |