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:
parent
d2e2e5ee3c
commit
6ef071603a
@ -40,6 +40,7 @@ public final class ExchangeSessionFactory {
|
|||||||
private static final Object LOCK = new Object();
|
private static final Object LOCK = new Object();
|
||||||
private static final Map<PoolKey, ExchangeSession> poolMap = new HashMap<PoolKey, ExchangeSession>();
|
private static final Map<PoolKey, ExchangeSession> poolMap = new HashMap<PoolKey, ExchangeSession>();
|
||||||
private static boolean configChecked;
|
private static boolean configChecked;
|
||||||
|
private static boolean errorSent;
|
||||||
|
|
||||||
static class PoolKey {
|
static class PoolKey {
|
||||||
public final String url;
|
public final String url;
|
||||||
@ -110,10 +111,14 @@ public final class ExchangeSessionFactory {
|
|||||||
}
|
}
|
||||||
// session opened, future failure will mean network down
|
// session opened, future failure will mean network down
|
||||||
configChecked = true;
|
configChecked = true;
|
||||||
|
// Reset so next time an problem occurs message will be sent once
|
||||||
|
errorSent = false;
|
||||||
} catch (UnknownHostException exc) {
|
} catch (UnknownHostException exc) {
|
||||||
handleNetworkDown(exc);
|
handleNetworkDown(exc);
|
||||||
} catch (NoRouteToHostException exc) {
|
} catch (NoRouteToHostException exc) {
|
||||||
handleNetworkDown(exc);
|
handleNetworkDown(exc);
|
||||||
|
} catch (ConnectException exc) {
|
||||||
|
handleNetworkDown(exc);
|
||||||
}
|
}
|
||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
@ -139,18 +144,12 @@ public final class ExchangeSessionFactory {
|
|||||||
}
|
}
|
||||||
// session opened, future failure will mean network down
|
// session opened, future failure will mean network down
|
||||||
configChecked = true;
|
configChecked = true;
|
||||||
|
// Reset so next time an problem occurs message will be sent once
|
||||||
} catch (UnknownHostException exc) {
|
errorSent = false;
|
||||||
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);
|
|
||||||
} catch (NetworkDownException exc) {
|
} catch (NetworkDownException exc) {
|
||||||
throw exc;
|
throw exc;
|
||||||
} catch (Exception exc) {
|
} catch (Exception exc) {
|
||||||
throw new DavMailException("EXCEPTION_DAVMAIL_CONFIGURATION", exc);
|
handleNetworkDown(exc);
|
||||||
} finally {
|
} finally {
|
||||||
testMethod.releaseConnection();
|
testMethod.releaseConnection();
|
||||||
}
|
}
|
||||||
@ -163,10 +162,18 @@ public final class ExchangeSessionFactory {
|
|||||||
throw new NetworkDownException("EXCEPTION_NETWORK_DOWN");
|
throw new NetworkDownException("EXCEPTION_NETWORK_DOWN");
|
||||||
} else {
|
} else {
|
||||||
BundleMessage message = new BundleMessage("EXCEPTION_CONNECT", exc.getClass().getName(), exc.getMessage());
|
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);
|
ExchangeSession.LOGGER.error(message);
|
||||||
throw new DavMailException("EXCEPTION_DAVMAIL_CONFIGURATION", message);
|
throw new DavMailException("EXCEPTION_DAVMAIL_CONFIGURATION", message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if at least one network interface is up and active (i.e. has an address)
|
* 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() {
|
public static void reset() {
|
||||||
configChecked = false;
|
configChecked = false;
|
||||||
|
errorSent = false;
|
||||||
poolMap.clear();
|
poolMap.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user