[jboss-cvs] JBoss Messaging SVN: r2807 - in trunk: tests/src/org/jboss/test/messaging/jms/message and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jun 27 11:21:58 EDT 2007


Author: sergeypk
Date: 2007-06-27 11:21:58 -0400 (Wed, 27 Jun 2007)
New Revision: 2807

Modified:
   trunk/src/main/org/jboss/jms/message/JBossMessage.java
   trunk/tests/src/org/jboss/test/messaging/jms/message/MessageTest.java
Log:
http://jira.jboss.com/jira/browse/JBMESSAGING-988 - allow JMSDestination and JMSReplyTo to be set to a foreign destination.

Modified: trunk/src/main/org/jboss/jms/message/JBossMessage.java
===================================================================
--- trunk/src/main/org/jboss/jms/message/JBossMessage.java	2007-06-27 14:49:17 UTC (rev 2806)
+++ trunk/src/main/org/jboss/jms/message/JBossMessage.java	2007-06-27 15:21:58 UTC (rev 2807)
@@ -34,7 +34,6 @@
 import javax.jms.BytesMessage;
 import javax.jms.DeliveryMode;
 import javax.jms.Destination;
-import javax.jms.InvalidDestinationException;
 import javax.jms.JMSException;
 import javax.jms.MapMessage;
 import javax.jms.Message;
@@ -275,7 +274,7 @@
    
    //Optimisation - we could just store this as a header like everything else - but we store
    //As an attribute so we can prevent an extra lookup on the server
-   private JBossDestination destination;
+   private Destination destination;
    
    // Constructors --------------------------------------------------
  
@@ -339,14 +338,9 @@
             setJMSCorrelationID(corrIDString);
          }
       }
-      if (foreign.getJMSReplyTo() instanceof JBossDestination)
-      {
-         setJMSReplyTo(foreign.getJMSReplyTo());
-      }
-      if (foreign.getJMSDestination() instanceof JBossDestination)
-      {
-         setJMSDestination(foreign.getJMSDestination());
-      }
+      
+      setJMSReplyTo(foreign.getJMSReplyTo());
+      setJMSDestination(foreign.getJMSDestination());
       setJMSDeliveryMode(foreign.getJMSDeliveryMode());
       setJMSExpiration(foreign.getJMSExpiration());
       setJMSPriority(foreign.getJMSPriority());
@@ -435,19 +429,7 @@
 
    public void setJMSReplyTo(Destination replyTo) throws JMSException
    {
-      //Need to be able to set null too
-      if (replyTo == null)
-      {
-         headers.put(REPLYTO_HEADER_NAME, null);
-      }
-      else
-      {      
-         if (!(replyTo instanceof JBossDestination))
-         {
-            throw new InvalidDestinationException("Replyto cannot be foreign");
-         }
-         headers.put(REPLYTO_HEADER_NAME, (JBossDestination)replyTo);
-      }
+      headers.put(REPLYTO_HEADER_NAME, replyTo);
    }
 
    public Destination getJMSDestination() throws JMSException
@@ -464,14 +446,9 @@
 
    public void setJMSDestination(Destination destination) throws JMSException
    {
-      if (!(destination instanceof JBossDestination))
-      {
-         throw new InvalidDestinationException("Destination cannot be foreign");
-      }
-      
       //We don't store as a header when setting - this allows us to avoid a lookup on the server
       //when routing the message
-      this.destination = (JBossDestination)destination; 
+      this.destination = destination; 
    }
    
    //We need to override getHeaders - so the JMSDestination header gets persisted to the db

Modified: trunk/tests/src/org/jboss/test/messaging/jms/message/MessageTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/message/MessageTest.java	2007-06-27 14:49:17 UTC (rev 2806)
+++ trunk/tests/src/org/jboss/test/messaging/jms/message/MessageTest.java	2007-06-27 15:21:58 UTC (rev 2807)
@@ -1232,7 +1232,52 @@
 
       ensureEquivalent(foreignTextMessage, copy);
    }
+   
+   public void testForeignJMSDestination() throws JMSException
+   {
+      Message message = queueProducerSession.createMessage();
+      
+      Destination foreignDestination = new ForeignDestination();
+      
+      message.setJMSDestination(foreignDestination);
+      
+      assertSame(foreignDestination, message.getJMSDestination());
+      
+      queueProducer.send(message);
+      
+      assertSame(queue, message.getJMSDestination());
+      
+      Message receivedMessage = queueConsumer.receive(100L);
+      
+      ensureEquivalent(receivedMessage, ((MessageProxy) message).getMessage());
+   }
+   
+   public void testForeignJMSReplyTo() throws JMSException
+   {
+      JBossMessage jbossMessage = ((MessageProxy) queueProducerSession.createTextMessage()).getMessage();
+      
+      Destination foreignDestination = new ForeignDestination();
+      
+      jbossMessage.setJMSReplyTo(foreignDestination);
+      
+      queueProducer.send(jbossMessage);
+      
+      Message receivedMessage = queueConsumer.receive(100L);
 
+      ensureEquivalent(receivedMessage, jbossMessage);
+   }
+   
+   public void testCopyForeignDestinationAndReplyTo() throws JMSException
+   {
+      Message foreignMessage = new SimpleJMSMessage();
+      foreignMessage.setJMSDestination(new ForeignDestination());
+      foreignMessage.setJMSReplyTo(new ForeignDestination());
+
+      JBossMessage copy = new JBossMessage(foreignMessage, 0);
+
+      ensureEquivalent(foreignMessage, copy);
+   }
+
    // Package protected ---------------------------------------------
 
    // Protected -----------------------------------------------------
@@ -1241,4 +1286,8 @@
 
    // Inner classes -------------------------------------------------
 
+   private static class ForeignDestination implements Destination, Serializable
+   {
+   }
+   
 }




More information about the jboss-cvs-commits mailing list