NIHVIVO-1261 Simplify the logic around smtpHost, to prepare for the change in ConfigurationProperties.
This commit is contained in:
parent
733a70faf4
commit
854536c531
1 changed files with 10 additions and 23 deletions
|
@ -20,7 +20,6 @@ import javax.mail.Transport;
|
||||||
import javax.mail.internet.AddressException;
|
import javax.mail.internet.AddressException;
|
||||||
import javax.mail.internet.InternetAddress;
|
import javax.mail.internet.InternetAddress;
|
||||||
import javax.mail.internet.MimeMessage;
|
import javax.mail.internet.MimeMessage;
|
||||||
import javax.servlet.ServletConfig;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
@ -51,28 +50,16 @@ public class ContactMailController extends FreemarkerHttpServlet {
|
||||||
private final static String TEMPLATE_BACKUP = "contactForm-backup.ftl";
|
private final static String TEMPLATE_BACKUP = "contactForm-backup.ftl";
|
||||||
private final static String TEMPLATE_ERROR = "contactForm-error.ftl";
|
private final static String TEMPLATE_ERROR = "contactForm-error.ftl";
|
||||||
|
|
||||||
private static String smtpHost = null;
|
private static String smtpHost = "";
|
||||||
|
|
||||||
public void init(ServletConfig servletConfig) throws javax.servlet.ServletException {
|
@Override
|
||||||
super.init(servletConfig);
|
public void init() {
|
||||||
smtpHost = getSmtpHostFromProperties();
|
smtpHost = ConfigurationProperties.getProperty("Vitro.smtpHost", "");
|
||||||
}
|
if (smtpHost.isEmpty()) {
|
||||||
|
|
||||||
public static boolean isSmtpHostConfigured() {
|
|
||||||
if( smtpHost==null || smtpHost.equals("")) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getSmtpHostFromProperties() {
|
|
||||||
String host = ConfigurationProperties.getProperty("Vitro.smtpHost");
|
|
||||||
if (host != null && !host.equals("")) {
|
|
||||||
log.debug("Found Vitro.smtpHost value of " + host);
|
|
||||||
} else {
|
|
||||||
log.debug("No Vitro.smtpHost specified");
|
log.debug("No Vitro.smtpHost specified");
|
||||||
|
} else {
|
||||||
|
log.debug("Found Vitro.smtpHost value of " + smtpHost);
|
||||||
}
|
}
|
||||||
return (host != null && host.length() > 0) ? host : null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -90,7 +77,7 @@ public class ContactMailController extends FreemarkerHttpServlet {
|
||||||
|
|
||||||
String statusMsg = null; // holds the error status
|
String statusMsg = null; // holds the error status
|
||||||
|
|
||||||
if (!isSmtpHostConfigured()) {
|
if (smtpHost.isEmpty()) {
|
||||||
body.put("errorMessage",
|
body.put("errorMessage",
|
||||||
"This application has not yet been configured to send mail. " +
|
"This application has not yet been configured to send mail. " +
|
||||||
"An smtp host has not been specified in the configuration properties file.");
|
"An smtp host has not been specified in the configuration properties file.");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue