## org.mortbay.jetty.handler.rewrite
Class RewriteHandler

    java.lang.Object
      org.mortbay.component.AbstractLifeCycle
          org.mortbay.jetty.handler.AbstractHandler
              org.mortbay.jetty.handler.AbstractHandlerContainer
                  org.mortbay.jetty.handler.HandlerWrapper
                      org.mortbay.jetty.handler.rewrite.RewriteHandler

All Implemented Interfaces:
  LifeCycle, Handler, HandlerContainer

    public class RewriteHandler

extends HandlerWrapper

The RewriteHandler is responsible for managing a list of rules to be applied to requests. Its capabilities are not only limited to url rewrites such as RewritePatternRule or RewriteRegexRule; there is also handling for cookies, headers, redirection, setting status or error codes whenever the rule finds a match.

The rules can be matched by the ff. options: pattern matching of PathMap (class PatternRule), regular expressions (class RegexRule) or certain conditions set (e.g. MsieSslRule - the requests must be in SSL mode). Here are the list of rules:

- CookiePatternRule - adds a new cookie in response.
- HeaderPatternRule - adds/modifies the HTTP headers in response.
- RedirectPatternRule - sets the redirect location.
- ResponsePatternRule - sets the status/error codes.
- RewritePatternRule - rewrites the requested URI.
- RewriteRegexRule - rewrites the requested URI using regular expression for pattern matching.
- MsieSslRule - disables the keep alive on SSL for IE5 and IE6.
- LegacyRule - the old version of rewrite.
- ForwardedSchemeHeaderRule - set the scheme according to the headers present.

The rules can be grouped into rule containers (class RuleContainerRule), and will only be applied if the request matches the conditions for their container (e.g., by virtual host name) Here are a list of rule containers:

- VirtualHostRuleContainer - checks whether the request matches one of a set of virtual host names.
- LowThreadsRuleContainer - checks whether the threadpool is low on threads

Nested Class Summary

Nested classes/interfaces inherited from interface org.mortbay.component.LifeCycle
`LifeCycle.Listener`

Field Summary

Fields inherited from class org.mortbay.jetty.handler.AbstractHandler
`_string`

Fields inherited from class org.mortbay.component.AbstractLifeCycle
`_listeners`

Fields inherited from interface org.mortbay.jetty.Handler
`ALL, DEFAULT, ERROR, FORWARD, INCLUDE, REQUEST`

Constructor Summary
`RewriteHandler()`

Method Summary
`void` `addRewriteRule(java.lang.String pattern, java.lang.String prefix)` Deprecated.
`void` `addRule(Rule rule)` Add a Rule
`java.lang.String` `getOriginalPathAttribute()`
`PathMap` `getRewrite()` Deprecated.
`Rule[]` `getRules()` Returns the list of rules.
`void` `handle(java.lang.String target, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, int dispatch)` Handle a request.
`boolean` `isRewritePathInfo()`
`boolean` `isRewriteRequestURI()`
`void` `setLegacyRule(LegacyRule legacyRule)` To enable configuration from jetty.xml on rewriteRequestURI, rewritePathInfo and originalPathAttribute
`void` `setOriginalPathAttribute(java.lang.String originalPathAttribute)`
`void` `setRewrite(PathMap rewrite)` Deprecated.
`void` `setRewritePathInfo(boolean rewritePathInfo)`
`void` `setRewriteRequestURI(boolean rewriteRequestURI)`
`void` `setRules(Rule[] rules)` Assigns the rules to process.
`void` `setRules(RuleContainer rules)` Assigns the rules to process.

Methods inherited from class org.mortbay.jetty.handler.HandlerWrapper
`addHandler, doStart, doStop, expandChildren, getHandler, removeHandler, setHandler, setServer`

Methods inherited from class org.mortbay.jetty.handler.AbstractHandlerContainer
`expandHandler, getChildHandlerByClass, getChildHandlers, getChildHandlersByClass`

Methods inherited from class org.mortbay.jetty.handler.AbstractHandler
`destroy, getServer, toString`

Methods inherited from class org.mortbay.component.AbstractLifeCycle
`addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Methods inherited from interface org.mortbay.component.LifeCycle
`addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop`

Constructor Detail

### RewriteHandler

    public RewriteHandler()

Method Detail

### setLegacyRule

    public void setLegacyRule(LegacyRule legacyRule)

  To enable configuration from jetty.xml on rewriteRequestURI, rewritePathInfo and originalPathAttribute

  Parameters:
    `legacyRule` - old style rewrite rule

### getRules

    public Rule[] getRules()

  Returns the list of rules.

  Returns:
    an array of `Rule`.

### setRules

    public void setRules(Rule[] rules)

  Assigns the rules to process.

  Parameters:
    `rules` - an array of `Rule`.

### setRules

    public void setRules(RuleContainer rules)

  Assigns the rules to process.

  Parameters:
    `rules` - a `RuleContainer` containing other rules to process

### addRule

    public void addRule(Rule rule)

  Add a Rule

  Parameters:
    `rule` - The rule to add to the end of the rules array

### isRewriteRequestURI

    public boolean isRewriteRequestURI()

  Returns:
    the rewriteRequestURI If true, this handler will rewrite the value returned by `HttpServletRequest.getRequestURI()`.

### setRewriteRequestURI

    public void setRewriteRequestURI(boolean rewriteRequestURI)

  Parameters:
    `rewriteRequestURI` - true if this handler will rewrite the value returned by `HttpServletRequest.getRequestURI()`.

### isRewritePathInfo

    public boolean isRewritePathInfo()

  Returns:
    true if this handler will rewrite the value returned by `HttpServletRequest.getPathInfo()`.

### setRewritePathInfo

    public void setRewritePathInfo(boolean rewritePathInfo)

  Parameters:
    `rewritePathInfo` - true if this handler will rewrite the value returned by `HttpServletRequest.getPathInfo()`.

### getOriginalPathAttribute

    public java.lang.String getOriginalPathAttribute()

  Returns:
    the originalPathAttribute. If non null, this string will be used as the attribute name to store the original request path.

### setOriginalPathAttribute

    public void setOriginalPathAttribute(java.lang.String originalPathAttribute)

  Parameters:
    `originalPathAttribute` - If non null, this string will be used as the attribute name to store the original request path.

### getRewrite

    public PathMap getRewrite()

  Deprecated.

### setRewrite

    public void setRewrite(PathMap rewrite)

  Deprecated.

### addRewriteRule

    public void addRewriteRule(java.lang.String pattern,
                               java.lang.String prefix)

  Deprecated.

### handle

    public void handle(java.lang.String target,
                       javax.servlet.http.HttpServletRequest request,
                       javax.servlet.http.HttpServletResponse response,
                       int dispatch)
                throws java.io.IOException,
                       javax.servlet.ServletException

  Description copied from interface: `Handler`
  Handle a request.

  Specified by:
    `handle` in interface `Handler`
  Overrides:
    `handle` in class `HandlerWrapper`
  Parameters:
    `target` - The target of the request - either a URI or a name.
    `request` - The request either as the `Request` object or a wrapper of that request. The `HttpConnection.getCurrentConnection()` method can be used access the Request object if required.
    `response` - The response as the `Response` object or a wrapper of that request. The `HttpConnection.getCurrentConnection()` method can be used access the Response object if required.
    `dispatch` - The dispatch mode: `Handler.REQUEST`, `Handler.FORWARD`, `Handler.INCLUDE`, `Handler.ERROR`
  Throws:
    `java.io.IOException`
    `javax.servlet.ServletException`

Copyright © 1995-2010 Mort Bay Consulting. All Rights Reserved.