1
0
mirror of https://github.com/moparisthebest/davmail synced 2024-12-13 11:12:22 -05:00

EWS: automatically detect Webdav not available and set davmail.enableEws flag

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1499 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2010-10-08 09:25:58 +00:00
parent d25e946254
commit 6a9ea37f60
3 changed files with 47 additions and 3 deletions

View File

@ -0,0 +1,34 @@
/*
* DavMail POP/IMAP/SMTP/CalDav/LDAP Exchange Gateway
* Copyright (C) 2010 Mickael Guessant
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package davmail.exception;
/**
* Exchange 2007 with Webdav disabled will trigger this exception.
*/
public class WebdavNotAvailableException extends DavMailException {
/**
* Create a DavMail exception with the given BundleMessage key and arguments.
*
* @param key message key
* @param arguments message values
*/
public WebdavNotAvailableException(String key, Object... arguments) {
super(key, arguments);
}
}

View File

@ -22,6 +22,7 @@ import davmail.BundleMessage;
import davmail.Settings;
import davmail.exception.DavMailAuthenticationException;
import davmail.exception.DavMailException;
import davmail.exception.WebdavNotAvailableException;
import davmail.exchange.dav.DavExchangeSession;
import davmail.exchange.ews.EwsExchangeSession;
import davmail.http.DavGatewayHttpClientFacade;
@ -114,7 +115,16 @@ public final class ExchangeSessionFactory {
if (Settings.getBooleanProperty("davmail.enableEws")) {
session = new EwsExchangeSession(poolKey.url, poolKey.userName, poolKey.password);
} else {
session = new DavExchangeSession(poolKey.url, poolKey.userName, poolKey.password);
try {
session = new DavExchangeSession(poolKey.url, poolKey.userName, poolKey.password);
} catch (WebdavNotAvailableException e) {
ExchangeSession.LOGGER.debug(e.getMessage()+", retry with EWS");
session = new EwsExchangeSession(poolKey.url, poolKey.userName, poolKey.password);
// success, enable EWS flag
ExchangeSession.LOGGER.debug("EWS found, changing davmail.enableEws setting");
Settings.setProperty("davmail.enableEws", "true");
Settings.save();
}
}
ExchangeSession.LOGGER.debug("Created new session: " + session);
}

View File

@ -662,7 +662,7 @@ public class DavExchangeSession extends ExchangeSession {
responses = DavGatewayHttpClientFacade.executePropFindMethod(
httpClient, URIUtil.encodePath(mailPath), 0, WELL_KNOWN_FOLDERS);
if (responses.length == 0) {
throw new DavMailException("EXCEPTION_UNABLE_TO_GET_MAIL_FOLDER", mailPath);
throw new WebdavNotAvailableException("EXCEPTION_UNABLE_TO_GET_MAIL_FOLDER", mailPath);
}
DavPropertySet properties = responses[0].getProperties(HttpStatus.SC_OK);
inboxUrl = getURIPropertyIfExists(properties, "inbox");
@ -728,7 +728,7 @@ public class DavExchangeSession extends ExchangeSession {
);
} catch (IOException e) {
LOGGER.error(e.getMessage());
throw new DavMailAuthenticationException("EXCEPTION_UNABLE_TO_GET_MAIL_FOLDER", mailPath);
throw new WebdavNotAvailableException("EXCEPTION_UNABLE_TO_GET_MAIL_FOLDER", mailPath);
}
}