You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ri...@apache.org on 2006/12/13 14:38:56 UTC

svn commit: r486647 - in /incubator/qpid/trunk/qpid/java/client/src: main/java/org/apache/qpid/client/ main/java/org/apache/qpid/client/message/ main/java/org/apache/qpid/jndi/ test/java/org/apache/qpid/test/unit/basic/

Author: ritchiem
Date: Wed Dec 13 05:38:55 2006
New Revision: 486647

URL: http://svn.apache.org/viewvc?view=rev&rev=486647
Log:
QPID-149
replyTo destination was invalid when using TemporaryQueues as the getEncodingName was using a simple method for encoding the Destination. This has been updated to use a BindingURL as this is more transportable. getEncodingName removed from all AMQDestination subclasses and now is implemented in AMQDestination as a call to toURL()

Created static Destination.createDestination(BindingURL) to create the correct destination from a BindingURL. PropertiesFileInitialContextFactory.java and AbstractJMSMessage.java updated to use this.

Modified:
    incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQDestination.java
    incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQHeadersExchange.java
    incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQQueue.java
    incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryQueue.java
    incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQTopic.java
    incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/message/AbstractJMSMessage.java
    incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactory.java
    incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/basic/PropertyValueTest.java

Modified: incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQDestination.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQDestination.java?view=diff&rev=486647&r1=486646&r2=486647
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQDestination.java (original)
+++ incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQDestination.java Wed Dec 13 05:38:55 2006
@@ -99,7 +99,10 @@
         _queueName = queueName;
     }
 
-    public abstract String getEncodedName();
+    public String getEncodedName()
+    {
+        return toURL();
+    }
 
     public boolean isDurable()
     {
@@ -244,7 +247,7 @@
             return false;
         }
         if ((_queueName == null && that._queueName != null) ||
-                (_queueName != null && !_queueName.equals(that._queueName)))
+            (_queueName != null && !_queueName.equals(that._queueName)))
         {
             return false;
         }
@@ -281,5 +284,27 @@
                 new StringRefAddr(this.getClass().getName(), toURL()),
                 AMQConnectionFactory.class.getName(),
                 null);          // factory location
+    }
+
+    public static Destination createDestination(BindingURL binding)
+    {
+        String type = binding.getExchangeClass();
+
+        if (type.equals(ExchangeDefaults.DIRECT_EXCHANGE_CLASS))
+        {
+            return new AMQQueue(binding);
+        }
+        else if (type.equals(ExchangeDefaults.TOPIC_EXCHANGE_CLASS))
+        {
+            return new AMQTopic(binding);
+        }
+        else if (type.equals(ExchangeDefaults.HEADERS_EXCHANGE_CLASS))
+        {
+            return new AMQHeadersExchange(binding);
+        }
+        else
+        {
+            throw new IllegalArgumentException("Unknown Exchange Class:" + type + " in binding:" + binding);
+        }
     }
 }

Modified: incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQHeadersExchange.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQHeadersExchange.java?view=diff&rev=486647&r1=486646&r2=486647
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQHeadersExchange.java (original)
+++ incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQHeadersExchange.java Wed Dec 13 05:38:55 2006
@@ -38,11 +38,6 @@
         super(queueName, ExchangeDefaults.HEADERS_EXCHANGE_CLASS, queueName, true, true, null);
     }
 
-    public String getEncodedName()
-    {
-        return getDestinationName();
-    }
-
     public String getRoutingKey()
     {
         return getDestinationName();

Modified: incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQQueue.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQQueue.java?view=diff&rev=486647&r1=486646&r2=486647
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQQueue.java (original)
+++ incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQQueue.java Wed Dec 13 05:38:55 2006
@@ -75,11 +75,7 @@
               autoDelete, queueName);
     }
 
