activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtu...@apache.org
Subject svn commit: r1504660 - in /activemq/trunk: activemq-broker/src/main/java/org/apache/activemq/broker/jmx/ activemq-unit-tests/src/test/java/org/apache/activemq/broker/jmx/
Date Thu, 18 Jul 2013 21:09:43 GMT
Author: gtully
Date: Thu Jul 18 21:09:43 2013
New Revision: 1504660

URL: http://svn.apache.org/r1504660
Log:
was having difficulty setting JMSreplyTo on message from jconsole. the header map operation
is greyed out. Seems it needs a special ui to populate. I added a simpler csn=v string where
body,username,password are special and where all other names are applied as properties. Jconsole
can now set a reply to via sendTextMessageWithProperties("body=hi,JMSReplyTo=Queue2"

Modified:
    activemq/trunk/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/DestinationView.java
    activemq/trunk/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/DestinationViewMBean.java
    activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java

Modified: activemq/trunk/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/DestinationView.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/DestinationView.java?rev=1504660&r1=1504659&r2=1504660&view=diff
==============================================================================
--- activemq/trunk/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/DestinationView.java
(original)
+++ activemq/trunk/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/DestinationView.java
Thu Jul 18 21:09:43 2013
@@ -20,6 +20,7 @@ import java.io.IOException;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -51,6 +52,8 @@ import org.apache.activemq.command.Messa
 import org.apache.activemq.filter.BooleanExpression;
 import org.apache.activemq.filter.MessageEvaluationContext;
 import org.apache.activemq.selector.SelectorParser;
+import org.apache.activemq.util.IntrospectionSupport;
+import org.apache.activemq.util.MarshallingSupport;
 import org.apache.activemq.util.URISupport;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -284,6 +287,19 @@ public class DestinationView implements 
     }
 
     @Override
+    public String sendTextMessageWithProperties(String properties) throws Exception {
+        String[] kvs = properties.split(",");
+        Map<String, String> props = new HashMap<String, String>();
+        for (String kv : kvs) {
+            String[] it = kv.split("=");
+            if (it.length == 2) {
+                props.put(it[0],it[1]);
+            }
+        }
+        return sendTextMessage(props, props.remove("body"), props.remove("username"), props.remove("password"));
+    }
+
+    @Override
     public String sendTextMessage(String body) throws Exception {
         return sendTextMessage(Collections.EMPTY_MAP, body);
     }

