jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1429128 - in /jmeter/trunk: src/core/org/apache/jmeter/gui/util/ src/core/org/apache/jmeter/resources/ src/protocol/jms/org/apache/jmeter/protocol/jms/client/ src/protocol/jms/org/apache/jmeter/protocol/jms/control/gui/ src/protocol/jms/or...
Date Fri, 04 Jan 2013 21:06:47 GMT
Author: pmouawad
Date: Fri Jan  4 21:06:46 2013
New Revision: 1429128

URL: http://svn.apache.org/viewvc?rev=1429128&view=rev
Log:
Bug 54182 - Support sending of ByteMessage for JMS Publisher. 
Bugzilla Id: 54182

Modified:
    jmeter/trunk/src/core/org/apache/jmeter/gui/util/JLabeledRadioI18N.java
    jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
    jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties
    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/PublisherSampler.java
    jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/SubscriberSampler.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/src/core/org/apache/jmeter/gui/util/JLabeledRadioI18N.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/gui/util/JLabeledRadioI18N.java?rev=1429128&r1=1429127&r2=1429128&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/gui/util/JLabeledRadioI18N.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/gui/util/JLabeledRadioI18N.java Fri Jan  4 21:06:46
2013
@@ -78,7 +78,7 @@ public class JLabeledRadioI18N extends J
      * the ButtonGroup.
      *
      * The resource name is used as the action command for the button model,
-     * and the reource value is used to set the button label.
+     * and the resource value is used to set the button label.
      *
      * @param resouces list of resource names
      * @param selected initially selected resource (if not null)
@@ -86,6 +86,21 @@ public class JLabeledRadioI18N extends J
      */
     private void init(String[] resouces, String selected) {
         this.add(mLabel);
+        initButtonGroup(resouces, selected);
+    }
+
+    /**
+     * Method is responsible for creating the JRadioButtons and adding them to
+     * the ButtonGroup.
+     *
+     * The resource name is used as the action command for the button model,
+     * and the resource value is used to set the button label.
+     *
+     * @param resouces list of resource names
+     * @param selected initially selected resource (if not null)
+     *
+     */
+    private void initButtonGroup(String[] resouces, String selected) {
         for (int idx = 0; idx < resouces.length; idx++) {
             JRadioButton btn = new JRadioButton(JMeterUtils.getResString(resouces[idx]));
             btn.setActionCommand(resouces[idx]);
@@ -99,6 +114,36 @@ public class JLabeledRadioI18N extends J
             }
         }
     }
