You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Raymond Hooker (rhooker)" <rh...@cisco.com> on 2010/05/20 20:25:13 UTC

BasicAuthCache and Httpclient 4.0.1

I am trying to do preemptive authentication as per the chapter on
authentication: 
 
http://hc.apache.org/httpcomponents-client/tutorial/html/authentication.
html
 
The problem is that it refers to classes BasicAuthCache and AuthCache.
I can seem to find them.  I have included both httpclient-4.0.1.jar and 
 httpcore-4.0.1.jar.  I have even looked in the source to see if I could
find the appropriate import.  I have seen some code with: 
 
import org.apache.http.impl.client.BasicAuthCache; 
 
 
Any help or hints? 

 

Ray 




HttpClient 4.0.1 and Timeout

Posted by "Raymond Hooker (rhooker)" <rh...@cisco.com>.
I am having trouble getting my client to timeout with a non-responsive host.  I should say up front that I am doing authentication discovery to setup valid auth credentials for hosts that I am managing.  

The other big deal is that I am using https and the hosts have self-signed certificates.  The reason I mention this it that I had to use a sample for custom protocol handler.  This has been deprecated but works nicely:

Protocol myhttps = new Protocol("https", (SecureProtocolSocketFactory) new EasySSLProtocolSocketFactory(), 443);

Here is my code:
***********************Begin Code Snippet*********
(I am importing apache.commons.httpclient version 3.1)
HttpClient CTMclient = new HttpClient();
Protocol myhttps = new Protocol("https", (SecureProtocolSocketFactory) new EasySSLProtocolSocketFactory(), 443);
Protocol.registerProtocol("https", myhttps);
CTMclient.getParams().setAuthenticationPreemptive(true);
CTMclient.getState().setCredentials(new AuthScope(AuthScope.ANY_HOST, 443, AuthScope.ANY_REALM), defaultcreds);
CTMclient.setConnectionTimeout(15000);  ****  Note I am setting the timeout.
GetMethod methodget = new GetMethod("https://"+CTMurl+"/cgi-bin?tbAction=TB_CONFIG_CALL_STATISTICS");

try {
	statusCode = CTMclient.executeMethod(methodget);
	.....................
**********************End Code Snippet **************

This works beautifully so long as the host is responsive.  I am able to handle the unsigned certificate transparently and successfully authenticate.  The only problem is that with non-responsive hosts, it never times out.  I saw some code snippets setting the timeout using httpparms, but I then have to switch to BasicHttpClient and away from httpcommons libraries.  I was not able to get the authentication to work.

Does anyone have a way to set the timeout other than the above?.. or a pointer to working code examples that include authentication and the use of custom protocol for the self-signed cert?

Ray



Re: BasicAuthCache and Httpclient 4.0.1

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Thu, 2010-05-20 at 13:25 -0500, Raymond Hooker (rhooker) wrote:
> I am trying to do preemptive authentication as per the chapter on
> authentication: 
>  
> http://hc.apache.org/httpcomponents-client/tutorial/html/authentication.
> html
>  
> The problem is that it refers to classes BasicAuthCache and AuthCache.
> I can seem to find them.  I have included both httpclient-4.0.1.jar and 
>  httpcore-4.0.1.jar.  I have even looked in the source to see if I could
> find the appropriate import.  I have seen some code with: 
>  
> import org.apache.http.impl.client.BasicAuthCache; 
>  
> 
> Any help or hints? 
> 
>  
> 
> Ray 

Ray

These classes are available in the 4.1 branch of HttpClient, which is
still ALPHA

http://hc.apache.org/httpcomponents-client/download.html

If you have issues with using non-GA releases, you can achieve pretty
much the same thing using 4.0.1 GA, just with a bit of extra code:

http://hc.apache.org/httpcomponents-client-4.0.1/tutorial/html/authentication.html#d4e950

Hope this helps

Oleg 




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