You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by pm...@apache.org on 2012/02/05 16:08:41 UTC

svn commit: r1240745 - in /jmeter/trunk/src/components/org/apache/jmeter: reporters/MailerModel.java visualizers/MailerVisualizer.java

Author: pmouawad
Date: Sun Feb  5 15:08:41 2012
New Revision: 1240745

URL: http://svn.apache.org/viewvc?rev=1240745&view=rev
Log:
Bug 52603 - MailerVisualizer : Enable SSL , TLS and Authentication
Fixed issues discussed on mailing list

Modified:
    jmeter/trunk/src/components/org/apache/jmeter/reporters/MailerModel.java
    jmeter/trunk/src/components/org/apache/jmeter/visualizers/MailerVisualizer.java

Modified: jmeter/trunk/src/components/org/apache/jmeter/reporters/MailerModel.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/reporters/MailerModel.java?rev=1240745&r1=1240744&r2=1240745&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/reporters/MailerModel.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/reporters/MailerModel.java Sun Feb  5 15:08:41 2012
@@ -107,7 +107,13 @@ public class MailerModel extends Abstrac
 
     private static final String DEFAULT_LIMIT = "2"; //$NON-NLS-1$
 
-    private static final int DEFAULT_SMTP_PORT = 25;
+    private static final String DEFAULT_SMTP_PORT = "25";
+
+    private static final String DEFAULT_PASSWORD_VALUE = ""; //$NON-NLS-1$
+
+    private static final String DEFAULT_MAIL_AUTH_TYPE_VALUE = MailAuthType.NONE.toString(); //$NON-NLS-1$
+
+    private static final String DEFAULT_LOGIN_VALUE = ""; //$NON-NLS-1$
 
     /** The listener for changes. */
     private transient ChangeListener changeListener;
@@ -299,7 +305,7 @@ public class MailerModel extends Abstrac
      */
     public void sendMail(String from, List<String> vEmails, String subject, String attText, String smtpHost) 
             throws AddressException, MessagingException {
-        sendMail(from, vEmails, subject, attText, smtpHost, null, null, null, null);   
+        sendMail(from, vEmails, subject, attText, smtpHost, Integer.parseInt(DEFAULT_SMTP_PORT), null, null, null);   
     }
     
     /**
@@ -325,7 +331,7 @@ public class MailerModel extends Abstrac
      */
     public void sendMail(String from, List<String> vEmails, String subject,
             String attText, String smtpHost, 
-            Integer smtpPort,
+            int smtpPort,
             final String user,
             final String password,
             MailAuthType mailAuthType)
@@ -344,9 +350,7 @@ public class MailerModel extends Abstrac
         Properties props = new Properties();
 
         props.put(MAIL_SMTP_HOST, host);
-        if(smtpPort != null) {
-            props.put(MAIL_SMTP_PORT, smtpPort);
-        }
+        props.put(MAIL_SMTP_PORT, smtpPort);
         Authenticator authenticator = null;
         if(mailAuthType != MailAuthType.NONE) {
             props.put(MAIL_SMTP_AUTH, "true");
@@ -374,9 +378,6 @@ public class MailerModel extends Abstrac
                     };
         }
         Session session = Session.getInstance(props, authenticator);
-        // N.B. properties are only used when the default session is first
-        // created
-        // so check if the mail host needs to be reset...
         session.setDebug(debug);
 
         // create a message
@@ -430,24 +431,23 @@ public class MailerModel extends Abstrac
         setProperty(HOST_KEY, str);
     }
 
-    public void setSmtpPort(Integer str) {
-        if(str== null) {
-            setProperty(PORT_KEY, DEFAULT_SMTP_PORT);
-        } else {
-            setProperty(PORT_KEY, str);            
+    public void setSmtpPort(String value) {
+        if(StringUtils.isEmpty(value)) {
+            value = DEFAULT_SMTP_PORT;
         }
+        setProperty(PORT_KEY, value, DEFAULT_SMTP_PORT);
     }
     
     public void setLogin(String login) {
-        setProperty(LOGIN, login);
+        setProperty(LOGIN, login, DEFAULT_LOGIN_VALUE);
     }
     
     public void setPassword(String password) {
-        setProperty(PASSWORD, password);
+        setProperty(PASSWORD, password, DEFAULT_PASSWORD_VALUE);
     }
     
     public void setMailAuthType(String value) {
-        setProperty(MAIL_AUTH_TYPE, value, "");
+        setProperty(MAIL_AUTH_TYPE, value, DEFAULT_MAIL_AUTH_TYPE_VALUE);
     }
     
     public void setFailureSubject(String str) {
@@ -489,7 +489,7 @@ public class MailerModel extends Abstrac
     }
 
     public int getSmtpPort() {
-        return getPropertyAsInt(PORT_KEY, DEFAULT_SMTP_PORT);
+        return getPropertyAsInt(PORT_KEY, Integer.parseInt(DEFAULT_SMTP_PORT));
     }
 
     public String getFailureSubject() {
@@ -517,15 +517,15 @@ public class MailerModel extends Abstrac
     }
 
     public String getLogin() {
-        return getPropertyAsString(LOGIN);
+        return getPropertyAsString(LOGIN, DEFAULT_LOGIN_VALUE);
     }
 
     public String getPassword() {
-        return getPropertyAsString(PASSWORD);
+        return getPropertyAsString(PASSWORD, DEFAULT_PASSWORD_VALUE);
     }
 
     public MailAuthType getMailAuthType() {
-        String authType = getPropertyAsString(MAIL_AUTH_TYPE, MailAuthType.NONE.toString());
+        String authType = getPropertyAsString(MAIL_AUTH_TYPE, DEFAULT_MAIL_AUTH_TYPE_VALUE);
         return MailAuthType.valueOf(authType);
     }
 }
\ No newline at end of file

Modified: jmeter/trunk/src/components/org/apache/jmeter/visualizers/MailerVisualizer.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/visualizers/MailerVisualizer.java?rev=1240745&r1=1240744&r2=1240745&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/visualizers/MailerVisualizer.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/visualizers/MailerVisualizer.java Sun Feb  5 15:08:41 2012
@@ -40,7 +40,6 @@ import javax.swing.border.EmptyBorder;
 import javax.swing.event.ChangeEvent;
 import javax.swing.event.ChangeListener;
 
-import org.apache.commons.lang.StringUtils;
 import org.apache.jmeter.gui.util.VerticalPanel;
 import org.apache.jmeter.reporters.MailerModel;
 import org.apache.jmeter.reporters.MailerResultCollector;
@@ -374,9 +373,7 @@ public class MailerVisualizer extends Ab
         mailerModel.setFailureSubject(failureSubjectField.getText());
         mailerModel.setFromAddress(fromField.getText());
         mailerModel.setSmtpHost(smtpHostField.getText());
-        mailerModel.setSmtpPort(
-                StringUtils.isEmpty(smtpPortField.getText()) ?
-                        null : Integer.valueOf(smtpPortField.getText()));
+        mailerModel.setSmtpPort(smtpPortField.getText());
         mailerModel.setLogin(smtpLoginField.getText());
         mailerModel.setPassword(smtpPasswordField.getText());
         mailerModel.setMailAuthType(