01: /*
02: * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/server/SimpleProxy.java,v 1.8 2004/12/11 22:35:26 olegk Exp $
03: * $Revision: 480424 $
04: * $Date: 2006-11-29 06:56:49 +0100 (Wed, 29 Nov 2006) $
05: *
06: * ====================================================================
07: *
08: * Licensed to the Apache Software Foundation (ASF) under one or more
09: * contributor license agreements. See the NOTICE file distributed with
10: * this work for additional information regarding copyright ownership.
11: * The ASF licenses this file to You under the Apache License, Version 2.0
12: * (the "License"); you may not use this file except in compliance with
13: * the License. You may obtain a copy of the License at
14: *
15: * http://www.apache.org/licenses/LICENSE-2.0
16: *
17: * Unless required by applicable law or agreed to in writing, software
18: * distributed under the License is distributed on an "AS IS" BASIS,
19: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20: * See the License for the specific language governing permissions and
21: * limitations under the License.
22: * ====================================================================
23: *
24: * This software consists of voluntary contributions made by many
25: * individuals on behalf of the Apache Software Foundation. For more
26: * information on the Apache Software Foundation, please see
27: * <http://www.apache.org/>.
28: *
29: */
30:
31: package org.apache.commons.httpclient.server;
32:
33: import java.io.IOException;
34:
35: import org.apache.commons.httpclient.Credentials;
36:
37: /**
38: * Simple server that registers default request handlers to act as a proxy.
39: *
40: * @author Ortwin Glueck
41: * @author Oleg Kalnichevski
42: */
43: public class SimpleProxy extends SimpleHttpServer {
44:
45: private SimpleConnManager connmanager = null;
46: private HttpRequestHandlerChain stdchain = null;
47:
48: public SimpleProxy(int port) throws IOException {
49: super (port);
50: this .connmanager = new SimpleConnManager();
51: this .stdchain = new HttpRequestHandlerChain();
52: this .stdchain
53: .appendHandler(new TransparentProxyRequestHandler());
54: this .stdchain.appendHandler(new ProxyRequestHandler(
55: this .connmanager));
56: setRequestHandler(this .stdchain);
57: }
58:
59: public SimpleProxy() throws IOException {
60: this (0);
61: }
62:
63: public void requireAuthentication(final Credentials creds,
64: final String realm, boolean keepalive) {
65: HttpRequestHandlerChain chain = new HttpRequestHandlerChain(
66: this .stdchain);
67: chain.prependHandler(new ProxyAuthRequestHandler(creds, realm,
68: keepalive));
69: setRequestHandler(chain);
70: }
71:
72: public void requireAuthentication(final Credentials creds) {
73: HttpRequestHandlerChain chain = new HttpRequestHandlerChain(
74: this .stdchain);
75: chain.prependHandler(new ProxyAuthRequestHandler(creds));
76: setRequestHandler(chain);
77: }
78:
79: public void destroy() {
80: super .destroy();
81: this .connmanager.shutdown();
82: }
83:
84: public void addHandler(final HttpRequestHandler handler) {
85: this.stdchain.prependHandler(handler);
86: }
87:
88: }
|