Hi Oleg, thanks for the answers! I realized there is some very good documentation available which I just did not find, because it is linked only from the HttpCommons Core and not from the Client...
Michael 2009/7/9 Oleg Kalnichevski <[email protected]> > Ken Krugler wrote: > >> A few answers in-line below. >> >> Disclaimer: I've ported some HttpClient 3.1 code to 4.0, but I haven't >> made heavy use of the full 4.0 functionality. >> >> I am new to HTTPComponents Client but have been using HttpClient 3.1 very >>> extensively... So I am facing some migration work. >>> >>> 1. How do I measure the time it took to get a response in a multithreaded >>> scenario with a limited size of max total connections? >>> >>> In 3.1 I had to hack this into a custom ProtocolSocketFactory. When the >>> socket is created I am rembering the time in a thread local scope. >>> >>> >> > >> Is that still the way to go? >>> >>> > Michael, > > I would recommend using custom protocol interceptors to collect performance > related metrics. Use a request interceptor to store the start time in the > HTTP context, and a response interceptor to store the finish time. For > details see: > > > http://hc.apache.org/httpcomponents-client/tutorial/html/fundamentals.html#d4e290 > > >>> 2. I want to set a different user agent per request >>> >>> In 3.1 I could set HostParams when executing the method. How does it work >>> now? >>> >> >> I believe you'd want to implement a RequestUserAgent class that sets up >> the user agent that you want. >> >> Seems like you might be able to do the same thing via using an >> HttpContext, but Oleg would know best. >> >> > One could also use the 'http.useragent' parameter: > > > http://hc.apache.org/httpcomponents-client/tutorial/html/fundamentals.html#d4e337 > > 3. Setting a proxy per request >>> >>> httpClient.execute(proxyHost, httpget, responseHandler); >>> >>> Correct? >>> >>> > Use 'http.route.default-proxy' parameter. > > http://hc.apache.org/httpcomponents-client/tutorial/html/ch02.html#d4e465 > http://hc.apache.org/httpcomponents-client/tutorial/html/ch02.html#d4e540 > > 4. Disabling redirects >>> >>> params.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, false); >>> >>> Correct? >>> >>> > Yes. > > 5. Enabling my own retry handler (which I just need because of verbose >>> logging) >>> >>> ((DefaultHttpClient) this.httpClient).setHttpRequestRetryHandler(XXX); >>> >>> Correct? >>> >>> > Yes. > > 6. When using the ThreadSafeClientConnManager how can I monitor the number >>> of threads used or threads waiting? >>> >> >> Well, you can call getConnectionsInPool() to get the number of in-use >> connections, though I think that would include connections that are no >> longer active but haven't been released back. >> >> "Threads waiting" would (I assume) mean the number of HTTP requests you've >> made where no free connection is available, and thus the request is hung in >> ClientConnectionRequest.getConnection() until it gets a connection to use, >> or it times out. >> >> There must be some way to find this out, but it's not obvious from the >> APIs. >> >> I guess the ThreadSafeClientConnManager is the replacement of the >>> MultiThreadedHttpConnectionManager? >>> >> >> Yes, I believe so. Or at least that's what I've changed my 3.1 code to use >> with 4.0. >> >> -- Ken >> > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > >
