activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject activemq git commit: https://issues.apache.org/jira/browse/AMQ-5711
Date Tue, 21 Apr 2015 21:46:06 GMT
Repository: activemq
Updated Branches:
  refs/heads/master ff1a1c498 -> b313209aa


https://issues.apache.org/jira/browse/AMQ-5711

Reject sender / receiver creation when the address is a temp destination
prefixed value but the destination doesn't map down to a temp
destination created using a dynamic link which means the orignal
connection ID where the destination was created cannot be determined. 

Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/b313209a
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/b313209a
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/b313209a

Branch: refs/heads/master
Commit: b313209aa27b2edc5a51e3c68cc614bab69e4b40
Parents: ff1a1c4
Author: Timothy Bish <tabish121@gmail.com>
Authored: Tue Apr 21 17:45:45 2015 -0400
Committer: Timothy Bish <tabish121@gmail.com>
Committed: Tue Apr 21 17:45:45 2015 -0400

----------------------------------------------------------------------
 .../transport/amqp/protocol/AmqpSession.java    | 16 ++++-
 .../amqp/interop/AmqpTempDestinationTest.java   | 63 ++++++++++++++++++++
 2 files changed, 77 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/b313209a/activemq-amqp/src/main/java/org/apache/activemq/transport/amqp/protocol/AmqpSession.java
----------------------------------------------------------------------
diff --git a/activemq-amqp/src/main/java/org/apache/activemq/transport/amqp/protocol/AmqpSession.java
b/activemq-amqp/src/main/java/org/apache/activemq/transport/amqp/protocol/AmqpSession.java
index 6ca4d71..d9f0c0f 100644
--- a/activemq-amqp/src/main/java/org/apache/activemq/transport/amqp/protocol/AmqpSession.java
+++ b/activemq-amqp/src/main/java/org/apache/activemq/transport/amqp/protocol/AmqpSession.java
@@ -179,6 +179,12 @@ public class AmqpSession implements AmqpResource {
                 });
             } else if (targetNodeName != null && !targetNodeName.isEmpty()) {
                 destination = createDestination(remoteTarget);
+                if (destination.isTemporary()) {
+                    String connectionId = ((ActiveMQTempDestination) destination).getConnectionId();
+                    if (connectionId == null) {
+                        throw new AmqpProtocolException(AmqpError.PRECONDITION_FAILED.toString(),
"Not a broker created temp destination");
+                    }
+                }
             }
 
             receiver.setDestination(destination);
@@ -276,6 +282,12 @@ public class AmqpSession implements AmqpResource {
                 });
             } else {
                 destination = createDestination(source);
+                if (destination.isTemporary()) {
+                    String connectionId = ((ActiveMQTempDestination) destination).getConnectionId();
+                    if (connectionId == null) {
+                        throw new AmqpProtocolException(AmqpError.INVALID_FIELD.toString(),
"Not a broker created temp destination");
+                    }
+                }
             }
 
             source.setFilter(supportedFilters.isEmpty() ? null : supportedFilters);
@@ -359,11 +371,11 @@ public class AmqpSession implements AmqpResource {
 
     //----- Internal Implementation ------------------------------------------//
 
-    protected ConsumerId getNextConsumerId() {
+    private ConsumerId getNextConsumerId() {
         return new ConsumerId(sessionId, nextConsumerId++);
     }
 
-    protected ProducerId getNextProducerId() {
+    private ProducerId getNextProducerId() {
         return new ProducerId(sessionId, nextProducerId++);
     }
 }

http://git-wip-us.apache.org/repos/asf/activemq/blob/b313209a/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/interop/AmqpTempDestinationTest.java
----------------------------------------------------------------------
diff --git a/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/interop/AmqpTempDestinationTest.java
b/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/interop/AmqpTempDestinationTest.java
index 2df5141..ea68639 100644
--- a/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/interop/AmqpTempDestinationTest.java
+++ b/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/interop/AmqpTempDestinationTest.java
@@ -21,6 +21,7 @@ import static org.apache.activemq.transport.amqp.AmqpSupport.TEMP_QUEUE_CAPABILI
 import static org.apache.activemq.transport.amqp.AmqpSupport.TEMP_TOPIC_CAPABILITY;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -46,6 +47,68 @@ import org.junit.Test;
 public class AmqpTempDestinationTest extends AmqpClientTestSupport {
 
     @Test(timeout = 60000)
+    public void testCannotCreateSenderWithNamedTempQueue() throws Exception {
+        doTestCannotCreateSenderWithNamedTempDestination(false);
+    }
+
+    @Test(timeout = 60000)
+    public void testCannotCreateSenderWithNamedTempTopic() throws Exception {
+        doTestCannotCreateSenderWithNamedTempDestination(true);
+    }
+
+    protected void doTestCannotCreateSenderWithNamedTempDestination(boolean topic) throws
Exception {
+
+        AmqpClient client = createAmqpClient();
+        AmqpConnection connection = client.connect();
+        AmqpSession session = connection.createSession();
+
+        String address = null;
+        if (topic) {
+            address = "temp-topic://" + getTestName();
+        } else {
+            address = "temp-queue://" + getTestName();
+        }
+
+        try {
+            session.createSender(address);
+            fail("Should not be able to create sender to a temp destination that doesn't
exist.");
+        } catch (Exception ex) {
+            LOG.info("Error creating sender: {}", ex.getMessage());
+        }
+    }
+
+    @Test(timeout = 60000)
+    public void testCanntCreateReceverWithNamedTempQueue() throws Exception {
+        doTestCannotCreateReceiverWithNamedTempDestination(false);
+    }
+
+    @Test(timeout = 60000)
+    public void testCannotCreateReceiverWithNamedTempTopic() throws Exception {
+        doTestCannotCreateReceiverWithNamedTempDestination(true);
+    }
+
+    protected void doTestCannotCreateReceiverWithNamedTempDestination(boolean topic) throws
Exception {
+
+        AmqpClient client = createAmqpClient();
+        AmqpConnection connection = client.connect();
+        AmqpSession session = connection.createSession();
+
+        String address = null;
+        if (topic) {
+            address = "temp-topic://" + getTestName();
+        } else {
+            address = "temp-queue://" + getTestName();
+        }
+
+        try {
+            session.createReceiver(address);
+            fail("Should not be able to create sender to a temp destination that doesn't
exist.");
+        } catch (Exception ex) {
+            LOG.info("Error creating sender: {}", ex.getMessage());
+        }
+    }
+
+    @Test(timeout = 60000)
     public void testCreateDynamicSenderToTopic() throws Exception {
         doTestCreateDynamicSender(true);
     }


Mime
View raw message