This is an automated email from the ASF dual-hosted git repository.

rgodfrey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/qpid-broker-j.git


The following commit(s) were added to refs/heads/master by this push:
     new 8c299bc  QPID-8388 : [Java Broker] Allow configuration of behaviour on 
unknown queue declare arguments
8c299bc is described below

commit 8c299bc827da86388831a11ccc11796f0652b820
Author: rgodfrey <[email protected]>
AuthorDate: Thu Dec 5 14:28:35 2019 +0100

    QPID-8388 : [Java Broker] Allow configuration of behaviour on unknown queue 
declare arguments
---
 .../java/org/apache/qpid/server/model/Queue.java   | 11 ++++
 .../qpid/server/queue/QueueArgumentsConverter.java | 18 +++++-
 .../protocol/v0_10/ServerSessionDelegate.java      |  8 ++-
 .../qpid/server/protocol/v0_8/AMQChannel.java      |  6 +-
 .../QueueDeclareInvalidOptionBehaviourTest.java    | 71 ++++++++++++++++++++++
 5 files changed, 109 insertions(+), 5 deletions(-)

diff --git a/broker-core/src/main/java/org/apache/qpid/server/model/Queue.java 
b/broker-core/src/main/java/org/apache/qpid/server/model/Queue.java
index 26dcdc0..3920a14 100644
--- a/broker-core/src/main/java/org/apache/qpid/server/model/Queue.java
+++ b/broker-core/src/main/java/org/apache/qpid/server/model/Queue.java
@@ -131,6 +131,17 @@ public interface Queue<X extends Queue<X>> extends 
ConfiguredObject<X>,
             description = "The behaviour of consumer if it tries to consumer a 
messages that it cannot convert.")
     MessageConversionExceptionHandlingPolicy 
DEFAULT_MESSAGE_CONVERSION_EXCEPTION_HANDLING_POLICY = 
MessageConversionExceptionHandlingPolicy.REJECT;
 
+    enum BehaviourOnUnknownDeclareArgument
+    {
+        IGNORE, LOG, FAIL
+    }
+
+    String UNKNOWN_QUEUE_DECLARE_ARGUMENT_BEHAVIOUR_NAME = 
"queue.behaviourOnUnknownDeclareArgument";
+    @ManagedContextDefault(name= UNKNOWN_QUEUE_DECLARE_ARGUMENT_BEHAVIOUR_NAME)
+    Queue.BehaviourOnUnknownDeclareArgument
+            ON_UNKNOWN_QUEUE_DECLARE_OPTION = 
Queue.BehaviourOnUnknownDeclareArgument.FAIL;
+
+
     @SuppressWarnings("unused")
     @ManagedAttribute( defaultValue = 
"${queue.defaultEnsureNonDestructiveConsumers}" )
     boolean isEnsureNondestructiveConsumers();
diff --git 
a/broker-core/src/main/java/org/apache/qpid/server/queue/QueueArgumentsConverter.java
 