Modified: activemq/trunk/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/DestinationViewMBean.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/DestinationViewMBean.java?rev=1504660&r1=1504659&r2=1504660&view=diff
==============================================================================
--- activemq/trunk/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/DestinationViewMBean.java
(original)
+++ activemq/trunk/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/DestinationViewMBean.java
Thu Jul 18 21:09:43 2013
@@ -148,6 +148,17 @@ public interface DestinationViewMBean {
     String sendTextMessage(@MBeanInfo("body") String body) throws Exception;
 
     /**
+     * Sends a TextMessage to the destination.
+     *
+     * @param properties the message properties to set as a comma sep name=value list. Can
only
+     *                contain Strings maped to primitive types or JMS properties. eg: body=hi,JMSReplyTo=Queue2
+     * @return the message id of the message sent.
+     * @throws Exception
+     */
+    @MBeanInfo("Sends a TextMessage to the destination.")
+    public String sendTextMessageWithProperties(String properties) throws Exception;
+
+    /**
      * Sends a TextMesage to the destination.
      *
      * @param headers the message headers and properties to set. Can only

Modified: activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java?rev=1504660&r1=1504659&r2=1504660&view=diff
==============================================================================
--- activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java
(original)
+++ activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java
Thu Jul 18 21:09:43 2013
@@ -92,6 +92,7 @@ public class MBeanTest extends EmbeddedB
         // test all the various MBeans now we have a producer, consumer and
         // messages on a queue
         assertSendViaMBean();
+        assertSendCsnvViaMBean();
         assertQueueBrowseWorks();
         assertCreateAndDestroyDurableSubscriptions();
         assertConsumerCounts();
@@ -394,6 +395,14 @@ public class MBeanTest extends EmbeddedB
             proxy.sendTextMessage(headers, body);
         }
 
+        browseAndVerify(proxy);
+    }
+
+    private void browseAndVerify(QueueViewMBean proxy) throws Exception {
+        browseAndVerifyTypes(proxy, false);
+    }
+
+    private void browseAndVerifyTypes(QueueViewMBean proxy, boolean allStrings) throws Exception
{
         CompositeData[] compdatalist = proxy.browse();
         if (compdatalist.length == 0) {
             fail("There is no message in the queue:");
@@ -418,17 +427,25 @@ public class MBeanTest extends EmbeddedB
             }
             assertComplexData(i, cdata, "PropertiesText", expected);
 
-            Map intProperties = CompositeDataHelper.getTabularMap(cdata, CompositeDataConstants.INT_PROPERTIES);
-            assertEquals("intProperties size()", 1, intProperties.size());
-            assertEquals("intProperties.MyHeader", i, intProperties.get("MyHeader"));
-
-            Map stringProperties = CompositeDataHelper.getTabularMap(cdata, CompositeDataConstants.STRING_PROPERTIES);
-            assertEquals("stringProperties size()", 1, stringProperties.size());
-            assertEquals("stringProperties.MyHeader", "StringHeader" + i, stringProperties.get("MyStringHeader"));
+            if (allStrings) {
+                Map stringProperties = CompositeDataHelper.getTabularMap(cdata, CompositeDataConstants.STRING_PROPERTIES);
+                assertEquals("stringProperties size()", 2, stringProperties.size());
+                assertEquals("stringProperties.MyHeader", "StringHeader" + i, stringProperties.get("MyStringHeader"));
+                assertEquals("stringProperties.MyHeader", "" + i, stringProperties.get("MyHeader"));
+
+            } else {
+                Map intProperties = CompositeDataHelper.getTabularMap(cdata, CompositeDataConstants.INT_PROPERTIES);
+                assertEquals("intProperties size()", 1, intProperties.size());
+                assertEquals("intProperties.MyHeader", i, intProperties.get("MyHeader"));
+
+                Map stringProperties = CompositeDataHelper.getTabularMap(cdata, CompositeDataConstants.STRING_PROPERTIES);
+                assertEquals("stringProperties size()", 1, stringProperties.size());
+                assertEquals("stringProperties.MyHeader", "StringHeader" + i, stringProperties.get("MyStringHeader"));
+            }
 
             Map properties = CompositeDataHelper.getMessageUserProperties(cdata);
             assertEquals("properties size()", 2, properties.size());
-            assertEquals("properties.MyHeader", i, properties.get("MyHeader"));
+            assertEquals("properties.MyHeader", allStrings ? "" + i : i, properties.get("MyHeader"));
             assertEquals("properties.MyHeader", "StringHeader" + i, properties.get("MyStringHeader"));
 
             assertComplexData(i, cdata, "JMSXGroupSeq", 1234);
@@ -437,6 +454,40 @@ public class MBeanTest extends EmbeddedB
         }
     }
 
+    protected void assertSendCsnvViaMBean() throws Exception {
+        String queueName = getDestinationString() + ".SendMBBean";
+
+        ObjectName brokerName = assertRegisteredObjectName(domain + ":type=Broker,brokerName=localhost");
+        echo("Create QueueView MBean...");
+        BrokerViewMBean broker = (BrokerViewMBean)MBeanServerInvocationHandler.newProxyInstance(mbeanServer,
brokerName, BrokerViewMBean.class, true);
+        broker.addQueue(queueName);
+
+        ObjectName queueViewMBeanName = assertRegisteredObjectName(domain + ":type=Broker,brokerName=localhost,destinationType=Queue,destinationName="
+ queueName);
+
+        echo("Create QueueView MBean...");
+        QueueViewMBean proxy = (QueueViewMBean)MBeanServerInvocationHandler.newProxyInstance(mbeanServer,
queueViewMBeanName, QueueViewMBean.class, true);
+
+        proxy.purge();
+
+        int count = 5;
+        for (int i = 0; i < count; i++) {
+            String props = "body=message:" + i;
+
+            props += ",JMSCorrelationID=MyCorrId";
+            props += ",JMSDeliveryMode=1";
+            props += ",JMSXGroupID=MyGroupID";
+            props += ",JMSXGroupSeq=1234";
+            props += ",JMSPriority=" + (i + 1);
+            props += ",JMSType=MyType";
+            props += ",MyHeader=" + i;
+            props += ",MyStringHeader=StringHeader" + i;
+
+            proxy.sendTextMessageWithProperties(props);
+        }
+
+        browseAndVerifyTypes(proxy, true);
+    }
+
     protected void assertComplexData(int messageIndex, CompositeData cdata, String name,
Object expected) {
         Object value = cdata.get(name);
         assertEquals("Message " + messageIndex + " CData field: " + name, expected, value);



Mime
View raw message