I got a client like this:
public enum RestClient {
INSTANCE;
private static final int CONNECTION_TIMEOUT = 10;
private static final int READ_TIMEOUT = 30;
private static final int WRITE_TIMEOUT = 30;
private final Rest restClient;
private RestClient() {
restClient = new Retrofit.Builder()
.baseUrl(App.getContext().getResources().getString(R.string.EP))
.addConverterFactory(JacksonConverterFactory.create())
.client(new okhttp3.OkHttpClient.Builder()
.connectTimeout(CONNECTION_TIMEOUT, TimeUnit.SECONDS)
.readTimeout(READ_TIMEOUT, TimeUnit.SECONDS)
.writeTimeout(WRITE_TIMEOUT, TimeUnit.SECONDS)
.build())
.build()
.create(Rest.class);
}
public Rest getRestClient() {return restClient;}
}
and i use this like this:
RestClient.INSTANCE.getRestClient().getAndroidConf().enqueue(new Callback<List<Config>>() {
@Override
public void onResponse(Call<List<Config>> call, Response<List<Config>> response) {
//
}
@Override
public void onFailure(Call<List<Config>> call, Throwable t) {
//
}
});
I've recently updated to retrofit 2 and okhttp3, the problem is that i was expecting that when a timeout occures it enter onFailure callback, as the old retrofit did.
Any suggestions? Thanks