Author: pmouawad
Date: Sun Mar 11 09:00:56 2012
New Revision: 1299341
URL: http://svn.apache.org/viewvc?rev=1299341&view=rev
Log:
Bug 52810 - Enable setting JMS Properties through JMS Publisher sampler
Modified:
jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/Utils.java
jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/Publisher.java
jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/control/gui/JMSPublisherGui.java
jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/JMSSampler.java
jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/PublisherSampler.java
jmeter/trunk/xdocs/changes.xml
Modified:
jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/Utils.java
URL:
http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/Utils.java?rev=1299341&r1=1299340&r2=1299341&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/Utils.java
(original)
+++ jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/Utils.java Sun
Mar 11 09:00:56 2012
@@ -31,6 +31,7 @@ import javax.jms.Session;
import javax.naming.Context;
import javax.naming.NamingException;
+import org.apache.jorphan.logging.LoggingManager;
import org.apache.log.Logger;
/**
@@ -38,6 +39,7 @@ import org.apache.log.Logger;
* WARNING - the API for this class is likely to change!
*/
public final class Utils {
+ private static final Logger log = LoggingManager.getLoggerForClass();
public static void close(MessageConsumer closeable, Logger log){
if (closeable != null){
@@ -162,4 +164,30 @@ public final class Utils {
}
throw new NamingException("Expected javax.jms.ConnectionFactory, found
"+objfac.getClass().getName());
}
+
+ /**
+ * Set JMS Properties to msg
+ * @param msg Message
+ * @param map Map<String, String>
+ * @throws JMSException
+ */
+ public static void addJMSProperties(Message msg, Map<String, String> map)
throws JMSException {
+ if(map == null) {
+ return;
+ }
+ for (Map.Entry<String, String> me : map.entrySet()) {
+ String name = me.getKey();
+ String value = me.getValue();
+ if (log.isDebugEnabled()) {
+ log.debug("Adding property [" + name + "=" + value + "]");
+ }
+
+ // WebsphereMQ does not allow corr. id. to be set using
setStringProperty()
+ if("JMSCorrelationID".equalsIgnoreCase(name)) { // $NON-NLS-1$
+ msg.setJMSCorrelationID(value);
+ } else {
+ msg.setStringProperty(name, value);
+ }
+ }
+ }
}
Modified:
jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/Publisher.java
URL:
http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/Publisher.java?rev=1299341&r1=1299340&r2=1299341&view=diff
==============================================================================
---
jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/Publisher.java
(original)
+++
jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/Publisher.java
Sun Mar 11 09:00:56 2012
@@ -53,6 +53,7 @@ public class Publisher implements Closea
private final boolean staticDest;
+
/**
* Create a publisher using either the jndi.properties file or the
provided parameters.
* Uses a static destination and persistent messages(for backward
compatibility)
@@ -146,12 +147,18 @@ public class Publisher implements Closea
public TextMessage publish(String text) throws JMSException,
NamingException {
- return publish(text, null);
+ return publish(text, null, null);
}
public TextMessage publish(String text, String destinationName)
throws JMSException, NamingException {
+ return publish(text, destinationName, null);
+ }
+
+ public TextMessage publish(String text, String destinationName,
Map<String, String> properties)
+ throws JMSException, NamingException {
TextMessage msg = session.createTextMessage(text);
+ Utils.addJMSProperties(msg, properties);
if (staticDest || destinationName == null) {
producer.send(msg);
} else {
@@ -160,15 +167,21 @@ public class Publisher implements Closea
}
return msg;
}
-
+
public ObjectMessage publish(Serializable contents) throws JMSException,
NamingException {
return publish(contents, null);
}
+
+ public ObjectMessage publish(Serializable contents, String
destinationName)
+ throws JMSException, NamingException {
+ return publish(contents, destinationName, null);
+ }
- public ObjectMessage publish(Serializable contents, String destinationName)
+ public ObjectMessage publish(Serializable contents, String
destinationName, Map<String, String> properties)
throws JMSException, NamingException {
ObjectMessage msg = session.createObjectMessage(contents);
+ Utils.addJMSProperties(msg, properties);
if (staticDest || destinationName == null) {
producer.send(msg);
} else {
@@ -180,12 +193,18 @@ public class Publisher implements Closea
public MapMessage publish(Map<String, Object> map) throws JMSException,
NamingException {
- return publish(map, null);
+ return publish(map, null, null);
}
public MapMessage publish(Map<String, Object> map, String destinationName)
throws JMSException, NamingException {
+ return publish(map, destinationName, null);
+ }
+
+ public MapMessage publish(Map<String, Object> map, String destinationName,
Map<String, String> properties)
+ throws JMSException, NamingException {
MapMessage msg = session.createMapMessage();
+ Utils.addJMSProperties(msg, properties);
for (Entry<String, Object> me : map.entrySet()) {
msg.setObject(me.getKey(), me.getValue());
}
Modified:
jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/control/gui/JMSPublisherGui.java
URL:
http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/control/gui/JMSPublisherGui.java?rev=1299341&r1=1299340&r2=1299341&view=diff
==============================================================================
---
jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/control/gui/JMSPublisherGui.java
(original)
+++
jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/control/gui/JMSPublisherGui.java
Sun Mar 11 09:00:56 2012
@@ -21,6 +21,7 @@ package org.apache.jmeter.protocol.jms.c
import java.awt.BorderLayout;
import java.awt.Dimension;
+import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JCheckBox;
import javax.swing.JOptionPane;
@@ -28,6 +29,8 @@ import javax.swing.JPanel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
+import org.apache.jmeter.config.Arguments;
+import org.apache.jmeter.config.gui.ArgumentsPanel;
import org.apache.jmeter.gui.util.FilePanel;
import org.apache.jmeter.gui.util.JLabeledRadioI18N;
import org.apache.jmeter.gui.util.VerticalPanel;
@@ -111,6 +114,8 @@ public class JMSPublisherGui extends Abs
private final JLabeledRadioI18N destSetup =
new JLabeledRadioI18N("jms_dest_setup", DEST_SETUP_ITEMS,
DEST_SETUP_STATIC); // $NON-NLS-1$
+ private ArgumentsPanel jmsPropertiesPanel;
+
public JMSPublisherGui() {
init();
}
@@ -143,6 +148,9 @@ public class JMSPublisherGui extends Abs
sampler.setIterations(iterations.getText());
sampler.setUseAuth(useAuth.isSelected());
sampler.setUseNonPersistentDelivery(useNonPersistentDelivery.isSelected());
+ Arguments args = (Arguments) jmsPropertiesPanel.createTestElement();
+ sampler.setJMSProperties(args);
+
return sampler;
}
@@ -170,6 +178,9 @@ public class JMSPublisherGui extends Abs
sampler.setUseAuth(useAuth.isSelected());
sampler.setDestinationStatic(destSetup.getText().equals(DEST_SETUP_STATIC));
sampler.setUseNonPersistentDelivery(useNonPersistentDelivery.isSelected());
+ Arguments args = (Arguments) jmsPropertiesPanel.createTestElement();
+ sampler.setJMSProperties(args);
+
}
/**
@@ -189,11 +200,12 @@ public class JMSPublisherGui extends Abs
mainPanel.add(urlField);
mainPanel.add(jndiConnFac);
mainPanel.add(createDestinationPane());
- mainPanel.add(useAuth);
- mainPanel.add(jmsUser);
- mainPanel.add(jmsPwd);
+ mainPanel.add(createAuthPane());
mainPanel.add(iterations);
+ jmsPropertiesPanel = new
ArgumentsPanel(JMeterUtils.getResString("jms_props")); //$NON-NLS-1$
+ mainPanel.add(jmsPropertiesPanel);
+
configChoice.setLayout(new BoxLayout(configChoice, BoxLayout.X_AXIS));
mainPanel.add(configChoice);
msgChoice.setLayout(new BoxLayout(msgChoice, BoxLayout.X_AXIS));
@@ -232,6 +244,7 @@ public class JMSPublisherGui extends Abs
jmsPwd.setEnabled(false);
destSetup.setText(DEST_SETUP_STATIC);
useNonPersistentDelivery.setSelected(false);
+ jmsPropertiesPanel.clear();
}
/**
@@ -260,6 +273,7 @@ public class JMSPublisherGui extends Abs
jmsPwd.setEnabled(useAuth.isSelected());
destSetup.setText(sampler.isDestinationStatic() ? DEST_SETUP_STATIC :
DEST_SETUP_DYNAMIC);
useNonPersistentDelivery.setSelected(sampler.getUseNonPersistentDelivery());
+ jmsPropertiesPanel.configure(sampler.getJMSProperties());
}
/**
@@ -317,6 +331,9 @@ public class JMSPublisherGui extends Abs
}
}
+ /**
+ * @return JPanel that contains destination infos
+ */
private JPanel createDestinationPane() {
JPanel pane = new JPanel(new BorderLayout(3, 0));
pane.add(jmsDestination, BorderLayout.WEST);
@@ -326,4 +343,18 @@ public class JMSPublisherGui extends Abs
pane.add(useNonPersistentDelivery, BorderLayout.EAST);
return pane;
}
+
+ /**
+ * @return JPanel Panel with checkbox to choose auth , user and password
+ */
+ private JPanel createAuthPane() {
+ JPanel pane = new JPanel();
+ pane.setLayout(new BoxLayout(pane, BoxLayout.X_AXIS));
+ pane.add(useAuth);
+ pane.add(Box.createHorizontalStrut(10));
+ pane.add(jmsUser);
+ pane.add(Box.createHorizontalStrut(10));
+ pane.add(jmsPwd);
+ return pane;
+ }
}
Modified:
jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/JMSSampler.java
URL:
http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/JMSSampler.java?rev=1299341&r1=1299340&r2=1299341&view=diff
==============================================================================
---
jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/JMSSampler.java
(original)
+++
jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/JMSSampler.java
Sun Mar 11 09:00:56 2012
@@ -186,20 +186,7 @@ public class JMSSampler extends Abstract
private void addJMSProperties(TextMessage msg) throws JMSException {
Map<String, String> map =
getArguments(JMSSampler.JMS_PROPERTIES).getArgumentsAsMap();
- for (Map.Entry<String, String> me : map.entrySet()) {
- String name = me.getKey();
- String value = me.getValue();
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("Adding property [" + name + "=" + value + "]");
- }
-
- // WebsphereMQ does not allow corr. id. to be set using
setStringProperty()
- if("JMSCorrelationID".equalsIgnoreCase(name)) { // $NON-NLS-1$
- msg.setJMSCorrelationID(value);
- } else {
- msg.setStringProperty(name, value);
- }
- }
+ Utils.addJMSProperties(msg, map);
}
public Arguments getJMSProperties() {
Modified:
jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/PublisherSampler.java
URL:
http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/PublisherSampler.java?rev=1299341&r1=1299340&r2=1299341&view=diff
==============================================================================
---
jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/PublisherSampler.java
(original)
+++
jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/PublisherSampler.java
Sun Mar 11 09:00:56 2012
@@ -26,18 +26,19 @@ import javax.jms.JMSException;
import javax.jms.Message;
import javax.naming.NamingException;
-import org.apache.jorphan.io.TextFile;
-import org.apache.jmeter.samplers.SampleResult;
-import org.apache.jmeter.services.FileServer;
-import org.apache.jmeter.testelement.TestListener;
-import org.apache.jmeter.util.JMeterUtils;
+import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.engine.event.LoopIterationEvent;
import org.apache.jmeter.protocol.jms.Utils;
-import org.apache.jmeter.protocol.jms.control.gui.JMSPublisherGui;
import org.apache.jmeter.protocol.jms.client.ClientPool;
import org.apache.jmeter.protocol.jms.client.InitialContextFactory;
import org.apache.jmeter.protocol.jms.client.Publisher;
-
+import org.apache.jmeter.protocol.jms.control.gui.JMSPublisherGui;
+import org.apache.jmeter.samplers.SampleResult;
+import org.apache.jmeter.services.FileServer;
+import org.apache.jmeter.testelement.TestListener;
+import org.apache.jmeter.testelement.property.TestElementProperty;
+import org.apache.jmeter.util.JMeterUtils;
+import org.apache.jorphan.io.TextFile;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.log.Logger;
@@ -62,6 +63,9 @@ public class PublisherSampler extends Ba
private static final String MESSAGE_CHOICE = "jms.config_msg_type";
//$NON-NLS-1$
private static final String NON_PERSISTENT_DELIVERY =
"jms.non_persistent"; //$NON-NLS-1$
+
+ private static final String JMS_PROPERTIES = "jms.jmsProperties"; //
$NON-NLS-1$
+
//--
// Does not need to be synch. because it is only accessed from the sampler
thread
@@ -156,12 +160,12 @@ public class PublisherSampler extends Ba
for (int idx = 0; idx < loop; idx++) {
if (JMSPublisherGui.TEXT_MSG_RSC.equals(type)){
String tmsg = getMessageContent();
- Message msg = publisher.publish(tmsg, getDestination());
+ Message msg = publisher.publish(tmsg, getDestination(),
getJMSProperties().getArgumentsAsMap());
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, getDestination());
+ Message msg = publisher.publish(m, getDestination(),
getJMSProperties().getArgumentsAsMap());
Utils.messageProperties(propBuffer, msg);
} else if (JMSPublisherGui.OBJECT_MSG_RSC.equals(type)){
throw new JMSException(type+ " is not yet supported");
@@ -183,6 +187,7 @@ 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();
@@ -360,4 +365,31 @@ public class PublisherSampler extends Ba
public boolean getUseNonPersistentDelivery() {
return getPropertyAsBoolean(NON_PERSISTENT_DELIVERY, false);
}
+
+ public void setArguments(Arguments args) {
+ setProperty(new TestElementProperty(JMS_PROPERTIES, args));
+ }
+
+ public Arguments getArguments(String name) {
+ return (Arguments) getProperty(name).getObjectValue();
+ }
+
+ /**
+ * @return Arguments JMS Properties
+ */
+ public Arguments getJMSProperties() {
+ Arguments arguments = getArguments(JMS_PROPERTIES);
+ if(arguments == null) {
+ arguments = new Arguments();
+ setArguments(arguments);
+ }
+ return arguments;
+ }
+
+ /**
+ * @param args Arguments JMS Properties
+ */
+ public void setJMSProperties(Arguments args) {
+ setProperty(new TestElementProperty(JMS_PROPERTIES, args));
+ }
}
Modified: jmeter/trunk/xdocs/changes.xml
URL:
http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1299341&r1=1299340&r2=1299341&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Sun Mar 11 09:00:56 2012
@@ -134,6 +134,7 @@ When doing replacement of User Defined V
<h3>Other samplers</h3>
<ul>
<li>Bug 52775 - JMS Publisher : Add Non Persistent Delivery option</li>
+<li>Bug 52810 - Enable setting JMS Properties through JMS Publisher
sampler</li>
</ul>
<h3>Controllers</h3>