jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1333460 - in /jmeter/trunk: src/core/org/apache/jmeter/resources/ src/protocol/jms/org/apache/jmeter/protocol/jms/control/gui/ src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/ xdocs/ xdocs/usermanual/
Date Thu, 03 May 2012 13:49:56 GMT
Author: pmouawad
Date: Thu May  3 13:49:55 2012
New Revision: 1333460

URL: http://svn.apache.org/viewvc?rev=1333460&view=rev
Log:
Bug 52936 - JMS Publisher : Support sending of JMS Object Messages

Modified:
    jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
    jmeter/trunk/src/core/org/apache/jmeter/resources/messages_es.properties
    jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties
    jmeter/trunk/src/core/org/apache/jmeter/resources/messages_pt_BR.properties
    jmeter/trunk/src/core/org/apache/jmeter/resources/messages_tr.properties
    jmeter/trunk/src/core/org/apache/jmeter/resources/messages_zh_TW.properties
    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/PublisherSampler.java
    jmeter/trunk/xdocs/changes.xml
    jmeter/trunk/xdocs/usermanual/component_reference.xml

Modified: jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties?rev=1333460&r1=1333459&r2=1333460&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties Thu May  3 13:49:55
2012
@@ -394,7 +394,6 @@ jms_dest_setup=Setup
 jms_dest_setup_dynamic=Each sample
 jms_dest_setup_static=At startup
 jms_durable_subscription_id=Durable Subscription ID
-jms_error_msg=Object message should read from an external file. Text input is currently selected,
please remember to change it.
 jms_file=File
 jms_initial_context_factory=Initial Context Factory
 jms_itertions=Number of samples to aggregate
@@ -427,7 +426,7 @@ jms_subscriber_on_message=Use MessageLis
 jms_subscriber_receive=Use MessageConsumer.receive()
 jms_subscriber_title=JMS Subscriber
 jms_testing_title=Messaging Request
-jms_text_message=Text Message
+jms_text_message=Text Message or Object Message serialized to XML by XStream
 jms_timeout=Timeout (milliseconds)
 jms_topic=Destination
 jms_use_auth=Use Authorization?

