Hello,
Im migrating code from httpclient3 to httpcllient4, and there are some
things I do with httpclient3 that Im not sure how to do with httpclient4. I
think my problems are in how to enable/disable cookies at connection manager
level, and how to manage idle connections (IdleConnectionHanfdler) at
connection manager level too.
---- The code for httpclient3 is:
----------------------------------------------------------------------------
----------------------
this.objHttp = new HttpClient(new MultiThreadedHttpConnectionManager());
this.objHttp.getHttpConnectionManager().getParams().setMaxTotalConnections(m
axConnections); // maxConnections
this.objHttp.getHttpConnectionManager().getParams().setConnectionTimeout(con
nectionTimeout); // connectionTimeout
this.objHttp.getParams().setSoTimeout(responseTimeout); //
responseTimeout
// Manage idle connections.
if (idleTimeout > 0)
{
this.ictt = new IdleConnectionsHandler();
this.ictt.addConnectionManager(this.objHttp.getHttpConnectionManager());
this.ictt.setTimeoutInterval(idleInterval);
this.ictt.setConnectionTimeout(idleTimeout);
this.ictt.start();
}
// Timeout for taking connections from pool (1 ms --> we dont wait)
this.objHttp.getParams().setConnectionManagerTimeout(1);
// "stale connections" and enable/disable "cookies".
this.objHttp.getHttpConnectionManager().getParams().setStaleCheckingEnabled(
true);
this.objHttp.getParams().setCookiePolicy(useCookies ? CookiePolicy.RFC_2109
: CookiePolicy.IGNORE_COOKIES);
---- Now the code for httpclient4:
----------------------------------------------------------------------------
----------------------
this.objHttpParams = new BasicHttpParams();
HttpProtocolParams.setVersion(this.objHttpParams, HttpVersion.HTTP_1_1);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http",
PlainSocketFactory.getSocketFactory(), 80));
schemeRegistry.register(new Scheme("https",
SSLSocketFactory.getSocketFactory(), 443));
ConnManagerParams.setMaxTotalConnections(this.objHttpParams,
maxConnections); // maxConnections
HttpConnectionParams.setConnectionTimeout(this.objHttpParams,
connectionTimeout); // connectionTimeout
HttpConnectionParams.setSoTimeout(this.objHttpParams, responseTimeout);
// responseTimeout
// Manage idle connections.
if (idleTimeout > 0)
{
NO IDEA. I could see IdleConnectionHandler and the method add, but at
connection level and not at connection manager level.
}
// Timeout for taking connections from pool (1 ms --> we dont wait)
ConnManagerParams.setTimeout(this.objHttpParams, 1);
// "stale connections" and "cookies".
HttpConnectionParams.setStaleCheckingEnabled(true);
if (useCookies) new RFC2109SpecFactory().newInstance(this.objHttpParams);
<------ is this OK? And how to disable cookies??????
// And create the 'HttpClient' with the 'ThreadSafeClientConnManager'.
ClientConnectionManager cm = new
ThreadSafeClientConnManager(this.objHttpParams, schemeRegistry);
this.objHttp = new DefaultHttpClient(cm, this.objHttpParams);
Thanks in advance,
Joan.