-    public String getEncodedName()
-    {
-        return 'Q' + getQueueName();
-    }
-
+  
     public String getRoutingKey()
     {
         return getQueueName();

Modified: incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryQueue.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryQueue.java?view=diff&rev=486647&r1=486646&r2=486647
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryQueue.java (original)
+++ incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQTemporaryQueue.java Wed Dec 13 05:38:55 2006
@@ -26,22 +26,25 @@
 /**
  * AMQ implementation of a TemporaryQueue.
  */
-final class AMQTemporaryQueue extends AMQQueue implements TemporaryQueue {
+final class AMQTemporaryQueue extends AMQQueue implements TemporaryQueue
+{
+
 
     /**
      * Create a new instance of an AMQTemporaryQueue
      */
-    public AMQTemporaryQueue() {
-        super("TempQueue" + Long.toString(System.currentTimeMillis()),
-                null, true, true);
+    public AMQTemporaryQueue()
+    {
+        super("TempQueue" + Long.toString(System.currentTimeMillis()), true);
     }
 
     /**
      * @see javax.jms.TemporaryQueue#delete()
      */
-    public void delete() throws JMSException {
+    public void delete() throws JMSException
+    {
         throw new UnsupportedOperationException("Delete not supported, " +
-            "will auto-delete when connection closed");
+                                                "will auto-delete when connection closed");
     }
-    
+
 }

Modified: incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQTopic.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQTopic.java?view=diff&rev=486647&r1=486646&r2=486647
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQTopic.java (original)
+++ incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/AMQTopic.java Wed Dec 13 05:38:55 2006
@@ -61,11 +61,6 @@
         return super.getDestinationName();
     }
 
-    public String getEncodedName()
-    {
-        return 'T' + getDestinationName();
-    }
-
      public String getRoutingKey()
     {
         return getDestinationName();

Modified: incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/message/AbstractJMSMessage.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/message/AbstractJMSMessage.java?view=diff&rev=486647&r1=486646&r2=486647
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/message/AbstractJMSMessage.java (original)
+++ incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/message/AbstractJMSMessage.java Wed Dec 13 05:38:55 2006
@@ -23,6 +23,9 @@
 import org.apache.commons.collections.map.ReferenceMap;
 import org.apache.mina.common.ByteBuffer;
 import org.apache.qpid.AMQException;
+import org.apache.qpid.url.BindingURL;
+import org.apache.qpid.url.AMQBindingURL;
+import org.apache.qpid.url.URLSyntaxException;
 import org.apache.qpid.client.AMQDestination;
 import org.apache.qpid.client.AMQQueue;
 import org.apache.qpid.client.AMQTopic;
@@ -136,19 +139,16 @@
             Destination dest = (Destination) _destinationCache.get(replyToEncoding);
             if (dest == null)
             {
-                char destType = replyToEncoding.charAt(0);
-                if (destType == 'Q')
+                try
                 {
-                    dest = new AMQQueue(replyToEncoding.substring(1));
+                    BindingURL binding = new AMQBindingURL(replyToEncoding);
+                    dest = AMQDestination.createDestination(binding);
                 }
-                else if (destType == 'T')
-                {
-                    dest = new AMQTopic(replyToEncoding.substring(1));
-                }
-                else
+                catch (URLSyntaxException e)
                 {
                     throw new JMSException("Illegal value in JMS_ReplyTo property: " + replyToEncoding);
                 }
+
                 _destinationCache.put(replyToEncoding, dest);
             }
             return dest;
@@ -163,7 +163,7 @@
         }
         if (!(destination instanceof AMQDestination))
         {
-            throw new IllegalArgumentException("ReplyTo destination my be an AMQ destination - passed argument was type " +
+            throw new IllegalArgumentException("ReplyTo destination may only be an AMQDestination - passed argument was type " +
                                                destination.getClass());
         }
         final AMQDestination amqd = (AMQDestination) destination;
@@ -389,9 +389,10 @@
         // is not specified. In our case, we only set the session field where client acknowledge mode is specified.
         if (_session != null)
         {
-        	if (_session.getAMQConnection().isClosed()){
-        		throw new javax.jms.IllegalStateException("Connection is already closed");
-        	}
+            if (_session.getAMQConnection().isClosed())
+            {
+                throw new javax.jms.IllegalStateException("Connection is already closed");
+            }
 
             // we set multiple to true here since acknowledgement implies acknowledge of all previous messages
             // received on the session

Modified: incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactory.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactory.java?view=diff&rev=486647&r1=486646&r2=486647
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactory.java (original)
+++ incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactory.java Wed Dec 13 05:38:55 2006
@@ -25,6 +25,7 @@
 import org.apache.qpid.client.AMQHeadersExchange;
 import org.apache.qpid.client.AMQQueue;
 import org.apache.qpid.client.AMQTopic;
+import org.apache.qpid.client.AMQDestination;
 import org.apache.qpid.exchange.ExchangeDefaults;
 import org.apache.qpid.url.AMQBindingURL;
 import org.apache.qpid.url.BindingURL;
@@ -177,21 +178,15 @@
             return null;
         }
 
-        if (binding.getExchangeClass().equals(ExchangeDefaults.TOPIC_EXCHANGE_CLASS))
-        {
-            return createTopic(binding);
-        }
-        else if (binding.getExchangeClass().equals(ExchangeDefaults.DIRECT_EXCHANGE_CLASS))
+        try
         {
-            return createQueue(binding);
+            return AMQDestination.createDestination(binding);
         }
-        else if (binding.getExchangeClass().equals(ExchangeDefaults.HEADERS_EXCHANGE_CLASS))
+        catch (IllegalArgumentException iaw)
         {
-            return createHeaderExchange(binding);
+            _logger.warn("Binding: '" + binding + "' not supported");
+            return null;
         }
-
-        _logger.warn("Binding: '" + binding + "' not supported");
-        return null;
     }
 
     /**

Modified: incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/basic/PropertyValueTest.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/basic/PropertyValueTest.java?view=diff&rev=486647&r1=486646&r2=486647
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/basic/PropertyValueTest.java (original)
+++ incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/basic/PropertyValueTest.java Wed Dec 13 05:38:55 2006
@@ -119,8 +119,17 @@
             m.setJMSPriority(100);
 
             //  Queue
-            Queue q = //_session.createTemporaryQueue();
-                    q = new AMQQueue("TestReply");
+            Queue q;
+
+            if (i / 2 == 0)
+            {
+                q = _session.createTemporaryQueue();
+            }
+            else
+            {
+                q = new AMQQueue("TestReply");
+            }
+
             m.setJMSReplyTo(q);
             m.setStringProperty("TempQueue", q.toString());
 
@@ -173,6 +182,8 @@
                                 (int) Integer.MAX_VALUE, m.getIntProperty("Int"));
             Assert.assertEquals("Check CorrelationID properties are correctly transported",
                                 "Correlation", m.getJMSCorrelationID());
+
+            _logger.warn("getJMSPriority not being verified.");
 //            Assert.assertEquals("Check Priority properties are correctly transported",
 //                                100, m.getJMSPriority());
 
@@ -180,8 +191,9 @@
             Assert.assertEquals("Check ReplyTo properties are correctly transported",
                                 m.getStringProperty("TempQueue"), m.getJMSReplyTo().toString());
 
-//            Assert.assertEquals("Check Type properties are correctly transported",
-//                                "Test", m.getJMSType());
+            Assert.assertEquals("Check Type properties are correctly transported",
+                                "Test", m.getJMSType());
+
             Assert.assertEquals("Check Short properties are correctly transported",
                                 (short) Short.MAX_VALUE, m.getShortProperty("Short"));
             Assert.assertEquals("Check UnsignedInt properties are correctly transported",