[jboss-cvs] JBoss Messaging SVN: r3352 - in branches/Branch_Stable: src/main/org/jboss/jms/client/container and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Nov 20 19:12:06 EST 2007


Author: clebert.suconic at jboss.com
Date: 2007-11-20 19:12:06 -0500 (Tue, 20 Nov 2007)
New Revision: 3352

Modified:
   branches/Branch_Stable/src/main/org/jboss/jms/client/JBossSession.java
   branches/Branch_Stable/src/main/org/jboss/jms/client/container/ProducerAspect.java
   branches/Branch_Stable/src/main/org/jboss/jms/destination/JBossTemporaryQueue.java
   branches/Branch_Stable/src/main/org/jboss/jms/destination/JBossTemporaryTopic.java
   branches/Branch_Stable/tests/src/org/jboss/test/messaging/jms/TemporaryDestinationTest.java
Log:
http://jira.jboss.org/jira/browse/JBMESSAGING-1158 - fix for temporaryTopic on send and

Modified: branches/Branch_Stable/src/main/org/jboss/jms/client/JBossSession.java
===================================================================
--- branches/Branch_Stable/src/main/org/jboss/jms/client/JBossSession.java	2007-11-20 19:20:29 UTC (rev 3351)
+++ branches/Branch_Stable/src/main/org/jboss/jms/client/JBossSession.java	2007-11-21 00:12:06 UTC (rev 3352)
@@ -301,10 +301,7 @@
       {
          throw new InvalidDestinationException("Not a JBossTopic:" + topic);
       }
-      if ("".equals(messageSelector))
-      {
-         messageSelector = null;
-      }
+      messageSelector = checkAndTrim(messageSelector);
 
       ConsumerDelegate cd = delegate.
          createConsumerDelegate((JBossTopic)topic, messageSelector, noLocal, name, false, true);
@@ -332,10 +329,7 @@
       {
          throw new InvalidDestinationException("Not a JBossQueue:" + queue);
       }
-      if ("".equals(messageSelector))
-      {
-         messageSelector = null;
-      }
+      messageSelector = checkAndTrim(messageSelector);
 
       BrowserDelegate del =
          delegate.createBrowserDelegate((JBossQueue)queue, messageSelector);
@@ -472,6 +466,19 @@
 
    // Private -------------------------------------------------------
 
+   private String checkAndTrim(String s)
+   {
+      if (s != null)
+      {
+         s = s.trim();
+         if ("".equals(s))
+         {
+            s = null;
+         }
+      }
+      return s;
+   }
+
    // Inner classes -------------------------------------------------
     
 }

Modified: branches/Branch_Stable/src/main/org/jboss/jms/client/container/ProducerAspect.java
===================================================================
--- branches/Branch_Stable/src/main/org/jboss/jms/client/container/ProducerAspect.java	2007-11-20 19:20:29 UTC (rev 3351)
+++ branches/Branch_Stable/src/main/org/jboss/jms/client/container/ProducerAspect.java	2007-11-21 00:12:06 UTC (rev 3352)
@@ -23,6 +23,7 @@
 
 import javax.jms.BytesMessage;
 import javax.jms.Destination;
+import javax.jms.InvalidDestinationException;
 import javax.jms.MapMessage;
 import javax.jms.Message;
 import javax.jms.MessageFormatException;
@@ -38,6 +39,9 @@
 import org.jboss.jms.client.state.SessionState;
 import org.jboss.jms.delegate.ConnectionDelegate;
 import org.jboss.jms.delegate.SessionDelegate;
+import org.jboss.jms.destination.JBossDestination;
+import org.jboss.jms.destination.JBossTemporaryQueue;
+import org.jboss.jms.destination.JBossTemporaryTopic;
 import org.jboss.jms.message.JBossBytesMessage;
 import org.jboss.jms.message.JBossMapMessage;
 import org.jboss.jms.message.JBossMessage;
@@ -168,6 +172,13 @@
          }
       }
 
+      // destination should aways be a JBossDestination as this is tested on the MessageProducer creation
+      // and on the send, so it should be safe to just do this cast
+      if (((JBossDestination)destination).isTemporary())
+      {
+         validateTemporaryDestination(destination);
+      }
+
       SessionState sessionState = (SessionState)producerState.getParent();
 
       // Generate the message id
@@ -268,7 +279,27 @@
       
       return null;
    }
