if (request instanceof HttpEntityEnclosingRequest) {
HttpEntity incoming = ((HttpEntityEnclosingRequest) request).getEntity();
byte[] data = EntityUtils.toByteArray(incoming);
ByteArrayEntity outgoing = new ByteArrayEntity(data);
outgoing.setChunked(false);
response.setEntity(outgoing);
} else {
StringEntity outgoing = new StringEntity("No content");
response.setEntity(outgoing);
}
}
});
this.server.start();
// Set protocol level to HTTP/1.0
this.client.getParams().setParameter(
CoreProtocolPNames.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().getProtocolVersion());
byte[] received = EntityUtils.toByteArray(response.getEntity());