+    
+    /**
+     * Method is responsible for removing current JRadioButtons of ButtonGroup and
+     * add creating the JRadioButtons and adding them to
+     * the ButtonGroup.
+     *
+     * The resource name is used as the action command for the button model,
+     * and the resource value is used to set the button label.
+     *
+     * @param resouces list of resource names
+     * @param selected initially selected resource (if not null)
+     *
+     */
+    public void resetButtons(String[] resouces, String selected) {
+        Enumeration<AbstractButton> buttons = bGroup.getElements();
+        List<AbstractButton> buttonsToRemove = new ArrayList<AbstractButton>(this.bGroup.getButtonCount());
+        while (buttons.hasMoreElements()) {
+            AbstractButton abstractButton = buttons
+                    .nextElement();
+            buttonsToRemove.add(abstractButton);
+        }
+        for (AbstractButton abstractButton : buttonsToRemove) {
+            abstractButton.removeActionListener(this);
+            bGroup.remove(abstractButton);
+        }
+        for (AbstractButton abstractButton : buttonsToRemove) {
+            this.remove(abstractButton);
+        }
+        initButtonGroup(resouces, selected);
+    }
 
     /**
      * The implementation will get the resource name from the selected radio button

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=1429128&r1=1429127&r2=1429128&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties Fri Jan  4 21:06:46
2013
@@ -414,6 +414,7 @@ java_request_defaults=Java Request Defau
 javascript_expression=JavaScript expression to evaluate
 jexl_expression=JEXL expression to evaluate
 jms_auth_required=Required
+jms_bytes_message=Bytes Message
 jms_client_caption=Receiver client uses MessageConsumer.receive() to listen for message.
 jms_client_caption2=MessageListener uses onMessage(Message) interface to listen for new messages.
 jms_client_id=Client ID
@@ -446,7 +447,7 @@ jms_pwd=Password
 jms_queue=Queue
 jms_queue_connection_factory=QueueConnection Factory
 jms_queueing=JMS Resources
-jms_random_file=Random File
+jms_random_file=Random folder containing files ending with .dat for bytes messages, .txt
or .obj for text and Object messages
 jms_read_response=Read Response
 jms_receive_queue=JNDI name Receive queue
 jms_request=Request Only

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=1429128&r1=1429127&r2=1429128&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 Fri Jan  4 21:06:46
2013
@@ -408,6 +408,7 @@ java_request_defaults=Requ\u00EAte Java 
 javascript_expression=Expression JavaScript \u00E0 \u00E9valuer
 jexl_expression=Expression JEXL \u00E0 \u00E9valuer
 jms_auth_required=Obligatoire
+jms_bytes_message=Message binaire
 jms_client_caption=Le client r\u00E9cepteur utilise MessageConsumer.receive () pour \u00E9couter
les messages.
 jms_client_caption2=MessageListener utilise l'interface onMessage(Message) pour \u00E9couter
les nouveaux messages.
 jms_client_id=ID du Client
@@ -440,7 +441,7 @@ jms_pwd=Mot de passe
 jms_queue=File
 jms_queue_connection_factory=Fabrique QueueConnection
 jms_queueing=Ressources JMS
-jms_random_file=Fichier al\u00E9atoire
+jms_random_file=Dossier contenant les fichiers al\u00E9atoires
 jms_read_response=Lire la r\u00E9ponse
 jms_receive_queue=Nom JNDI de la file d'attente Receive 
 jms_request=Requ\u00EAte seule

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=1429128&r1=1429127&r2=1429128&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 Fri
Jan  4 21:06:46 2013
@@ -23,11 +23,13 @@ import java.io.Serializable;
 import java.util.Map;
 import java.util.Map.Entry;
 
+import javax.jms.BytesMessage;
 import javax.jms.Connection;
 import javax.jms.DeliveryMode;
 import javax.jms.Destination;
 import javax.jms.JMSException;
 import javax.jms.MapMessage;
+import javax.jms.Message;
 import javax.jms.MessageProducer;
 import javax.jms.ObjectMessage;
 import javax.jms.Session;
@@ -145,58 +147,56 @@ public class Publisher implements Closea
         }
     }
 
-    public TextMessage publish(String text) throws JMSException,
+    public Message publish(String text) throws JMSException,
             NamingException {
         return publish(text, null, null);
     }
     
-    public TextMessage publish(String text, String destinationName)
+    public Message publish(String text, String destinationName)
             throws JMSException, NamingException {
         return publish(text, destinationName, null);
     }
     
-    public TextMessage publish(String text, String destinationName, Map<String, String>
properties)
+    public Message 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 {
-            Destination dest = Utils.lookupDestination(ctx, destinationName);
-            producer.send(dest, msg);
-        }
-        return msg;
+        return setPropertiesAndSend(destinationName, properties, msg);
     }
     
-    public ObjectMessage publish(Serializable contents) throws JMSException,
+    public Message publish(Serializable contents) throws JMSException,
             NamingException {
         return publish(contents, null);
     }
 
-    public ObjectMessage publish(Serializable contents, String destinationName) 
+    public Message publish(Serializable contents, String destinationName) 
             throws JMSException, NamingException {
         return publish(contents, destinationName, null);
     }
     
-    public ObjectMessage publish(Serializable contents, String destinationName, Map<String,
String> properties)
+    public Message 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 {
-            Destination dest = Utils.lookupDestination(ctx, destinationName);
-            producer.send(dest, msg);
-        }
-        return msg;
+        return setPropertiesAndSend(destinationName, properties, msg);
+    }
+    
+    public BytesMessage publish(byte[] bytes, String destinationName)
+            throws JMSException, NamingException {
+        return publish(bytes, destinationName);
+    }
+    
+    public Message publish(byte[] bytes, String destinationName, Map<String, String>
properties)
+            throws JMSException, NamingException {
+        BytesMessage msg = session.createBytesMessage();
+        msg.writeBytes(bytes);
+        return setPropertiesAndSend(destinationName, properties, msg);
     }
 
-    public MapMessage publish(Map<String, Object> map) throws JMSException,
+    public Message publish(Map<String, Object> map) throws JMSException,
             NamingException {
         return publish(map, null, null);
     }
     
-    public MapMessage publish(Map<String, Object> map, String destinationName)
+    public Message publish(Map<String, Object> map, String destinationName)
             throws JMSException, NamingException {
         return publish(map, destinationName, null);
     }
@@ -204,10 +204,24 @@ public class Publisher implements Closea
     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());
         }
+        return (MapMessage)setPropertiesAndSend(destinationName, properties, msg);
+    }
+
+    /**
+     * @param destinationName 
+     * @param properties Map<String, String>
+     * @param msg Message
+     * @return Message
+     * @throws JMSException
+     * @throws NamingException
+     */
+    private Message setPropertiesAndSend(String destinationName,
+            Map<String, String> properties, Message msg)
+            throws JMSException, NamingException {
+        Utils.addJMSProperties(msg, properties);
         if (staticDest || destinationName == null) {
             producer.send(msg);
         } else {

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=1429128&r1=1429127&r2=1429128&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
Fri Jan  4 21:06:46 2013
@@ -42,8 +42,7 @@ import org.apache.jorphan.gui.JLabeledTe
 import org.apache.jorphan.gui.JLabeledTextField;
 
 /**
- * This is the GUI for JMS Publisher <br>
- * Created on: October 13, 2003
+ * This is the GUI for JMS Publisher
  *
  */
 public class JMSPublisherGui extends AbstractSamplerGui implements ChangeListener {
@@ -66,12 +65,17 @@ public class JMSPublisherGui extends Abs
     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$
+    /** Create a BytesMessage */
+    public static final String BYTES_MSG_RSC = "jms_bytes_message"; //$NON-NLS-1$
     //-- End of names used in JMX files
 
+    // Button group resources when Bytes Message is selected
+    private static final String[] CONFIG_ITEMS_BYTES_MSG = { USE_FILE_RSC, USE_RANDOM_RSC};
+
     // 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, MAP_MSG_RSC, OBJECT_MSG_RSC
};
+    private static final String[] MSGTYPES_ITEMS = { TEXT_MSG_RSC, MAP_MSG_RSC, OBJECT_MSG_RSC,
BYTES_MSG_RSC };
 
     private final JCheckBox useProperties = new JCheckBox(JMeterUtils.getResString("jms_use_properties_file"),
false); //$NON-NLS-1$
 
@@ -267,6 +271,7 @@ public class JMSPublisherGui extends Abs
         destSetup.setText(sampler.isDestinationStatic() ? DEST_SETUP_STATIC : DEST_SETUP_DYNAMIC);
         useNonPersistentDelivery.setSelected(sampler.getUseNonPersistentDelivery());
         jmsPropertiesPanel.configure(sampler.getJMSProperties());
+        updateChoice(msgChoice.getText());
     }
 
     /**
@@ -277,6 +282,8 @@ public class JMSPublisherGui extends Abs
     public void stateChanged(ChangeEvent event) {
         if (event.getSource() == configChoice) {
             updateConfig(configChoice.getText());
+        } else if (event.getSource() == msgChoice) {
+            updateChoice(msgChoice.getText());
         } else if (event.getSource() == useProperties) {
             jndiICF.setEnabled(!useProperties.isSelected());
             urlField.setEnabled(!useProperties.isSelected());
@@ -286,6 +293,26 @@ public class JMSPublisherGui extends Abs
         }
     }
     /**
+     * Update choice contains the actual logic for hiding or showing Textarea if Bytes message
+     * is selected
+     *
+     * @param command
+     * @since 2.9
+     */
+    private void updateChoice(String command) {
+        String oldChoice = configChoice.getText();
+        if (BYTES_MSG_RSC.equals(command)) {
+            String newChoice = USE_TEXT_RSC.equals(oldChoice) ? 
+                    USE_FILE_RSC : oldChoice;
+            configChoice.resetButtons(CONFIG_ITEMS_BYTES_MSG, newChoice);
+            textMessage.setEnabled(false);
+        } else {
+            configChoice.resetButtons(CONFIG_ITEMS, oldChoice);
+            textMessage.setEnabled(true);
+        }
+        validate();
+    }
+    /**
      * Update config contains the actual logic for enabling or disabling text
      * message, file or random path.
      *

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=1429128&r1=1429127&r2=1429128&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
Fri Jan  4 21:06:46 2013
@@ -18,6 +18,7 @@
 package org.apache.jmeter.protocol.jms.sampler;
 
 import java.io.BufferedInputStream;
+import java.io.File;
 import java.io.FileInputStream;
 import java.io.InputStream;
 import java.io.Serializable;
@@ -30,6 +31,7 @@ import javax.jms.JMSException;
 import javax.jms.Message;
 import javax.naming.NamingException;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.jmeter.config.Arguments;
 import org.apache.jmeter.protocol.jms.Utils;
 import org.apache.jmeter.protocol.jms.client.ClientPool;
@@ -85,6 +87,8 @@ public class PublisherSampler extends Ba
     // 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;
+    // Cache for bytes-message, only used when parsing from a file 
+    private byte[] bytes_msg_file_contents = null;
 
     public PublisherSampler() {
     }
@@ -176,6 +180,10 @@ public class PublisherSampler extends Ba
                     Serializable omsg = getObjectContent();
                     Message msg = publisher.publish(omsg, getDestination(), getJMSProperties().getArgumentsAsMap());
                     Utils.messageProperties(propBuffer, msg);
+                } else if (JMSPublisherGui.BYTES_MSG_RSC.equals(type)){
+                    byte[] bmsg = getBytesContent();
+                    Message msg = publisher.publish(bmsg, getDestination(), getJMSProperties().getArgumentsAsMap());
+                    Utils.messageProperties(propBuffer, msg);
                 } else {
                     throw new JMSException(type+ " is not recognised");                 
  
                 }
@@ -289,6 +297,55 @@ public class PublisherSampler extends Ba
     }
     
     /**
+     * This method will load the contents for the JMS BytesMessage.
+     * The contents are either loaded from file (might be cached), random file
+     * 
+     * @return byte[] as loaded from the specified input file
+     * @since 2.9
+     */
+    private  byte[] getBytesContent() {
+        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 (bytes_msg_file_contents == null) {
+                bytes_msg_file_contents = getFileBytesContent(getInputFile());
+            }
+
+            return bytes_msg_file_contents;
+        } else if (getConfigChoice().equals(JMSPublisherGui.USE_RANDOM_RSC)) {
+            final String fname = FSERVER.getRandomFile(getRandomPath(), new String[] {".dat"})
+                .getAbsolutePath();
+
+            return getFileBytesContent(fname);
+        } else {
+            throw new IllegalArgumentException("Type of input not handled:" + getConfigChoice());
+        }
+    }
+    
+    /**
+     * 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 byte[]  instance
+     * @since 2.9
+     */
+    private static byte[] getFileBytesContent(final String path) {
+        InputStream inputStream = null;
+        try {
+            File file = new File(path);
+            inputStream = new BufferedInputStream(new FileInputStream(file));
+            return IOUtils.toByteArray(inputStream, (int)file.length());
+        } catch (Exception e) {
+            log.error(e.getLocalizedMessage(), e);
+            throw new IllegalStateException("Unable to load file", e);
+        } finally {
+            JOrphanUtils.closeQuietly(inputStream);
+        }
+    }
+    
+    /**
      * 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.

Modified: jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/SubscriberSampler.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/SubscriberSampler.java?rev=1429128&r1=1429127&r2=1429128&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/SubscriberSampler.java
(original)
+++ jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/SubscriberSampler.java
Fri Jan  4 21:06:46 2013
@@ -19,9 +19,11 @@ package org.apache.jmeter.protocol.jms.s
 
 import java.util.Enumeration;
 
+import javax.jms.BytesMessage;
 import javax.jms.JMSException;
 import javax.jms.MapMessage;
 import javax.jms.Message;
+import javax.jms.ObjectMessage;
 import javax.jms.TextMessage;
 import javax.naming.NamingException;
 
@@ -236,6 +238,16 @@ public class SubscriberSampler extends B
             try {
                 if (msg instanceof TextMessage){
                     buffer.append(((TextMessage) msg).getText());
+                } else if (msg instanceof ObjectMessage){
+                    ObjectMessage objectMessage = (ObjectMessage) msg;
+                    if(objectMessage.getObject() != null) {
+                        buffer.append(objectMessage.getObject().getClass());
+                    } else {
+                        buffer.append("object is null");
+                    }
+                } else if (msg instanceof BytesMessage){
+                    BytesMessage bytesMessage = (BytesMessage) msg;
+                    buffer.append(bytesMessage.getBodyLength() + " bytes received in BytesMessage");
                 } else if (msg instanceof MapMessage){
                     MapMessage mapm = (MapMessage) msg;
                     @SuppressWarnings("unchecked") // MapNames are Strings

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1429128&r1=1429127&r2=1429128&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Fri Jan  4 21:06:46 2013
@@ -203,6 +203,7 @@ and right angle bracket (&gt;) in search
 <li><bugzilla>54107</bugzilla> - JSR223TestElement : Enable compilation
and caching of Script Text</li>
 <li><bugzilla>54109</bugzilla> - JSR223TestElement : SampleResult properties
should be set before entering script to allow user setting different code</li>
 <li><bugzilla>54230</bugzilla> - TCP Sampler, additions of "Close Connection",
"SO_LINGER" and "End of line(EOL) byte value" options</li>
+<li><bugzilla>54182</bugzilla> - Support sending of ByteMessage for JMS
Publisher.</li>
 </ul>
 
 <h3>Controllers</h3>



Mime
View raw message