mirror of
https://github.com/moparisthebest/davmail
synced 2025-01-12 14:08:38 -05:00
Fix autodiscover support
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1407 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
add2abb818
commit
93a296b4ef
@ -78,6 +78,34 @@ public class EwsExchangeSession extends ExchangeSession {
|
|||||||
super(url, userName, password);
|
super(url, userName, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check endpoint url.
|
||||||
|
*
|
||||||
|
* @param endPointUrl endpoint url
|
||||||
|
* @throws IOException on error
|
||||||
|
*/
|
||||||
|
protected void checkEndPointUrl(String endPointUrl) throws IOException {
|
||||||
|
HttpMethod getMethod = new GetMethod(endPointUrl);
|
||||||
|
getMethod.setFollowRedirects(false);
|
||||||
|
try {
|
||||||
|
int status = DavGatewayHttpClientFacade.executeNoRedirect(httpClient, getMethod);
|
||||||
|
if (status != HttpStatus.SC_MOVED_TEMPORARILY) {
|
||||||
|
throw DavGatewayHttpClientFacade.buildHttpException(getMethod);
|
||||||
|
}
|
||||||
|
// check Location
|
||||||
|
Header locationHeader = getMethod.getResponseHeader("Location");
|
||||||
|
if (locationHeader == null || !"/ews/services.wsdl".equalsIgnoreCase(locationHeader.getValue())) {
|
||||||
|
throw new IOException("Ews endpoint not available at " + getMethod.getURI().toString());
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOGGER.debug(e.getMessage());
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
getMethod.releaseConnection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void buildSessionInfo(HttpMethod method) throws DavMailException {
|
protected void buildSessionInfo(HttpMethod method) throws DavMailException {
|
||||||
// also need to retrieve email and alias
|
// also need to retrieve email and alias
|
||||||
@ -89,27 +117,16 @@ public class EwsExchangeSession extends ExchangeSession {
|
|||||||
|
|
||||||
// nothing to do, mailPath not used in EWS mode
|
// nothing to do, mailPath not used in EWS mode
|
||||||
// check EWS access
|
// check EWS access
|
||||||
HttpMethod getMethod = new GetMethod("/ews/exchange.asmx");
|
|
||||||
getMethod.setFollowRedirects(false);
|
|
||||||
try {
|
try {
|
||||||
int status = DavGatewayHttpClientFacade.executeNoRedirect(httpClient, getMethod);
|
checkEndPointUrl("/ews/exchange.asmx");
|
||||||
if (status != HttpStatus.SC_MOVED_TEMPORARILY) {
|
|
||||||
throw DavGatewayHttpClientFacade.buildHttpException(getMethod);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOGGER.debug(e.getMessage());
|
|
||||||
try {
|
try {
|
||||||
// failover, try to retrieve EWS url from autodiscover
|
// failover, try to retrieve EWS url from autodiscover
|
||||||
getMethod.releaseConnection();
|
checkEndPointUrl(getEwsUrlFromAutoDiscover());
|
||||||
getMethod = new GetMethod(getEwsUrlFromAutoDiscover());
|
|
||||||
getMethod.setFollowRedirects(false);
|
|
||||||
} catch (IOException e2) {
|
} catch (IOException e2) {
|
||||||
LOGGER.error(e2.getMessage());
|
LOGGER.error(e2.getMessage());
|
||||||
throw new DavMailAuthenticationException("EXCEPTION_EWS_NOT_AVAILABLE");
|
throw new DavMailAuthenticationException("EXCEPTION_EWS_NOT_AVAILABLE");
|
||||||
}
|
}
|
||||||
|
|
||||||
} finally {
|
|
||||||
getMethod.releaseConnection();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -147,7 +164,10 @@ public class EwsExchangeSession extends ExchangeSession {
|
|||||||
@Override
|
@Override
|
||||||
protected void processResponseBody(HttpState httpState, HttpConnection httpConnection) {
|
protected void processResponseBody(HttpState httpState, HttpConnection httpConnection) {
|
||||||
Header contentTypeHeader = getResponseHeader("Content-Type");
|
Header contentTypeHeader = getResponseHeader("Content-Type");
|
||||||
if (contentTypeHeader != null && "text/xml; charset=utf-8".equals(contentTypeHeader.getValue())) {
|
if (contentTypeHeader != null &&
|
||||||
|
("text/xml; charset=utf-8".equals(contentTypeHeader.getValue())
|
||||||
|
|| "text/html; charset=utf-8".equals(contentTypeHeader.getValue())
|
||||||
|
)) {
|
||||||
BufferedReader autodiscoverReader = null;
|
BufferedReader autodiscoverReader = null;
|
||||||
try {
|
try {
|
||||||
autodiscoverReader = new BufferedReader(new InputStreamReader(getResponseBodyAsStream()));
|
autodiscoverReader = new BufferedReader(new InputStreamReader(getResponseBodyAsStream()));
|
||||||
|
Loading…
Reference in New Issue
Block a user