I found this example
https://github.com/square/retrofit/issues/1557
Here we set custom url client connection client before before we build API rest service implementation.
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import retrofit.Endpoint
import retrofit.RestAdapter
import retrofit.client.Request
import retrofit.client.UrlConnectionClient
import retrofit.converter.GsonConverter
class ClientBuilder {
public static <T> T buildClient(final Class<T> client, final String serviceUrl) {
Endpoint mCustomRetrofitEndpoint = new CustomRetrofitEndpoint()
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create()
RestAdapter.Builder builder = new RestAdapter.Builder()
.setEndpoint(mCustomRetrofitEndpoint)
.setConverter(new GsonConverter(gson))
.setClient(new MyUrlConnectionClient())
RestAdapter restAdapter = builder.build()
return restAdapter.create(client)
}
}
public final class MyUrlConnectionClient extends UrlConnectionClient {
@Override
protected HttpURLConnection openConnection(Request request) {
HttpURLConnection connection = super.openConnection(request);
connection.setConnectTimeout(15 * 1000);
connection.setReadTimeout(30 * 1000);
return connection;
}
}