Author: sebb
Date: Wed Jun 23 00:54:03 2010
New Revision: 957092
URL: http://svn.apache.org/viewvc?rev=957092&view=rev
Log:
Support basic MapMessage generation
Modified:
jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/control/gui/JMSPublisherGui.java
jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/PublisherSampler.java
Modified:
jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties?rev=957092&r1=957091&r2=957092&view=diff
==============================================================================
---
jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
(original)
+++
jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
Wed Jun 23 00:54:03 2010
@@ -338,7 +338,7 @@ jms_client_caption2=MessageListener uses
jms_client_type=Client
jms_communication_style=Communication style
jms_concrete_connection_factory=Concrete Connection Factory
-jms_config=Configuration
+jms_config=Message source
jms_config_title=JMS Configuration
jms_connection_factory=Connection Factory
jms_correlation_title=Use alternate fields for message correlation
@@ -348,6 +348,7 @@ jms_initial_context_factory=Initial Cont
jms_itertions=Number of samples to aggregate
jms_jndi_defaults_title=JNDI Default Configuration
jms_jndi_props=JNDI Properties
+jms_map_message=Map Message
jms_message_title=Message properties
jms_message_type=Message Type
jms_msg_content=Content
Modified:
jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/control/gui/JMSPublisherGui.java
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/control/gui/JMSPublisherGui.java?rev=957092&r1=957091&r2=957092&view=diff
==============================================================================
---
jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/control/gui/JMSPublisherGui.java
(original)
+++
jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/control/gui/JMSPublisherGui.java
Wed Jun 23 00:54:03 2010
@@ -54,18 +54,25 @@ public class JMSPublisherGui extends Abs
private static final String ALL_FILES = "*.*"; //$NON-NLS-1$
//++ These names are used in the JMX files, and must not be changed
+ /** Take source from the named file */
public static final String USE_FILE_RSC = "jms_use_file"; //$NON-NLS-1$
+ /** Take source from a random file */
public static final String USE_RANDOM_RSC = "jms_use_random_file";
//$NON-NLS-1$
+ /** Take source from the text area */
private static final String USE_TEXT_RSC = "jms_use_text"; //$NON-NLS-1$
- private static final String TEXT_MSG_RSC = "jms_text_message";
//$NON-NLS-1$
- private static final String OBJECT_MSG_RSC = "jms_object_message";
//$NON-NLS-1$
+ /** Create a TextMessage */
+ public static final String TEXT_MSG_RSC = "jms_text_message"; //$NON-NLS-1$
+ /** Create a MapMessage */
+ public static final String MAP_MSG_RSC = "jms_map_message"; //$NON-NLS-1$
+ /** Create an ObjectMessage */
+ public static final String OBJECT_MSG_RSC = "jms_object_message";
//$NON-NLS-1$
//--
// Button group resources
private static final String[] CONFIG_ITEMS = { USE_FILE_RSC,
USE_RANDOM_RSC, USE_TEXT_RSC };
- private static final String[] MSGTYPES_ITEMS = { TEXT_MSG_RSC,
OBJECT_MSG_RSC };
+ private static final String[] MSGTYPES_ITEMS = { TEXT_MSG_RSC,
MAP_MSG_RSC, OBJECT_MSG_RSC };
private final JCheckBox useProperties = new
JCheckBox(JMeterUtils.getResString("jms_use_properties_file"), false);
//$NON-NLS-1$
@@ -91,7 +98,7 @@ public class JMSPublisherGui extends Abs
private final FilePanel randomFile = new
FilePanel(JMeterUtils.getResString("jms_random_file"), ALL_FILES); //$NON-NLS-1$
- private final JLabeledTextArea textMessage = new
JLabeledTextArea(TEXT_MSG_RSC);
+ private final JLabeledTextArea textMessage = new
JLabeledTextArea(JMeterUtils.getResString("jms_text_message"));
private final JLabeledRadioI18N msgChoice = new
JLabeledRadioI18N("jms_message_type", MSGTYPES_ITEMS, TEXT_MSG_RSC);
//$NON-NLS-1$
Modified:
jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/PublisherSampler.java
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/PublisherSampler.java?rev=957092&r1=957091&r2=957092&view=diff
==============================================================================
---
jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/PublisherSampler.java
(original)
+++
jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/PublisherSampler.java
Wed Jun 23 00:54:03 2010
@@ -17,6 +17,11 @@
package org.apache.jmeter.protocol.jms.sampler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
import javax.jms.JMSException;
import javax.jms.Message;
import javax.naming.NamingException;
@@ -152,12 +157,23 @@ public class PublisherSampler extends Ba
StringBuilder propBuffer = new StringBuilder();
int loop = getIterationCount();
result.sampleStart();
+ String type = getMessageChoice();
try {
for (int idx = 0; idx < loop; idx++) {
- String tmsg = getMessageContent();
- Message msg = publisher.publish(tmsg);
- buffer.append(tmsg);
- Utils.messageProperties(propBuffer, msg);
+ if (JMSPublisherGui.TEXT_MSG_RSC.equals(type)){
+ String tmsg = getMessageContent();
+ Message msg = publisher.publish(tmsg);
+ buffer.append(tmsg);
+ Utils.messageProperties(propBuffer, msg);
+ } else if (JMSPublisherGui.MAP_MSG_RSC.equals(type)){
+ Map<String, Object> m = getMapContent();
+ Message msg = publisher.publish(m);
+ Utils.messageProperties(propBuffer, msg);
+ } else if (JMSPublisherGui.OBJECT_MSG_RSC.equals(type)){
+ throw new JMSException(type+ " is not yet supported");
+ } else {
+ throw new JMSException(type+ " is not recognised");
+ }
}
result.setResponseCodeOK();
result.setResponseMessage(loop + " messages published");
@@ -173,6 +189,34 @@ public class PublisherSampler extends Ba
return result;
}
+ private Map<String, Object> getMapContent() throws ClassNotFoundException,
SecurityException, NoSuchMethodException, IllegalArgumentException,
IllegalAccessException, InvocationTargetException {
+ Map<String,Object> m = new HashMap<String,Object>();
+ String text = getMessageContent();
+ String[] lines = text.split("\n");
+ for (String line : lines){
+ String[] parts = line.split(",",3);
+ if (parts.length != 3) {
+ throw new IllegalArgumentException("line must have 3 parts:
"+line);
+ }
+ String name = parts[0];
+ String type = parts[1];
+ if (!type.contains(".")){// Allow shorthand names
+ type = "java.lang."+type;
+ }
+ String value = parts[2];
+ Object obj;
+ if (type.equals("java.lang.String")){
+ obj = value;
+ } else {
+ Class <?> clazz = Class.forName(type);
+ Method method = clazz.getMethod("valueOf", new
Class<?>[]{String.class});
+ obj = method.invoke(clazz, value);
+ }
+ m.put(name, obj);
+ }
+ return m;
+ }
+
/**
* Method will check the setting and get the contents for the message.
*
@@ -211,7 +255,7 @@ public class PublisherSampler extends Ba
// ------------- get/set properties ----------------------//
/**
- * set the config choice
+ * set the source of the message
*
* @param choice
*/
@@ -224,7 +268,7 @@ public class PublisherSampler extends Ba
private static final String USE_RANDOM_LOCALNAME =
JMeterUtils.getResString(JMSPublisherGui.USE_RANDOM_RSC);
/**
- * return the config choice
+ * return the source of the message
* Converts from old JMX files which used the local language string
*/
public String getConfigChoice() {
@@ -242,7 +286,7 @@ public class PublisherSampler extends Ba
}
/**
- * set the source of the message
+ * set the type of the message
*
* @param choice
*/
@@ -251,7 +295,7 @@ public class PublisherSampler extends Ba
}
/**
- * return the source of the message
+ * return the type of the message (Text, Object, Map)
*
*/
public String getMessageChoice() {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]