我有我使用我的整个应用程序,许多休息的呼叫RestService接口。
我设置处理超时connection
和read-timeouts
ClientHttpRequestFactory httpFactory = myRestService.getRestTemplate().getRequestFactory();
if(httpFactory!=null)
{
if(httpFactory instanceof SimpleClientHttpRequestFactory)
{
((SimpleClientHttpRequestFactory)httpFactory).setConnectTimeout(10*1000);
((SimpleClientHttpRequestFactory)httpFactory).setReadTimeout(30*1000);
}
else if(httpFactory instanceof HttpComponentsClientHttpRequestFactory)
{
((HttpComponentsClientHttpRequestFactory)httpFactory).setConnectTimeout(10*1000);
((HttpComponentsClientHttpRequestFactory)httpFactory).setReadTimeout(30*1000);
}
}
但我坚持处理超时的情况。 我想用这种方法,但休息时调用失败它没有进入这个循环。
myRestService.getRestTemplate().setErrorHandler(new ResponseErrorHandler()
{
@Override
public boolean hasError(ClientHttpResponse paramClientHttpResponse) throws IOException
{
Log.e(TAG, paramClientHttpResponse==null?"Null response" : ("Has Error : " + paramClientHttpResponse.getStatusText()+" , status code : "+paramClientHttpResponse.getStatusCode()));
return false;
}
@Override
public void handleError(ClientHttpResponse paramClientHttpResponse) throws IOException
{
Log.e(TAG, paramClientHttpResponse==null?"Null response":("Handle Error : " + paramClientHttpResponse.getStatusText()+" , status code : "+paramClientHttpResponse.getStatusCode()));
}
});
任何人可以帮助我这个..!?