[jboss-cvs] JBoss Messaging SVN: r3346 - in branches/Branch_Stable: tests/src/org/jboss/test/messaging/jms and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Nov 19 13:21:03 EST 2007


Author: clebert.suconic at jboss.com
Date: 2007-11-19 13:21:03 -0500 (Mon, 19 Nov 2007)
New Revision: 3346

Modified:
   branches/Branch_Stable/src/main/org/jboss/jms/server/endpoint/ServerBrowserEndpoint.java
   branches/Branch_Stable/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java
   branches/Branch_Stable/tests/src/org/jboss/test/messaging/jms/BrowserTest.java
Log:
http://jira.jboss.org/jira/browse/JBMESSAGING-1156 - Validate destination on browser.enumeration()

Modified: branches/Branch_Stable/src/main/org/jboss/jms/server/endpoint/ServerBrowserEndpoint.java
===================================================================
--- branches/Branch_Stable/src/main/org/jboss/jms/server/endpoint/ServerBrowserEndpoint.java	2007-11-19 16:49:13 UTC (rev 3345)
+++ branches/Branch_Stable/src/main/org/jboss/jms/server/endpoint/ServerBrowserEndpoint.java	2007-11-19 18:21:03 UTC (rev 3346)
@@ -29,6 +29,7 @@
 import javax.jms.Message;
 
 import org.jboss.jms.delegate.BrowserEndpoint;
+import org.jboss.jms.destination.JBossDestination;
 import org.jboss.jms.message.JBossMessage;
 import org.jboss.jms.server.selector.Selector;
 import org.jboss.jms.wireformat.Dispatcher;
@@ -62,19 +63,21 @@
    private boolean closed;
    private ServerSessionEndpoint session;
    private Channel destination;
+   private JBossDestination jmsDestination;
    private Filter filter;
    private Iterator iterator;
 
    // Constructors ---------------------------------------------------------------------------------
 
    ServerBrowserEndpoint(ServerSessionEndpoint session, String id,
-                         Channel destination, String messageSelector) throws JMSException
+                         Channel destination, String messageSelector, JBossDestination jmsDestination) throws JMSException
    {     
       this.session = session;
       this.id = id;
       this.destination = destination;
+      this.jmsDestination = jmsDestination;
 
-		if (messageSelector != null)
+      if (messageSelector != null)
 		{	
 			filter = new Selector(messageSelector);		
 		}
@@ -91,6 +94,8 @@
             throw new IllegalStateException("Browser is closed");
          }
 
+         validateDestination();
+
          log.trace(this + " is being resetted");
 
          iterator = createIterator();
@@ -222,6 +227,12 @@
 
    // Package protected ----------------------------------------------------------------------------
    
+
+   void validateDestination() throws JMSException
+   {
+      session.validateDestination(jmsDestination);
+   }
+
    void localClose() throws JMSException
    {
       if (closed)

Modified: branches/Branch_Stable/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java
===================================================================
--- branches/Branch_Stable/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java	2007-11-19 16:49:13 UTC (rev 3345)
+++ branches/Branch_Stable/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java	2007-11-19 18:21:03 UTC (rev 3346)
@@ -1603,8 +1603,17 @@
          log.error("Failed to prompt delivery", t);
       }
    }
-   
 
+   /** Helper method to valid destinations on the destinationManager */
+   void validateDestination(JBossDestination jmsDestination)
+           throws InvalidDestinationException
+   {
+      if (dm.getDestination(jmsDestination.getName(), jmsDestination.isQueue()) == null)
+      {
+         throw new InvalidDestinationException("No such destination: " + jmsDestination);
+      }
+   }
+
    // Protected ------------------------------------------------------------------------------------
 
    // Private --------------------------------------------------------------------------------------
@@ -2191,10 +2200,7 @@
          throw new IllegalStateException("Cannot browse a topic");
       }
 
-      if (dm.getDestination(jmsDestination.getName(), jmsDestination.isQueue()) == null)
-      {
-         throw new InvalidDestinationException("No such destination: " + jmsDestination);
-      }
+      validateDestination(jmsDestination);
 
       log.trace(this + " creating browser for " + jmsDestination +
          (selector == null ? "" : ", selector '" + selector + "'"));
@@ -2208,7 +2214,7 @@
       
       String browserID = GUIDGenerator.generateGUID();
 
-      ServerBrowserEndpoint ep = new ServerBrowserEndpoint(this, browserID, binding.queue, selector);
+      ServerBrowserEndpoint ep = new ServerBrowserEndpoint(this, browserID, binding.queue, selector, jmsDestination);
 
       // still need to synchronized since close() can come in on a different thread
       synchronized (browsers)

Modified: branches/Branch_Stable/tests/src/org/jboss/test/messaging/jms/BrowserTest.java
===================================================================
--- branches/Branch_Stable/tests/src/org/jboss/test/messaging/jms/BrowserTest.java	2007-11-19 16:49:13 UTC (rev 3345)
+++ branches/Branch_Stable/tests/src/org/jboss/test/messaging/jms/BrowserTest.java	2007-11-19 18:21:03 UTC (rev 3346)
@@ -29,6 +29,7 @@
 import javax.jms.Message;
 import javax.jms.MessageConsumer;
 import javax.jms.MessageFormatException;
+import javax.jms.TemporaryQueue;
 import javax.jms.MessageProducer;
 import javax.jms.QueueBrowser;
 import javax.jms.Session;
@@ -40,6 +41,7 @@
 /**
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
  * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
+ * @author <a href="mailto:clebert.suconic at jboss.com">Clebert Suconic</a>
  * @version <tt>$Revision$</tt>
  *
  * $Id$
@@ -113,11 +115,65 @@
       {
          if (pconn != null)
          {
-         	pconn.close();         	
+         	pconn.close();
          }
       }
    }
 
+   public void testCreateBrowserOnTemporaryDeletedQueue() throws Exception
+   {
+      Connection pconn = cf.createConnection();
+
+      try
+      {
+         Session ps = pconn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         TemporaryQueue queue = ps.createTemporaryQueue();
+
+         try
+         {
+            QueueBrowser browser = ps.createBrowser(queue);
+            queue.delete();
+            browser.getEnumeration();
+
+
+            fail("should throw exception");
+         }
+         catch(InvalidDestinationException e)
+         {
+            // OK
+         }
+      }
+      finally
+      {
+         if (pconn != null)
+         {
+         	pconn.close();
+         }
+      }
+   }
+
+   public void testCreateBrowserOnTemporaryQueue() throws Exception
+   {
+      Connection pconn = cf.createConnection();
+
+      try
+      {
+         Session ps = pconn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         TemporaryQueue queue = ps.createTemporaryQueue();
+
+         QueueBrowser browser = ps.createBrowser(queue);
+         browser.getEnumeration();
+         queue.delete();
+      }
+      finally
+      {
+         if (pconn != null)
+         {
+         	pconn.close();
+         }
+      }
+   }
+
 	public void testBrowse() throws Exception
 	{
 		Connection conn = null;




More information about the jboss-cvs-commits mailing list