-   
+
+   private void validateTemporaryDestination(Destination destination)
+           throws InvalidDestinationException
+   {
+      if (destination instanceof JBossTemporaryTopic)
+      {
+         if (((JBossTemporaryTopic)destination).isDeleted())
+         {
+            throw new InvalidDestinationException("Temporary topic was deleted");
+         }
+      }
+      else
+      if (destination instanceof JBossTemporaryQueue)
+      {
+         if (((JBossTemporaryQueue)destination).isDeleted())
+         {
+            throw new InvalidDestinationException("Temporary queue was deleted");
+         }
+      }
+   }
+
    public Object handleSetDisableMessageID(Invocation invocation) throws Throwable
    { 
       Object[] args = ((MethodInvocation)invocation).getArguments();

Modified: branches/Branch_Stable/src/main/org/jboss/jms/destination/JBossTemporaryQueue.java
===================================================================
--- branches/Branch_Stable/src/main/org/jboss/jms/destination/JBossTemporaryQueue.java	2007-11-20 19:20:29 UTC (rev 3351)
+++ branches/Branch_Stable/src/main/org/jboss/jms/destination/JBossTemporaryQueue.java	2007-11-21 00:12:06 UTC (rev 3352)
@@ -43,6 +43,7 @@
    // Attributes ----------------------------------------------------
    
    private transient SessionDelegate delegate;
+   private boolean deleted = false;
    
    
    // Static --------------------------------------------------------
@@ -64,6 +65,7 @@
    
    public void delete() throws JMSException
    {
+      deleted = true;
       if (delegate != null)
       {
          delegate.deleteTemporaryDestination(this);
@@ -77,6 +79,11 @@
       return true;
    }
 
+   public boolean isDeleted()
+   {
+      return deleted;
+   }
+
    // Public --------------------------------------------------------
 
    public String toString()

Modified: branches/Branch_Stable/src/main/org/jboss/jms/destination/JBossTemporaryTopic.java
===================================================================
--- branches/Branch_Stable/src/main/org/jboss/jms/destination/JBossTemporaryTopic.java	2007-11-20 19:20:29 UTC (rev 3351)
+++ branches/Branch_Stable/src/main/org/jboss/jms/destination/JBossTemporaryTopic.java	2007-11-21 00:12:06 UTC (rev 3352)
@@ -42,6 +42,7 @@
    // Attributes ----------------------------------------------------
    
    private transient SessionDelegate delegate;
+   private boolean deleted = false;
    
    // Static --------------------------------------------------------
    
@@ -62,6 +63,7 @@
    
    public void delete() throws JMSException
    {
+      deleted = true;
       if (delegate != null) delegate.deleteTemporaryDestination(this);
    }
    
@@ -72,6 +74,11 @@
       return true;
    }
 
+   public boolean isDeleted()
+   {
+      return deleted;
+   }
+
    // Public --------------------------------------------------------
 
    public String toString()

Modified: branches/Branch_Stable/tests/src/org/jboss/test/messaging/jms/TemporaryDestinationTest.java
===================================================================
--- branches/Branch_Stable/tests/src/org/jboss/test/messaging/jms/TemporaryDestinationTest.java	2007-11-20 19:20:29 UTC (rev 3351)
+++ branches/Branch_Stable/tests/src/org/jboss/test/messaging/jms/TemporaryDestinationTest.java	2007-11-21 00:12:06 UTC (rev 3352)
@@ -188,6 +188,75 @@
    		}
    	}
    }
+
+   public void testTemporaryTopicDeleted() throws Exception
+   {
+      Connection conn = null;
+
+      try
+      {
+         conn = cf.createConnection();
+
+         Session producerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         TemporaryTopic tempTopic =  producerSession.createTemporaryTopic();
+         MessageProducer producer = producerSession.createProducer(tempTopic);
+         tempTopic.delete();
+
+         try
+         {
+            TextMessage invalidMessage = producerSession.createTextMessage("garbage");
+            log.info("Sending message");
+            producer.send(invalidMessage);
+            fail("Should throw JMSException");
+         }
+         catch (JMSException e)
+         {
+            //Should fail - you can't delete a temp queue if it has active consumers
+         }
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            conn.close();
+         }
+      }
+   }
+
+
+   public void testTemporaryQueueDeletedSend() throws Exception
+   {
+      Connection conn = null;
+
+      try
+      {
+         conn = cf.createConnection();
+
+         Session producerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         TemporaryQueue tempQueue = producerSession.createTemporaryQueue();
+         MessageProducer producer = producerSession.createProducer(tempQueue);
+         tempQueue.delete();
+
+         try
+         {
+            TextMessage invalidMessage = producerSession.createTextMessage("garbage");
+            log.info("Sending message");
+            producer.send(invalidMessage);
+            fail("Should throw JMSException");
+         }
+         catch (JMSException e)
+         {
+            //Should fail - you can't delete a temp queue if it has active consumers
+         }
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            conn.close();
+         }
+      }
+   }
    
    public void testTemporaryQueueDeleteWithConsumer() throws Exception
    {




More information about the jboss-cvs-commits mailing list