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);
}