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 Ole Matzura <ol...@eviware.com> on 2005/09/26 23:38:20 UTC

problems with cached credentials

Hi!

newbie problem coming up; I'm using HttpClient with the 
MultiThreadedHttpConnectionManager in a MT environment where I have my 
own CredentialsProvider set up for providing credentials on 
authentication challenges.

HttpClient seems to internally cache the credentials returned by my 
provider which is a problem in my case since I want to provide different 
credentials for different requests to the same host..

my current work-around is to instantiate a new HttpClient for each 
request, which seems a bit "harsh".. is there any way of clearing some 
internal "credentials cache"?

hope this is understandable.. thanks for any help!

regards,
Ole


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


Re: problems with cached credentials

Posted by Ole Matzura <ol...@eviware.com>.
ah! learn from the masters!

thanks!

/Ole

Oleg Kalnichevski wrote:

>On Mon, 2005-09-26 at 23:38 +0200, Ole Matzura wrote:
>  
>
>>Hi!
>>
>>newbie problem coming up; I'm using HttpClient with the 
>>MultiThreadedHttpConnectionManager in a MT environment where I have my 
>>own CredentialsProvider set up for providing credentials on 
>>authentication challenges.
>>
>>HttpClient seems to internally cache the credentials returned by my 
>>provider which is a problem in my case since I want to provide different 
>>credentials for different requests to the same host..
>>
>>my current work-around is to instantiate a new HttpClient for each 
>>request, which seems a bit "harsh".. is there any way of clearing some 
>>internal "credentials cache"?
>>    
>>
>
>HttpState#clear() is what you want. 
>
>httpclient.getState().clear();
>
>Alternatively you may want to create a new HttpState instance per
>request / session
>
>// shared by several threads
>MultiThreadedHttpConnectionManager mtcm = new
>MultiThreadedHttpConnectionManager();
>HttpClient httpclient =  new HttpClient(mtcm);
>
>// per thread / host / session / request
>HttpState state = new HttpState();
>HostConfiguration hostconf = new HostConfiguration();
>hostconf.setHost("targethost");
>GetMethod httpget = new GetMethod("/stuff");
>httpclient.executeMethod(hostconf, httpget, state);
>
>Hope this helps
>
>Oleg
>
>  
>
>>hope this is understandable.. thanks for any help!
>>
>>regards,
>>Ole
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
>>
>>
>>    
>>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
>
>
>  
>



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


Re: problems with cached credentials

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Mon, 2005-09-26 at 23:38 +0200, Ole Matzura wrote:
> Hi!
> 
> newbie problem coming up; I'm using HttpClient with the 
> MultiThreadedHttpConnectionManager in a MT environment where I have my 
> own CredentialsProvider set up for providing credentials on 
> authentication challenges.
> 
> HttpClient seems to internally cache the credentials returned by my 
> provider which is a problem in my case since I want to provide different 
> credentials for different requests to the same host..
> 
> my current work-around is to instantiate a new HttpClient for each 
> request, which seems a bit "harsh".. is there any way of clearing some 
> internal "credentials cache"?

HttpState#clear() is what you want. 

httpclient.getState().clear();

Alternatively you may want to create a new HttpState instance per
request / session

// shared by several threads
MultiThreadedHttpConnectionManager mtcm = new
MultiThreadedHttpConnectionManager();
HttpClient httpclient =  new HttpClient(mtcm);

// per thread / host / session / request
HttpState state = new HttpState();
HostConfiguration hostconf = new HostConfiguration();
hostconf.setHost("targethost");
GetMethod httpget = new GetMethod("/stuff");
httpclient.executeMethod(hostconf, httpget, state);

Hope this helps

Oleg

> 
> hope this is understandable.. thanks for any help!
> 
> regards,
> Ole
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
> 
> 


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