Raduan Santos
Raduan Santos

Reputation: 1063

Disable or delay timeout in Apache Httpclient request

I have a REST webservice with some methods.

I'm sending requests to the rest with Apache HttpClient 4.

When I make a connection to this rest, in a method that is bigger and slower, it throws a NoHttpResponseException.

After googling, I discovered that the server is cutting down the connection with my client app.

So, I tried to disable the timeout this way :

DefaultHttpClient httpclient = null;
HttpParams params = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(params, 0);
HttpConnectionParams.setSoTimeout(params, 0);
HttpConnectionParams.setStaleCheckingEnabled(params, true);

httpclient = new DefaultHttpClient(params);
httpclient.execute(httpRequest, httpContext);

But it failed. The request dies in 15 seconds (possible default timeout?) Does anyone know the best way to do this?

Upvotes: 1

Views: 1876

Answers (1)

Zagrev
Zagrev

Reputation: 2020

I would suggest that you return data to the client before the timeout can occur. This may just be some bytes that says "working" to the client. By trickling the data out, you should be able to keep the client alive.

Upvotes: 1

Related Questions