Search code examples
javaapacheexceptionfluenthttp-request

Java - NoHttpResponseException when using apache fluent api to post


I am continuously posting data to server using Java with Apache fluent api.

Content content = Request.Post(URL)
    .bodyForm(param)
    .execute()
    .returnContent();

The above works perfectly but after some random execution time I am getting org.apache.http.NoHttpResponseException: failed to respond. How I can handle this to post the same parameter again after getting this exception.

EDIT

Ok, I have to handle response, something like this but still don't have any clue how this can be done.

Content content = Request.Post(URL)
        .bodyForm(param)
        .execute().handleResponse(new ResponseHandler<Content>() {

            public Content handleResponse(HttpResponse arg0)
                    throws ClientProtocolException, IOException {
                // TODO Auto-generated method stub
                return null;
            }
        });

Solution

  • Instead of using fluent API I used the following below method and overcome my own problem:- get NoHttpResponseException for load testing Apache HttpClient Interim Error: NoHttpResponseException