1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 package org.apache.commons.httpclient.server;
33
34 import java.io.IOException;
35
36 import org.apache.commons.httpclient.Credentials;
37
38 /***
39 * Simple server that registers default request handlers to act as a proxy.
40 *
41 * @author Ortwin Glueck
42 * @author Oleg Kalnichevski
43 */
44 public class SimpleProxy extends SimpleHttpServer {
45
46 private SimpleConnManager connmanager = null;
47 private HttpRequestHandlerChain chain = null;
48
49 /***
50 * @throws IOException
51 */
52 public SimpleProxy() throws IOException {
53 super();
54 this.connmanager = new SimpleConnManager();
55 this.chain = new HttpRequestHandlerChain();
56 this.chain.appendHandler(new TransparentProxyRequestHandler());
57 this.chain.appendHandler(new ProxyRequestHandler(this.connmanager));
58 setRequestHandler(this.chain);
59 }
60
61 /***
62 * @param port
63 * The local TCP port to listen on
64 * @throws IOException
65 */
66 public SimpleProxy(int port) throws IOException {
67 super(port);
68 }
69
70 public void requireCredentials(Credentials creds) {
71 this.chain.prependHandler(new ProxyAuthRequestHandler(creds));
72 }
73
74 public void destroy() {
75 this.connmanager.shutdown();
76 super.destroy();
77 }
78
79 }