// Set protocol level to HTTP/1.0
this.client.getParams().setParameter(
HttpProtocolParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_0);
DefaultHttpClientConnection conn = new DefaultHttpClientConnection();
HttpHost host = new HttpHost("localhost", this.server.getPort());
try {
for (int r = 0; r < reqNo; r++) {
if (!conn.isOpen()) {
Socket socket = new Socket(host.getHostName(), host.getPort());
conn.bind(socket, this.client.getParams());
}
BasicHttpEntityEnclosingRequest post = new BasicHttpEntityEnclosingRequest("POST", "/");
byte[] data = (byte[]) testData.get(r);
ByteArrayEntity outgoing = new ByteArrayEntity(data);
post.setEntity(outgoing);
HttpResponse response = this.client.execute(post, host, conn);
assertEquals(HttpVersion.HTTP_1_0, response.getStatusLine().getHttpVersion());
byte[] received = EntityUtils.toByteArray(response.getEntity());
byte[] expected = (byte[]) testData.get(r);
assertEquals(expected.length, received.length);
for (int i = 0; i < expected.length; i++) {
assertEquals(expected[i], received[i]);
}
if (!this.client.keepAlive(response)) {
conn.close();
}
}
//Verify the connection metrics
HttpConnectionMetrics cm = conn.getMetrics();
assertEquals(reqNo, cm.getRequestCount());
assertEquals(reqNo, cm.getResponseCount());
} finally {
conn.close();
this.server.shutdown();
}
}