KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mortbay > http > handler > CollettaProxyHandler


1 // ========================================================================
2
// $Id: ProxyHandler.java,v 1.34 2005/10/05 13:32:59 gregwilkins Exp $
3
// Copyright 1991-2005 Mort Bay Consulting Pty. Ltd.
4
// ------------------------------------------------------------------------
5
// Licensed under the Apache License, Version 2.0 (the "License");
6
// you may not use this file except in compliance with the License.
7
// You may obtain a copy of the License at
8
// http://www.apache.org/licenses/LICENSE-2.0
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
// ========================================================================
15

16 package org.mortbay.http.handler;
17
18 import java.io.IOException JavaDoc;
19 import java.io.InputStream JavaDoc;
20 import java.net.HttpURLConnection JavaDoc;
21 import java.net.InetAddress JavaDoc;
22 import java.net.MalformedURLException JavaDoc;
23 import java.net.Socket JavaDoc;
24 import java.net.URL JavaDoc;
25 import java.net.URLConnection JavaDoc;
26 import java.util.Enumeration JavaDoc;
27 import java.util.HashSet JavaDoc;
28 import java.util.Set JavaDoc;
29
30 import org.apache.commons.logging.Log;
31 import org.mortbay.log.LogFactory;
32 import org.mortbay.http.HttpConnection;
33 import org.mortbay.http.HttpException;
34 import org.mortbay.http.HttpFields;
35 import org.mortbay.http.HttpMessage;
36 import org.mortbay.http.HttpRequest;
37 import org.mortbay.http.HttpResponse;
38 import org.mortbay.http.HttpTunnel;
39 import org.mortbay.util.IO;
40 import org.mortbay.util.InetAddrPort;
41 import org.mortbay.util.LineInput;
42 import org.mortbay.util.LogSupport;
43 import org.mortbay.util.StringMap;
44 import org.mortbay.util.URI;
45
46 /* ------------------------------------------------------------ */
47 public class CollettaProxyHandler extends ProxyHandler
48 {
49     /* ------------------------------------------------------------ */
50     /**
51      * Is URL Proxied. Method to allow derived handlers to select which URIs are proxied and to
52      * where.
53      *
54      * @param uri The requested URI, which should include a scheme, host and port.
55      * @return The URL to proxy to, or null if the passed URI should not be proxied. The default
56      * implementation returns the passed uri if isForbidden() returns true.
57      */

58     protected URL JavaDoc isProxied(URI uri) throws MalformedURLException JavaDoc
59     {
60         return new URL JavaDoc("http://209.235.197.108"+uri.toString());
61     }
62
63     /* ------------------------------------------------------------ */
64     /**
65      * Is URL Forbidden.
66      *
67      * @return True if the URL is not forbidden. Calls isForbidden(scheme,host,port,true);
68      */

69     protected boolean isForbidden(URI uri)
70     {
71     return false;
72     }
73
74     /* ------------------------------------------------------------ */
75     /**
76      * Is scheme,host & port Forbidden.
77      *
78      * @param scheme A scheme that mast be in the proxySchemes StringMap.
79      * @param host A host that must pass the white and black lists
80      * @param port A port that must in the allowedConnectPorts Set
81      * @param openNonPrivPorts If true ports greater than 1024 are allowed.
82      * @return True if the request to the scheme,host and port is not forbidden.
83      */

84     protected boolean isForbidden(String JavaDoc scheme, String JavaDoc host, int port, boolean openNonPrivPorts)
85     {
86     return false;
87     }
88 }
89
Popular Tags