4

Retrofit Call:

 RestAdapter restAdapter = new RestAdapter.Builder()
        .setEndpoint("BASE URL")
        .setLogLevel(RestAdapter.LogLevel.FULL)
        .setClient(new OkClient(getOkHttpClient()))
        .build();

Dependencies:

compile 'com.squareup.okhttp:okhttp:2.7.2'
compile 'com.squareup.retrofit:retrofit:1.9.0'

Error: user_id=XXXX&item_id=X&item_quantity=1&item_cost=XXXX&pay_id=stripe&process_fee=XXX&total_cost=XXX&is_nagotiation=0&negotiate_id=&tips=XXX&card_id=XXXX

09-07 11:45:08.628 23473-24373/com.bridgellc.bridge D/Retrofit: ---> END HTTP (177-byte body) 09-07 11:45:18.635 23473-24373/com.bridgellc.bridge D/Retrofit: ---- ERROR http:XXXXXX 09-07 11:45:18.650 23473-24373/com.bridgellc.bridge D/Retrofit: java.net.SocketTimeoutException

1
  • 1
    Explain question properly. When are you getting this error? What solution you tried? Commented Sep 7, 2016 at 6:56

3 Answers 3

4

It depends on various factor one of those is timeout like connectionTimeout etc.If your server is not responding within timeout it will throw SocketTimeoutException. you can try increasing default timeout of okhttp

private static OkHttpClient okClient() {
        return new OkHttpClient.Builder()
                .connectTimeout(1, TimeUnit.MINUTES)
                .writeTimeout(1, TimeUnit.MINUTES)
                .readTimeout(1, TimeUnit.MINUTES)
                .build();
    }

and set it to Retrofit instance.

Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(Util.APP_UPDATE)
                .client(RestClient.okClient())
                .addConverterFactory(GsonConverterFactory.create(gson))
                .build();
Sign up to request clarification or add additional context in comments.

3 Comments

".addConverterFactory(GsonConverterFactory.create(gson))" is not supported Dependencies: compile 'com.squareup.retrofit:retrofit:1.9.0'
I am not using "compile 'com.squareup.retrofit2:retrofit:2.1.0'" i am using "compile 'com.squareup.retrofit:retrofit:1.9.0'" both are different
This is just reference on setting custom Ok client to retrofit instance same you can set it to RestAdapter in case of 1.9.
2

Try to set a timeout for your OkHttp2 Client. First create an OkHttp2 client,

OkHttpClient client = new OkHttpClient.Builder()
client.setConnectTimeout(5, TimeUnit.MINUTES);
client.setReadTimeout(5, TimeUnit.MINUTES);
.build();

Then add it as the default client to the Retrofit

RestAdapter restAdapter = new RestAdapter.Builder()
.setEndpoint("BASE_URL")
.setLogLevel(RestAdapter.LogLevel.FULL)
.setClient(client).build();

10 Comments

Retrofit default Okclient connection timeout is 10 sec.but I am changed that connection time values are 20 sec same like your method. RestAdapter restAdapter = new RestAdapter.Builder() .setEndpoint(AppConstants.BASE_URL) .setLogLevel(RestAdapter.LogLevel.FULL) .setClient(new OkClient(getOkHttpClient())) .build();
//Ok client Waiting time customize private OkHttpClient getOkHttpClient() { final OkHttpClient okHttpClient = new OkHttpClient(); okHttpClient.setReadTimeout(20, TimeUnit.SECONDS); okHttpClient.setConnectTimeout(20, TimeUnit.SECONDS); return okHttpClient; }
Where did you change the timeout value? Did you try the code I suggested?
client Waiting time customize private OkHttpClient getOkHttpClient() { final OkHttpClient okHttpClient = new OkHttpClient(); okHttpClient.setReadTimeout(20, TimeUnit.SECONDS); okHttpClient.setConnectTimeout(20, TimeUnit.SECONDS); return okHttpClient; } –
Can you try with a large timout value? Let's say, 120 sec ?
|
1

You can fix this issue by adding android:vmSafeMode="true" in the Android configuration file. There is discussion on the above problem can be found in github. https://github.com/square/okhttp/issues/1771 https://github.com/square/okhttp/issues/1518#issuecomment-87996760

1 Comment

android:vmSafeMode="true" already i mentioned that code in my manifest file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.