@Test
public void testReplaceResponseBound() throws Exception {
RequestHandlerChain chain = new RequestHandlerChain();
IHttpRequestHandler filter = new IHttpRequestHandler() {
public void onRequest(final IHttpExchange exchange) throws IOException {
IHttpResponseHandler respHdl = new IHttpResponseHandler() {
public void onResponse(IHttpResponse response) throws IOException {
BodyDataSink bodyDataSink = exchange.send(new HttpResponseHeader(200, "text/plain"), 9);
bodyDataSink.write("Hello");
QAUtil.sleep(200);
bodyDataSink.write(" You");
bodyDataSink.close();
}
public void onException(IOException ioe) {
}
};
exchange.forward(exchange.getRequest(), respHdl);
}
};
chain.addLast(filter);
chain.addLast(new EchoHandler());
IServer server = new HttpServer(0, chain);
ConnectionUtils.start(server);