diff options
author | Gordon Sim <gsim@apache.org> | 2015-04-10 13:06:52 +0000 |
---|---|---|
committer | Gordon Sim <gsim@apache.org> | 2015-04-10 13:06:52 +0000 |
commit | 7eb32a94b9ed5f380a85ae867b109cc4834ccf18 (patch) | |
tree | d4432f26a521e6739d09aa32c9a9a2a37dbb5bbc /cpp | |
parent | a34d8e8c1a0d4d8ad972b1af6a50b3020e7fc0a1 (diff) | |
download | qpid-python-7eb32a94b9ed5f380a85ae867b109cc4834ccf18.tar.gz |
QPID-6484: check for non-existent error description
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1672639 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/src/amqp.cmake | 2 | ||||
-rw-r--r-- | cpp/src/qpid/messaging/amqp/ConnectionContext.cpp | 42 | ||||
-rw-r--r-- | cpp/src/qpid/messaging/amqp/SenderContext.cpp | 13 | ||||
-rw-r--r-- | cpp/src/qpid/messaging/amqp/util.cpp | 43 | ||||
-rw-r--r-- | cpp/src/qpid/messaging/amqp/util.h | 36 |
5 files changed, 97 insertions, 39 deletions
diff --git a/cpp/src/amqp.cmake b/cpp/src/amqp.cmake index 044267afbc..2602c30c27 100644 --- a/cpp/src/amqp.cmake +++ b/cpp/src/amqp.cmake @@ -146,6 +146,8 @@ if (BUILD_AMQP) qpid/messaging/amqp/TcpTransport.cpp qpid/messaging/amqp/Transaction.h qpid/messaging/amqp/Transaction.cpp + qpid/messaging/amqp/util.h + qpid/messaging/amqp/util.cpp ) if (WIN32) diff --git a/cpp/src/qpid/messaging/amqp/ConnectionContext.cpp b/cpp/src/qpid/messaging/amqp/ConnectionContext.cpp index 0c516311da..586c8a87d6 100644 --- a/cpp/src/qpid/messaging/amqp/ConnectionContext.cpp +++ b/cpp/src/qpid/messaging/amqp/ConnectionContext.cpp @@ -27,6 +27,7 @@ #include "SessionContext.h" #include "Transaction.h" #include "Transport.h" +#include "util.h" #include "qpid/amqp/descriptors.h" #include "qpid/amqp/Encoder.h" #include "qpid/amqp/Descriptor.h" @@ -58,7 +59,6 @@ namespace amqp { using types::Variant; namespace { - //remove conditional when 0.5 is no longer supported #ifdef HAVE_PROTON_TRACER void do_trace(pn_transport_t* transport, const char* message) @@ -85,7 +85,7 @@ std::string get_error(pn_connection_t* connection, pn_transport_t* transport) pn_error_t* cerror = pn_connection_error(connection); if (cerror) text << "connection error " << pn_error_text(cerror) << " [" << cerror << "]"; pn_condition_t* tcondition = pn_transport_condition(transport); - if (pn_condition_is_set(tcondition)) text << "transport error: " << pn_condition_get_name(tcondition) << ", " << pn_condition_get_description(tcondition); + if (pn_condition_is_set(tcondition)) text << get_error_string(tcondition, "transport error", ": "); return text.str(); } #else @@ -592,15 +592,9 @@ bool ConnectionContext::checkDisconnected() { reset(); } else { if ((pn_connection_state(connection) & REQUIRES_CLOSE) == REQUIRES_CLOSE) { - pn_condition_t* error = pn_connection_remote_condition(connection); - std::stringstream text; - if (pn_condition_is_set(error)) { - text << "Connection closed by peer with " << pn_condition_get_name(error) << ": " << pn_condition_get_description(error); - } else { - text << "Connection closed by peer"; - } + std::string text = get_error_string(pn_connection_remote_condition(connection), "Connection closed by peer"); pn_connection_close(connection); - throw qpid::messaging::ConnectionError(text.str()); + throw qpid::messaging::ConnectionError(text); } } return state == DISCONNECTED; @@ -652,15 +646,9 @@ void ConnectionContext::checkClosed(boost::shared_ptr<SessionContext> ssn) check(); ssn->error.raise(); if ((pn_session_state(ssn->session) & REQUIRES_CLOSE) == REQUIRES_CLOSE) { - pn_condition_t* error = pn_session_remote_condition(ssn->session); - std::stringstream text; - if (pn_condition_is_set(error)) { - text << "Session ended by peer with " << pn_condition_get_name(error) << ": " << pn_condition_get_description(error); - } else { - text << "Session ended by peer"; - } + std::string text = get_error_string(pn_session_remote_condition(ssn->session), "Session ended by peer"); pn_session_close(ssn->session); - throw qpid::messaging::SessionError(text.str()); + throw qpid::messaging::SessionError(text); } else if ((pn_session_state(ssn->session) & IS_CLOSED) == IS_CLOSED) { throw qpid::messaging::SessionClosed(); } @@ -688,21 +676,15 @@ void ConnectionContext::checkClosed(boost::shared_ptr<SessionContext> ssn, pn_li checkClosed(ssn); if ((pn_link_state(lnk) & REQUIRES_CLOSE) == REQUIRES_CLOSE) { pn_condition_t* error = pn_link_remote_condition(lnk); - std::string name; - std::stringstream text; - if (pn_condition_is_set(error)) { - name = pn_condition_get_name(error); - text << "Link detached by peer with " << name << ": " << pn_condition_get_description(error); - } else { - text << "Link detached by peer"; - } + std::string text = get_error_string(error, "Link detached by peer"); pn_link_close(lnk); + std::string name = pn_condition_get_name(error); if (name == qpid::amqp::error_conditions::NOT_FOUND) { - throw qpid::messaging::NotFound(text.str()); + throw qpid::messaging::NotFound(text); } else if (name == qpid::amqp::error_conditions::UNAUTHORIZED_ACCESS) { - throw qpid::messaging::UnauthorizedAccess(text.str()); + throw qpid::messaging::UnauthorizedAccess(text); } else { - throw qpid::messaging::LinkError(text.str()); + throw qpid::messaging::LinkError(text); } } else if ((pn_link_state(lnk) & IS_CLOSED) == IS_CLOSED) { throw qpid::messaging::LinkError("Link is not attached"); @@ -1297,7 +1279,7 @@ bool ConnectionContext::checkTransportError(std::string& text) #ifdef USE_PROTON_TRANSPORT_CONDITION pn_condition_t* tcondition = pn_transport_condition(engine); if (pn_condition_is_set(tcondition)) - info << "transport error: " << pn_condition_get_name(tcondition) << ", " << pn_condition_get_description(tcondition); + info << get_error_string(tcondition, "transport error", ": "); #else pn_error_t* terror = pn_transport_error(engine); if (terror) info << "transport error " << pn_error_text(terror) << " [" << terror << "]"; diff --git a/cpp/src/qpid/messaging/amqp/SenderContext.cpp b/cpp/src/qpid/messaging/amqp/SenderContext.cpp index b12af5eb25..5289fbdf9b 100644 --- a/cpp/src/qpid/messaging/amqp/SenderContext.cpp +++ b/cpp/src/qpid/messaging/amqp/SenderContext.cpp @@ -22,6 +22,7 @@ #include "Transaction.h" #include "EncodedMessage.h" #include "PnData.h" +#include "util.h" #include "qpid/messaging/AddressImpl.h" #include "qpid/messaging/exceptions.h" #include "qpid/Exception.h" @@ -128,15 +129,9 @@ bool SenderContext::send(const qpid::messaging::Message& message, SenderContext: void SenderContext::check() { if (pn_link_state(sender) & PN_REMOTE_CLOSED && !(pn_link_state(sender) & PN_LOCAL_CLOSED)) { - pn_condition_t* error = pn_link_remote_condition(sender); - std::stringstream text; - if (pn_condition_is_set(error)) { - text << "Link detached by peer with " << pn_condition_get_name(error) << ": " << pn_condition_get_description(error); - } else { - text << "Link detached by peer"; - } + std::string text = get_error_string(pn_link_remote_condition(sender), "Link detached by peer"); pn_link_close(sender); - throw qpid::messaging::LinkError(text.str()); + throw qpid::messaging::LinkError(text); } } @@ -574,7 +569,7 @@ std::string SenderContext::Delivery::error() { pn_condition_t *condition = pn_disposition_condition(pn_delivery_remote(token)); return (condition && pn_condition_is_set(condition)) ? - Msg() << pn_condition_get_name(condition) << ": " << pn_condition_get_description(condition) : + Msg() << get_error_string(condition, std::string(), std::string()) : std::string(); } diff --git a/cpp/src/qpid/messaging/amqp/util.cpp b/cpp/src/qpid/messaging/amqp/util.cpp new file mode 100644 index 0000000000..870a89e364 --- /dev/null +++ b/cpp/src/qpid/messaging/amqp/util.cpp @@ -0,0 +1,43 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +#include "util.h" +#include <sstream> + +namespace qpid { +namespace messaging { +namespace amqp { + +std::string get_error_string(pn_condition_t* error, const std::string& general, const std::string& delim) +{ + std::string name; + std::stringstream text; + if (pn_condition_is_set(error)) { + name = pn_condition_get_name(error); + text << general << delim << name; + const char* desc = pn_condition_get_description(error); + if (desc) text << ": " << desc; + } else { + text << general; + } + return text.str(); +} + +}}} // namespace qpid::messaging::amqp diff --git a/cpp/src/qpid/messaging/amqp/util.h b/cpp/src/qpid/messaging/amqp/util.h new file mode 100644 index 0000000000..d10ef406dc --- /dev/null +++ b/cpp/src/qpid/messaging/amqp/util.h @@ -0,0 +1,36 @@ +#ifndef QPID_MESSAGING_AMQP_UTIL_H +#define QPID_MESSAGING_AMQP_UTIL_H + +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +#include <string> +extern "C" { +#include <proton/engine.h> +} +namespace qpid { +namespace messaging { +namespace amqp { + +std::string get_error_string(pn_condition_t* error, const std::string& general, const std::string& delim = std::string(" with ")); + +}}} // namespace qpid::messaging::amqp + +#endif /*!QPID_MESSAGING_AMQP_UTIL_H*/ |