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 Florent Georges <li...@fgeorges.org> on 2009/02/22 19:59:46 UTC

Scope of credentials: the request instead of client

  Hi,

  I use client.getCredentialsProvider() to set credentials for
Basic or Digest authentication.  So for now, the scope of the
credential settings are the Http Client.  But I would like
they have the scope of one single request instead.  Is it
possible?

  Regards,

-- 
Florent Georges
http://www.fgeorges.org/





















      

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


Re: Scope of credentials: the request instead of client

Posted by Florent Georges <li...@fgeorges.org>.
Oleg Kalnichevski wrote:

> If you are creating a new connection manager for each
> request, this effectively prevents HttpClient from re-using
> persistent connections. Moreover, if you do not shut down
> connection manager after each request, you are leaving it up
> to the garbage collector to close persistent connections and
> deallocate system resources. Thus, open onnections can pile
> up increasing the risk of running out of system resources.

  Very well anticipated :-)  I did not shut the manager down, and got warning messages about that.  Thanks to your message, I solved the problem.

  Thanks for your help, regards,

-- 
Florent Georges
http://www.fgeorges.org/






















      

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


Re: Scope of credentials: the request instead of client

Posted by Oleg Kalnichevski <ol...@apache.org>.
Florent Georges wrote:
> Oleg Kalnichevski wrote:
>> Florent Georges wrote:
> 
>   Hi,
> 
>>>   I use client.getCredentialsProvider() to set credentials
>>> for Basic or Digest authentication.  So for now, the scope of
>>> the credential settings are the Http Client.  But I would
>>> like they have the scope of one single request instead.  Is
>>> it possible?
> 
>> You can create a new local context for each request and bind an
>> instance specific CredentialsProvider to it.
> 
>   Thanks for the answer.  Actually, in between, I used the other
> way around.  The credentials must be set for one single request,
> and cookies must survive among several requests, so I create one
> CookieStore and instantiate a new HTTP client for each request
> (each one bound to the same cookie store.)
> 
>   Is there a big difference between this approach and what you
> suggested (if I am right, using the same client but a different
> context for each request) ? 

If you are creating a new connection manager for each request, this 
effectively prevents HttpClient from re-using persistent connections. 
Moreover, if you do not shut down connection manager after each request, 
you are leaving it up to the garbage collector to close persistent 
connections and deallocate system resources. Thus, open onnections can 
pile up increasing the risk of running out of system resources.

Oleg


  Are there any other info that would
> be shared using the same client?  What I like in my approach is
> that I control exactly what is shared between every requests,
> instead of declaring what shouldn't be shared...
> 
>   Regards,
> 


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


Re: Scope of credentials: the request instead of client

Posted by Florent Georges <li...@fgeorges.org>.
Oleg Kalnichevski wrote:
> Florent Georges wrote:

  Hi,

> >   I use client.getCredentialsProvider() to set credentials
> > for Basic or Digest authentication.  So for now, the scope of
> > the credential settings are the Http Client.  But I would
> > like they have the scope of one single request instead.  Is
> > it possible?

> You can create a new local context for each request and bind an
> instance specific CredentialsProvider to it.

  Thanks for the answer.  Actually, in between, I used the other
way around.  The credentials must be set for one single request,
and cookies must survive among several requests, so I create one
CookieStore and instantiate a new HTTP client for each request
(each one bound to the same cookie store.)

  Is there a big difference between this approach and what you
suggested (if I am right, using the same client but a different
context for each request) ?  Are there any other info that would
be shared using the same client?  What I like in my approach is
that I control exactly what is shared between every requests,
instead of declaring what shouldn't be shared...

  Regards,

-- 
Florent Georges
http://www.fgeorges.org/





















      

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


Re: Scope of credentials: the request instead of client

Posted by Oleg Kalnichevski <ol...@apache.org>.
Florent Georges wrote:
>   Hi,
> 
>   I use client.getCredentialsProvider() to set credentials for
> Basic or Digest authentication.  So for now, the scope of the
> credential settings are the Http Client.  But I would like
> they have the scope of one single request instead.  Is it
> possible?
> 
>   Regards,
> 

Florent,

You can create a new local context for each request and bind an instance 
specific CredentialsProvider to it.

This example shows how to bind a custom instance of CookieStore to the 
local context. You can do the same with CredentialsProvider

http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/examples/org/apache/http/examples/client/ClientCustomContext.java

Oleg

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