View | Details | Raw Unified | Return to bug 52936
Collapse All | Expand All

(-)src/protocol/jms/org/apache/jmeter/protocol/jms/control/gui/JMSPublisherGui.java (-40 / +31 lines)
Lines 131-159 Link Here
131
     * @see org.apache.jmeter.gui.JMeterGUIComponent#createTestElement()
131
     * @see org.apache.jmeter.gui.JMeterGUIComponent#createTestElement()
132
     */
132
     */
133
    public TestElement createTestElement() {
133
    public TestElement createTestElement() {
134
        PublisherSampler sampler = new PublisherSampler();
134
      PublisherSampler sampler = new PublisherSampler();
135
        this.configureTestElement(sampler);
135
      setupSamplerProperties(sampler);
136
        sampler.setUseJNDIProperties(String.valueOf(useProperties.isSelected()));
137
        sampler.setJNDIIntialContextFactory(jndiICF.getText());
138
        sampler.setProviderUrl(urlField.getText());
139
        sampler.setConnectionFactory(jndiConnFac.getText());
140
        sampler.setDestination(jmsDestination.getText());
141
        sampler.setUsername(jmsUser.getText());
142
        sampler.setPassword(jmsPwd.getText());
143
        sampler.setTextMessage(textMessage.getText());
144
        sampler.setInputFile(messageFile.getFilename());
145
        sampler.setRandomPath(randomFile.getFilename());
146
        sampler.setConfigChoice(configChoice.getText());
147
        sampler.setMessageChoice(msgChoice.getText());
148
        sampler.setIterations(iterations.getText());
149
        sampler.setUseAuth(useAuth.isSelected());
150
        sampler.setUseNonPersistentDelivery(useNonPersistentDelivery.isSelected());
151
        Arguments args = (Arguments) jmsPropertiesPanel.createTestElement();
152
        sampler.setJMSProperties(args);
153
136
154
        return sampler;
137
      return sampler;
155
    }
138
  }
156
157
    /**
139
    /**
158
     * Modifies a given TestElement to mirror the data in the gui components.
140
     * Modifies a given TestElement to mirror the data in the gui components.
159
     *
141
     *
Lines 161-186 Link Here
161
     */
143
     */
162
    public void modifyTestElement(TestElement s) {
144
    public void modifyTestElement(TestElement s) {
163
        PublisherSampler sampler = (PublisherSampler) s;
145
        PublisherSampler sampler = (PublisherSampler) s;
164
        this.configureTestElement(sampler);
146
        setupSamplerProperties(sampler);
165
        sampler.setUseJNDIProperties(String.valueOf(useProperties.isSelected()));
166
        sampler.setJNDIIntialContextFactory(jndiICF.getText());
167
        sampler.setProviderUrl(urlField.getText());
168
        sampler.setConnectionFactory(jndiConnFac.getText());
169
        sampler.setDestination(jmsDestination.getText());
170
        sampler.setUsername(jmsUser.getText());
171
        sampler.setPassword(jmsPwd.getText());
172
        sampler.setTextMessage(textMessage.getText());
173
        sampler.setInputFile(messageFile.getFilename());
174
        sampler.setRandomPath(randomFile.getFilename());
175
        sampler.setConfigChoice(configChoice.getText());
176
        sampler.setMessageChoice(msgChoice.getText());
177
        sampler.setIterations(iterations.getText());
178
        sampler.setUseAuth(useAuth.isSelected());
179
        sampler.setDestinationStatic(destSetup.getText().equals(DEST_SETUP_STATIC));
147
        sampler.setDestinationStatic(destSetup.getText().equals(DEST_SETUP_STATIC));
180
        sampler.setUseNonPersistentDelivery(useNonPersistentDelivery.isSelected());
148
    }
181
        Arguments args = (Arguments) jmsPropertiesPanel.createTestElement();
182
        sampler.setJMSProperties(args);
183
149
150
    /**
151
     * Initialize the provided {@link PublisherSampler} with all the values as configured in the GUI.
152
     * 
153
     * @param sampler {@link PublisherSampler} instance
154
     */
155
    private void setupSamplerProperties(final PublisherSampler sampler) {
156
      this.configureTestElement(sampler);
157
      sampler.setUseJNDIProperties(String.valueOf(useProperties.isSelected()));
158
      sampler.setJNDIIntialContextFactory(jndiICF.getText());
159
      sampler.setProviderUrl(urlField.getText());
160
      sampler.setConnectionFactory(jndiConnFac.getText());
161
      sampler.setDestination(jmsDestination.getText());
162
      sampler.setUsername(jmsUser.getText());
163
      sampler.setPassword(jmsPwd.getText());
164
      sampler.setTextMessage(textMessage.getText());
165
      sampler.setInputFile(messageFile.getFilename());
166
      sampler.setRandomPath(randomFile.getFilename());
167
      sampler.setConfigChoice(configChoice.getText());
168
      sampler.setMessageChoice(msgChoice.getText());
169
      sampler.setIterations(iterations.getText());
170
      sampler.setUseAuth(useAuth.isSelected());
171
      sampler.setUseNonPersistentDelivery(useNonPersistentDelivery.isSelected());
172
     
173
      Arguments args = (Arguments) jmsPropertiesPanel.createTestElement();
174
      sampler.setJMSProperties(args);
184
    }
175
    }
