1

I am writing tests for a RESTful API using Apache HTTPClient, and when I do a large request (over 80,000 characters returned), the response is cut off. The point of cut off is usually around 85,275. I can run the exact same request from the command line in curl and get the entire statement back.

The system I am hitting is running Tomcat, and the server logs indicate the entire response is being returned, so it seems to me like the problem is in the way HTTPClient is bringing back in the data.

I've done this both with Rest Assured (which uses HTTPClient) and HTTPClient directly to make sure the issue wasn't with Rest Assured. I have altered several parameters including CoreConnectionPNames parameters CONNECTION_TIMEOUT, MAX_LINE_LENGTH, SO_TIMEOUT, and SOCKET_BUFFER_SIZE .

As examples, in Rest Assured

given()
    .param("areaCode", "515")
    .param("quantity", "5000")
.expect()
    .statusCode(200)
    .body("SearchResults.ResultCount", equalTo("5000"),
          "SearchResults.TelephoneNumberList.TelephoneNumber[0]", startsWith("515"),
          "SearchResults.TelephoneNumberList.TelephoneNumber[1]", startsWith("515"),            
          "SearchResults.TelephoneNumberList.TelephoneNumber[2]", startsWith("515"))
.when()
    .get("/accounts/1/availableNumbers");

or in HTTPClient

// I've set up an httpclient with standard stuff to ignore the self-signed 
// certs in our development environment
DefaultHttpClient httpclient = getNewHttpClient();

httpclient.getCredentialsProvider().
    setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
                   new UsernamePasswordCredentials("xxxx", "xxxx"));

org.apache.http.client.utils.URIBuilder builder = 
    new org.apache.http.client.utils.URIBuilder();

builder.setScheme("https")
    .setHost("api.test.xxxx.com")
    .setPath("/accounts/1/availableNumbers")
    .setParameter("areaCode", "515")
    .setParameter("quantity", "5000");

URI uri = builder.build();

HttpGet httpget = new HttpGet(uri);

// print out request URI
System.out.println(httpget.getURI());

HttpResponse response = httpclient.execute(httpget);

if (response.getStatusLine().getStatusCode() != 200)
{
    throw new RuntimeException("Failed : HTTP error code : " + response.getStatusLine().getStatusCode());
}

BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent())));

String output;
System.out.println("Output from Server .... \n");
while ((output = br.readLine()) != null)
{
   System.out.println(output);
}
jhamilton
  • 11
  • 4
  • what exception are you getting ? did you put some timeout setting? – Dungeon Hunter Aug 06 '12 at 13:19
  • which method do you use to get the response? – billdoor Aug 06 '12 at 13:56
  • @Sunny I get an exception when I try to process the response that an XML tag is not properly closed, but that is because the response is truncated. I have tried with whatever sort of default timeouts, and with the ones I listed above. – jhamilton Aug 06 '12 at 20:43
  • @billdoor I have updated the post with info on how I made the calls – jhamilton Aug 06 '12 at 20:53
  • What you could do is submit the same http request with curl from the command line, to make sure the problem is with the client or the server. – Tom Aug 06 '12 at 21:11
  • you could also try to get the reponse with "httpclient.getResponseBodyAsStream()" after the execute. Maybe there is actually a problem with the length? – billdoor Aug 07 '12 at 09:21

0 Answers0