withHttp(uri: host )
{
def client = getClient()
client.setHttpRequestRetryHandler( new DefaultHttpRequestRetryHandler(1, true) )
def httpParams = client.getParams()
httpParams.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, TIMEOUT)
httpParams.setParameter(CoreConnectionPNames.SO_TIMEOUT, TIMEOUT)
handler.failure = { resp ->
return new Response(resp)
}
request( GET, XML ) { req ->
response.success = { resp ->
def payload = resp?.entity?.content?.text
rr = new Response(resp)
}
}
}
Notice that we are also setting the retry count = 1
DefaultHttpRequestRetryHandler(int retryCount, boolean requestSentRetryEnabled)
Also notice that in addition to setting the connection timeout, we also should set the socket timeout (otherwise weird exceptions will occur if there's a problem).
No comments:
Post a Comment