Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch NoHttpResponseException #135

Closed
gorodechnyj opened this issue Nov 13, 2012 · 9 comments
Closed

Catch NoHttpResponseException #135

gorodechnyj opened this issue Nov 13, 2012 · 9 comments

Comments

@gorodechnyj
Copy link

Hello, I'm getting this oftenly.

11-13 14:57:53.224: W/System.err(2002): org.apache.http.NoHttpResponseException: The target server failed to respond
11-13 14:57:53.224: W/System.err(2002):     at org.apache.http.impl.conn.DefaultResponseParser.parseHead(DefaultResponseParser.java:85)
11-13 14:57:53.224: W/System.err(2002):     at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:174)
11-13 14:57:53.224: W/System.err(2002):     at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:180)
11-13 14:57:53.224: W/System.err(2002):     at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:235)
11-13 14:57:53.224: W/System.err(2002):     at org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:259)
11-13 14:57:53.224: W/System.err(2002):     at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:279)
11-13 14:57:53.224: W/System.err(2002):     at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:121)
11-13 14:57:53.224: W/System.err(2002):     at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:428)
11-13 14:57:53.224: W/System.err(2002):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
11-13 14:57:53.224: W/System.err(2002):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
11-13 14:57:53.224: W/System.err(2002):     at com.loopj.android.http.AsyncHttpRequest.makeRequest(AsyncHttpRequest.java:74)
11-13 14:57:53.224: W/System.err(2002):     at com.loopj.android.http.AsyncHttpRequest.makeRequestWithRetries(AsyncHttpRequest.java:93)
11-13 14:57:53.224: W/System.err(2002):     at com.loopj.android.http.AsyncHttpRequest.run(AsyncHttpRequest.java:55)
11-13 14:57:53.224: W/System.err(2002):     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:442)
11-13 14:57:53.224: W/System.err(2002):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
11-13 14:57:53.224: W/System.err(2002):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
11-13 14:57:53.224: W/System.err(2002):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
11-13 14:57:53.224: W/System.err(2002):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
11-13 14:57:53.224: W/System.err(2002):     at java.lang.Thread.run(Thread.java:856)

The issue resolves by just reloading an Activity or resending the request, but I cannot just handle that, `cause the exception already handled somewhere and I don't know where. I'm using 1.4.2 jar-ed version.

@gorodechnyj
Copy link
Author

And one more thing - it definitely happens before onFailure(Throwable, String), so request just hangs

@cesards
Copy link

cesards commented Nov 14, 2012

It happens something similar to me...

I send a request, but I doesn't get the response eve:

LoodicRestClient.get(Api.PLACES_EXPLORE, null, new JsonHttpResponseHandler() {
@OverRide
public void onStart() {
super.onStart();
Log.v(CLASSTAG, "PLACES_EXPLORE onStart");
}

        @Override
        public void onSuccess(String content) {
            super.onSuccess(content);
            Log.v(CLASSTAG, "PLACES_EXPLORE onSuccess");
        }

        @Override
        public void onSuccess(int statusCode, JSONArray response) {
            // TODO Auto-generated method stub
            super.onSuccess(statusCode, response);
            Log.v(CLASSTAG, "PLACES_EXPLORE onSuccess");
        }

        @Override
        public void onSuccess(int statusCode, String content) {
            // TODO Auto-generated method stub
            super.onSuccess(statusCode, content);
            Log.v(CLASSTAG, "PLACES_EXPLORE onSuccess");
        }

        @Override
        public void onFailure(Throwable e, JSONObject errorResponse) {
            super.onFailure(e, errorResponse);
            Log.v(CLASSTAG, "PLACES_EXPLORE onFailure");
        }

        @Override
        public void onFailure(Throwable e, JSONArray errorResponse) {
            super.onFailure(e, errorResponse);
            Log.v(CLASSTAG, "PLACES_EXPLORE onFailure");
        }

        @Override
        public void onFailure(Throwable error, String content) {
            super.onFailure(error, content);
            Log.v(CLASSTAG, "PLACES_EXPLORE onFailure");
        }

        @Override
        public void onFinish() {
            super.onFinish();
            Log.v(CLASSTAG, "PLACES_EXPLORE onFinish");
        }


    });

I doesn't get the onFinish never...

@cesards
Copy link

cesards commented Nov 14, 2012

Solved... I forgot internet permission...

Why android doesn't warm you about permissions? :S

@gorodechnyj
Copy link
Author

I also solved the issue.
Firstly, the docs misleading not showing that you also need to override other onSuccess and onFailure methods, the ones that you have in JsonHttpResponse's parents. So, NoHttpResponse or SocketTimeout leads to empty response and JsonHttpResponse skips its parsing and calls onFailure(Throwable, String) instead of onFailure(Throwable, JSONObject) with empty second parameter (what I excpected to happen).
Secondly, Retry won't work if the request was made with POST method. This is also not very clear for me, because I can use this client to work with, let's say, not very well-formed API's. In my case I had to send every request with POST.

@raphaeloliveira
Copy link

Hi, I'm still having this issue. I have internet permission on my manifest, I overrode the methods and I get the callback to show an error message, its is ok but why it happens so often?

@gorodechnyj
Copy link
Author

Look. We debuged the issue on server side and figured out that client prematurely closing connection while setting keep-alive header to connection. Setting header "connection: close" helped a lot in our case. Try it.

@raphaeloliveira
Copy link

By default this lib set this header (connection:keep-alive)? Do you notice low performance after this change?

@gorodechnyj
Copy link
Author

I only do 2-3 requests per activity load. This does not affect performace, even on server side

@zaur
Copy link

zaur commented Sep 14, 2013

solution that worked for me:

public AsyncHttpClient() {
.....
HttpConnectionParams.setSoKeepalive(httpParams, false);
.....
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants