From 31214b1be26c3f4730111383531dc2e7d9748b82 Mon Sep 17 00:00:00 2001 From: mguessan Date: Tue, 12 Apr 2011 21:30:52 +0000 Subject: [PATCH] Serialize session creation in workstation mode to avoid multiple OTP requests git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1664 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- .../davmail/exchange/ExchangeSessionFactory.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/java/davmail/exchange/ExchangeSessionFactory.java b/src/java/davmail/exchange/ExchangeSessionFactory.java index 1d2870c6..556242b9 100644 --- a/src/java/davmail/exchange/ExchangeSessionFactory.java +++ b/src/java/davmail/exchange/ExchangeSessionFactory.java @@ -84,9 +84,20 @@ public final class ExchangeSessionFactory { * @throws IOException on error */ public static ExchangeSession getInstance(String userName, String password) throws IOException { + String baseUrl = Settings.getProperty("davmail.url"); + if (Settings.getBooleanProperty("davmail.server")) { + return getInstance(baseUrl, userName, password); + } else { + // serialize session creation in workstation mode to avoid multiple OTP requests + synchronized (LOCK) { + return getInstance(baseUrl, userName, password); + } + } + } + + public static ExchangeSession getInstance(String baseUrl, String userName, String password) throws IOException { ExchangeSession session = null; try { - String baseUrl = Settings.getProperty("davmail.url"); // prepend default windows domain prefix String defaultDomain = Settings.getProperty("davmail.defaultDomain");