From 713dbcd70b5d2da2488c09676f18f1752683654e Mon Sep 17 00:00:00 2001 From: Robert Godfrey Date: Fri, 7 Mar 2014 17:18:27 +0000 Subject: QPID-5601 : Address review comments from Robbie Gemmell git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1575335 13f79535-47bb-0310-9956-ffa450edef68 --- .../server/virtualhost/AbstractVirtualHost.java | 3 ++- .../protocol/v0_10/ServerSessionDelegate.java | 11 +++++--- .../v0_8/handler/BasicConsumeMethodHandler.java | 4 +-- .../v0_8/handler/ExchangeBoundHandler.java | 29 ++++++++++++---------- .../v0_8/handler/ExchangeDeclareHandler.java | 7 +++++- .../v0_8/handler/ExchangeDeleteHandler.java | 12 +++++++-- .../protocol/v0_8/handler/QueueBindHandler.java | 10 ++++++-- .../protocol/v0_8/handler/QueueUnbindHandler.java | 8 +++++- .../v0_8_v0_10/MessageConverter_0_10_to_0_8.java | 2 +- 9 files changed, 59 insertions(+), 27 deletions(-) (limited to 'qpid/java') diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/AbstractVirtualHost.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/AbstractVirtualHost.java index c5eb70c1f0..2eb2790382 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/AbstractVirtualHost.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhost/AbstractVirtualHost.java @@ -34,6 +34,7 @@ import java.util.concurrent.TimeUnit; import org.apache.commons.configuration.ConfigurationException; import org.apache.log4j.Logger; +import org.apache.qpid.exchange.ExchangeDefaults; import org.apache.qpid.server.configuration.updater.TaskExecutor; import org.apache.qpid.server.exchange.AMQUnknownExchangeType; import org.apache.qpid.server.exchange.ExchangeImpl; @@ -382,7 +383,7 @@ public abstract class AbstractVirtualHost implements VirtualHost, IConnectionReg String exchangeName = queueConfiguration.getExchange(); - if("".equals(exchangeName)) + if(ExchangeDefaults.DEFAULT_EXCHANGE_NAME.equals(exchangeName)) { //get routing keys in configuration (returns empty list if none are defined) List routingKeys = queueConfiguration.getRoutingKeys(); diff --git a/qpid/java/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/ServerSessionDelegate.java b/qpid/java/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/ServerSessionDelegate.java index d21da824e9..e258a27255 100644 --- a/qpid/java/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/ServerSessionDelegate.java +++ b/qpid/java/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/ServerSessionDelegate.java @@ -685,8 +685,9 @@ public class ServerSessionDelegate extends SessionDelegate return; } } - if(method.getExchange() == null || method.getExchange().equals("")) + if(nameNullOrEmpty(method.getExchange())) { + // special case handling to fake the existence of the default exchange for 0-10 if(!DirectExchange.TYPE.getType().equals(method.getType())) { exception(session, method, ExecutionErrorCode.NOT_ALLOWED, @@ -694,7 +695,7 @@ public class ServerSessionDelegate extends SessionDelegate + " of type " + DirectExchange.TYPE.getType() + " to " + method.getType() +"."); } - if(method.hasAlternateExchange() && !"".equals(method.getAlternateExchange())) + if(!nameNullOrEmpty(method.getAlternateExchange())) { exception(session, method, ExecutionErrorCode.NOT_ALLOWED, "Attempt to set alternate exchange of the default exchange " @@ -901,8 +902,9 @@ public class ServerSessionDelegate extends SessionDelegate final String exchangeName = method.getName(); - if(exchangeName == null || exchangeName.equals("")) + if(nameNullOrEmpty(exchangeName)) { + // Fake the existence of the "default" exchange for 0-10 result.setDurable(true); result.setType(DirectExchange.TYPE.getType()); result.setNotFound(false); @@ -1046,7 +1048,7 @@ public class ServerSessionDelegate extends SessionDelegate ExchangeImpl exchange; AMQQueue queue; boolean isDefaultExchange; - if(method.hasExchange() && !method.getExchange().equals("")) + if(!nameNullOrEmpty(method.getExchange())) { isDefaultExchange = false; exchange = virtualHost.getExchange(method.getExchange()); @@ -1064,6 +1066,7 @@ public class ServerSessionDelegate extends SessionDelegate if(isDefaultExchange) { + // fake the existence of the "default" exchange for 0-10 if(method.hasQueue()) { queue = getQueue(session, method.getQueue()); diff --git a/qpid/java/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/handler/BasicConsumeMethodHandler.java b/qpid/java/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/handler/BasicConsumeMethodHandler.java index cb4f758fb7..37e531bd2a 100644 --- a/qpid/java/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/handler/BasicConsumeMethodHandler.java +++ b/qpid/java/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/handler/BasicConsumeMethodHandler.java @@ -129,7 +129,7 @@ public class BasicConsumeMethodHandler implements StateAwareMethodListener255) - { - message = message.substring(0,254); - } response = methodRegistry.createExchangeBoundOkBody(SPECIFIC_QUEUE_NOT_BOUND_WITH_RK, // replyCode - new AMQShortString(message)); // replyText + AMQShortString.validValueOf(message)); // replyText } } } @@ -225,11 +222,17 @@ public class ExchangeBoundHandler implements StateAwareMethodListener { throw body.getChannelException(AMQConstant.NOT_FOUND, "Queue " + queueName + " does not exist."); } - final String exchangeName = body.getExchange() == null ? null : body.getExchange().toString(); - if(exchangeName == null || "".equals(exchangeName)) + if(isDefaultExchange(body.getExchange())) { throw body.getConnectionException(AMQConstant.NOT_ALLOWED, "Cannot bind the queue " + queueName + " to the default exchange"); } + final String exchangeName = body.getExchange().toString(); + final ExchangeImpl exch = virtualHost.getExchange(exchangeName); if (exch == null) { @@ -148,4 +149,9 @@ public class QueueBindHandler implements StateAwareMethodListener } } + + protected boolean isDefaultExchange(final AMQShortString exchangeName) + { + return exchangeName == null || exchangeName.equals(AMQShortString.EMPTY_STRING); + } } diff --git a/qpid/java/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/handler/QueueUnbindHandler.java b/qpid/java/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/handler/QueueUnbindHandler.java index abc9c8541c..f1bcce2ade 100644 --- a/qpid/java/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/handler/QueueUnbindHandler.java +++ b/qpid/java/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/handler/QueueUnbindHandler.java @@ -94,7 +94,7 @@ public class QueueUnbindHandler implements StateAwareMethodListener