From 8947927c0186f4c64e0fee17dc97f3f352c58a64 Mon Sep 17 00:00:00 2001 From: mguessan Date: Tue, 27 Jul 2010 10:26:19 +0000 Subject: [PATCH] EWS: Exchange 2010 compatibility: add test cookie, access /ews/exchange.asmx endpoint git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1296 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- src/java/davmail/exchange/ExchangeSession.java | 3 +++ .../davmail/exchange/ews/EwsExchangeSession.java | 12 ++++++------ src/java/davmail/util/StringUtil.java | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/java/davmail/exchange/ExchangeSession.java b/src/java/davmail/exchange/ExchangeSession.java index a515b6a4..a4633048 100644 --- a/src/java/davmail/exchange/ExchangeSession.java +++ b/src/java/davmail/exchange/ExchangeSession.java @@ -422,6 +422,9 @@ public abstract class ExchangeSession { ((PostMethod) logonMethod).addParameter(passwordInput, password); ((PostMethod) logonMethod).addParameter("trusted", "4"); ((PostMethod) logonMethod).addParameter("flags", "4"); + + // add exchange 2010 cookie + logonMethod.addRequestHeader("Cookie", "PBack=0"); logonMethod = DavGatewayHttpClientFacade.executeFollowRedirects(httpClient, logonMethod); // test form based authentication diff --git a/src/java/davmail/exchange/ews/EwsExchangeSession.java b/src/java/davmail/exchange/ews/EwsExchangeSession.java index 70217023..23fc5473 100644 --- a/src/java/davmail/exchange/ews/EwsExchangeSession.java +++ b/src/java/davmail/exchange/ews/EwsExchangeSession.java @@ -29,7 +29,7 @@ import org.apache.commons.codec.binary.Base64; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpMethod; import org.apache.commons.httpclient.HttpStatus; -import org.apache.commons.httpclient.methods.HeadMethod; +import org.apache.commons.httpclient.methods.GetMethod; import java.io.IOException; import java.net.HttpURLConnection; @@ -83,17 +83,17 @@ public class EwsExchangeSession extends ExchangeSession { protected void buildSessionInfo(HttpMethod method) throws DavMailException { // nothing to do, mailPath not used in EWS mode // check EWS access - HttpMethod headMethod = new HeadMethod("/ews/services.wsdl"); + HttpMethod getMethod = new GetMethod("/ews/exchange.asmx"); try { - headMethod = DavGatewayHttpClientFacade.executeFollowRedirects(httpClient, headMethod); - if (headMethod.getStatusCode() != HttpStatus.SC_OK) { - throw DavGatewayHttpClientFacade.buildHttpException(headMethod); + getMethod = DavGatewayHttpClientFacade.executeFollowRedirects(httpClient, getMethod); + if (getMethod.getStatusCode() != HttpStatus.SC_OK) { + throw DavGatewayHttpClientFacade.buildHttpException(getMethod); } } catch (IOException e) { LOGGER.error(e.getMessage()); throw new DavMailAuthenticationException("EXCEPTION_EWS_NOT_AVAILABLE"); } finally { - headMethod.releaseConnection(); + getMethod.releaseConnection(); } try { diff --git a/src/java/davmail/util/StringUtil.java b/src/java/davmail/util/StringUtil.java index ad7ab0cf..0dcca9ae 100644 --- a/src/java/davmail/util/StringUtil.java +++ b/src/java/davmail/util/StringUtil.java @@ -169,7 +169,7 @@ public final class StringUtil { */ public static String urlDecodeAmpersand(String name) { String result = name; - if (name.indexOf("%26") >= 0) { + if (name != null && name.indexOf("%26") >= 0) { result = URLENCODED_AMP_PATTERN.matcher(result).replaceAll("&"); } return result;