You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@jakarta.apache.org by se...@apache.org on 2010/09/01 14:12:56 UTC
svn commit: r991510 - in /jakarta/jmeter/trunk: docs/images/screenshots/
src/core/org/apache/jmeter/resources/
src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/
src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/gui/
src/protocol/mail/o...
Author: sebb
Date: Wed Sep 1 12:12:56 2010
New Revision: 991510
URL: http://svn.apache.org/viewvc?rev=991510&view=rev
Log:
Bug 49775 - Allow sending messages without a body
Modified:
jakarta/jmeter/trunk/docs/images/screenshots/smtp_sampler.png
jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/SmtpSampler.java
jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/gui/SmtpPanel.java
jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/gui/SmtpSamplerGui.java
jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/protocol/SendMailCommand.java
jakarta/jmeter/trunk/xdocs/changes.xml
jakarta/jmeter/trunk/xdocs/images/screenshots/smtp_sampler.png
jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml
Modified: jakarta/jmeter/trunk/docs/images/screenshots/smtp_sampler.png
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/docs/images/screenshots/smtp_sampler.png?rev=991510&r1=991509&r2=991510&view=diff
==============================================================================
Binary files - no diff available.
Modified: jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties?rev=991510&r1=991509&r2=991510&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties (original)
+++ jakarta/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties Wed Sep 1 12:12:56 2010
@@ -807,6 +807,7 @@ smtp_message=Message:
smtp_message_settings=Message settings
smtp_messagesize=Calculate message size
smtp_password=Password:
+smtp_plainbody=Send plain body (i.e. not multipart/mixed)
smtp_sampler_title=SMTP Sampler
smtp_security_settings=Security settings
smtp_server_port=Port:
Modified: jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/SmtpSampler.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/SmtpSampler.java?rev=991510&r1=991509&r2=991510&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/SmtpSampler.java (original)
+++ jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/SmtpSampler.java Wed Sep 1 12:12:56 2010
@@ -37,6 +37,7 @@ import org.apache.jmeter.protocol.smtp.s
import org.apache.jmeter.samplers.AbstractSampler;
import org.apache.jmeter.samplers.Entry;
import org.apache.jmeter.samplers.SampleResult;
+import org.apache.jmeter.services.FileServer;
import org.apache.jmeter.testelement.property.CollectionProperty;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.log.Logger;
@@ -68,6 +69,7 @@ public class SmtpSampler extends Abstrac
public final static String SUBJECT = "SMTPSampler.subject"; // $NON-NLS-1$
public final static String SUPPRESS_SUBJECT = "SMTPSampler.suppressSubject"; // $NON-NLS-1$
public final static String MESSAGE = "SMTPSampler.message"; // $NON-NLS-1$
+ public final static String PLAIN_BODY = "SMTPSampler.plainBody"; // $NON-NLS-1$
public final static String INCLUDE_TIMESTAMP = "SMTPSampler.include_timestamp"; // $NON-NLS-1$
public final static String ATTACH_FILE = "SMTPSampler.attachFile"; // $NON-NLS-1$
public final static String MESSAGE_SIZE_STATS = "SMTPSampler.messageSizeStatistics"; // $NON-NLS-1$
@@ -149,11 +151,18 @@ public class SmtpSampler extends Abstrac
if (!getPropertyAsBoolean(USE_EML)) { // part is only needed if we
// don't send an .eml-file
instance.setMailBody(getPropertyAsString(MESSAGE));
+ instance.setPlainBody(getPropertyAsBoolean(PLAIN_BODY));
final String filesToAttach = getPropertyAsString(ATTACH_FILE);
if (!filesToAttach.equals("")) {
String[] attachments = filesToAttach.split(FILENAME_SEPARATOR);
for (String attachment : attachments) {
- instance.addAttachment(new File(attachment));
+ File file = new File(attachment);
+ if(!file.isAbsolute() && !file.exists()){
+ log.debug("loading file with relative path: " +attachment);
+ file = new File(FileServer.getFileServer().getBaseDir(), attachment);
+ log.debug("file path set to: "+attachment);
+ }
+ instance.addAttachment(file);
}
}
Modified: jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/gui/SmtpPanel.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/gui/SmtpPanel.java?rev=991510&r1=991509&r2=991510&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/gui/SmtpPanel.java (original)
+++ jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/gui/SmtpPanel.java Wed Sep 1 12:12:56 2010
@@ -22,6 +22,7 @@ import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.io.File;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@@ -63,6 +64,7 @@ public class SmtpPanel extends JPanel {
private JTextField tfAttachment;
private JTextField tfEmlMessage;
private JTextArea taMessage;
+ private JCheckBox cbPlainBody;
private JLabel jlAddressFrom;
private JLabel jlAddressTo;
@@ -298,6 +300,24 @@ public class SmtpPanel extends JPanel {
}
/**
+ * Returns true if message body should be plain (i.e. not multipart/mixed)
+ *
+ * @return true if using plain message body (i.e. not multipart/mixed)
+ */
+ public boolean isPlainBody() {
+ return cbPlainBody.isSelected();
+ }
+
+ /**
+ * Sets the property that defines if the body should be plain (i.e. not multipart/mixed)
+ *
+ * @param plainBody whether to use a plain body (i.e. not multipart/mixed)
+ */
+ public void setPlainBody(boolean plainBody) {
+ cbPlainBody.setSelected(plainBody);
+ }
+
+ /**
* Returns if mail-server needs authentication (checkbox)
*
* @return true if authentication is used
@@ -484,6 +504,8 @@ public class SmtpPanel extends JPanel {
taMessage = new JTextArea(5, 20);
+ cbPlainBody = new JCheckBox(JMeterUtils.getResString("smtp_plainbody")); // $NON-NLS-1$
+
cbSuppressSubject = new JCheckBox(JMeterUtils.getResString("smtp_suppresssubj")); // $NON-NLS-1$
cbSuppressSubject.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
@@ -742,6 +764,13 @@ public class SmtpPanel extends JPanel {
gridBagConstraints.gridy = 3;
gridBagConstraints.fill = GridBagConstraints.BOTH;
panelMessageSettings.add(taMessage, gridBagConstraints);
+
+ cbPlainBody.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
+ cbPlainBody.setMargin(new java.awt.Insets(0, 0, 0, 0));
+ gridBagConstraints.gridx = 2;
+ gridBagConstraints.gridy = 3;
+ gridBagConstraints.fill = GridBagConstraints.NONE;
+ panelMessageSettings.add(cbPlainBody, gridBagConstraints);
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 4;
@@ -844,15 +873,17 @@ public class SmtpPanel extends JPanel {
* ActionEvent to be handled
*/
private void attachmentFolderFileChooserActionPerformed(ActionEvent evt) {
+ File chosen = attachmentFileChooser.getSelectedFile();
+ if (chosen == null){
+ return;
+ }
final String attachments = tfAttachment.getText().trim();
if (null != attachments && attachments.length() > 0) {
tfAttachment.setText(attachments
+ SmtpSampler.FILENAME_SEPARATOR
- + attachmentFileChooser.getSelectedFile()
- .getAbsolutePath());
+ + chosen.getAbsolutePath());
} else {
- tfAttachment.setText(attachmentFileChooser.getSelectedFile()
- .getAbsolutePath());
+ tfAttachment.setText(chosen.getAbsolutePath());
}
}
@@ -939,6 +970,7 @@ public class SmtpPanel extends JPanel {
tfMailToBCC.setText("");
tfMailToCC.setText("");
tfSubject.setText("");
+ cbPlainBody.setSelected(false);
cbSuppressSubject.setSelected(false);
securitySettingsPanel.clear();
clearHeaderFields();
@@ -1041,4 +1073,5 @@ public class SmtpPanel extends JPanel {
}
}
}
+
}
\ No newline at end of file
Modified: jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/gui/SmtpSamplerGui.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/gui/SmtpSamplerGui.java?rev=991510&r1=991509&r2=991510&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/gui/SmtpSamplerGui.java (original)
+++ jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/gui/SmtpSamplerGui.java Wed Sep 1 12:12:56 2010
@@ -74,6 +74,7 @@ public class SmtpSamplerGui extends Abst
smtpPanel.setReceiverBCC(element.getPropertyAsString(SmtpSampler.RECEIVER_BCC));
smtpPanel.setBody(element.getPropertyAsString(SmtpSampler.MESSAGE));
+ smtpPanel.setPlainBody(element.getPropertyAsBoolean(SmtpSampler.PLAIN_BODY));
smtpPanel.setSubject(element.getPropertyAsString(SmtpSampler.SUBJECT));
smtpPanel.setSuppressSubject(element.getPropertyAsBoolean(SmtpSampler.SUPPRESS_SUBJECT));
smtpPanel.setIncludeTimestamp(element.getPropertyAsBoolean(SmtpSampler.INCLUDE_TIMESTAMP));
@@ -130,6 +131,7 @@ public class SmtpSamplerGui extends Abst
te.setProperty(SmtpSampler.SUPPRESS_SUBJECT, Boolean.toString(smtpPanel.isSuppressSubject()));
te.setProperty(SmtpSampler.INCLUDE_TIMESTAMP, Boolean.toString(smtpPanel.isIncludeTimestamp()));
te.setProperty(SmtpSampler.MESSAGE, smtpPanel.getBody());
+ te.setProperty(SmtpSampler.PLAIN_BODY, Boolean.toString(smtpPanel.isPlainBody()));
te.setProperty(SmtpSampler.ATTACH_FILE, smtpPanel.getAttachments());
SecuritySettingsPanel secPanel = smtpPanel.getSecuritySettingsPanel();
Modified: jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/protocol/SendMailCommand.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/protocol/SendMailCommand.java?rev=991510&r1=991509&r2=991510&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/protocol/SendMailCommand.java (original)
+++ jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/smtp/sampler/protocol/SendMailCommand.java Wed Sep 1 12:12:56 2010
@@ -21,6 +21,7 @@ package org.apache.jmeter.protocol.smtp.
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
@@ -38,6 +39,7 @@ import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
+import org.apache.commons.io.IOUtils;
import org.apache.jmeter.config.Argument;
import org.apache.jmeter.services.FileServer;
import org.apache.jmeter.testelement.property.CollectionProperty;
@@ -90,9 +92,11 @@ public class SendMailCommand {
private boolean synchronousMode;
private Session session;
- private Message message;
- private StringBuffer serverResponse = new StringBuffer();
+ private StringBuffer serverResponse = new StringBuffer(); // TODO this is not populated currently
+
+ /** send plain body, i.e. not multipart/mixed */
+ private boolean plainBody;
/**
* Standard-Constructor
@@ -165,6 +169,8 @@ public class SendMailCommand {
}
session = Session.getInstance(props, null);
+
+ Message message;
if (sendEmlMessage) {
message = new MimeMessage(session, new FileInputStream(emlMessage));
@@ -172,18 +178,33 @@ public class SendMailCommand {
message = new MimeMessage(session);
// handle body and attachments
Multipart multipart = new MimeMultipart();
- BodyPart body = new MimeBodyPart();
- body.setText(mailBody);
- multipart.addBodyPart(body);
-
- for (File f : attachments) {
- BodyPart attach = new MimeBodyPart();
- attach.setFileName(f.getName());
- attach.setDataHandler(new DataHandler(new FileDataSource(f)));
- multipart.addBodyPart(attach);
+ final int attachmentCount = attachments.size();
+ if (plainBody &&
+ (attachmentCount == 0 || (mailBody.length() == 0 && attachmentCount == 1))) {
+ if (attachmentCount == 1) { // i.e. mailBody is empty
+ File first = attachments.get(0);
+ InputStream is = null;
+ try {
+ is = new FileInputStream(first);
+ message.setText(IOUtils.toString(is));
+ } finally {
+ IOUtils.closeQuietly(is);
+ }
+ } else {
+ message.setText(mailBody);
+ }
+ } else {
+ BodyPart body = new MimeBodyPart();
+ body.setText(mailBody);
+ multipart.addBodyPart(body);
+ for (File f : attachments) {
+ BodyPart attach = new MimeBodyPart();
+ attach.setFileName(f.getName());
+ attach.setDataHandler(new DataHandler(new FileDataSource(f.getAbsolutePath())));
+ multipart.addBodyPart(attach);
+ }
+ message.setContent(multipart);
}
-
- message.setContent(multipart);
}
// set from field and subject
@@ -722,6 +743,15 @@ public class SendMailCommand {
public void setMailBody(String body){
mailBody = body;
}
+
+ /**
+ * Set whether to send a plain body (i.e. not multipart/mixed)
+ *
+ * @param plainBody <code>true</code> if sending a plain body (i.e. not multipart/mixed)
+ */
+ public void setPlainBody(boolean plainBody){
+ this.plainBody = plainBody;
+ }
public StringBuffer getServerResponse() {
return this.serverResponse;
Modified: jakarta/jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/changes.xml?rev=991510&r1=991509&r2=991510&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/changes.xml (original)
+++ jakarta/jmeter/trunk/xdocs/changes.xml Wed Sep 1 12:12:56 2010
@@ -112,6 +112,7 @@ To override the default local language f
<ul>
<li>Bug 49622 - Allow sending messages without a subject (SMTP Sampler)</li>
<li>Bug 49603 - Allow accepting expired certificates on Mail Reader Sampler</li>
+<li>Bug 49775 - Allow sending messages without a body</li>
</ul>
<h3>Controllers</h3>
Modified: jakarta/jmeter/trunk/xdocs/images/screenshots/smtp_sampler.png
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/images/screenshots/smtp_sampler.png?rev=991510&r1=991509&r2=991510&view=diff
==============================================================================
Binary files - no diff available.
Modified: jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml?rev=991510&r1=991509&r2=991510&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml (original)
+++ jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml Wed Sep 1 12:12:56 2010
@@ -1505,7 +1505,7 @@ In non-GUI mode, JMeter will exit if som
</component>
-<component name="SMTP Sampler" index="§-num;.1.19" width="625" height="777" screenshot="smtp_sampler.png">
+<component name="SMTP Sampler" index="§-num;.1.19" width="710" height="779" screenshot="smtp_sampler.png">
<description>
<p>
The SMTP Sampler can send mail messages using SMTP/SMTPS protocol.
@@ -1546,6 +1546,11 @@ This is different from sending an empty
<property name="Include timestamp in subject" required="">Includes the System.currentTimemilis() in the subject line.</property>
<property name="Add Header" required="No">Additional headers can be defined using this button.</property>
<property name="Message" required="">The message body.</property>
+<property name="Send plain body (i.e. not multipart/mixed)">
+If selected, then send the body as a plain message, i.e. not multipart/mixed, if possible.
+If the message body is empty and there is a single file, then send the file contents as the message body.
+Note: If the message body is not empty, and there is at least one attached file, then the body is sent as multipart/mixed.
+</property>
<property name="Attach files" required="">Files to be attached to the message.</property>
<property name="Send .eml" required="">If set, the .eml file will be sent instead of the entries in the Subject, Message, and Attached files</property>
<property name="Calculate message size" required="">Calculates the message size and stores it in the sample result.</property>
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@jakarta.apache.org
For additional commands, e-mail: notifications-help@jakarta.apache.org