From 9ff350033f72ebf0851a9b63b4a59e86d13bbb79 Mon Sep 17 00:00:00 2001 From: "Timothy A. Bish" Date: Fri, 14 Oct 2011 20:52:35 +0000 Subject: [PATCH] fix for: https://issues.apache.org/jira/browse/AMQ-3543 Unit test added. git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1183495 13f79535-47bb-0310-9956-ffa450edef68 --- .../stomp/LegacyFrameTranslator.java | 4 +- .../transport/stomp/ProtocolConverter.java | 18 ++---- .../activemq/transport/stomp/StompTest.java | 62 +++++++++++++++++++ 3 files changed, 70 insertions(+), 14 deletions(-) diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/stomp/LegacyFrameTranslator.java b/activemq-core/src/main/java/org/apache/activemq/transport/stomp/LegacyFrameTranslator.java index 4b984f8550..cb4ba8921f 100644 --- a/activemq-core/src/main/java/org/apache/activemq/transport/stomp/LegacyFrameTranslator.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/stomp/LegacyFrameTranslator.java @@ -183,9 +183,9 @@ public class LegacyFrameTranslator implements FrameTranslator { 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); diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/stomp/ProtocolConverter.java b/activemq-core/src/main/java/org/apache/activemq/transport/stomp/ProtocolConverter.java index 4b6255a9b1..8dce4356ce 100644 --- a/activemq-core/src/main/java/org/apache/activemq/transport/stomp/ProtocolConverter.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/stomp/ProtocolConverter.java @@ -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); diff --git a/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTest.java b/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTest.java index aea5dd9f67..94f8cd52b1 100644 --- a/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTest.java @@ -1703,6 +1703,68 @@ public class StompTest extends CombinationTestSupport { 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 properties = new HashMap(); + 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