You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by di...@multitask.com.au on 2002/12/17 02:24:27 UTC
Moving from HttpMultiClient to HttpClient
Is there a good summary somewhere of the changes made so that the new
HttpClient can be used in place of the old MultiClient?
I was hoping for something other than a diff/visual scan....
--
dIon Gillard, Multitask Consulting
Blog: http://www.freeroller.net/page/dion/Weblog
Work: http://www.multitask.com.au
Re: Moving from HttpMultiClient to HttpClient
Posted by Jeffrey Dever <js...@sympatico.ca>.
All I have at this point is the commit comment:
What's new:
- HostConfiguration, a new class for combining host/proxy info
- HttpConnectionManager, this is a new interface to replace the previous
class
- SimpleHttpConnectionManager, an implementation of
HttpConnectionManager that gives access to a single connection
- When using HttpClient with the multi-threaded connection manager
HttpConnections must be released before they can be reused. Currently
there are three ways of doing this:
1) HttpMethod.releaseConnection(), following a client.executeMethod()
2) fully read the method's response stream
3) allow the connection to be garbage collected by losing a reference to
the method. this is not terribly efficient and is mostly just a safety
mechanism to ensure that connections are not lost.
What's changed:
- HttpConnectionManager has been renamed to
MultiThreadedHttpConnectionManager and complies with the
HttpConnectionManager interface
- HttpClient, most of the previous methods have been deprecated and
replaced by ones that make sense for multiple thread access. an attempt
has been made to make all data thread-safe.
dion@multitask.com.au wrote:
>Is there a good summary somewhere of the changes made so that the new
>HttpClient can be used in place of the old MultiClient?
>
>I was hoping for something other than a diff/visual scan....
>--
>dIon Gillard, Multitask Consulting
>Blog: http://www.freeroller.net/page/dion/Weblog
>Work: http://www.multitask.com.au
>
>
>--
>To unsubscribe, e-mail: <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>
>
>
Re: Moving from HttpMultiClient to HttpClient
Posted by Michael Becke <be...@u.washington.edu>.
Please do.
Mike
On Tuesday, December 17, 2002, at 02:54 AM, Ortwin Glück wrote:
> Mike, can we include this in our Samples?
>
> Odi
>
> Michael Becke wrote:
>> Here's a simple example of how to get started with the HttpClient
>> from multiple threads. Hope this helps.
>> Mike
>> ----------------------------------------------------------------------
>> --
>> import org.apache.commons.httpclient.HttpClient;
>> import
>> org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
>> import org.apache.commons.httpclient.methods.GetMethod;
>> /**
>> * An example that reads news.google.com from multiple threads.
>> */
>> public class MultiThreadedExample {
>> /**
>> * Constructor for MultiThreadedExample.
>> */
>> public MultiThreadedExample() {
>> super();
>> }
>> public static void main(String[] args) {
>> HttpClient httpClient = new HttpClient(
>> new MultiThreadedHttpConnectionManager() );
>> // set the default host to google news
>> httpClient.getHostConfiguration().setHost( "news.google.com",
>> -1, "http" );
>> // create 4 reading threads
>> ReadSomeGoogle[] threads = new ReadSomeGoogle[4];
>> for (int i = 0; i < threads.length; i++) {
>> threads[i] = new ReadSomeGoogle( httpClient, i + 1 );
>> }
>> // start the threads
>> for (int j = 0; j < threads.length; j++) {
>> threads[j].start();
>> }
>> }
>> /**
>> * A thread that performs a GET from an HttpClient.
>> */
>> static class ReadSomeGoogle extends Thread {
>> private HttpClient httpClient;
>> private int id;
>> public ReadSomeGoogle( HttpClient httpClient, int id
>> ) {
>> this.httpClient = httpClient;
>> this.id = id;
>> }
>> public void run() {
>> GetMethod get = new GetMethod("/");
>> get.setFollowRedirects(true);
>> try {
>> System.out.println( id + " - about to
>> get something" );
>> httpClient.executeMethod( get );
>> System.out.println( id + " - get executed" );
>> byte[] bytes = get.getResponseBody();
>> System.out.println( id + " - " + bytes.length + "
>> bytes read" );
>> } catch ( Exception e ) {
>> System.out.println( id + " - error: " + e );
>> } finally {
>> get.releaseConnection();
>> System.out.println( id + " - connection released" );
>> }
>> }
>> }
>> }
>> ----------------------------------------------------------------------
>> --
>> On Monday, December 16, 2002, at 08:24 PM, dion@multitask.com.au
>> wrote:
>>> Is there a good summary somewhere of the changes made so that the new
>>> HttpClient can be used in place of the old MultiClient?
>>>
>>> I was hoping for something other than a diff/visual scan....
>>> --
>>> dIon Gillard, Multitask Consulting
>>> Blog: http://www.freeroller.net/page/dion/Weblog
>>> Work: http://www.multitask.com.au
>>>
>>>
>>> --
>>> To unsubscribe, e-mail:
>>> <ma...@jakarta.apache.org>
>>> For additional commands, e-mail:
>>> <ma...@jakarta.apache.org>
>>>
>> ----------------------------------------------------------------------
>> --
>> --
>> To unsubscribe, e-mail:
>> <ma...@jakarta.apache.org>
>> For additional commands, e-mail:
>> <ma...@jakarta.apache.org>
>
> --
> _________________________________________________________________
> NOSE applied intelligence ag
> [www] http://www.nose.ch
> ortwin glück [email] ortwin.glueck@nose.ch
> hardturmstrasse 171 [pgp key] 0x81CF3416
> 8005 zurich [office] +41-1-277 57 35
> switzerland [fax] +41-1-277 57 12
>
>
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
>
Re: Moving from HttpMultiClient to HttpClient
Posted by Ortwin Glück <or...@nose.ch>.
Mike, can we include this in our Samples?
Odi
Michael Becke wrote:
> Here's a simple example of how to get started with the HttpClient from
> multiple threads. Hope this helps.
>
> Mike
>
>
> ------------------------------------------------------------------------
>
> import org.apache.commons.httpclient.HttpClient;
> import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
> import org.apache.commons.httpclient.methods.GetMethod;
>
> /**
> * An example that reads news.google.com from multiple threads.
> */
> public class MultiThreadedExample {
>
> /**
> * Constructor for MultiThreadedExample.
> */
> public MultiThreadedExample() {
> super();
> }
>
> public static void main(String[] args) {
>
> HttpClient httpClient = new HttpClient(
> new MultiThreadedHttpConnectionManager()
> );
>
> // set the default host to google news
> httpClient.getHostConfiguration().setHost( "news.google.com", -1, "http" );
>
> // create 4 reading threads
> ReadSomeGoogle[] threads = new ReadSomeGoogle[4];
> for (int i = 0; i < threads.length; i++) {
> threads[i] = new ReadSomeGoogle( httpClient, i + 1 );
> }
>
> // start the threads
> for (int j = 0; j < threads.length; j++) {
> threads[j].start();
> }
>
> }
>
> /**
> * A thread that performs a GET from an HttpClient.
> */
> static class ReadSomeGoogle extends Thread {
>
> private HttpClient httpClient;
> private int id;
>
> public ReadSomeGoogle( HttpClient httpClient, int id ) {
> this.httpClient = httpClient;
> this.id = id;
> }
>
> public void run() {
>
> GetMethod get = new GetMethod("/");
> get.setFollowRedirects(true);
>
> try {
>
> System.out.println( id + " - about to get something" );
> httpClient.executeMethod( get );
> System.out.println( id + " - get executed" );
> byte[] bytes = get.getResponseBody();
> System.out.println( id + " - " + bytes.length + " bytes read" );
>
> } catch ( Exception e ) {
> System.out.println( id + " - error: " + e );
> } finally {
> get.releaseConnection();
> System.out.println( id + " - connection released" );
> }
>
> }
>
> }
>
> }
>
>
> ------------------------------------------------------------------------
>
>
>
> On Monday, December 16, 2002, at 08:24 PM, dion@multitask.com.au wrote:
>
>> Is there a good summary somewhere of the changes made so that the new
>> HttpClient can be used in place of the old MultiClient?
>>
>> I was hoping for something other than a diff/visual scan....
>> --
>> dIon Gillard, Multitask Consulting
>> Blog: http://www.freeroller.net/page/dion/Weblog
>> Work: http://www.multitask.com.au
>>
>>
>> --
>> To unsubscribe, e-mail:
>> <ma...@jakarta.apache.org>
>> For additional commands, e-mail:
>> <ma...@jakarta.apache.org>
>>
>
>
> ------------------------------------------------------------------------
>
> --
> To unsubscribe, e-mail: <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
--
_________________________________________________________________
NOSE applied intelligence ag
[www] http://www.nose.ch
ortwin glück [email] ortwin.glueck@nose.ch
hardturmstrasse 171 [pgp key] 0x81CF3416
8005 zurich [office] +41-1-277 57 35
switzerland [fax] +41-1-277 57 12
Re: Moving from HttpMultiClient to HttpClient
Posted by Michael Becke <be...@u.washington.edu>.
Here's a simple example of how to get started with the HttpClient from
multiple threads. Hope this helps.
Mike