}
}
final HttpEntity incoming = ((HttpEntityEnclosingRequest) request).getEntity();
final String line = EntityUtils.toString(incoming);
final ContentType contentType = ContentType.getOrDefault(incoming);
Charset charset = contentType.getCharset();
if (charset == null) {
charset = HTTP.DEF_CONTENT_CHARSET;
}
final RepeatingEntity outgoing = new RepeatingEntity(line, charset, n);
outgoing.setChunked(n % 2 == 0);
response.setEntity(outgoing);
} else {
throw new HttpException("Invalid request: POST request expected");
}
}
});
this.server.start();
final DefaultBHttpClientConnection conn = client.createConnection();
final HttpHost host = new HttpHost("localhost", this.server.getPort());
try {
for (final String pattern : patterns) {
for (int n = 1000; n < 1020; n++) {
if (!conn.isOpen()) {
client.connect(host, conn);
}
final BasicHttpEntityEnclosingRequest post = new BasicHttpEntityEnclosingRequest(
"POST", "/?n=" + n);
final StringEntity outgoing = new StringEntity(pattern);
outgoing.setChunked(n % 2 == 0);
post.setEntity(outgoing);
final HttpResponse response = this.client.execute(post, host, conn);
final HttpEntity incoming = response.getEntity();
Assert.assertNotNull(incoming);
final InputStream instream = incoming.getContent();
final ContentType contentType = ContentType.getOrDefault(incoming);
Charset charset = contentType.getCharset();
if (charset == null) {
charset = HTTP.DEF_CONTENT_CHARSET;
}
Assert.assertNotNull(instream);
final BufferedReader reader = new BufferedReader(new InputStreamReader(instream, charset));