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 |