.setParameter(CoreProtocolPNames.USER_AGENT, "HttpComponents/1.1");
final ConnectingIOReactor connectingIOReactor = new DefaultConnectingIOReactor(
1, params);
final ListeningIOReactor listeningIOReactor = new DefaultListeningIOReactor(
1, params);
BasicHttpProcessor originServerProc = new BasicHttpProcessor();
originServerProc.addInterceptor(new RequestContent());
originServerProc.addInterceptor(new RequestTargetHost());
originServerProc.addInterceptor(new RequestConnControl());
originServerProc.addInterceptor(new RequestUserAgent());
originServerProc.addInterceptor(new RequestExpectContinue());
BasicHttpProcessor clientProxyProcessor = new BasicHttpProcessor();
clientProxyProcessor.addInterceptor(new ResponseDate());
clientProxyProcessor.addInterceptor(new ResponseServer());
clientProxyProcessor.addInterceptor(new ResponseContent());
clientProxyProcessor.addInterceptor(new ResponseConnControl());
NHttpClientHandler connectingHandler = new ConnectingHandler(
originServerProc,
new DefaultConnectionReuseStrategy(),
params);
NHttpServiceHandler listeningHandler = new ListeningHandler(
targetHost,
connectingIOReactor,
clientProxyProcessor,
new DefaultHttpResponseFactory(),
new DefaultConnectionReuseStrategy(),
params);
final IOEventDispatch connectingEventDispatch = new DefaultClientIOEventDispatch(
connectingHandler, params);
final IOEventDispatch listeningEventDispatch = new DefaultServerIOEventDispatch(
listeningHandler, params);
Thread t = new Thread(new Runnable() {
public void run() {
try {
connectingIOReactor.execute(connectingEventDispatch);
} catch (InterruptedIOException ex) {
System.err.println("Interrupted");
} catch (IOException e) {
System.err.println("I/O error: " + e.getMessage());
}
}
});
t.start();
try {
listeningIOReactor.listen(new InetSocketAddress(8888));
listeningIOReactor.execute(listeningEventDispatch);
} catch (InterruptedIOException ex) {
System.err.println("Interrupted");
} catch (IOException e) {
System.err.println("I/O error: " + e.getMessage());
}