Hey guys,
It seems that connection timeout parameter doesn't work on Linux Mint 16
(which is
basically Ubuntu). *Code runs perfectly fine on Windows.* Here's my setup :
*Windows 7 Pro x64 - OK*
Oracle Java JDK 1.7.0_51 x64
*Linux Mint 16 (Petra) - PROBLEM*
java version "1.7.0_51"
OpenJDK Runtime Environment (IcedTea 2.4.4) (7u51-2.4.4-0ubuntu0.13.10.1)
OpenJDK 64-Bit Server VM (build 24.45-b08, mixed mode)
...and here's the code (attached as well) :
public static String doGET(URI uri, ResponseHandler<String> handler) {
String response = "";
CloseableHttpClient httpclient = null;
try {
httpclient = HttpClients.custom()
.setRetryHandler(customRetryHandler)
.build();
HttpGet httpget = new HttpGet(uri);
RequestConfig requestConfig = RequestConfig.custom()
* .setConnectTimeout(1000)*
.build();
httpget.setConfig(requestConfig);
// hide pass data in URI
String toLog = hidePassInURI(uri);
// Execute HTTP request
logger.info("Executing request " + toLog);
response = httpclient.execute(httpget, handler == null ? new
DummyHandler() : handler);
} catch (ConnectException e) {
logger.error("========================================");
logger.error("Database is not available!");
logger.error("========================================");
} catch (ClientProtocolException e) {
logger.error("",e);
} catch (IOException e) {
logger.error("",e);
} finally {
if (httpclient != null) {
try {
httpclient.close();
} catch (IOException e) {
}
}
}
return response;
}
*Here's the retry handler :*
public boolean retryRequest(IOException exception, int executionCount,
HttpContext context) {
logger.info("Retrying : exe count is "+executionCount);
if (executionCount >= 10) {
// Do not retry if over max retry count
return false;
}
if (exception instanceof InterruptedIOException) {
* // Timeout - keep retrying return true;*
}
if (exception instanceof UnknownHostException) {
// Unknown host
return false;
}
if (exception instanceof ConnectTimeoutException) {
* // Connection refused - keep retrying return true;*
}
if (exception instanceof SSLException) {
// SSL handshake exception
return false;
}
HttpClientContext clientContext = HttpClientContext.adapt(context);
HttpRequest request = clientContext.getRequest();
boolean idempotent = !(request instanceof
HttpEntityEnclosingRequest);
if (idempotent) {
// Retry if the request is considered idempotent
return true;
}
return false;
}
*The problem : when I run this code on linux, there's no 1 sec delay
between consecutive attempts. It just*
*goes over 10 attempts and finished within ~200ms. Why?*
*Am I doing something wrong or this is a bug? Please help.*
*P.S. I'm using http client 4.3.2.*
--
Bratislav Stojanovic, M.Sc.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]