I´ve implemented a retrofit sync call inside AsyncTask that gets called via SwipeRefreshLayout.
The first time I make the swipe to refresh I get a 304 Not Modified http status but if I do it again just after the first call I get the body of the call inside the status line and throws a java.net.ProtocolException: Unexpected status line. I can only reproduce this if I do it quickly enough.
Is there something I´m missing? Maybe a misconfiguration somewhere? Maybe related to https://github.com/square/retrofit/issues/735 ?
This is my client configuration part
Gson gson = new GsonBuilder()
.registerTypeAdapter(Me.class, new MeDeserializer())
.registerTypeAdapter(Assistant.class, new AssistantDeserializer())
.registerTypeAdapter(Meeting.class, new MeetingDeserializer())
.registerTypeAdapter(Schedule.class, new ScheduleDeserializer())
.registerTypeAdapter(Speaker.class, new SpeakerDeserializer())
.registerTypeAdapter(Sponsor.class, new SponsorsDeserializer())
.registerTypeAdapter(Entity.class, new EntityDeserializer())
.create();
RestAdapter restAdapter = new RestAdapter.Builder()
.setLogLevel(RestAdapter.LogLevel.BASIC)
.setEndpoint(ENDPOINT)
.setConverter(new GsonConverter(gson))
.setRequestInterceptor(new CustomRequestInterceptor())
.build();
mService = restAdapter.create(AppEventosService.class);
I´ve some workload to generate a Authorization header on the CustomRequestInterceptor.
This is the log thrown by the logcat.
04-13 13:39:52.310 8856-8970/com.irontec.welcome2015 D/Retrofit﹕ ---> HTTP GET http://test218.irontec.com/app-eventos/rest/contacts
04-13 13:39:52.478 8856-8970/com.irontec.welcome2015 D/Retrofit﹕ <--- HTTP 304 http://test218.irontec.com/app-eventos/rest/contacts (168ms)
04-13 13:39:54.497 8856-8971/com.irontec.welcome2015 D/Retrofit﹕ ---> HTTP GET http://test218.irontec.com/app-eventos/rest/contacts
04-13 13:39:54.691 8856-8971/com.irontec.welcome2015 D/Retrofit﹕ ---- ERROR http://test218.irontec.com/app-eventos/rest/contacts
04-13 13:39:54.697 8856-8971/com.irontec.welcome2015 D/Retrofit﹕ java.net.ProtocolException: Unexpected status line: {"debug":{"module":"rest","controller":"contacts","action":"index"},"message":"Not Modified","total":33,"contacts":[{"id":573,"createdAt":"2015-04-13 10:43:40","status":"accepted","emailShare":1,"cellphoneShare":1,"responseDate":null,"moment":"atOneHour","sendedByMe":false,"assistants":{"id":353,"name":"Daniel","lastName":"Rendon Arias","email":"[email protected]","company":"Irontec","cellPhone":"987456321","position":"LOL","picUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistants\/353-turkey-sqaure.jpg","picCircleUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistantsCircle\/353-turkey-sqaure.jpg"}},{"id":574,"createdAt":"2015-04-13 11:46:03","status":"accepted","emailShare":1,"cellphoneShare":1,"responseDate":null,"moment":"atHalfHour","sendedByMe":true,"assistants":{"id":353,"name":"Daniel","lastName":"Rendon Arias","email":"[email protected]","company":"Irontec","cellPhone":"987456321","position":"LOL","picUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistants\/353-turkey-sqaure.jpg","picCircleUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistantsCircle\/353-turkey-sqaure.jpg"}},{"id":575,"createdAt":"2015-04-13 11:51:15","status":"accepted","emailShare":1,"cellphoneShare":1,"responseDate":null,"moment":"atHalfHour","sendedByMe":true,"assistants":{"id":353,"name":"Daniel","lastName":"Rendon Arias","email":"[email protected]","company":"Irontec","cellPhone":"987456321","position":"LOL","picUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistants\/353-turkey-sqaure.jpg","picCircleUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistantsCircle\/353-turkey-sqaure.jpg"}},{"id":576,"createdAt":"2015-04-13 11:54:04","status":"accepted","emailShare":1,"cellphoneShare":1,"responseDate":null,"moment":"atOneHour","sendedByMe":false,"assistants":{"id":353,"name":"Daniel","lastName":"Rendon Arias","email":"[email protected]","company":"Irontec","cellPhone":"987456321","position":"LOL","picUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistants\/353-turkey-sqaure.jpg","picCircleUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistantsCircle\/353-turkey-sqaure.jpg"}},{"id":577,"createdAt":"2015-04-13 11:55:00","status":"accepted","emailShare":1,"cellphoneShare":1,"responseDate":null,"moment":"atOneHour","sendedByMe":false,"assistants":{"id":353,"name":"Daniel","lastName":"Rendon Arias","email":"[email protected]","company":"Irontec","cellPhone":"987456321","position":"LOL","picUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistants\/353-turkey-sqaure.jpg","picCircleUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistantsCircle\/353-turkey-sqaure.jpg"}},{"id":578,"createdAt":"2015-04-13 11:57:05","status":"accepted","emailShare":1,"cellphoneShare":1,"responseDate":null,"moment":"atRightNow","sendedByMe":false,"assistants":{"id":353,"name":"Daniel","lastName":"Rendon Arias","email":"[email protected]","company":"Irontec","cellPhone":"987456321","position":"LOL","picUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistants\/353-turkey-sqaure.jpg","picCircleUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistantsCircle\/353-turkey-sqaure.jpg"}},{"id":579,"createdAt":"2015-04-13 11:59:02","status":"accepted","emailShare":1,"cellphoneShare":1,"responseDate":null,"moment":"atRightNow","sendedByMe":false,"assistants":{"id":353,"name":"Daniel","lastName":"Rendon Arias","email":"[email protected]","company":"Irontec","cellPhone":"987456321","position":"LOL","picUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistants\/353-turkey-sqaure.jpg","picCircleUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistantsCircle\/353-turkey-sqaure.jpg"}},{"id":580,"createdAt":"2015-04-13 12:00:49","status":"accepted","emailShare":1,"cellphoneShare":1,"responseDate":null,"moment":"atHalfHour","sendedByMe":true,"assistants":{"id":353,"name":"Daniel","lastName":"Rendon Arias","e
04-13 13:39:54.698 8856-8971/com.irontec.welcome2015 D/Retrofit﹕ mail":"[email protected]","company":"Irontec","cellPhone":"987456321","position":"LOL","picUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistants\/353-turkey-sqaure.jpg","picCircleUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistantsCircle\/353-turkey-sqaure.jpg"}},{"id":581,"createdAt":"2015-04-13 12:01:27","status":"canceled","emailShare":0,"cellphoneShare":0,"responseDate":null,"moment":"","sendedByMe":true,"assistants":{"id":353,"name":"Daniel","lastName":"Rendon Arias","email":"","company":"Irontec","cellPhone":"","position":"LOL","picUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistants\/353-turkey-sqaure.jpg","picCircleUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistantsCircle\/353-turkey-sqaure.jpg"}},{"id":582,"createdAt":"2015-04-13 12:26:04","status":"accepted","emailShare":1,"cellphoneShare":1,"responseDate":null,"moment":"atRightNow","sendedByMe":false,"assistants":{"id":353,"name":"Daniel","lastName":"Rendon Arias","email":"[email protected]","company":"Irontec","cellPhone":"987456321","position":"LOL","picUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistants\/353-turkey-sqaure.jpg","picCircleUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistantsCircle\/353-turkey-sqaure.jpg"}},{"id":583,"createdAt":"2015-04-13 12:28:22","status":"accepted","emailShare":1,"cellphoneShare":1,"responseDate":null,"moment":"atHalfHour","sendedByMe":true,"assistants":{"id":353,"name":"Daniel","lastName":"Rendon Arias","email":"[email protected]","company":"Irontec","cellPhone":"987456321","position":"LOL","picUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistants\/353-turkey-sqaure.jpg","picCircleUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistantsCircle\/353-turkey-sqaure.jpg"}},{"id":584,"createdAt":"2015-04-13 12:29:40","status":"accepted","emailShare":1,"cellphoneShare":1,"responseDate":null,"moment":"atRightNow","sendedByMe":true,"assistants":{"id":353,"name":"Daniel","lastName":"Rendon Arias","email":"[email protected]","company":"Irontec","cellPhone":"987456321","position":"LOL","picUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistants\/353-turkey-sqaure.jpg","picCircleUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistantsCircle\/353-turkey-sqaure.jpg"}},{"id":585,"createdAt":"2015-04-13 12:30:35","status":"accepted","emailShare":1,"cellphoneShare":1,"responseDate":null,"moment":"atRightNow","sendedByMe":true,"assistants":{"id":353,"name":"Daniel","lastName":"Rendon Arias","email":"[email protected]","company":"Irontec","cellPhone":"987456321","position":"LOL","picUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistants\/353-turkey-sqaure.jpg","picCircleUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistantsCircle\/353-turkey-sqaure.jpg"}},{"id":586,"createdAt":"2015-04-13 12:30:48","status":"accepted","emailShare":1,"cellphoneShare":1,"responseDate":null,"moment":"atRightNow","sendedByMe":false,"assistants":{"id":353,"name":"Daniel","lastName":"Rendon Arias","email":"[email protected]","company":"Irontec","cellPhone":"987456321","position":"LOL","picUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistants\/353-turkey-sqaure.jpg","picCircleUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistantsCircle\/353-turkey-sqaure.jpg"}},{"id":587,"createdAt":"2015-04-13 12:30:58","status":"accepted","emailShare":1,"cellphoneShare":1,"responseDate":null,"moment":"atRightNow","sendedByMe":true,"assistants":{"id":353,"name":"Daniel","lastName":"Rendon Arias","email":"[email protected]","company":"Irontec","cellPhone":"987456321","position":"LOL","picUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistants\/353-turkey-sqaure.jpg","picCircleUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistantsCircle\/353-turkey-sqaure.jpg"}},{"id":588,"createdAt":"2015-04-13 12:31:29","status":"accepted","emailShare":1,"cellphoneShare":1,"responseDate":null,"moment":"atRightNow
04-13 13:39:54.698 8856-8971/com.irontec.welcome2015 D/Retrofit﹕ ","sendedByMe":true,"assistants":{"id":353,"name":"Daniel","lastName":"Rendon Arias","email":"[email protected]","company":"Irontec","cellPhone":"987456321","position":"LOL","picUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistants\/353-turkey-sqaure.jpg","picCircleUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistantsCircle\/353-turkey-sqaure.jpg"}},{"id":589,"createdAt":"2015-04-13 12:34:08","status":"accepted","emailShare":1,"cellphoneShare":1,"responseDate":null,"moment":"atRightNow","sendedByMe":true,"assistants":{"id":353,"name":"Daniel","lastName":"Rendon Arias","email":"[email protected]","company":"Irontec","cellPhone":"987456321","position":"LOL","picUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistants\/353-turkey-sqaure.jpg","picCircleUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistantsCircle\/353-turkey-sqaure.jpg"}},{"id":590,"createdAt":"2015-04-13 12:39:01","status":"canceled","emailShare":0,"cellphoneShare":0,"responseDate":null,"moment":"","sendedByMe":true,"assistants":{"id":353,"name":"Daniel","lastName":"Rendon Arias","email":"","company":"Irontec","cellPhone":"","position":"LOL","picUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistants\/353-turkey-sqaure.jpg","picCircleUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistantsCircle\/353-turkey-sqaure.jpg"}},{"id":591,"createdAt":"2015-04-13 12:39:14","status":"accepted","emailShare":1,"cellphoneShare":0,"responseDate":null,"moment":"atRightNow","sendedByMe":true,"assistants":{"id":353,"name":"Daniel","lastName":"Rendon Arias","email":"[email protected]","company":"Irontec","cellPhone":"","position":"LOL","picUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistants\/353-turkey-sqaure.jpg","picCircleUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistantsCircle\/353-turkey-sqaure.jpg"}},{"id":592,"createdAt":"2015-04-13 12:45:59","status":"accepted","emailShare":1,"cellphoneShare":1,"responseDate":null,"moment":"atRightNow","sendedByMe":true,"assistants":{"id":353,"name":"Daniel","lastName":"Rendon Arias","email":"[email protected]","company":"Irontec","cellPhone":"987456321","position":"LOL","picUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistants\/353-turkey-sqaure.jpg","picCircleUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistantsCircle\/353-turkey-sqaure.jpg"}},{"id":593,"createdAt":"2015-04-13 12:51:20","status":"accepted","emailShare":1,"cellphoneShare":0,"responseDate":null,"moment":"atRightNow","sendedByMe":false,"assistants":{"id":353,"name":"Daniel","lastName":"Rendon Arias","email":"[email protected]","company":"Irontec","cellPhone":"","position":"LOL","picUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistants\/353-turkey-sqaure.jpg","picCircleUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistantsCircle\/353-turkey-sqaure.jpg"}},{"id":594,"createdAt":"2015-04-13 12:52:45","status":"accepted","emailShare":1,"cellphoneShare":0,"responseDate":null,"moment":"atRightNow","sendedByMe":false,"assistants":{"id":353,"name":"Daniel","lastName":"Rendon Arias","email":"[email protected]","company":"Irontec","cellPhone":"","position":"LOL","picUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistants\/353-turkey-sqaure.jpg","picCircleUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistantsCircle\/353-turkey-sqaure.jpg"}},{"id":595,"createdAt":"2015-04-13 12:55:41","status":"accepted","emailShare":1,"cellphoneShare":0,"responseDate":null,"moment":"atRightNow","sendedByMe":false,"assistants":{"id":353,"name":"Daniel","lastName":"Rendon Arias","email":"[email protected]","company":"Irontec","cellPhone":"","position":"LOL","picUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistants\/353-turkey-sqaure.jpg","picCircleUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistantsCircle\/353-turkey-sqaure.jpg"}},{"id":596,"createdAt":"2015-04-13 13:01:09","status":"accepted","emailShare":1,"cellph
04-13 13:39:54.698 8856-8971/com.irontec.welcome2015 D/Retrofit﹕ oneShare":0,"responseDate":null,"moment":"atRightNow","sendedByMe":false,"assistants":{"id":353,"name":"Daniel","lastName":"Rendon Arias","email":"[email protected]","company":"Irontec","cellPhone":"","position":"LOL","picUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistants\/353-turkey-sqaure.jpg","picCircleUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistantsCircle\/353-turkey-sqaure.jpg"}},{"id":597,"createdAt":"2015-04-13 13:01:42","status":"accepted","emailShare":1,"cellphoneShare":0,"responseDate":null,"moment":"atRightNow","sendedByMe":false,"assistants":{"id":353,"name":"Daniel","lastName":"Rendon Arias","email":"[email protected]","company":"Irontec","cellPhone":"","position":"LOL","picUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistants\/353-turkey-sqaure.jpg","picCircleUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistantsCircle\/353-turkey-sqaure.jpg"}},{"id":598,"createdAt":"2015-04-13 13:02:35","status":"accepted","emailShare":1,"cellphoneShare":1,"responseDate":null,"moment":"atRightNow","sendedByMe":false,"assistants":{"id":353,"name":"Daniel","lastName":"Rendon Arias","email":"[email protected]","company":"Irontec","cellPhone":"987456321","position":"LOL","picUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistants\/353-turkey-sqaure.jpg","picCircleUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistantsCircle\/353-turkey-sqaure.jpg"}},{"id":599,"createdAt":"2015-04-13 13:08:05","status":"accepted","emailShare":1,"cellphoneShare":1,"responseDate":null,"moment":"atRightNow","sendedByMe":false,"assistants":{"id":353,"name":"Daniel","lastName":"Rendon Arias","email":"[email protected]","company":"Irontec","cellPhone":"987456321","position":"LOL","picUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistants\/353-turkey-sqaure.jpg","picCircleUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistantsCircle\/353-turkey-sqaure.jpg"}},{"id":600,"createdAt":"2015-04-13 13:23:59","status":"accepted","emailShare":1,"cellphoneShare":1,"responseDate":null,"moment":"atRightNow","sendedByMe":false,"assistants":{"id":353,"name":"Daniel","lastName":"Rendon Arias","email":"[email protected]","company":"Irontec","cellPhone":"987456321","position":"LOL","picUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistants\/353-turkey-sqaure.jpg","picCircleUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistantsCircle\/353-turkey-sqaure.jpg"}},{"id":601,"createdAt":"2015-04-13 13:24:28","status":"accepted","emailShare":1,"cellphoneShare":1,"responseDate":null,"moment":"atRightNow","sendedByMe":false,"assistants":{"id":353,"name":"Daniel","lastName":"Rendon Arias","email":"[email protected]","company":"Irontec","cellPhone":"987456321","position":"LOL","picUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistants\/353-turkey-sqaure.jpg","picCircleUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistantsCircle\/353-turkey-sqaure.jpg"}},{"id":602,"createdAt":"2015-04-13 13:25:40","status":"accepted","emailShare":1,"cellphoneShare":1,"responseDate":null,"moment":"atRightNow","sendedByMe":false,"assistants":{"id":353,"name":"Daniel","lastName":"Rendon Arias","email":"[email protected]","company":"Irontec","cellPhone":"987456321","position":"LOL","picUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistants\/353-turkey-sqaure.jpg","picCircleUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistantsCircle\/353-turkey-sqaure.jpg"}},{"id":603,"createdAt":"2015-04-13 13:26:05","status":"accepted","emailShare":1,"cellphoneShare":1,"responseDate":null,"moment":"atRightNow","sendedByMe":false,"assistants":{"id":353,"name":"Daniel","lastName":"Rendon Arias","email":"[email protected]","company":"Irontec","cellPhone":"987456321","position":"LOL","picUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistants\/353-turkey-sqaure.jpg","picCircleUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistantsCircle\/3
04-13 13:39:54.698 8856-8971/com.irontec.welcome2015 D/Retrofit﹕ 53-turkey-sqaure.jpg"}},{"id":604,"createdAt":"2015-04-13 13:28:33","status":"accepted","emailShare":1,"cellphoneShare":1,"responseDate":null,"moment":"atRightNow","sendedByMe":true,"assistants":{"id":353,"name":"Daniel","lastName":"Rendon Arias","email":"[email protected]","company":"Irontec","cellPhone":"987456321","position":"LOL","picUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistants\/353-turkey-sqaure.jpg","picCircleUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistantsCircle\/353-turkey-sqaure.jpg"}},{"id":605,"createdAt":"2015-04-13 13:30:21","status":"accepted","emailShare":1,"cellphoneShare":1,"responseDate":null,"moment":"atRightNow","sendedByMe":false,"assistants":{"id":353,"name":"Daniel","lastName":"Rendon Arias","email":"[email protected]","company":"Irontec","cellPhone":"987456321","position":"LOL","picUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistants\/353-turkey-sqaure.jpg","picCircleUrl":"http:\/\/test218.irontec.com\/app-eventos\/image\/assistantsCircle\/353-turkey-sqaure.jpg"}}],"code":304}HTTP/1.1 200 OK
at com.squareup.okhttp.internal.http.StatusLine.parse(StatusLine.java:54)
at com.squareup.okhttp.internal.http.HttpConnection.readResponse(HttpConnection.java:190)
at com.squareup.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:80)
at com.squareup.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:830)
at com.squareup.okhttp.internal.http.HttpEngine.access$200(HttpEngine.java:95)
at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:823)
at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:684)
at com.squareup.okhttp.Call.getResponse(Call.java:272)
at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:228)
at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:199)
at com.squareup.okhttp.Call.execute(Call.java:79)
at retrofit.client.OkClient.execute(OkClient.java:53)
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:326)
at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:240)
at java.lang.reflect.Proxy.invoke(Proxy.java:397)
at $Proxy1.getContacts(Unknown Source)
at com.irontec.welcome2015.fragments.MeetingsFragment$SyncMeetings.downloadDataFromAPI(MeetingsFragment.java:199)
at com.irontec.welcome2015.fragments.MeetingsFragment$SyncMeetings.doInBackground(MeetingsFragment.java:186)
at com.irontec.welcome2015.fragments.MeetingsFragment$SyncMeetings.doInBackground(MeetingsFragment.java:169)
at android.os.AsyncTask$2.call(AsyncTask.java:292)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
04-13 13:39:54.698 8856-8971/com.irontec.welcome2015 D/Retrofit﹕ ---- END ERROR
'''
I´ve solved my issue adding a new header "Connection:close"
@Override
public void intercept(RequestFacade request) {
String token = generateToken(mPreferences.getString(AppEventosClient.APP_CODE, ""));
request.addHeader("Authorization", token);
request.addHeader("Connection", "close");
}
As seen in this StackOverflow answer:
http://stackoverflow.com/questions/23238397/retrofit-java-net-protocolexception-unexpected-status-line-anyone
It seems that there might be some kind of issue with the pooling.
It's either an issue with pooling in OkHttp or a problem with your server writing responses. Either way, Retrofit is where the error shows up but has nothing to do with it. We're just the wrapper around the HTTP client. Without more information it's impossible to diagnose anyways. You can file an issue on OkHttp, but you'll need a lot more information in order to have any hope for resolution.
Hi,
did you get any answer from Okhttp ?
I'm facing the same issue…
@mushu8 can you provide an executable test case to demonstrate the problem?
Code :
class ApiInterceptor implements Interceptor {
@Override
public Response intercept(Interceptor.Chain chain) throws IOException {
Request request = chain.request();
Response response = null;
SharedPreferences preferences = MyApplication.getAppContext()
.getSharedPreferences("LWUserPreferences", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
// Do anything with request here
// set api token
// if not route api/login
if (!"/api/login".equalsIgnoreCase(request.url().encodedPath())) {
String apiToken = preferences.getString("apiToken", null);
// set authorization header
request = request.newBuilder()
.header("Authorization", "Bearer " + apiToken)
.build();
response = chain.proceed(request); // <-- error ProtocolException thrown at this line
[UPDATE]
} else {
// route api/login
request = request.newBuilder()
.header("Connection", "close")
.build();
return chain.proceed(request);
}
// Do anything with response here
if (response.code() >= 400 && response.code() < 500)
{
// Unauthorized from api
// re-authorize with user
// clean user data
goToLogin();
}
else
{
String authorisationHeader = response.header("Authorization");
if (authorisationHeader != null && !authorisationHeader.trim().isEmpty())
{
String token = authorisationHeader.substring("Bearer ".length());
editor.putString("apiToken", token);
editor.apply();
}
}
return response;
}
Error :
02-22 22:14:01.006 8588-8588/debug W/System.err: java.net.ProtocolException: Unexpected status line: array(5) {
02-22 22:14:01.007 8588-8588/debug W/System.err: at okhttp3.internal.http.StatusLine.parse(StatusLine.java:54)
02-22 22:14:01.007 8588-8588/debug W/System.err: at okhttp3.internal.http.Http1xStream.readResponse(Http1xStream.java:185)
02-22 22:14:01.007 8588-8588/debug W/System.err: at okhttp3.internal.http.Http1xStream.readResponseHeaders(Http1xStream.java:126)
02-22 22:14:01.007 8588-8588/debug W/System.err: at okhttp3.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:707)
02-22 22:14:01.007 8588-8588/debug W/System.err: at okhttp3.internal.http.HttpEngine.access$200(HttpEngine.java:81)
02-22 22:14:01.007 8588-8588/debug W/System.err: at okhttp3.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:692)
02-22 22:14:01.007 8588-8588/debug W/System.err: at okhttp3.internal.http.HttpEngine.readResponse(HttpEngine.java:547)
02-22 22:14:01.007 8588-8588/debug W/System.err: at okhttp3.RealCall.getResponse(RealCall.java:242)
02-22 22:14:01.007 8588-8588/debug W/System.err: at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:199)
02-22 22:14:01.007 8588-8588/debug W/System.err: at api.ApiInterceptor.intercept(ApiClient.java:100)
02-22 22:14:01.007 8588-8588/debug W/System.err: at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:188)
02-22 22:14:01.007 8588-8588/debug W/System.err: at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
02-22 22:14:01.007 8588-8588/debug W/System.err: at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:188)
02-22 22:14:01.008 8588-8588/debug W/System.err: at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:161)
02-22 22:14:01.008 8588-8588/debug W/System.err: at okhttp3.RealCall.access$100(RealCall.java:30)
02-22 22:14:01.008 8588-8588/debug W/System.err: at okhttp3.RealCall$AsyncCall.execute(RealCall.java:127)
02-22 22:14:01.008 8588-8588/debug W/System.err: at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:33)
02-22 22:14:01.008 8588-8588/debug W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
02-22 22:14:01.008 8588-8588/debug W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
02-22 22:14:01.008 8588-8588/debug W/System.err: at java.lang.Thread.run(Thread.java:818)
In the first line of the log 02-22 22:14:01.006 8588-8588/debug W/System.err: java.net.ProtocolException: Unexpected status line: array(5) {
The array(5) look like the beginning of my answer body.
When i run the same request with same args with Postman a json file is returned with at root an array of 5 elements…
This happens when a previous request did not read and/or close the response
body. As such bytes were left on the socket and are read by the next
request.
On Wed, Feb 24, 2016 at 4:42 AM Alexandre Sagette [email protected]
wrote:
Code :
class ApiInterceptor implements Interceptor {
@Override
public Response intercept(Interceptor.Chain chain) throws IOException {Request request = chain.request(); Response response = null; SharedPreferences preferences = MyApplication.getAppContext() .getSharedPreferences("LWUserPreferences", Context.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); // Do anything with request here // set api token // if not route api/login if (!"/api/login".equalsIgnoreCase(request.url().encodedPath())) { String apiToken = preferences.getString("apiToken", null); // set authorization header request = request.newBuilder() .header("Authorization", "Bearer " + apiToken) .build(); response = chain.proceed(request); // <-- error ProtocolException thrown at this line [...]Error :
02-22 22:14:01.006 8588-8588/debug W/System.err: java.net.ProtocolException: Unexpected status line: array(5) {
02-22 22:14:01.007 8588-8588/debug W/System.err: at okhttp3.internal.http.StatusLine.parse(StatusLine.java:54)
02-22 22:14:01.007 8588-8588/debug W/System.err: at okhttp3.internal.http.Http1xStream.readResponse(Http1xStream.java:185)
02-22 22:14:01.007 8588-8588/debug W/System.err: at okhttp3.internal.http.Http1xStream.readResponseHeaders(Http1xStream.java:126)
02-22 22:14:01.007 8588-8588/debug W/System.err: at okhttp3.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:707)
02-22 22:14:01.007 8588-8588/debug W/System.err: at okhttp3.internal.http.HttpEngine.access$200(HttpEngine.java:81)
02-22 22:14:01.007 8588-8588/debug W/System.err: at okhttp3.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:692)
02-22 22:14:01.007 8588-8588/debug W/System.err: at okhttp3.internal.http.HttpEngine.readResponse(HttpEngine.java:547)
02-22 22:14:01.007 8588-8588/debug W/System.err: at okhttp3.RealCall.getResponse(RealCall.java:242)
02-22 22:14:01.007 8588-8588/debug W/System.err: at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:199)
02-22 22:14:01.007 8588-8588/debug W/System.err: at api.ApiInterceptor.intercept(ApiClient.java:100)
02-22 22:14:01.007 8588-8588/debug W/System.err: at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:188)
02-22 22:14:01.007 8588-8588/debug W/System.err: at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
02-22 22:14:01.007 8588-8588/debug W/System.err: at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:188)
02-22 22:14:01.008 8588-8588/debug W/System.err: at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:161)
02-22 22:14:01.008 8588-8588/debug W/System.err: at okhttp3.RealCall.access$100(RealCall.java:30)
02-22 22:14:01.008 8588-8588/debug W/System.err: at okhttp3.RealCall$AsyncCall.execute(RealCall.java:127)
02-22 22:14:01.008 8588-8588/debug W/System.err: at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:33)
02-22 22:14:01.008 8588-8588/debug W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
02-22 22:14:01.008 8588-8588/debug W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
02-22 22:14:01.008 8588-8588/debug W/System.err: at java.lang.Thread.run(Thread.java:818)In the first line of the log 02-22 22:14:01.006 8588-8588/debug
W/System.err: java.net.ProtocolException: Unexpected status line: array(5) {The array(5) look like the beginning of my answer body.
When i run the same request with same args with Postman
https://www.getpostman.com/ a json file is returned with at root an
array of 5 elements…—
Reply to this email directly or view it on GitHub
https://github.com/square/retrofit/issues/805#issuecomment-188164470.
what could i do on the server side to close the body
instead of doing on the client side something like `request.header("Connection", "close")`` ?
(previous request received response http 202 accepted)
You shouldn't need to close the connection. The error is indicative of a
client bug, usually in an interceptor that ends up discarding a response
body without closing it. Does that sound like something your code it doing?
On Wed, Feb 24, 2016 at 9:58 AM Alexandre Sagette [email protected]
wrote:
what could i do on the server side to close the body
instead of doing on the client side something like request.header("Connection",
"close")` ?—
Reply to this email directly or view it on GitHub
https://github.com/square/retrofit/issues/805#issuecomment-188291195.
i updated the rest of the code in my second post
which shows what i do with the response.
I only check in the headers of the response if the server sent me back a new jwt token so i can store it client-side.
Is there code after the if block? The included code doesn't show return in all cases.
my bad, i forgot some lines…
code updated
@JakeWharton Is there any update on this? I didn't even have an interceptor and had the same problem. I'm using OkHttpClient as client (with 30 seconds timeout because of slow server). It happens if I enqueue a request and then immediately open another Activity (by clicking). In the new Activity there is a new request which failes. This is the stacktrace:
java.net.ProtocolException: Unexpected status line: {"data":[]}HTTP/1.1 200 OK
at okhttp3.internal.http.StatusLine.parse(StatusLine.java:69)
at okhttp3.internal.http.Http1xStream.readResponse(Http1xStream.java:184)
at okhttp3.internal.http.Http1xStream.readResponseHeaders(Http1xStream.java:125)
at okhttp3.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:775)
at okhttp3.internal.http.HttpEngine.access$200(HttpEngine.java:86)
at okhttp3.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:760)
at okhttp3.internal.http.HttpEngine.readResponse(HttpEngine.java:613)
at okhttp3.RealCall.getResponse(RealCall.java:244)
at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:201)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:163)
at okhttp3.RealCall.access$100(RealCall.java:30)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:127)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
OkHttpClient:
new OkHttpClient.Builder()
.connectTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.writeTimeout(30, TimeUnit.SECONDS)
.build();
Retrofit:
retrofit = new Retrofit.Builder()
.baseUrl(baseURL)
.addConverterFactory(new StringConverterFactory())
.addConverterFactory(new JsonConverterFactory())
.client(okHttpClient)
.build();
@kevinvanmierlo my guess is the preceding call sent a response body but had headers suggesting the wouldn't be one. Can you hook up the logging interceptor and get the preceding call so we can confirm?
@swankjesse I assumed you meant this logging interceptor: https://github.com/square/okhttp/tree/master/okhttp-logging-interceptor
In that case I set the Level to HEADERS and this is what came up (first and second request):
01-05 16:09:37.911 26382-26646/ D/OkHttp: --> POST {{url}} http/1.1
01-05 16:09:37.911 26382-26646/ D/OkHttp: Content-Type: application/json; charset=utf-8
01-05 16:09:37.911 26382-26646/ D/OkHttp: Content-Length: 30
01-05 16:09:37.912 26382-26646/ D/OkHttp: --> END POST
01-05 16:09:38.018 26382-26646/ D/OkHttp: <-- 200 OK {{url}} (105ms)
01-05 16:09:38.018 26382-26646/ D/OkHttp: Date: Thu, 05 Jan 2017 15:09:38 GMT
01-05 16:09:38.018 26382-26646/ D/OkHttp: Server: Apache/2.4.6 (CentOS) PHP/5.6.28
01-05 16:09:38.018 26382-26646/ D/OkHttp: X-Powered-By: PHP/5.6.28
01-05 16:09:38.018 26382-26646/ D/OkHttp: Set-Cookie: PHPSESSID={{sessid}}; path=/; HttpOnly
01-05 16:09:38.018 26382-26646/ D/OkHttp: Expires: Thu, 19 Nov 1981 08:52:00 GMT
01-05 16:09:38.018 26382-26646/ D/OkHttp: Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
01-05 16:09:38.018 26382-26646/ D/OkHttp: Pragma: no-cache
01-05 16:09:38.018 26382-26646/ D/OkHttp: Content-Length: 3255
01-05 16:09:38.018 26382-26646/ D/OkHttp: Keep-Alive: timeout=5, max=98
01-05 16:09:38.018 26382-26646/ D/OkHttp: Connection: Keep-Alive
01-05 16:09:38.018 26382-26646/ D/OkHttp: Content-Type: application/json
01-05 16:09:38.018 26382-26646/ D/OkHttp: <-- END HTTP
01-05 16:09:46.619 26382-26646/ D/OkHttp: --> POST {{url}} http/1.1
01-05 16:09:46.619 26382-26646/ D/OkHttp: Content-Type: application/json; charset=utf-8
01-05 16:09:46.619 26382-26646/ D/OkHttp: Content-Length: 30
01-05 16:09:46.619 26382-26646/ D/OkHttp: --> END POST
01-05 16:09:46.813 26382-26646/ D/OkHttp: <-- 304 Not Modified {{url}} (193ms)
01-05 16:09:46.813 26382-26646/ D/OkHttp: Date: Thu, 05 Jan 2017 15:09:46 GMT
01-05 16:09:46.814 26382-26646/ D/OkHttp: Server: Apache/2.4.6 (CentOS) PHP/5.6.28
01-05 16:09:46.814 26382-26646/ D/OkHttp: Connection: Keep-Alive
01-05 16:09:46.814 26382-26646/ D/OkHttp: Keep-Alive: timeout=5, max=100
01-05 16:09:46.814 26382-26646/ D/OkHttp: Expires: Thu, 19 Nov 1981 08:52:00 GMT
01-05 16:09:46.814 26382-26646/ D/OkHttp: Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
01-05 16:09:46.814 26382-26646/ D/OkHttp: Set-Cookie: PHPSESSID={{sessid}}; path=/; HttpOnly
01-05 16:09:46.814 26382-26646/ D/OkHttp: <-- END HTTP
01-05 16:09:47.425 26382-26646/ D/OkHttp: --> POST {{url}} http/1.1
01-05 16:09:47.425 26382-26646/ D/OkHttp: Content-Type: application/json; charset=utf-8
01-05 16:09:47.425 26382-26646/ D/OkHttp: Content-Length: 2
01-05 16:09:47.425 26382-26646/ D/OkHttp: --> END POST
01-05 16:09:47.514 26382-26646/ D/OkHttp: <-- HTTP FAILED: java.net.ProtocolException: Unexpected status line: {"data":[]}HTTP/1.1 200 OK
@kevinvanmierlo see where your server returns 304 Not Modified? It’s not allowed to send any response body bytes but it does anyway. That’s corrupting your connection and preventing the follow-up request from succeeding. Ask your server to fix!
@swankjesse Wow good eye! That was indeed the problem, now it works again. Thanks!
Most helpful comment
I´ve solved my issue adding a new header "Connection:close"
As seen in this StackOverflow answer:
http://stackoverflow.com/questions/23238397/retrofit-java-net-protocolexception-unexpected-status-line-anyone
It seems that there might be some kind of issue with the pooling.