Joan Balagueró wrote:
Hello,

I’ve just migrated the code from HttpClient3 to HttpClient4, and before starting tests I’d 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?


This value represents a default port for a particular scheme. If a request URI does not explicitly specify a port the default port value will be used when connecting to the target host

'http://www.whatever.com/' -> connect to www.whatever.com: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?

This is correct.


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? (I’ve 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)).getCookies();

Is this the right way to do this?


Yes, it is


   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 I’m not sure if it’s right:

this.objHttp.setCookieStore(null);

this.objHttp.setCookieSpecs(null);


To completely disable cookie processing remove these two protocol interceptors from the protocol processing chain

---
DefaultHttpClient httpclient = new DefaultHttpClient(); httpclient.removeRequestInterceptorByClass(RequestAddCookies.class);
httpclient.removeResponseInterceptorByClass(ResponseProcessCookies.class);
---


   5. Receive a null HttpEntity means that the server sent an empty
      response?


No, that usually can only happen if an HTTP response may not enclose a response body at all: it is a response to a HEAD request, or a response with status code 204, 205, 304.

Hope this helps

Oleg

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

www.grupoventus.com <http://www.grupoventus.com>

 __



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to