hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: HTTP Authentication - set Credentials/State at execute method
Date Wed, 11 Dec 2013 13:16:25 GMT
On Wed, 2013-12-11 at 18:20 +0530, srihari na wrote:
> Hello Folks,
> 
> I have scenario for authentication where I need to pass credentials at
> execute method level. Details are below:
> 
> Using http client 3.1
> We set the authentication credentials to the HTTP execute call by passing
> the state as an argument which can be set for every invocation,
> Here is the sample code we used in 3.1
> httpCode = HttpClient.executeMethod(_hostConfig,_method,_httpState);
> 
> however the same option to pass the state is not available in http client
> API 4.2.5.
> 
> Once we migrated to HTTP client API v4.2.5, we do setting of authentication
> credentials  at client level
> Here is the sample code
> _httpState = ((DefaultHttpClient)_client).getCredentialsProvider();
> _httpState.setCredentials(authScope,credentials);
> 
> It is working fine when we use the the single client, single connection
> manager connecting to various endpoints with different authentication
> credentials As we have only one client, when two reqests with two different
> authentication credentials were run,
> -first request, registers with authentication credentials1  and is working
> fine till the second request started
> -second request, registers(overwrites the previous) with authentication
> credentials2 and is working fine now
> however due to new authentication credentials registration the first
> request execution now fails (as it needs authentication credentials1 but
> getting authentication credentials2)
> ------------
> 1. Is there a way we can set authentication credentials for every execute
> call(passing the state object as param) with 4.2.5 client API instead of
> directly setting the state of the http client.
> 2. Is there a way we can set authentication credentials at method or
> context level so that we can pass it for every request?
> 
> 

One can set a credentials provider in HttpContext instance and pass it
as a parameter to the #execute method.

Oleg 


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


Mime
View raw message