1
0
mirror of https://github.com/moparisthebest/davmail synced 2024-12-14 03:32:22 -05:00

Merged another patch from Dan Foody on network down detection

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@694 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2009-09-03 00:06:03 +00:00
parent d2e2e5ee3c
commit 6ef071603a

View File

@ -40,6 +40,7 @@ public final class ExchangeSessionFactory {
private static final Object LOCK = new Object();
private static final Map<PoolKey, ExchangeSession> poolMap = new HashMap<PoolKey, ExchangeSession>();
private static boolean configChecked;
private static boolean errorSent;
static class PoolKey {
public final String url;
@ -110,10 +111,14 @@ public final class ExchangeSessionFactory {
}
// session opened, future failure will mean network down
configChecked = true;
// Reset so next time an problem occurs message will be sent once
errorSent = false;
} catch (UnknownHostException exc) {
handleNetworkDown(exc);
} catch (NoRouteToHostException exc) {
handleNetworkDown(exc);
} catch (ConnectException exc) {
handleNetworkDown(exc);
}
return session;
}
@ -139,18 +144,12 @@ public final class ExchangeSessionFactory {
}
// session opened, future failure will mean network down
configChecked = true;
} catch (UnknownHostException exc) {
handleNetworkDown(exc);
} catch (NoRouteToHostException exc) {
handleNetworkDown(exc);
// Could not open the port (probably because it is blocked behind a firewall)
} catch (ConnectException exc) {
handleNetworkDown(exc);
// Reset so next time an problem occurs message will be sent once
errorSent = false;
} catch (NetworkDownException exc) {
throw exc;
} catch (Exception exc) {
throw new DavMailException("EXCEPTION_DAVMAIL_CONFIGURATION", exc);
handleNetworkDown(exc);
} finally {
testMethod.releaseConnection();
}
@ -163,10 +162,18 @@ public final class ExchangeSessionFactory {
throw new NetworkDownException("EXCEPTION_NETWORK_DOWN");
} else {
BundleMessage message = new BundleMessage("EXCEPTION_CONNECT", exc.getClass().getName(), exc.getMessage());
if (errorSent) {
ExchangeSession.LOGGER.warn(message);
throw new NetworkDownException("EXCEPTION_DAVMAIL_CONFIGURATION");
} else {
// Mark that an error has been sent so you only get one
// error in a row (not a repeating string of errors).
errorSent = true;
ExchangeSession.LOGGER.error(message);
throw new DavMailException("EXCEPTION_DAVMAIL_CONFIGURATION", message);
}
}
}
/**
* Check if at least one network interface is up and active (i.e. has an address)
@ -197,6 +204,7 @@ public final class ExchangeSessionFactory {
*/
public static void reset() {
configChecked = false;
errorSent = false;
poolMap.clear();
}
}