185
176
186
    /**
177
    /**
(-)src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/PublisherSampler.java (-1 / +79 lines)
Lines 17-22 Link Here
17
17
18
package org.apache.jmeter.protocol.jms.sampler;
18
package org.apache.jmeter.protocol.jms.sampler;
19
19
20
import java.io.FileInputStream;
21
import java.io.Serializable;
20
import java.lang.reflect.InvocationTargetException;
22
import java.lang.reflect.InvocationTargetException;
21
import java.lang.reflect.Method;
23
import java.lang.reflect.Method;
22
import java.util.HashMap;
24
import java.util.HashMap;
Lines 42-47 Link Here
42
import org.apache.jorphan.logging.LoggingManager;
44
import org.apache.jorphan.logging.LoggingManager;
43
import org.apache.log.Logger;
45
import org.apache.log.Logger;
44
46
47
import com.thoughtworks.xstream.XStream;
48
45
/**
49
/**
46
 * This class implements the JMS Publisher sampler.
50
 * This class implements the JMS Publisher sampler.
47
 */
51
 */
Lines 76-81 Link Here
76
80
77
    // Cache for file. Only used by sample() in a single thread
81
    // Cache for file. Only used by sample() in a single thread
78
    private String file_contents = null;
82
    private String file_contents = null;
83
    // Cache for object-message, only used when parsing from a file because in text-area
84
    // property replacement might have been used
85
    private Serializable object_msg_file_contents = null;
79
86
80
    public PublisherSampler() {
87
    public PublisherSampler() {
81
    }
88
    }
Lines 168-174 Link Here
168
                    Message msg = publisher.publish(m, getDestination(), getJMSProperties().getArgumentsAsMap());
175
                    Message msg = publisher.publish(m, getDestination(), getJMSProperties().getArgumentsAsMap());
169
                    Utils.messageProperties(propBuffer, msg);
176
                    Utils.messageProperties(propBuffer, msg);
170
                } else if (JMSPublisherGui.OBJECT_MSG_RSC.equals(type)){
177
                } else if (JMSPublisherGui.OBJECT_MSG_RSC.equals(type)){
171
                    throw new JMSException(type+ " is not yet supported");
178
                    Serializable omsg = getObjectContent();
179
                    Message msg = publisher.publish(omsg, getDestination(), getJMSProperties().getArgumentsAsMap());
180
                    Utils.messageProperties(propBuffer, msg);
172
                } else {
181
                } else {
173
                    throw new JMSException(type+ " is not recognised");                    
182
                    throw new JMSException(type+ " is not recognised");                    
174
                }
183
                }
Lines 252-257 Link Here
252
        return tf.getText();
261
        return tf.getText();
253
    }
262
    }
254
263
264
    /**
265
     * This method will load the contents for the JMS Object Message.
266
     * The contents are either loaded from file (might be cached), random file
267
     * or from the GUI text-area.
268
     * 
269
     * @return Serialized object as loaded from the specified input file
270
     */
271
    private Serializable getObjectContent() {
272
        if (getConfigChoice().equals(JMSPublisherGui.USE_FILE_RSC)) {
273
            // in the case the test uses a file, we set it locally and
274
            // prevent loading the file repeatedly
275
            if (object_msg_file_contents == null) {
276
                object_msg_file_contents = getFileObjectContent(getInputFile());
277
            }
278
279
            return object_msg_file_contents;
280
        } else if (getConfigChoice().equals(JMSPublisherGui.USE_RANDOM_RSC)) {
281
            // Maybe we should consider creating a global cache for the
282
            // random files to make JMeter more efficient.
283
            final String fname = FSERVER.getRandomFile(getRandomPath(), new String[] {".txt", ".obj"})
284
                .getAbsolutePath();
285
286
            return getFileObjectContent(fname);
287
        } else {
288
            final String xmlMessage = getTextMessage();
289
            return transformXmlToObjectMessage(xmlMessage);
290
        }
291
    }
292
    
293
    /**
294
     * Try to load an object from a provided file, so that it can be used as body
295
     * for a JMS message.
296
     * An {@link IllegalStateException} will be thrown if loading the object fails.
297
     * 
298
     * @param path Path to the file that will be serialized
299
     * @return Serialized object instance
300
     */
301
    private Serializable getFileObjectContent(final String path) {
302
      Serializable readObject = null;
303
      try {
304
        XStream xstream = new XStream();
305
        readObject = (Serializable) xstream.fromXML(new FileInputStream(path), readObject);
306
      } catch (Exception e) {
307
        log.error(e.getLocalizedMessage(), e);
308
        throw new IllegalStateException("Unable to load object instance from file", e);
309
      }
310
      return readObject;
311
    }
312
    
313
    /**
314
     * Try to load an object via XStream from XML text, so that it can be used as body
315
     * for a JMS message.
316
     * An {@link IllegalStateException} will be thrown if transforming the XML to an object fails.
317
     *
318
     * @param xmlMessage String containing XML text as input for the transformation
319
     * @return Serialized object instance
320
     */
321
    private Serializable transformXmlToObjectMessage(final String xmlMessage) {
322
      Serializable readObject = null;
323
      try {
324
        XStream xstream = new XStream();
325
        readObject = (Serializable) xstream.fromXML(xmlMessage, readObject);
326
      } catch (Exception e) {
327
        log.error(e.getLocalizedMessage(), e);
328
        throw new IllegalStateException("Unable to load object instance from text", e);
329
      }
330
      return readObject;
331
    }
332
    
255
    // ------------- get/set properties ----------------------//
333
    // ------------- get/set properties ----------------------//
256
    /**
334
    /**
257
     * set the source of the message
335
     * set the source of the message

Return to bug 52936