--- src/protocol/jms/org/apache/jmeter/protocol/jms/control/gui/JMSPublisherGui.java (revision 1305743) +++ src/protocol/jms/org/apache/jmeter/protocol/jms/control/gui/JMSPublisherGui.java (working copy) @@ -131,29 +131,11 @@ * @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); + PublisherSampler sampler = new PublisherSampler(); + setupSamplerProperties(sampler); - return sampler; - } - + return sampler; + } /** * Modifies a given TestElement to mirror the data in the gui components. * @@ -161,26 +143,35 @@ */ 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); } /** --- src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/PublisherSampler.java (revision 1305743) +++ src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/PublisherSampler.java (working copy) @@ -17,6 +17,8 @@ package org.apache.jmeter.protocol.jms.sampler; +import java.io.FileInputStream; +import java.io.Serializable; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.HashMap; @@ -42,6 +44,8 @@ import org.apache.jorphan.logging.LoggingManager; import org.apache.log.Logger; +import com.thoughtworks.xstream.XStream; + /** * This class implements the JMS Publisher sampler. */ @@ -76,6 +80,8 @@ // Cache for file. Only used by sample() in a single thread private String file_contents = null; + // Cache for object-file. + private Serializable file_object_contents = null; public PublisherSampler() { } @@ -168,7 +174,9 @@ 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 +260,39 @@ return tf.getText(); } + /** + * This method will either return the 'cached' object loaded previously from a file, + * or it will attempt to load the file for the first time. + * + * @return Serialized object as loaded from the specified input file + */ + private Serializable getObjectContent() { + if (file_object_contents == null) { + file_object_contents = getFileObjectContent(getInputFile()); + } + return file_object_contents; + } + + /** + * 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 Serializable getFileObjectContent(final String path) { + Serializable readObject = null; + try { + XStream xstream = new XStream(); + readObject = (Serializable) xstream.fromXML(new FileInputStream(path), readObject); + } catch (Exception e) { + log.error(e.getLocalizedMessage(), e); + throw new IllegalStateException("Unable to load object instance from file", e); + } + return readObject; + } + // ------------- get/set properties ----------------------// /** * set the source of the message --- build.properties (revision 1305743) +++ build.properties (working copy) @@ -199,10 +199,10 @@ tidy.md5 = 6A9121561B8F98C0A8FB9B6E57F50E6B # XStream can be found at: http://xstream.codehaus.org/ -xstream.version = 1.3.1 +xstream.version = 1.4.2 xstream.jar = xstream-${xstream.version}.jar xstream.loc = ${maven2.repo}/com/thoughtworks/xstream/xstream/${xstream.version} -xstream.md5 = 4DFEBEC402E7606B2C1F66DEC1773E8F +xstream.md5 = 23947B036DD0D9CD23CB2F388C373181 xpp3.version = 1.1.4c xpp3.jar = xpp3_min-${xpp3.version}.jar @@ -263,4 +263,4 @@ velocity.version = 1.7 velocity.jar = velocity-${velocity.version}.jar velocity.loc = ${maven2.repo}/org/apache/velocity/velocity/${velocity.version} -velocity.md5 = 3692dd72f8367cb35fb6280dc2916725 +velocity.md5 = 3692dd72f8367cb35fb6280dc2916725