prevent attemps to consume from temporary destinations created by another 
connection


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

Branch: refs/heads/master
Commit: e1c1de74e0180518ffc51da68baf8baca690f331
Parents: 184acd2
Author: Robert Gemmell <rob...@apache.org>
Authored: Tue Jan 13 13:06:48 2015 +0000
Committer: Robert Gemmell <rob...@apache.org>
Committed: Tue Jan 13 16:02:08 2015 +0000

----------------------------------------------------------------------
 .../src/main/java/org/apache/qpid/jms/JmsConnection.java    | 9 +++++++++
 .../main/java/org/apache/qpid/jms/JmsMessageConsumer.java   | 4 ++++
 2 files changed, 13 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/e1c1de74/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnection.java
----------------------------------------------------------------------
diff --git 
a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnection.java 
b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnection.java
index b2f5c76..51c238d 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnection.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnection.java
@@ -37,6 +37,7 @@ import javax.jms.ConnectionMetaData;
 import javax.jms.Destination;
 import javax.jms.ExceptionListener;
 import javax.jms.IllegalStateException;
+import javax.jms.InvalidDestinationException;
 import javax.jms.JMSException;
 import javax.jms.Queue;
 import javax.jms.QueueConnection;
@@ -544,6 +545,7 @@ public class JmsConnection implements Connection, 
TopicConnection, QueueConnecti
         JmsTemporaryQueue queue = new JmsTemporaryQueue(destinationName);
         queue = createResource(queue);
         tempDestinations.put(queue, queue);
+        queue.setConnection(this);
         return queue;
     }
 
@@ -555,6 +557,7 @@ public class JmsConnection implements Connection, 
TopicConnection, QueueConnecti
         JmsTemporaryTopic topic = new JmsTemporaryTopic(destinationName);
         topic = createResource(topic);
         tempDestinations.put(topic, topic);
+        topic.setConnection(this);
         return topic;
     }
 
@@ -587,6 +590,12 @@ public class JmsConnection implements Connection, 
TopicConnection, QueueConnecti
         }
     }
 
+    protected void 
checkConsumeFromTemporaryDestination(JmsTemporaryDestination destination) 
throws JMSException {
+        if (!this.equals(destination.getConnection())) {
+            throw new InvalidDestinationException("Can't consume from a 
temporary destination created using another connection");
+        }
+    }
+
     protected void checkClosed() throws IllegalStateException {
         if (this.closed.get()) {
             throw new IllegalStateException("The Connection is closed");

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/e1c1de74/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageConsumer.java
----------------------------------------------------------------------
diff --git 
a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageConsumer.java 
b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageConsumer.java
index d56dfe6..b88de22 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageConsumer.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageConsumer.java
@@ -91,6 +91,10 @@ public class JmsMessageConsumer implements MessageConsumer, 
JmsMessageAvailableC
         this.connection = session.getConnection();
         this.acknowledgementMode = session.acknowledgementMode();
 
+        if(destination.isTemporary()) {
+            
connection.checkConsumeFromTemporaryDestination((JmsTemporaryDestination) 
destination);
+        }
+
         if (connection.isMessagePrioritySupported()) {
             this.messageQueue = new PriorityMessageQueue();
         } else {


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

Reply via email to