org.mortbay.jetty.handler.rewrite
Class RewriteHandler

java.lang.Object
  extended by org.mortbay.component.AbstractLifeCycle
      extended by org.mortbay.jetty.handler.AbstractHandler
          extended by org.mortbay.jetty.handler.AbstractHandlerContainer
              extended by org.mortbay.jetty.handler.HandlerWrapper
                  extended by org.mortbay.jetty.handler.rewrite.RewriteHandler
All Implemented Interfaces:
org.mortbay.component.LifeCycle, org.mortbay.jetty.Handler, org.mortbay.jetty.HandlerContainer

public class RewriteHandler
extends org.mortbay.jetty.handler.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:

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:


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.mortbay.component.LifeCycle
org.mortbay.component.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()
           
 org.mortbay.jetty.servlet.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)
           
 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(org.mortbay.jetty.servlet.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 org.mortbay.jetty.servlet.PathMap getRewrite()
Deprecated. 


setRewrite

public void setRewrite(org.mortbay.jetty.servlet.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
Specified by:
handle in interface org.mortbay.jetty.Handler
Overrides:
handle in class org.mortbay.jetty.handler.HandlerWrapper
Throws:
java.io.IOException
javax.servlet.ServletException


Copyright © 2009 Mortbay Consulting Pty. Ltd. All Rights Reserved.