Duzayak (I hope I got your name right),

You can create an instance of the HttpState class per thread and pass the respective 
HttpState object along with the HTTP method to be executed:

// shared by all the worker threads
HttpConnectionManager connman = new MultiThreadedHttpConnectionManager();
HttpClient agent = new HttpClient(connman);

// one per thread
HttpState httpstate = new HttpState();

// in the worker thread
GetMethod httpget = new GetMethod("http://www.whatever.com";);
try {
  agent.executeMethod(null, httpget, httpstate);
  // do something useful with the result
} finally {
  httpget.releaseConnection();
}


For more details see

http://jakarta.apache.org/commons/httpclient/apidocs/org/apache/commons/httpclient/HttpClient.html#executeMethod(org.apache.commons.httpclient.HostConfiguration,%20org.apache.commons.httpclient.HttpMethod,%20org.apache.commons.httpclient.HttpState)

HTH

Oleg

-----Original Message-----
From: Cabbar Duzayak [mailto:[EMAIL PROTECTED]
Sent: Wednesday, May 12, 2004 9:33
To: [EMAIL PROTECTED]
Subject: HttpClient initialization, when/where?


Hi,

I will be writing a gateway which will invoke URLs in
behalf of several threads and they will return the
content. Each thread needs to invoke different URLs
with different context (cookies, etc).

It looks like right way of doing this is to
instantiate the HttpClient once with
MultiThreadedHttpConnectionManager and each thread
will use httpClient.executeMethod on this HttpClient
instance. Or the other alternative is to instantiate
one object for each thread, and keep calling
executeMethods on them.

However, since you can set the state of the
HttpClient, I was wondering if I can use the
HttpClient for iterative http invocations with
different contexts? I mean, is there an in-memory
state other than the HttpState that is preserved
between these invocations? Would it be enough to
create an HttpState and GetMethod for each call, and
set it before calling executeMethod?

Shortly, what is the optimum mechanism for this
functionality?

TIA...




        
__________________________________
Do you Yahoo!?
Yahoo! Movies - Buy advance tickets for 'Shrek 2'
http://movies.yahoo.com/showtimes/movie?mid=1808405861

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


***************************************************************************************************
The information in this email is confidential and may be legally privileged.  Access 
to this email by anyone other than the intended addressee is unauthorized.  If you are 
not the intended recipient of this message, any review, disclosure, copying, 
distribution, retention, or any action taken or omitted to be taken in reliance on it 
is prohibited and may be unlawful.  If you are not the intended recipient, please 
reply to or forward a copy of this message to the sender and delete the message, any 
attachments, and any copies thereof from your system.
***************************************************************************************************

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to