After going through the code of Olingo client library came across a workaround for this.
ODataClient
has a Configuration
property, which has HttpClientFactory
parameter. I had to create a class which extended DefaultHttpClientFactory
and override it's methods to update HttpClient
with timeout and retry policy changes.
Complete code is as below.
private class RequestRetryHttpClientFactory extends DefaultHttpClientFactory {
private final int HTTP_REQUEST_TIMEOUT = 2 * 60 * 1000;
@Override
public org.apache.http.impl.client.DefaultHttpClient create(HttpMethod method, URI uri) {
final HttpRequestRetryHandler myRetryHandler = new HttpRequestRetryHandler() {
@Override
public boolean retryRequest(IOException e, int i, HttpContext httpContext) {
Log.d(getClass().getSimpleName(), "RETRY REQUEST");
return false;
}
};
final DefaultHttpClient httpClient = super.create(method, uri);
HttpConnectionParams.setConnectionTimeout(httpClient.getParams(), HTTP_REQUEST_TIMEOUT);
HttpConnectionParams.setSoTimeout(httpClient.getParams(), HTTP_REQUEST_TIMEOUT);
httpClient.setHttpRequestRetryHandler(myRetryHandler);
return httpClient;
}
}
I added this to my oDataClient as bellow.
ODataClient oDataClient = ODataClientFactory.getV4();
oDataClient.getConfiguration().setHttpClientFactory(new RequestRetryHttpClientFactory());
ODataEntityCreateRequest<ODataEntity> req = oDataClient.getCUDRequestFactory()
.getEntityCreateRequest(uri, oDataEntity);
I hope this will help someone.