ISIS-1557: adds in configuration properties for email service to set socket 
timeout and socket connection timeout


Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/07b0ecfa
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/07b0ecfa
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/07b0ecfa

Branch: refs/heads/maint-1.13.3
Commit: 07b0ecfa0544560b381d7f3483acdce699de7a06
Parents: c074b8b
Author: Dan Haywood <d...@haywood-associates.co.uk>
Authored: Wed Dec 21 12:44:55 2016 +0000
Committer: Dan Haywood <d...@haywood-associates.co.uk>
Committed: Wed Dec 21 12:44:55 2016 +0000

----------------------------------------------------------------------
 .../guides/_rgcfg_configuring-core.adoc         | 21 ++++++++++++++++++++
 .../guides/_rgsvc_api_EmailService.adoc         |  7 +++++++
 .../services/email/EmailServiceDefault.java     | 19 ++++++++++++++++++
 3 files changed, 47 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/07b0ecfa/adocs/documentation/src/main/asciidoc/guides/_rgcfg_configuring-core.adoc
----------------------------------------------------------------------
diff --git 
a/adocs/documentation/src/main/asciidoc/guides/_rgcfg_configuring-core.adoc 
b/adocs/documentation/src/main/asciidoc/guides/_rgcfg_configuring-core.adoc
index eb7dffa..7223385 100644
--- a/adocs/documentation/src/main/asciidoc/guides/_rgcfg_configuring-core.adoc
+++ b/adocs/documentation/src/main/asciidoc/guides/_rgcfg_configuring-core.adoc
@@ -285,6 +285,27 @@ NB: note that the key is mis-spelt, (`isis.service.email` 
rather than `isis.serv
 
 | `isis.service.` +
 `email.` +
+`socketConnectionTimeout`
+|milliseconds +
+(2000)
+|(`1.13.3-SNAPSHOT`) The socket connection timeout
+
+NB: note that the key is mis-spelt, (`isis.service.email` rather than 
`isis.services.email`)
+
+
+| `isis.service.` +
+`email.` +
+`socketTimeout`
+|milliseconds +
+(2000)
+|(`1.13.3-SNAPSHOT`) The socket timeout
+
+NB: note that the key is mis-spelt, (`isis.service.email` rather than 
`isis.services.email`)
+
+
+
+| `isis.service.` +
+`email.` +
 `throwExceptionOnFail`
 |`true`,`false` +
 (`true`)

http://git-wip-us.apache.org/repos/asf/isis/blob/07b0ecfa/adocs/documentation/src/main/asciidoc/guides/_rgsvc_api_EmailService.adoc
----------------------------------------------------------------------
diff --git 
a/adocs/documentation/src/main/asciidoc/guides/_rgsvc_api_EmailService.adoc 
b/adocs/documentation/src/main/asciidoc/guides/_rgsvc_api_EmailService.adoc
index f05c63e..7c58b40 100644
--- a/adocs/documentation/src/main/asciidoc/guides/_rgsvc_api_EmailService.adoc
+++ b/adocs/documentation/src/main/asciidoc/guides/_rgsvc_api_EmailService.adoc
@@ -73,6 +73,13 @@ In addition (as of `1.13.3-SNAPSHOT`), the following 
properties can be set:
 Whether to throw an exception if there the email cannot be sent (probably 
because of some misconfiguration).
 This behaviour is (now) the default; the old behaviour (of just returning 
`false` from the `send()` method) can be re-enabled by setting this property to 
`false`.
 
+* `isis.service.email.socketTimeout` +
++
+The socket timeout, defaulting to 2000ms.
+
+* `isis.service.email.socketConnectionTimeout` +
++
+The socket connection timeout, defaulting to 2000ms.
 
 
 == Alternative Implementations

http://git-wip-us.apache.org/repos/asf/isis/blob/07b0ecfa/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 f40bb2d..76d7d02 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
@@ -73,6 +73,12 @@ public class EmailServiceDefault implements EmailService {
     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;
 
+    private static final String ISIS_SERVICE_EMAIL_SOCKET_TIMEOUT = 
"isis.service.email.socketTimeout";
+    private static final int ISIS_SERVICE_EMAIL_SOCKET_TIMEOUT_DEFAULT = 2000;
+
+    private static final String ISIS_SERVICE_EMAIL_SOCKET_CONNECTION_TIMEOUT = 
"isis.service.email.socketConnectionTimeout";
+    private static final int 
ISIS_SERVICE_EMAIL_SOCKET_CONNECTION_TIMEOUT_DEFAULT = 2000;
+
     //endregion
 
     //region > init
@@ -121,6 +127,14 @@ public class EmailServiceDefault implements EmailService {
     protected Boolean isThrowExceptionOnFail() {
         return 
configuration.getBoolean(ISIS_SERVICE_EMAIL_THROW_EXCEPTION_ON_FAIL, 
ISIS_SERVICE_EMAIL_THROW_EXCEPTION_ON_FAIL_DEFAULT);
     }
+
+    protected int getSocketTimeout() {
+        return configuration.getInteger(ISIS_SERVICE_EMAIL_SOCKET_TIMEOUT, 
ISIS_SERVICE_EMAIL_SOCKET_TIMEOUT_DEFAULT);
+    }
+
+    protected int getSocketConnectionTimeout() {
+        return 
configuration.getInteger(ISIS_SERVICE_EMAIL_SOCKET_CONNECTION_TIMEOUT, 
ISIS_SERVICE_EMAIL_SOCKET_CONNECTION_TIMEOUT_DEFAULT);
+    }
     //endregion
 
     //region > isConfigured
@@ -147,6 +161,8 @@ public class EmailServiceDefault implements EmailService {
             final String senderEmailHostName = getSenderEmailHostName();
             final Integer senderEmailPort = getSenderEmailPort();
             final Boolean senderEmailTlsEnabled = getSenderEmailTlsEnabled();
+            final int socketTimeout = getSocketTimeout();
+            final int socketConnectionTimeout = getSocketConnectionTimeout();
 
             email.setAuthenticator(new 
DefaultAuthenticator(senderEmailAddress, senderEmailPassword));
             email.setHostName(senderEmailHostName);
@@ -154,6 +170,9 @@ public class EmailServiceDefault implements EmailService {
             email.setStartTLSEnabled(senderEmailTlsEnabled);
             email.setDataSourceResolver(new DataSourceClassPathResolver("/", 
true));
 
+            email.setSocketTimeout(socketTimeout);
+            email.setSocketConnectionTimeout(socketConnectionTimeout);
+
             final Properties properties = 
email.getMailSession().getProperties();
 
             properties.put("mail.smtps.auth", "true");

Reply via email to