Modified: jmeter/trunk/src/core/org/apache/jmeter/resources/messages_es.properties
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/resources/messages_es.properties?rev=1333460&r1=1333459&r2=1333460&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/resources/messages_es.properties (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/resources/messages_es.properties Thu May  3 13:49:55
2012
@@ -328,7 +328,6 @@ jms_correlation_title=Usar campos altern
 jms_dest_setup=Configuraci\u00F3n
 jms_dest_setup_dynamic=En cada muestra
 jms_dest_setup_static=Al arranque
-jms_error_msg=Object message deber\u00EDa leer de un archivo externo. Entrad de texto est\u00E1
seleccionada actu\u00E1lmente, recuerde cambiarlo.
 jms_file=Archivo
 jms_initial_context_factory=Factor\u00EDa de Initial Context
 jms_itertions=N\u00FAmero de muestras a agregar

Modified: jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties?rev=1333460&r1=1333459&r2=1333460&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties Thu May  3 13:49:55
2012
@@ -388,7 +388,6 @@ jms_dest_setup=Evaluer
 jms_dest_setup_dynamic=A chaque \u00E9chantillon
 jms_dest_setup_static=Au d\u00E9marrage
 jms_durable_subscription_id=ID d'abonnement durable
-jms_error_msg=L'objet du message peut \u00EAtre lu depuis un fichier externe. L'entr\u00E9e
par texte est actuellement s\u00E9lectionn\u00E9e, ne pas oublier de la changer
 jms_file=Fichier
 jms_initial_context_factory=Fabrique de connexion initiale
 jms_itertions=Nombre d'\u00E9chantillons \u00E0 agr\u00E9ger
@@ -421,7 +420,7 @@ jms_subscriber_on_message=Utiliser Messa
 jms_subscriber_receive=Utiliser MessageConsumer.receive()
 jms_subscriber_title=Requ\u00EAte JMS Abonnement
 jms_testing_title=Messagerie Request
-jms_text_message=Message texte
+jms_text_message=Message texte ou Message Objet s\u00E9rialis\u00E9 en XML par XStream
 jms_timeout=D\u00E9lai (millisecondes)
 jms_topic=Destination
 jms_use_auth=Utiliser l'authentification ?

Modified: jmeter/trunk/src/core/org/apache/jmeter/resources/messages_pt_BR.properties
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/resources/messages_pt_BR.properties?rev=1333460&r1=1333459&r2=1333460&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/resources/messages_pt_BR.properties (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/resources/messages_pt_BR.properties Thu May  3
13:49:55 2012
@@ -312,7 +312,6 @@ jms_concrete_connection_factory=F\u00E1b
 jms_config=Configura\u00E7\u00E3o
 jms_config_title=Configura\u00E7\u00E3o JMS
 jms_connection_factory=F\u00E1brica de Conex\u00E3o
-jms_error_msg=Mensagens deveriam ser lidas de um arquivo externo. Entrada de texto est\u00E1
selecionado agora, favor lembrar de alter\u00E1-la.
 jms_file=Arquivo
 jms_initial_context_factory=F\u00E1brica de Contexto Inicial
 jms_itertions=N\u00FAmeros de amostras para agregar

Modified: jmeter/trunk/src/core/org/apache/jmeter/resources/messages_tr.properties
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/resources/messages_tr.properties?rev=1333460&r1=1333459&r2=1333460&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/resources/messages_tr.properties (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/resources/messages_tr.properties Thu May  3 13:49:55
2012
@@ -296,7 +296,6 @@ jms_concrete_connection_factory=Somut Ba
 jms_config=Ayarlar
 jms_config_title=JMS Ayar\u0131
 jms_connection_factory=Ba\u011Flant\u0131 Fabrikas\u0131
-jms_error_msg=Nesne mesaj\u0131 harici bir dosyadan okunmal\u0131. Metin girdisi se\u00E7ili
durumda, l\u00FCtfen de\u011Fi\u015Ftirmeyi unutmay\u0131n.
 jms_file=Dosya
 jms_initial_context_factory=Ba\u015Flang\u0131\u00E7 Ba\u011Flam Fabrikas\u0131
 jms_itertions=Toplanacak istek say\u0131s\u0131

Modified: jmeter/trunk/src/core/org/apache/jmeter/resources/messages_zh_TW.properties
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/resources/messages_zh_TW.properties?rev=1333460&r1=1333459&r2=1333460&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/resources/messages_zh_TW.properties (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/resources/messages_zh_TW.properties Thu May  3
13:49:55 2012
@@ -246,7 +246,6 @@ jms_concrete_connection_factory=\u5805\u
 jms_config=\u8A2D\u7F6E
 jms_config_title=JMS \u8A2D\u7F6E
 jms_connection_factory=\u9023\u7DDA\u5DE5\u5EE0
-jms_error_msg=\u7269\u4EF6\u8A0A\u606F\u9808\u7531\u5916\u90E8\u6A94\u6848\u8B80\u5F97.\u76EE\u524D\u662F\u9078\u7528\u6587\u5B57\u8F38\u5165,\u8ACB\u8A18\u5F97\u8B8A\u66F4\u8A2D\u5B9A
 jms_file=\u6A94\u6848
 jms_initial_context_factory=JNDI \u521D\u59CB\u672C\u6587\u5DE5\u5EE0
 jms_itertions=\u8981\u7D2F\u8A08\u7684\u53D6\u6A23\u6578

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=1333460&r1=1333459&r2=1333460&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
Thu May  3 13:49:55 2012
@@ -24,7 +24,6 @@ import java.awt.Dimension;
 import javax.swing.Box;
 import javax.swing.BoxLayout;
 import javax.swing.JCheckBox;
-import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.event.ChangeEvent;
 import javax.swing.event.ChangeListener;
@@ -131,29 +130,11 @@ public class JMSPublisherGui extends Abs
      * @see org.apache.jmeter.gui.JMeterGUIComponent#createTestElement()
      */
     public TestElement createTestElement() {
-        PublisherSampler sampler = new PublisherSampler();
-        this.configureTestElement(sampler);
-        sampler.setUseJNDIProperties(String.valueOf(useProperties.isSelected()));
-        sampler.setJNDIIntialContextFactory(jndiICF.getText());
-        sampler.setProviderUrl(urlField.getText());
-        sampler.setConnectionFactory(jndiConnFac.getText());
-        sampler.setDestination(jmsDestination.getText());
-        sampler.setUsername(jmsUser.getText());
-        sampler.setPassword(jmsPwd.getText());
-        sampler.setTextMessage(textMessage.getText());
-        sampler.setInputFile(messageFile.getFilename());
-        sampler.setRandomPath(randomFile.getFilename());
-        sampler.setConfigChoice(configChoice.getText());
-        sampler.setMessageChoice(msgChoice.getText());
-        sampler.setIterations(iterations.getText());
-        sampler.setUseAuth(useAuth.isSelected());
-        sampler.setUseNonPersistentDelivery(useNonPersistentDelivery.isSelected());
-        Arguments args = (Arguments) jmsPropertiesPanel.createTestElement();
-        sampler.setJMSProperties(args);
-
-        return sampler;
-    }
+      PublisherSampler sampler = new PublisherSampler();
+      setupSamplerProperties(sampler);
 
+      return sampler;
+  }
     /**
      * Modifies a given TestElement to mirror the data in the gui components.
      *
@@ -161,26 +142,35 @@ public class JMSPublisherGui extends Abs
      */
     public void modifyTestElement(TestElement s) {
         PublisherSampler sampler = (PublisherSampler) s;
-        this.configureTestElement(sampler);
-        sampler.setUseJNDIProperties(String.valueOf(useProperties.isSelected()));
-        sampler.setJNDIIntialContextFactory(jndiICF.getText());
-        sampler.setProviderUrl(urlField.getText());
-        sampler.setConnectionFactory(jndiConnFac.getText());
-        sampler.setDestination(jmsDestination.getText());
-        sampler.setUsername(jmsUser.getText());
-        sampler.setPassword(jmsPwd.getText());
-        sampler.setTextMessage(textMessage.getText());
-        sampler.setInputFile(messageFile.getFilename());
-        sampler.setRandomPath(randomFile.getFilename());
-        sampler.setConfigChoice(configChoice.getText());
-        sampler.setMessageChoice(msgChoice.getText());
-        sampler.setIterations(iterations.getText());
-        sampler.setUseAuth(useAuth.isSelected());
+        setupSamplerProperties(sampler);
         sampler.setDestinationStatic(destSetup.getText().equals(DEST_SETUP_STATIC));
-        sampler.setUseNonPersistentDelivery(useNonPersistentDelivery.isSelected());
-        Arguments args = (Arguments) jmsPropertiesPanel.createTestElement();
-        sampler.setJMSProperties(args);
+    }
 
+    /**
+     * Initialize the provided {@link PublisherSampler} with all the values as configured
in the GUI.
+     * 
+     * @param sampler {@link PublisherSampler} instance
+     */
+    private void setupSamplerProperties(final PublisherSampler sampler) {
+      this.configureTestElement(sampler);
+      sampler.setUseJNDIProperties(String.valueOf(useProperties.isSelected()));
+      sampler.setJNDIIntialContextFactory(jndiICF.getText());
+      sampler.setProviderUrl(urlField.getText());
+      sampler.setConnectionFactory(jndiConnFac.getText());
+      sampler.setDestination(jmsDestination.getText());
+      sampler.setUsername(jmsUser.getText());
+      sampler.setPassword(jmsPwd.getText());
+      sampler.setTextMessage(textMessage.getText());
+      sampler.setInputFile(messageFile.getFilename());
+      sampler.setRandomPath(randomFile.getFilename());
+      sampler.setConfigChoice(configChoice.getText());
+      sampler.setMessageChoice(msgChoice.getText());
+      sampler.setIterations(iterations.getText());
+      sampler.setUseAuth(useAuth.isSelected());
+      sampler.setUseNonPersistentDelivery(useNonPersistentDelivery.isSelected());
+     
+      Arguments args = (Arguments) jmsPropertiesPanel.createTestElement();
+      sampler.setJMSProperties(args);
     }
 
     /**
@@ -283,8 +273,6 @@ public class JMSPublisherGui extends Abs
     public void stateChanged(ChangeEvent event) {
         if (event.getSource() == configChoice) {
             updateConfig(configChoice.getText());
-        } else if (event.getSource() == msgChoice) {
-            updateMessageType(msgChoice.getText());
         } else if (event.getSource() == useProperties) {
             jndiICF.setEnabled(!useProperties.isSelected());
             urlField.setEnabled(!useProperties.isSelected());
@@ -315,21 +303,6 @@ public class JMSPublisherGui extends Abs
             randomFile.enableFile(false);
         }
     }
-
-    /**
-     *
-     * @param msgType
-     */
-    private void updateMessageType(String msgType) {
-        if (msgType.equals(OBJECT_MSG_RSC)) {
-            if (configChoice.getText().equals(USE_TEXT_RSC)) {
-                JOptionPane.showConfirmDialog(this,
-                        JMeterUtils.getResString("jms_error_msg"),  //$NON-NLS-1$
-                        "Warning",
-                        JOptionPane.OK_CANCEL_OPTION, JOptionPane.ERROR_MESSAGE);
-            }
-        }
-    }
     
     /**
      * @return JPanel that contains destination infos

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=1333460&r1=1333459&r2=1333460&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
Thu May  3 13:49:55 2012
@@ -17,6 +17,9 @@
 
 package org.apache.jmeter.protocol.jms.sampler;
 
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.io.Serializable;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.util.HashMap;
@@ -40,8 +43,11 @@ import org.apache.jmeter.testelement.pro
 import org.apache.jmeter.util.JMeterUtils;
 import org.apache.jorphan.io.TextFile;
 import org.apache.jorphan.logging.LoggingManager;
+import org.apache.jorphan.util.JOrphanUtils;
 import org.apache.log.Logger;
 
+import com.thoughtworks.xstream.XStream;
+
 /**
  * This class implements the JMS Publisher sampler.
  */
@@ -76,6 +82,9 @@ public class PublisherSampler extends Ba
 
     // Cache for file. Only used by sample() in a single thread
     private String file_contents = null;
+    // Cache for object-message, only used when parsing from a file because in text-area
+    // property replacement might have been used
+    private Serializable object_msg_file_contents = null;
 
     public PublisherSampler() {
     }
@@ -168,7 +177,9 @@ public class PublisherSampler extends Ba
                     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");
+                    Serializable omsg = getObjectContent();
+                    Message msg = publisher.publish(omsg, getDestination(), getJMSProperties().getArgumentsAsMap());
+                    Utils.messageProperties(propBuffer, msg);
                 } else {
                     throw new JMSException(type+ " is not recognised");                 
  
                 }
@@ -252,6 +263,79 @@ public class PublisherSampler extends Ba
         return tf.getText();
     }
 
+    /**
+     * This method will load the contents for the JMS Object Message.
+     * The contents are either loaded from file (might be cached), random file
+     * or from the GUI text-area.
+     * 
+     * @return Serialized object as loaded from the specified input file
+     */
+    private Serializable getObjectContent() {
+        if (getConfigChoice().equals(JMSPublisherGui.USE_FILE_RSC)) {
+            // in the case the test uses a file, we set it locally and
+            // prevent loading the file repeatedly
+            if (object_msg_file_contents == null) {
+                object_msg_file_contents = getFileObjectContent(getInputFile());
+            }
+
+            return object_msg_file_contents;
+        } else if (getConfigChoice().equals(JMSPublisherGui.USE_RANDOM_RSC)) {
+            // Maybe we should consider creating a global cache for the
+            // random files to make JMeter more efficient.
+            final String fname = FSERVER.getRandomFile(getRandomPath(), new String[] {".txt",
".obj"})
+                .getAbsolutePath();
+
+            return getFileObjectContent(fname);
+        } else {
+            final String xmlMessage = getTextMessage();
+            return transformXmlToObjectMessage(xmlMessage);
+        }
+    }
+    
+    /**
+     * Try to load an object from a provided file, so that it can be used as body
+     * for a JMS message.
+     * An {@link IllegalStateException} will be thrown if loading the object fails.
+     * 
+     * @param path Path to the file that will be serialized
+     * @return Serialized object instance
+     */
+    private static Serializable getFileObjectContent(final String path) {
+      Serializable readObject = null;
+      InputStream inputStream = null;
+      try {
+          inputStream = new FileInputStream(path);
+          XStream xstream = new XStream();
+        readObject = (Serializable) xstream.fromXML(inputStream, readObject);
+      } catch (Exception e) {
+          log.error(e.getLocalizedMessage(), e);
+          throw new IllegalStateException("Unable to load object instance from file", e);
+      } finally {
+          JOrphanUtils.closeQuietly(inputStream);
+      }
+      return readObject;
+    }
+    
+    /**
+     * Try to load an object via XStream from XML text, so that it can be used as body
+     * for a JMS message.
+     * An {@link IllegalStateException} will be thrown if transforming the XML to an object
fails.
+     *
+     * @param xmlMessage String containing XML text as input for the transformation
+     * @return Serialized object instance
+     */
+    private static Serializable transformXmlToObjectMessage(final String xmlMessage) {
+      Serializable readObject = null;
+      try {
+          XStream xstream = new XStream();
+          readObject = (Serializable) xstream.fromXML(xmlMessage, readObject);
+      } catch (Exception e) {
+          log.error(e.getLocalizedMessage(), e);
+          throw new IllegalStateException("Unable to load object instance from text", e);
+      }
+      return readObject;
+    }
+    
     // ------------- get/set properties ----------------------//
     /**
      * set the source of the message

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1333460&r1=1333459&r2=1333460&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Thu May  3 13:49:55 2012
@@ -171,6 +171,7 @@ Graph Full Results Listener has been rem
 <li>Bug 53073 - Allow to assign the OUT result of a JDBC CALLABLE to JMeter variables</li>
 <li>Bug 53164 - New System Sampler</li>
 <li>Bug 53172 - OS Process Sampler - allow specification of Environment Variables</li>
+<li>Bug 52936 - JMS Publisher : Support sending of JMS Object Messages</li>
 </ul>
 
 <h3>Controllers</h3>

Modified: jmeter/trunk/xdocs/usermanual/component_reference.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/usermanual/component_reference.xml?rev=1333460&r1=1333459&r2=1333460&view=diff
==============================================================================
--- jmeter/trunk/xdocs/usermanual/component_reference.xml (original)
+++ jmeter/trunk/xdocs/usermanual/component_reference.xml Thu May  3 13:49:55 2012
@@ -1310,7 +1310,16 @@ size,Integer,1234
 This is a very simple implementation; it is not intended to support all possible object types.
 </p>
 <p>
-<b>Note: </b> the Object message type is not implemented yet.
+<note> 
+The Object message is implemented since 2.7 and works as follow:
+<ul>
+<li>Put the JAR that contain you object and its dependencies in jmeter_home/lib/ folder
</li>
+<li>Serialize your object as XML using XStream</li>
+<li>Either put result in a file suffixed with .txt or .obj or put XML content direclty
in Text Area</li>  
+</ul>
+Note that if message is in an file, replacement of properties will not occur while it will
happen if you use Text Area.
+</note>
+
 </p>
 <p>
 The following table shows some values which may be useful when configuring JMS:



Mime
View raw message