summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorGordon Sim <gsim@apache.org>2009-11-19 23:07:20 +0000
committerGordon Sim <gsim@apache.org>2009-11-19 23:07:20 +0000
commit92cea0bb1467c58cb1f826bbf3497fd98bf0cddd (patch)
tree0f4414537ff943faa4b757d97c5dd2e533a05d26 /cpp/src
parent3c9a8fdd71d8d1e29de4da3126cf35e1a88a069b (diff)
downloadqpid-python-92cea0bb1467c58cb1f826bbf3497fd98bf0cddd.tar.gz
QPID-664: Bring address option names in to line with those used in python client.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@882348 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/qpid/client/amqp0_10/AddressResolution.cpp63
-rw-r--r--cpp/src/qpid/messaging/Address.cpp32
-rw-r--r--cpp/src/tests/MessagingSessionTests.cpp22
3 files changed, 73 insertions, 44 deletions
diff --git a/cpp/src/qpid/client/amqp0_10/AddressResolution.cpp b/cpp/src/qpid/client/amqp0_10/AddressResolution.cpp
index b1e6a9b671..edf1ed74f5 100644
--- a/cpp/src/qpid/client/amqp0_10/AddressResolution.cpp
+++ b/cpp/src/qpid/client/amqp0_10/AddressResolution.cpp
@@ -71,6 +71,7 @@ const std::string FILTER("filter");
const std::string RELIABILITY("reliability");
const std::string NAME("subscription-name");
const std::string NODE_PROPERTIES("node-properties");
+const std::string X_PROPERTIES("x-properties");
//policy types
const std::string CREATE("create");
@@ -102,13 +103,12 @@ const std::string WILDCARD_ANY("*");
//some amqp 0-10 specific options
namespace xamqp{
-const std::string AUTO_DELETE("x-amqp0-10-auto-delete");
-const std::string EXCHANGE_TYPE("x-amqp0-10-exchange-type");
-const std::string EXCLUSIVE("x-amqp0-10-exclusive");
-const std::string ALTERNATE_EXCHANGE("x-amqp0-10-alternate-exchange");
-const std::string ARGUMENTS("x-amqp0-10-arguments");
-const std::string QUEUE_ARGUMENTS("x-amqp0-10-queue-arguments");
-const std::string SUBSCRIBE_ARGUMENTS("x-amqp0-10-queue-arguments");
+const std::string AUTO_DELETE("auto-delete");
+const std::string EXCHANGE_TYPE("type");
+const std::string EXCLUSIVE("exclusive");
+const std::string ALTERNATE_EXCHANGE("alternate-exchange");
+const std::string QUEUE_ARGUMENTS("x-queue-arguments");
+const std::string SUBSCRIBE_ARGUMENTS("x-subscribe-arguments");
}
class Node
@@ -692,20 +692,27 @@ void Queue::checkAssert(qpid::client::AsyncSession& session, CheckMode mode)
void Queue::configure(const Address& address)
{
- const Variant& properties = address.getOption(NODE_PROPERTIES);
- if (!properties.isVoid()) {
- Variant::Map p = properties.asMap();
- durable = p[DURABLE];
- autoDelete = p[xamqp::AUTO_DELETE];
- exclusive = p[xamqp::EXCLUSIVE];
- alternateExchange = p[xamqp::ALTERNATE_EXCHANGE].asString();
- if (!p[xamqp::ARGUMENTS].isVoid()) {
- translate(p[xamqp::ARGUMENTS].asMap(), arguments);
+ const Variant& v = address.getOption(NODE_PROPERTIES);
+ if (!v.isVoid()) {
+ Variant::Map nodeProps = v.asMap();
+ durable = nodeProps[DURABLE];
+ Variant::Map::const_iterator x = nodeProps.find(X_PROPERTIES);
+ if (x != nodeProps.end()) {
+ const Variant::Map& xProps = x->second.asMap();
+ Variant::Map passthrough;
+ for (Variant::Map::const_iterator i = xProps.begin(); i != xProps.end(); ++i) {
+ if (i->first == xamqp::AUTO_DELETE) autoDelete = i->second;
+ else if (i->first == xamqp::EXCLUSIVE) exclusive = i->second;
+ else if (i->first == xamqp::ALTERNATE_EXCHANGE) alternateExchange = i->second.asString();
+ else passthrough[i->first] = i->second;
+ }
+ translate(passthrough, arguments);
}
}
}
Exchange::Exchange(const Address& a) : Node(a),
+ type(TOPIC_EXCHANGE),
durable(false),
autoDelete(false)
{
@@ -778,15 +785,21 @@ void Exchange::checkAssert(qpid::client::AsyncSession& session, CheckMode mode)
void Exchange::configure(const Address& address)
{
- const Variant& properties = address.getOption(NODE_PROPERTIES);
- if (!properties.isVoid()) {
- Variant::Map p = properties.asMap();
- durable = p[DURABLE];
- autoDelete = p[xamqp::AUTO_DELETE];
- type = p[xamqp::EXCHANGE_TYPE].asString();
- alternateExchange = p[xamqp::ALTERNATE_EXCHANGE].asString();
- if (!p[xamqp::ARGUMENTS].isVoid()) {
- translate(p[xamqp::ARGUMENTS].asMap(), arguments);
+ const Variant& v = address.getOption(NODE_PROPERTIES);
+ if (!v.isVoid()) {
+ Variant::Map nodeProps = v.asMap();
+ durable = nodeProps[DURABLE];
+ Variant::Map::const_iterator x = nodeProps.find(X_PROPERTIES);
+ if (x != nodeProps.end()) {
+ const Variant::Map& xProps = x->second.asMap();
+ Variant::Map passthrough;
+ for (Variant::Map::const_iterator i = xProps.begin(); i != xProps.end(); ++i) {
+ if (i->first == xamqp::AUTO_DELETE) autoDelete = i->second;
+ else if (i->first == xamqp::EXCHANGE_TYPE) type = i->second.asString();
+ else if (i->first == xamqp::ALTERNATE_EXCHANGE) alternateExchange = i->second.asString();
+ else passthrough[i->first] = i->second;
+ }
+ translate(passthrough, arguments);
}
}
}
diff --git a/cpp/src/qpid/messaging/Address.cpp b/cpp/src/qpid/messaging/Address.cpp
index 5262cec0db..ff72f62705 100644
--- a/cpp/src/qpid/messaging/Address.cpp
+++ b/cpp/src/qpid/messaging/Address.cpp
@@ -114,20 +114,36 @@ void Address::setOptions(const Variant::Map& options) { impl->options = options;
namespace{
const Variant EMPTY_VARIANT;
const std::string EMPTY_STRING;
+const std::string NODE_PROPERTIES="node-properties";
+}
+
+const Variant& find(const Variant::Map& map, const std::string& key)
+{
+ Variant::Map::const_iterator i = map.find(key);
+ if (i == map.end()) return EMPTY_VARIANT;
+ else return i->second;
}
std::string Address::getType() const
{
- const Variant& type = getOption(TYPE);
- return type.isVoid() ? EMPTY_STRING : type.asString();
+ const Variant& props = getOption(NODE_PROPERTIES);
+ if (props.getType() == VAR_MAP) {
+ const Variant& type = find(props.asMap(), TYPE);
+ if (!type.isVoid()) return type.asString();
+ }
+ return EMPTY_STRING;
+}
+
+void Address::setType(const std::string& type)
+{
+ Variant& props = impl->options[NODE_PROPERTIES];
+ if (props.isVoid()) props = Variant::Map();
+ props.asMap()[TYPE] = type;
}
-void Address::setType(const std::string& type) { impl->options[TYPE] = type; }
const Variant& Address::getOption(const std::string& key) const
{
- Variant::Map::const_iterator i = impl->options.find(key);
- if (i == impl->options.end()) return EMPTY_VARIANT;
- else return i->second;
+ return find(impl->options, key);
}
std::ostream& operator<<(std::ostream& out, const Address& address)
@@ -144,7 +160,7 @@ AddressParser::AddressParser(const std::string& s) : input(s), current(0) {}
bool AddressParser::error(const std::string& message)
{
- throw MalformedAddress(message);//TODO: add more debug detail to error message (position etc)
+ throw MalformedAddress((boost::format("%1%, character %2% of %3%") % message % current % input).str());
}
bool AddressParser::parse(Address& address)
@@ -210,7 +226,7 @@ bool AddressParser::readKeyValuePair(Variant::Map& map)
map[key] = value;
return true;
} else {
- return error("Bad key-value pair!");
+ return error("Bad key-value pair, expected ':'");
}
} else {
return false;
diff --git a/cpp/src/tests/MessagingSessionTests.cpp b/cpp/src/tests/MessagingSessionTests.cpp
index 1293ce9429..07112f52dc 100644
--- a/cpp/src/tests/MessagingSessionTests.cpp
+++ b/cpp/src/tests/MessagingSessionTests.cpp
@@ -249,7 +249,7 @@ QPID_AUTO_TEST_CASE(testSenderError)
ScopedSuppressLogging sl;
BOOST_CHECK_THROW(fix.session.createSender("NonExistentAddress"), qpid::messaging::InvalidAddress);
fix.session = fix.connection.newSession();
- BOOST_CHECK_THROW(fix.session.createSender("NonExistentAddress; {create:receiver, type:queue}"),
+ BOOST_CHECK_THROW(fix.session.createSender("NonExistentAddress; {create:receiver}"),
qpid::messaging::InvalidAddress);
}
@@ -259,7 +259,7 @@ QPID_AUTO_TEST_CASE(testReceiverError)
ScopedSuppressLogging sl;
BOOST_CHECK_THROW(fix.session.createReceiver("NonExistentAddress"), qpid::messaging::InvalidAddress);
fix.session = fix.connection.newSession();
- BOOST_CHECK_THROW(fix.session.createReceiver("NonExistentAddress; {create:sender, type:queue}"),
+ BOOST_CHECK_THROW(fix.session.createReceiver("NonExistentAddress; {create:sender}"),
qpid::messaging::InvalidAddress);
}
@@ -491,13 +491,13 @@ struct QueueCreatePolicyFixture : public MessagingFixture
QPID_AUTO_TEST_CASE(testCreatePolicyQueueAlways)
{
- QueueCreatePolicyFixture fix("#; {create:always, type:queue}");
+ QueueCreatePolicyFixture fix("#; {create:always, node-properties:{type:queue}}");
fix.test();
}
QPID_AUTO_TEST_CASE(testCreatePolicyQueueReceiver)
{
- QueueCreatePolicyFixture fix("#; {create:receiver, type:queue}");
+ QueueCreatePolicyFixture fix("#; {create:receiver, node-properties:{type:queue}}");
Receiver r = fix.session.createReceiver(fix.address);
fix.test();
r.cancel();
@@ -505,7 +505,7 @@ QPID_AUTO_TEST_CASE(testCreatePolicyQueueReceiver)
QPID_AUTO_TEST_CASE(testCreatePolicyQueueSender)
{
- QueueCreatePolicyFixture fix("#; {create:sender, type:queue}");
+ QueueCreatePolicyFixture fix("#; {create:sender, node-properties:{type:queue}}");
Sender s = fix.session.createSender(fix.address);
fix.test();
s.cancel();
@@ -535,14 +535,14 @@ struct ExchangeCreatePolicyFixture : public MessagingFixture
QPID_AUTO_TEST_CASE(testCreatePolicyTopic)
{
- ExchangeCreatePolicyFixture fix("#; {create:always, type:topic, node-properties:{x-amqp0-10-exchange-type:topic}}",
+ ExchangeCreatePolicyFixture fix("#; {create:always, node-properties:{type:topic}}",
"topic");
fix.test();
}
QPID_AUTO_TEST_CASE(testCreatePolicyTopicReceiverFanout)
{
- ExchangeCreatePolicyFixture fix("#/my-subject; {create:receiver, type:topic, node-properties:{x-amqp0-10-exchange-type:fanout}}", "fanout");
+ ExchangeCreatePolicyFixture fix("#/my-subject; {create:receiver, node-properties:{type:topic, x-properties:{type:fanout}}}", "fanout");
Receiver r = fix.session.createReceiver(fix.address);
fix.test();
r.cancel();
@@ -550,7 +550,7 @@ QPID_AUTO_TEST_CASE(testCreatePolicyTopicReceiverFanout)
QPID_AUTO_TEST_CASE(testCreatePolicyTopicSenderDirect)
{
- ExchangeCreatePolicyFixture fix("#/my-subject; {create:sender, type:topic, node-properties:{x-amqp0-10-exchange-type:direct}}", "direct");
+ ExchangeCreatePolicyFixture fix("#/my-subject; {create:sender, node-properties:{type:topic, x-properties:{type:direct}}}", "direct");
Sender s = fix.session.createSender(fix.address);
fix.test();
s.cancel();
@@ -673,18 +673,18 @@ QPID_AUTO_TEST_CASE(testDeletePolicyExchange)
QPID_AUTO_TEST_CASE(testAssertPolicyQueue)
{
MessagingFixture fix;
- std::string a1 = "q; {create:always, assert:always, type:queue, node-properties:{durable:false, x-amqp0-10-arguments:{qpid.max-count:100}}}";
+ std::string a1 = "q; {create:always, assert:always, node-properties:{type:queue, durable:false, x-properties:{qpid.max-count:100}}}";
Sender s1 = fix.session.createSender(a1);
s1.cancel();
Receiver r1 = fix.session.createReceiver(a1);
r1.cancel();
- std::string a2 = "q; {assert:receiver, node-properties:{durable:true, x-amqp0-10-arguments:{qpid.max-count:100}}}";
+ std::string a2 = "q; {assert:receiver, node-properties:{durable:true, x-properties:{qpid.max-count:100}}}";
Sender s2 = fix.session.createSender(a2);
s2.cancel();
BOOST_CHECK_THROW(fix.session.createReceiver(a2), qpid::messaging::InvalidAddress);
- std::string a3 = "q; {assert:sender, node-properties:{x-amqp0-10-arguments:{qpid.max-count:99}}}";
+ std::string a3 = "q; {assert:sender, node-properties:{x-properties:{qpid.max-count:99}}}";
BOOST_CHECK_THROW(fix.session.createSender(a3), qpid::messaging::InvalidAddress);
Receiver r3 = fix.session.createReceiver(a3);
r3.cancel();