b/broker-core/src/main/java/org/apache/qpid/server/queue/QueueArgumentsConverter.java
index 05330eb..f9b054d 100644
--- 
a/broker-core/src/main/java/org/apache/qpid/server/queue/QueueArgumentsConverter.java
+++ 
b/broker-core/src/main/java/org/apache/qpid/server/queue/QueueArgumentsConverter.java
@@ -139,7 +139,8 @@ public class QueueArgumentsConverter
 
     public static Map<String,Object> convertWireArgsToModel(final String 
queueName,
                                                             final Map<String, 
Object> wireArguments,
-                                                            final Model model)
+                                                            final Model model,
+                                                            final 
Queue.BehaviourOnUnknownDeclareArgument unknownArgumentBehaviour)
     {
         Map<String,Object> modelArguments = new HashMap<>();
         if(wireArguments != null)
@@ -251,8 +252,19 @@ public class QueueArgumentsConverter
 
             if (!wireArgumentNames.isEmpty())
             {
-                throw new IllegalArgumentException(String.format("Unsupported 
queue declare argument(s) : %s",
-                                                                 
String.join(",", wireArgumentNames)));
+
+                switch(unknownArgumentBehaviour)
+                {
+                    case LOG:
+                        LOGGER.warn("Unsupported queue declare argument(s) : 
{}", String.join(",", wireArgumentNames));
+                        break;
+                    case IGNORE:
+                        break;
+                    case FAIL:
+                    default:
+                        throw new 
IllegalArgumentException(String.format("Unsupported queue declare argument(s) : 
%s",
+                                                                         
String.join(",", wireArgumentNames)));
+                }
             }
         }
         return modelArguments;
diff --git 
a/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/ServerSessionDelegate.java
 
b/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/ServerSessionDelegate.java
index 06c1690..da95578 100644
--- 
a/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/ServerSessionDelegate.java
+++ 
b/broker-plugins/amqp-0-10-protocol/src/main/java/org/apache/qpid/server/protocol/v0_10/ServerSessionDelegate.java
@@ -1588,10 +1588,16 @@ public class ServerSessionDelegate extends 
MethodDelegate<ServerSession> impleme
         {
             try
             {
+
+                Queue.BehaviourOnUnknownDeclareArgument 
unknownArgumentBehaviour =
+                        
session.getAMQPConnection().getContextValue(Queue.BehaviourOnUnknownDeclareArgument.class,
+                                                   
Queue.UNKNOWN_QUEUE_DECLARE_ARGUMENT_BEHAVIOUR_NAME);
+
                 final Map<String, Object> arguments = 
QueueArgumentsConverter.convertWireArgsToModel(queueName,
                                                                                
                      method.getArguments(),
                                                                                
                      session.getAMQPConnection()
-                                                                               
                             .getModel());
+                                                                               
                             .getModel(),
+                                                                               
                      unknownArgumentBehaviour);
                 final String alternateExchangeName = 
method.getAlternateExchange();
                 if (method.hasAlternateExchange() && 
!nameNullOrEmpty(alternateExchangeName))
                 {
diff --git 
a/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/AMQChannel.java
 
b/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/AMQChannel.java
index c783687..152e919 100644
--- 
a/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/AMQChannel.java
+++ 
b/broker-plugins/amqp-0-8-protocol/src/main/java/org/apache/qpid/server/protocol/v0_8/AMQChannel.java
@@ -3034,8 +3034,12 @@ public class AMQChannel extends 
AbstractAMQPSession<AMQChannel, ConsumerTarget_0
                     validateAlternateExchangeIsNotQueue(virtualHost, 
alternateExchangeName);
                 }
 
+                Queue.BehaviourOnUnknownDeclareArgument 
unknownArgumentBehaviour =
+                        
getConnection().getContextValue(Queue.BehaviourOnUnknownDeclareArgument.class,
+                                                        
Queue.UNKNOWN_QUEUE_DECLARE_ARGUMENT_BEHAVIOUR_NAME);
+
                 Map<String, Object> attributes =
-                        
QueueArgumentsConverter.convertWireArgsToModel(queueNameString, wireArguments, 
getModel());
+                        
QueueArgumentsConverter.convertWireArgsToModel(queueNameString, wireArguments, 
getModel(), unknownArgumentBehaviour);
 
                 attributes.put(Queue.NAME, queueNameString);
                 attributes.put(Queue.DURABLE, durable);
diff --git 
a/systests/protocol-tests-amqp-0-8/src/test/java/org/apache/qpid/tests/protocol/v0_8/extension/queue/QueueDeclareInvalidOptionBehaviourTest.java
 
b/systests/protocol-tests-amqp-0-8/src/test/java/org/apache/qpid/tests/protocol/v0_8/extension/queue/QueueDeclareInvalidOptionBehaviourTest.java
new file mode 100644
index 0000000..8966401
--- /dev/null
+++ 
b/systests/protocol-tests-amqp-0-8/src/test/java/org/apache/qpid/tests/protocol/v0_8/extension/queue/QueueDeclareInvalidOptionBehaviourTest.java
@@ -0,0 +1,71 @@
+/*
+ * 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.
+ *
+ */
+package org.apache.qpid.tests.protocol.v0_8.extension.queue;
+
+import static org.apache.qpid.tests.utils.BrokerAdmin.KIND_BROKER_J;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import java.util.Collections;
+
+import org.junit.Test;
+
+import org.apache.qpid.server.protocol.v0_8.AMQShortString;
+import org.apache.qpid.server.protocol.v0_8.transport.ChannelOpenOkBody;
+import org.apache.qpid.server.protocol.v0_8.transport.QueueDeclareOkBody;
+import org.apache.qpid.tests.protocol.v0_8.FrameTransport;
+import org.apache.qpid.tests.protocol.v0_8.Interaction;
+import org.apache.qpid.tests.utils.BrokerAdminUsingTestBase;
+import org.apache.qpid.tests.utils.BrokerSpecific;
+import org.apache.qpid.tests.utils.ConfigItem;
+
+@BrokerSpecific(kind = KIND_BROKER_J)
+@ConfigItem(name = "queue.behaviourOnUnknownDeclareArgument", value = "IGNORE")
+public class QueueDeclareInvalidOptionBehaviourTest extends 
BrokerAdminUsingTestBase
+{
+    private static final String TEST_QUEUE = "testQueue";
+
+    @Test
+    public void queueDeclareInvalidWireArguments() throws Exception
+    {
+        try (FrameTransport transport = new 
FrameTransport(getBrokerAdmin()).connect())
+        {
+            final Interaction interaction = transport.newInteraction();
+
+            QueueDeclareOkBody response = interaction.negotiateOpen()
+                                                     .channel()
+                                                     .open()
+                                                     
.consumeResponse(ChannelOpenOkBody.class)
+                                                     .queue()
+                                                     .declareName(TEST_QUEUE)
+                                                     
.declareArguments(Collections.singletonMap("foo", "bar"))
+                                                     .declare()
+                                                     .consumeResponse()
+                                                     
.getLatestResponse(QueueDeclareOkBody.class);
+
+
+            assertThat(response.getQueue(), 
is(equalTo(AMQShortString.valueOf(TEST_QUEUE))));
+            assertThat(response.getMessageCount(), is(equalTo(0L)));
+            assertThat(response.getConsumerCount(), is(equalTo(0L)));
+
+        }
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to