Switch to MultiThreadedHttpConnectionManager for http connection management

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@218 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2008-12-08 12:59:47 +00:00
parent e0d46770f7
commit 146c29c136
2 changed files with 7 additions and 22 deletions

View File

@ -373,19 +373,6 @@ public class ExchangeSession {
} }
} }
/**
* Close session.
* This will only close http client, not the actual Exchange session
*/
void close() {
try {
wdr.close();
LOGGER.debug("Session " + this + " closed");
} catch (IOException e) {
LOGGER.warn("Exception closing session", e);
}
}
/** /**
* Create message in current folder * Create message in current folder
* *

View File

@ -2,13 +2,7 @@ package davmail.http;
import davmail.Settings; import davmail.Settings;
import davmail.tray.DavGatewayTray; import davmail.tray.DavGatewayTray;
import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.NTCredentials;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.methods.GetMethod;
import java.io.IOException; import java.io.IOException;
@ -17,7 +11,10 @@ import java.io.IOException;
* Create HttpClient instance according to DavGateway Settings * Create HttpClient instance according to DavGateway Settings
*/ */
public class DavGatewayHttpClientFacade { public class DavGatewayHttpClientFacade {
static final MultiThreadedHttpConnectionManager multiThreadedHttpConnectionManager = new MultiThreadedHttpConnectionManager();
static { static {
multiThreadedHttpConnectionManager.setMaxConnectionsPerHost(10);
// force XML response with Internet Explorer header // force XML response with Internet Explorer header
System.getProperties().setProperty("httpclient.useragent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)"); System.getProperties().setProperty("httpclient.useragent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)");
} }
@ -43,6 +40,7 @@ public class DavGatewayHttpClientFacade {
* @param httpClient current Http client * @param httpClient current Http client
*/ */
public static void configureClient(HttpClient httpClient) { public static void configureClient(HttpClient httpClient) {
httpClient.setHttpConnectionManager(multiThreadedHttpConnectionManager);
// do not send basic auth automatically // do not send basic auth automatically
httpClient.getState().setAuthenticationPreemptive(false); httpClient.getState().setAuthenticationPreemptive(false);
@ -131,7 +129,7 @@ public class DavGatewayHttpClientFacade {
public static HttpMethod executeFollowRedirects(HttpClient httpClient, HttpMethod method) throws IOException { public static HttpMethod executeFollowRedirects(HttpClient httpClient, HttpMethod method) throws IOException {
try { try {
DavGatewayTray.debug("executeFollowRedirects: "+method.getURI()); DavGatewayTray.debug("executeFollowRedirects: " + method.getURI());
httpClient.executeMethod(method); httpClient.executeMethod(method);
Header location = method.getResponseHeader("Location"); Header location = method.getResponseHeader("Location");
int redirectCount = 0; int redirectCount = 0;
@ -141,7 +139,7 @@ public class DavGatewayHttpClientFacade {
method.releaseConnection(); method.releaseConnection();
method = new GetMethod(location.getValue()); method = new GetMethod(location.getValue());
method.setFollowRedirects(false); method.setFollowRedirects(false);
DavGatewayTray.debug("executeFollowRedirects: "+method.getURI()+" redirectCount:"+redirectCount); DavGatewayTray.debug("executeFollowRedirects: " + method.getURI() + " redirectCount:" + redirectCount);
httpClient.executeMethod(method); httpClient.executeMethod(method);
location = method.getResponseHeader("Location"); location = method.getResponseHeader("Location");
} }