Hello,
Ive just migrated the code from HttpClient3 to HttpClient4, and before
starting tests Id like to make you some questions:
1. When I set the Schema new Scheme("http",
PlainSocketFactory.getSocketFactory(), 80), what does it mean? It means
that the ThreadSafeClientConnManager can only send http requests, or it
can only send http requests to destination port 80?
2. With HttpClient3, I set the retryHandler at method level with:
objPost.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new
HttpRetryHandler(3));
With HttpClient4, this is similar but at connection level:
this.objHttp.setHttpRequestRetryHandler(new
DefaultHttpRequestRetryHandler(3, false));
Is it right? For every get/post HttpClient will retry the request 3 times
for any non-fatal error? Or should I set the retry handler at method level
like I used to do with HttpClient3? (Ive not seen a method to do this).
3. With HttpClient3, I used HttpState for managing cookies.
With HttpClient4, I set a cookieStore to a HttpContext in this way:
HttpContext localContext = new BasicHttpContext();
CookieStore cookieStore = new BasicCookieStore();
// Set cookies.
for (int j = 0; j < cookieSize; j++)
{
BasicClientCookie bcc = new
BasicClientCookie(this.arrCookies[j].getName(),
this.arrCookies[j].getValue());
cookieStore.addCookie(bcc);
}
localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
this.objHttp.execute(objGet, localContext)
And, when I receive the server response, I get cookies using the same
HttpContext:
List<Cookie> auxCookies =
((CookieStore)localContext.getAttribute(ClientContext.COOKIE_STORE)).getCook
ies();
Is this the right way to do this?
4. In HttpClient3, the documentation says that a small performance can
be gained by disabling cookies. The same for HttpClient4? If I want to
disable cookies, what I should to do? I saw this piece of code on Internet,
but Im not sure if its right:
this.objHttp.setCookieStore(null);
this.objHttp.setCookieSpecs(null);
5. Receive a null HttpEntity means that the server sent an empty
response?
Thanks for your time.
JOAN BALAGUERÓ
GRUPO VENTUS
C/ Balmes 195, 4º 4ª // 08006 BCN
Telf.: 902 43 05 75 // Fax: 93 292 01 49
<http://www.grupoventus.com> www.grupoventus.com