ISIS-1557: adds the throwExceptionOnFail config property for EmailServiceDefault
Project: http://git-wip-us.apache.org/repos/asf/isis/repo Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/66ff5034 Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/66ff5034 Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/66ff5034 Branch: refs/heads/maint-1.13.3 Commit: 66ff503427afb40e091dc3e54b81a18628b95a9b Parents: a942d1b Author: Dan Haywood <d...@haywood-associates.co.uk> Authored: Wed Dec 21 12:14:16 2016 +0000 Committer: Dan Haywood <d...@haywood-associates.co.uk> Committed: Wed Dec 21 12:14:16 2016 +0000 ---------------------------------------------------------------------- .../services/email/EmailServiceDefault.java | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/isis/blob/66ff5034/core/runtime/src/main/java/org/apache/isis/core/runtime/services/email/EmailServiceDefault.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/email/EmailServiceDefault.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/email/EmailServiceDefault.java index 28a12ed..f40bb2d 100644 --- a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/email/EmailServiceDefault.java +++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/email/EmailServiceDefault.java @@ -50,6 +50,13 @@ public class EmailServiceDefault implements EmailService { private static final Logger LOG = LoggerFactory.getLogger(EmailServiceDefault.class); + public static class EmailServiceException extends RuntimeException { + static final long serialVersionUID = 1L; + public EmailServiceException(final EmailException cause) { + super(cause); + } + } + //region > constants private static final String ISIS_SERVICE_EMAIL_SENDER_ADDRESS = "isis.service.email.sender.address"; private static final String ISIS_SERVICE_EMAIL_SENDER_PASSWORD = "isis.service.email.sender.password"; @@ -63,6 +70,9 @@ public class EmailServiceDefault implements EmailService { private static final String ISIS_SERVICE_EMAIL_TLS_ENABLED = "isis.service.email.tls.enabled"; private static final boolean ISIS_SERVICE_EMAIL_TLS_ENABLED_DEFAULT = true; + private static final String ISIS_SERVICE_EMAIL_THROW_EXCEPTION_ON_FAIL = "isis.service.email.throwExceptionOnFail"; + private static final boolean ISIS_SERVICE_EMAIL_THROW_EXCEPTION_ON_FAIL_DEFAULT = true; + //endregion //region > init @@ -107,6 +117,10 @@ public class EmailServiceDefault implements EmailService { protected Boolean getSenderEmailTlsEnabled() { return configuration.getBoolean(ISIS_SERVICE_EMAIL_TLS_ENABLED, ISIS_SERVICE_EMAIL_TLS_ENABLED_DEFAULT); } + + protected Boolean isThrowExceptionOnFail() { + return configuration.getBoolean(ISIS_SERVICE_EMAIL_THROW_EXCEPTION_ON_FAIL, ISIS_SERVICE_EMAIL_THROW_EXCEPTION_ON_FAIL_DEFAULT); + } //endregion //region > isConfigured @@ -174,7 +188,11 @@ public class EmailServiceDefault implements EmailService { email.send(); } catch (EmailException ex) { - LOG.error("An error occurred while trying to send an email about user email verification", ex); + LOG.error("An error occurred while trying to send an email", ex); + final Boolean throwExceptionOnFail = isThrowExceptionOnFail(); + if(throwExceptionOnFail) { + throw new EmailServiceException(ex); + } return false; }