diff --git a/src/java/davmail/exchange/ExchangeSession.java b/src/java/davmail/exchange/ExchangeSession.java index 7451e360..f50196a6 100644 --- a/src/java/davmail/exchange/ExchangeSession.java +++ b/src/java/davmail/exchange/ExchangeSession.java @@ -151,22 +151,7 @@ public class ExchangeSession { try { boolean isBasicAuthentication = isBasicAuthentication(poolKey.url); - // get proxy configuration from setttings properties - URL urlObject = new URL(poolKey.url); - // webdavresource is unable to create the correct url type - HttpURL httpURL; - if (poolKey.url.startsWith("http://")) { - httpURL = new HttpURL(poolKey.userName, poolKey.password, - urlObject.getHost(), urlObject.getPort()); - } else if (poolKey.url.startsWith("https://")) { - httpURL = new HttpsURL(poolKey.userName, poolKey.password, - urlObject.getHost(), urlObject.getPort()); - } else { - throw new DavMailException("LOG_INVALID_URL", poolKey.url); - } - - - httpClient = DavGatewayHttpClientFacade.getInstance(httpURL); + httpClient = DavGatewayHttpClientFacade.getInstance(poolKey.url, poolKey.userName, poolKey.password); // avoid 401 roundtrips httpClient.getParams().setParameter(HttpClientParams.PREEMPTIVE_AUTHENTICATION, true); diff --git a/src/java/davmail/http/DavGatewayHttpClientFacade.java b/src/java/davmail/http/DavGatewayHttpClientFacade.java index 3648d454..fe85de57 100644 --- a/src/java/davmail/http/DavGatewayHttpClientFacade.java +++ b/src/java/davmail/http/DavGatewayHttpClientFacade.java @@ -20,6 +20,7 @@ package davmail.http; import davmail.Settings; import davmail.BundleMessage; +import davmail.exception.DavMailException; import davmail.ui.tray.DavGatewayTray; import org.apache.commons.httpclient.*; import org.apache.commons.httpclient.auth.AuthPolicy; @@ -37,6 +38,7 @@ import org.apache.jackrabbit.webdav.client.methods.PropFindMethod; import java.io.IOException; import java.util.ArrayList; +import java.net.URL; /** * Create HttpClient instance according to DavGateway Settings @@ -73,16 +75,19 @@ public final class DavGatewayHttpClientFacade { return httpClient; } - public static HttpClient getInstance(HttpURL httpURL) throws URIException { + public static HttpClient getInstance(String url, String userName, String password) throws DavMailException { HttpClient httpClient = new HttpClient(); httpClient.getParams().setParameter(HttpMethodParams.USER_AGENT, IE_USER_AGENT); httpClient.getParams().setParameter(HttpClientParams.MAX_REDIRECTS, MAX_REDIRECTS); HostConfiguration hostConfig = httpClient.getHostConfiguration(); - hostConfig.setHost(httpURL); - String userName = httpURL.getUser(); - String password = httpURL.getPassword(); - AuthScope authScope = new AuthScope(httpURL.getHost(), httpURL.getPort(), AuthScope.ANY_REALM); - httpClient.getState().setCredentials(authScope, new UsernamePasswordCredentials(userName, password)); + try { + URI httpURI = new URI(url, true); + hostConfig.setHost(httpURI); + AuthScope authScope = new AuthScope(httpURI.getHost(), httpURI.getPort(), AuthScope.ANY_REALM); + httpClient.getState().setCredentials(authScope, new UsernamePasswordCredentials(userName, password)); + } catch (URIException e) { + throw new DavMailException("LOG_INVALID_URL", url); + } configureClient(httpClient); return httpClient; }