You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by or...@apache.org on 2017/09/12 16:14:15 UTC

[2/2] qpid-broker-j git commit: QPID-7771: [Java Broker] Verify that specified destination exists in exchange operations 'bind' and 'unbind'

QPID-7771: [Java Broker] Verify that specified destination exists in exchange operations 'bind' and 'unbind'


Project: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/commit/c1fe20da
Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/c1fe20da
Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/c1fe20da

Branch: refs/heads/master
Commit: c1fe20da0ea717eb83643ad291932191633d6d02
Parents: f8d12e6
Author: Alex Rudyy <or...@apache.org>
Authored: Tue Sep 12 17:13:55 2017 +0100
Committer: Alex Rudyy <or...@apache.org>
Committed: Tue Sep 12 17:13:55 2017 +0100

----------------------------------------------------------------------
 .../qpid/server/exchange/AbstractExchange.java  | 54 ++++++++++++--------
 1 file changed, 32 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/c1fe20da/broker-core/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java
----------------------------------------------------------------------
diff --git a/broker-core/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java b/broker-core/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java
index 8aefd5a..21635b5 100644
--- a/broker-core/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java
+++ b/broker-core/src/main/java/org/apache/qpid/server/exchange/AbstractExchange.java
@@ -662,6 +662,12 @@ public abstract class AbstractExchange<T extends AbstractExchange<T>>
                         Map<String, Object> arguments,
                         boolean replaceExistingArguments)
     {
+        MessageDestination messageDestination = getAttainedMessageDestination(destination);
+        if (messageDestination == null)
+        {
+            throw new IllegalArgumentException(String.format("Destination '%s' is not found.", destination));
+        }
+
         if(bindingKey == null)
         {
             bindingKey = "";
@@ -670,8 +676,9 @@ public abstract class AbstractExchange<T extends AbstractExchange<T>>
         {
             arguments = Collections.emptyMap();
         }
+
         Binding newBinding = new BindingImpl(bindingKey, destination, arguments);
-        MessageDestination messageDestination = getAttainedMessageDestination(newBinding.getDestination());
+
         boolean modified = false;
         for(Binding b : _bindings)
         {
@@ -782,35 +789,38 @@ public abstract class AbstractExchange<T extends AbstractExchange<T>>
     public boolean unbind(@Param(name = "destination", mandatory = true) final String destination,
                           @Param(name = "bindingKey") String bindingKey)
     {
-        Iterator<Binding> bindingIterator = _bindings.iterator();
-        if(bindingKey == null)
-        {
-            bindingKey = "";
-        }
         MessageDestination messageDestination = getAttainedMessageDestination(destination);
-        while(bindingIterator.hasNext())
+        if (messageDestination != null)
         {
-            Binding binding = bindingIterator.next();
-            if(binding.getBindingKey().equals(bindingKey) && binding.getDestination().equals(destination))
+            Iterator<Binding> bindingIterator = _bindings.iterator();
+            if (bindingKey == null)
             {
-                _bindings.remove(binding);
-                messageDestination.linkRemoved(this, binding);
-                onUnbind(new BindingIdentifier(bindingKey, messageDestination));
-                if(!autoDeleteIfNecessary())
+                bindingKey = "";
+            }
+
+            while (bindingIterator.hasNext())
+            {
+                Binding binding = bindingIterator.next();
+                if (binding.getBindingKey().equals(bindingKey) && binding.getDestination().equals(destination))
                 {
-                    if (isDurable() && messageDestination.isDurable())
+                    _bindings.remove(binding);
+                    messageDestination.linkRemoved(this, binding);
+                    onUnbind(new BindingIdentifier(bindingKey, messageDestination));
+                    if (!autoDeleteIfNecessary())
                     {
-                        final Collection<Binding> durableBindings = getDurableBindings();
-                        attributeSet(DURABLE_BINDINGS, durableBindings, durableBindings);
+                        if (isDurable() && messageDestination.isDurable())
+                        {
+                            final Collection<Binding> durableBindings = getDurableBindings();
+                            attributeSet(DURABLE_BINDINGS, durableBindings, durableBindings);
+                        }
                     }
-                }
-                final Map<String, Object> bindArguments =
-                        UNBIND_ARGUMENTS_CREATOR.createMap(bindingKey, destination);
-                getEventLogger().message(_logSubject, BindingMessages.DELETED(String.valueOf(bindArguments)));
+                    final Map<String, Object> bindArguments =
+                            UNBIND_ARGUMENTS_CREATOR.createMap(bindingKey, destination);
+                    getEventLogger().message(_logSubject, BindingMessages.DELETED(String.valueOf(bindArguments)));
 
-                return true;
+                    return true;
+                }
             }
-
         }
         return false;
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org