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/24 16:26:25 UTC
HttpClient 4.0.1 and Timeout
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