    All Packages  Class Hierarchy  This Package  Previous  Next  Index

# Class w3c.www.protocol.http.proxy.ProxyDispatcher

    java.lang.Object
       |
       +----w3c.www.protocol.http.proxy.ProxyDispatcher

public class ProxyDispatcher
extends Object
implements PropRequestFilter, PropertyMonitoring

The proxy dispatcher applies some rules to a request. The goal of that filter is to allow special pre-processing of requests based, on their target host, before sending them off the net.

The filter is configured through a rule file whose format is described by the following BNF: `rule-file=(record)*
record=EOL|comment|rule
comment=#(^EOL)*EOL
rule=rule-lhs(SPACE)*rule-rhs
rule-lhs=(token) |(token (. token)*
rule-lhr=forbid|direct|redirect |proxy|authorization
forbid=FORBID|forbid
direct=DIRECT|direct
redirect=(REDIRECT|proxy) url
proxy=(PROXY|proxy) url
url=any valid URL authorization=(AUTHORIZATION|authorization user password
`

A sample rule file looks like this: `# Some comments edu proxy http://class.w3.org:8001/ org proxy http://class.w3.org:8001/ fr direct www.evilsite.com redirect http://www.goodsite.com/warning.html www.w3.org direct 138.96.24 direct www.playboy.com forbid default proxy http://cache.inria.fr:8080/`

The algorithm used to lookup rules is the following:

- Split all rules left hand side into its components, eg H1.H2.H3 is splitted into { H1, H2, H3 }, then reverse the components and map that to the rule. In our example above, { org, w3, www} would be mapped to direct.
- Split the fully qualified host name into its components, eg, A.B.C is splitted into { A, B, C } and reverse it.
- Find the longest match in the mapping table of rules, and get apply the given rule.

In our example, a request to www.isi.edu would match the edu rule, and a request for www.w3.org would match the direct rule, for example.

Three rules are defined:

direct
  Run that request directly against the target host.
forbid
  Emit a forbid message, indicating that the user is not allowed to contact this host.
proxy
  Run that request through the given proxy.

For numeric IP addresses, the most significant part is the beginning, so {A, B, C} are deducted directly. In the example { 138, 96, 24 } is mapped to direct.

If no rules are applied, then the default rule (root rule) is applied. See the example.

##

debug
  Are we in debug mode ?
DEBUG_P
  Name of the property turning that filter in debug mode.
disabled
props
  The properties we initialized ourself from.
RULE_P
  Name of the property giving the rule file URL.
rules
  The current set of rules to apply.

##

ProxyDispatcher()
  Empty constructor, for dynamic instantiation.

##

exceptionFilter(Request, HttpException)
  Filter requests when an error occurs during the process.
ingoingFilter(Request)
  Filter requests before they are emitted.
initialize(HttpManager)
outgoingFilter(Request, Reply)
  Filter requests after processing.
parseRules()
  Parse the default set of rules.
parseRules(InputStream)
  Parse the given input stream as a rule file.
propertyChanged(String)
  PropertyMonitoring implementation - Commit property changes.
sync()
  We don't maintain cached infos.

##

RULE_P

     public static final String RULE_P

  Name of the property giving the rule file URL.

DEBUG_P

     public static final String DEBUG_P

  Name of the property turning that filter in debug mode.

props

     protected ObservableProperties props

  The properties we initialized ourself from.

rules

     protected RuleNode rules

  The current set of rules to apply.

debug

     protected boolean debug

  Are we in debug mode ?

disabled

     protected static final String disabled

##

ProxyDispatcher

     public ProxyDispatcher()

  Empty constructor, for dynamic instantiation.

##

parseRules

     protected void parseRules(InputStream in) throws IOException, RuleParserException

  Parse the given input stream as a rule file.

  Parameters:
    in - The input stream to parse.

parseRules

     protected void parseRules()

  Parse the default set of rules.

  IOf the rules cannot be parsed, the filter emits an error message to standard error, and turn itself into transparent mode.

ingoingFilter

     public Reply ingoingFilter(Request request)

  Filter requests before they are emitted. Look for a matching rule, and if found apply it before continuing the process. If a forbid rule was apply, this method will return with a forbidden message.

  Parameters:
    request - The request to filter.
  Returns:
    A Reply instance, if processing is not to be continued, falseotherwise.

exceptionFilter

     public boolean exceptionFilter(Request request,
                                    HttpException ex)

  Filter requests when an error occurs during the process. This filter tries to do a direct connection if it is needed

  Parameters:
    reques - The request to filter.
    reply - It's associated reply.
  Returns:
    Always null.

outgoingFilter

     public Reply outgoingFilter(Request request,
                                 Reply reply)

  Filter requests after processing. This filter doesn't do any post-processing.

  Parameters:
    reques - The request to filter.
    reply - It's associated reply.
  Returns:
    Always null.

propertyChanged

     public boolean propertyChanged(String name)

  PropertyMonitoring implementation - Commit property changes.

  Parameters:
    name - The name of the property that has changed.
  Returns:
    A boolean true if change was commited, false otherwise.

initialize

     public void initialize(HttpManager manager)

sync

     public void sync()

  We don't maintain cached infos.

    All Packages  Class Hierarchy  This Package  Previous  Next  Index