You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2011/10/14 22:52:36 UTC

svn commit: r1183495 - in /activemq/trunk/activemq-core/src: main/java/org/apache/activemq/transport/stomp/ test/java/org/apache/activemq/transport/stomp/

Author: tabish
Date: Fri Oct 14 20:52:35 2011
New Revision: 1183495

URL: http://svn.apache.org/viewvc?rev=1183495&view=rev
Log:
fix for: https://issues.apache.org/jira/browse/AMQ-3543

Unit test added.

Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/LegacyFrameTranslator.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/ProtocolConverter.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTest.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/LegacyFrameTranslator.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/LegacyFrameTranslator.java?rev=1183495&r1=1183494&r2=1183495&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/LegacyFrameTranslator.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/LegacyFrameTranslator.java Fri Oct 14 20:52:35 2011
@@ -183,9 +183,9 @@ public class LegacyFrameTranslator imple
             String tName = name.substring("/remote-temp-topic/".length(), name.length());
             return ActiveMQDestination.createDestination(tName, ActiveMQDestination.TEMP_TOPIC_TYPE);
         } else if (name.startsWith("/temp-queue/")) {
-            return converter.createTempQueue(name);
+            return converter.createTempDestination(name, false);
         } else if (name.startsWith("/temp-topic/")) {
-            return converter.createTempTopic(name);
+            return converter.createTempDestination(name, true);
         } else {
             try {
                 ActiveMQDestination fallback = ActiveMQDestination.getUnresolvableDestinationTransformer().transform(name);

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/ProtocolConverter.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/ProtocolConverter.java?rev=1183495&r1=1183494&r2=1183495&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/ProtocolConverter.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/stomp/ProtocolConverter.java Fri Oct 14 20:52:35 2011
@@ -774,20 +774,14 @@ public class ProtocolConverter {
         return stompTransport;
     }
 
-    public ActiveMQDestination createTempQueue(String name) {
+    public ActiveMQDestination createTempDestination(String name, boolean topic) {
         ActiveMQDestination rc = tempDestinations.get(name);
         if( rc == null ) {
-            rc = new ActiveMQTempQueue(connectionId, tempDestinationGenerator.getNextSequenceId());
-            sendToActiveMQ(new DestinationInfo(connectionId, DestinationInfo.ADD_OPERATION_TYPE, rc), null);
-            tempDestinations.put(name, rc);
-        }
-        return rc;
-    }
-
-    public ActiveMQDestination createTempTopic(String name) {
-        ActiveMQDestination rc = tempDestinations.get(name);
-        if( rc == null ) {
-            rc = new ActiveMQTempTopic(connectionId, tempDestinationGenerator.getNextSequenceId());
+            if (topic) {
+                rc = new ActiveMQTempTopic(connectionId, tempDestinationGenerator.getNextSequenceId());
+            } else {
+                rc = new ActiveMQTempQueue(connectionId, tempDestinationGenerator.getNextSequenceId());
+            }
             sendToActiveMQ(new DestinationInfo(connectionId, DestinationInfo.ADD_OPERATION_TYPE, rc), null);
             tempDestinations.put(name, rc);
             tempDestinationAmqToStompMap.put(rc.getQualifiedName(), name);

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTest.java?rev=1183495&r1=1183494&r2=1183495&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTest.java (original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTest.java Fri Oct 14 20:52:35 2011
@@ -1703,6 +1703,68 @@ public class StompTest extends Combinati
         assertEquals(0, queueView.getQueueSize());
     }
 
+    public void testReplyToDestinationNaming() throws Exception {
+
+        String frame = "CONNECT\n" + "login: system\n" + "passcode: manager\n\n" + Stomp.NULL;
+        stompConnection.sendFrame(frame);
+
+        frame = stompConnection.receiveFrame();
+        assertTrue(frame.startsWith("CONNECTED"));
+
+        doTestActiveMQReplyToTempDestination("topic");
+        doTestActiveMQReplyToTempDestination("queue");
+    }
+
+    private void doTestActiveMQReplyToTempDestination(String type) throws Exception {
+        LOG.info("Starting test on Temp Destinations using a temporary: " + type);
+
+        final String dest = "/" + type + "/" + getQueueName();
+        final String tempDest = String.format("/temp-%s/2C26441740C0ECC9tt1", type);
+        LOG.info("Test is using out-bound topic: " + dest + ", and replyTo dest: " + tempDest);
+
+        // Subscribe both to the out-bound destination and the response tempt destination
+        stompConnection.subscribe(dest);
+        stompConnection.subscribe(tempDest);
+
+        // Send a Message with the ReplyTo value set.
+        HashMap<String, String> properties = new HashMap<String, String>();
+        properties.put(Stomp.Headers.Send.REPLY_TO, tempDest);
+        LOG.info(String.format("Sending request message: SEND with %s=%s", Stomp.Headers.Send.REPLY_TO, tempDest));
+        stompConnection.send(dest, "REQUEST", null, properties);
+
+        // The subscription should receive a response with the ReplyTo property set.
+        StompFrame received = stompConnection.receive();
+        assertNotNull(received);
+        String remoteReplyTo = received.getHeaders().get(Stomp.Headers.Send.REPLY_TO);
+        assertNotNull(remoteReplyTo);
+        assertTrue(remoteReplyTo.startsWith(String.format("/temp-%s/", type)));
+        LOG.info(String.format("Received request message: %s with %s=%s", received.getAction(), Stomp.Headers.Send.REPLY_TO, remoteReplyTo));
+
+        // Reply to the request using the given ReplyTo destination
+        stompConnection.send(remoteReplyTo, "RESPONSE");
+
+        // The response should be received by the Temporary Destination subscription
+        StompFrame reply = stompConnection.receive();
+        assertNotNull(reply);
+        assertEquals("MESSAGE", reply.getAction());
+        LOG.info(String.format("Response %s received", reply.getAction()));
+
+        BrokerViewMBean broker = getProxyToBroker();
+        if (type.equals("topic")) {
+            assertEquals(1, broker.getTemporaryTopics().length);
+        } else {
+            assertEquals(1, broker.getTemporaryQueues().length);
+        }
+    }
+
+    private BrokerViewMBean getProxyToBroker() throws MalformedObjectNameException, JMSException {
+        ObjectName brokerViewMBean = new ObjectName(
+            "org.apache.activemq:Type=Broker,BrokerName=localhost");
+        BrokerViewMBean proxy = (BrokerViewMBean) broker.getManagementContext()
+                .newProxyInstance(brokerViewMBean, BrokerViewMBean.class, true);
+        return proxy;
+    }
+
     private QueueViewMBean getProxyToQueue(String name) throws MalformedObjectNameException, JMSException {
         ObjectName queueViewMBeanName = new ObjectName("org.apache.activemq"
                 + ":Type=Queue,Destination=" + name