You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by "Sharma, Siddharth" <Si...@Staples.com> on 2006/06/10 01:14:11 UTC

Concurrency question

Hi

I am using httpclient-3.0-rc4.
I am writing a wrapper around httpclient.
We will use this wrapper (and so the wrapped httpclient api) to make
conversational B2B requests with remote services over https(s) and
content-type text/xml.

In other words, the client is a J2EE container in which our application runs
and the target is an arbitrary xml over http(s) service. It is important to
note that even though the client is the application server, the conversation
needs to be maintained on behalf of the end-browser OR the application
server is making the request to the remote service on behalf of the end
user.

Since the connection needs to be conversational, we need to maintain
cookies. I noticed the class that wraps this is HttpState.
HttpClient wraps this class.
But the page 'Optimization Guide'
http://jakarta.apache.org/commons/httpclient/performance.html states that it
is better to reuse httpclient. But if httpclient maintains state for a
client, how can it be reused?

So I declared HttpClient as static to reuse it for all requests to all
remote services. And I passed it the MultiThreadedHttpConnectionManager for
handling concurrent requests. But I cannot figure out how to set HttpState
in a thread-safe manner. The easiest way is to create HttpClient per user
request but that is contradictory to the optimization guide's reuse
suggestion.

Am I missing something here?
Is it a wrong assumption that httpclient can be reused even for
conversational requests?
Is it a wrong assumption that httpclient can be reused for all remote
services? Or it should only be reused for each unique HostConfiguration?

Thanks in advance
Sidd


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Re: Concurrency question

Posted by Roland Weber <ht...@dubioso.net>.
Hello Sidd,

> Since the connection needs to be conversational, we need to maintain
> cookies. I noticed the class that wraps this is HttpState.
> HttpClient wraps this class.

HttpClient wraps only the default HttpState object, for those that
don't need to maintain separate states.

> So I declared HttpClient as static to reuse it for all requests to all
> remote services. And I passed it the MultiThreadedHttpConnectionManager for
> handling concurrent requests. But I cannot figure out how to set HttpState
> in a thread-safe manner.

The trick is to choose the appropriate executeRequest(...) method.
This one will use the HttpState you pass as the third argument:

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)

hope that helps,
  Roland

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org