1
0
mirror of https://github.com/moparisthebest/davmail synced 2024-08-13 16:53:51 -04:00

Simplify HttpClient creation to avoid password decoding bug in commons httpclient ('+' in password decoded as ' ')

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@678 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2009-08-18 18:15:05 +00:00
parent 3b7a369e33
commit dfe241dc2b
2 changed files with 12 additions and 22 deletions

View File

@ -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);

View File

@ -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);
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;
}