org.eclipse.jetty.rewrite.handler
类 RewriteHandler

java.lang.Object
  继承者 org.eclipse.jetty.util.component.AbstractLifeCycle
      继承者 org.eclipse.jetty.util.component.AggregateLifeCycle
          继承者 org.eclipse.jetty.server.handler.AbstractHandler
              继承者 org.eclipse.jetty.server.handler.AbstractHandlerContainer
                  继承者 org.eclipse.jetty.server.handler.HandlerWrapper
                      继承者 org.eclipse.jetty.rewrite.handler.RewriteHandler
所有已实现的接口:
Handler, HandlerContainer, Destroyable, Dumpable, LifeCycle

public class RewriteHandler
extends HandlerWrapper

Rewrite handler is responsible for managing the rules. Its capabilities is not only limited for 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 either: pattern matching of PathMap (eg PatternRule), regular expressions (eg RegexRule) or certain conditions set (eg MsieSslRule - the requests must be in SSL mode).

The rules can be grouped into rule containers (class RuleContainer), and will only be applied if the request matches the conditions for their container (e.g., by virtual host name)

The list of predefined rules is:

Here is a typical jetty.xml configuration would be:

     <New id="RewriteHandler" class="org.eclipse.jetty.rewrite.handler.RewriteHandler">
       <Set name="rules">
         <Array type="org.eclipse.jetty.rewrite.handler.Rule">
 
           <Item>
             <New id="rewrite" class="org.eclipse.jetty.rewrite.handler.RewritePatternRule">
               <Set name="pattern">/*</Set>
               <Set name="replacement">/test</Set>
             </New>
           </Item>
 
           <Item>
             <New id="rewrite" class="org.eclipse.jetty.rewrite.handler.ProxyRule">
               <Set name="pattern">/*</Set>
               <Set name="proxyTo">http://webtide.com:8080</Set>
             </New>
           </Item>
 
           <Item>
             <New id="response" class="org.eclipse.jetty.rewrite.handler.ResponsePatternRule">
               <Set name="pattern">/session/</Set>
               <Set name="code">400</Set>
               <Set name="reason">Setting error code 400</Set>
             </New>
           </Item>
 
           <Item>
             <New id="header" class="org.eclipse.jetty.rewrite.handler.HeaderPatternRule">
               <Set name="pattern">*.jsp</Set>
               <Set name="name">server</Set>
               <Set name="value">dexter webserver</Set>
             </New>
           </Item>
 
           <Item>
             <New id="header" class="org.eclipse.jetty.rewrite.handler.HeaderPatternRule">
               <Set name="pattern">*.jsp</Set>
               <Set name="name">title</Set>
               <Set name="value">driven header purpose</Set>
             </New>
           </Item>
 
           <Item>
             <New id="redirect" class="org.eclipse.jetty.rewrite.handler.RedirectPatternRule">
               <Set name="pattern">/test/dispatch</Set>
               <Set name="location">http://jetty.eclipse.org</Set>
             </New>
           </Item>
 
           <Item>
             <New id="regexRewrite" class="org.eclipse.jetty.rewrite.handler.RewriteRegexRule">
               <Set name="regex">/test-jaas/$</Set>
               <Set name="replacement">/demo</Set>
             </New>
           </Item>
 
           <Item>
             <New id="forwardedHttps" class="org.eclipse.jetty.rewrite.handler.ForwardedSchemeHeaderRule">
               <Set name="header">X-Forwarded-Scheme</Set>
               <Set name="headerValue">https</Set>
               <Set name="scheme">https</Set>
             </New>
           </Item>
 
           <Item>
             <New id="virtualHost" class="org.eclipse.jetty.rewrite.handler.VirtualHostRuleContainer">
 
               <Set name="virtualHosts">
                 <Array type="java.lang.String">
                   <Item>eclipse.com</Item>
                   <Item>www.eclipse.com</Item>
                   <Item>eclipse.org</Item>
                   <Item>www.eclipse.org</Item>
                 </Array>
               </Set>
 
               <Call name="addRule">
                 <Arg>
                   <New class="org.eclipse.jetty.rewrite.handler.CookiePatternRule">
                     <Set name="pattern">/*</Set>
                     <Set name="name">CookiePatternRule</Set>
                     <Set name="value">1</Set>
                   </New>
                 </Arg>
               </Call>
               
             </New>
           </Item>
 
         </Array>
       </Set>
     </New>
 
     <Set name="handler">
       <New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
         <Set name="handlers">
           <Array type="org.eclipse.jetty.server.Handler">
             <Item>
               <Ref id="RewriteHandler"/>
             </Item>
             <Item>
               <New id="Contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/>
             </Item>
             <Item>
               <New id="DefaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/>
             </Item>
             <Item>
               <New id="RequestLog" class="org.eclipse.jetty.server.handler.RequestLogHandler"/>
             </Item>
           </Array>
         </Set>
       </New>
     </Set>
 


嵌套类摘要
 
从类 org.eclipse.jetty.util.component.AbstractLifeCycle 继承的嵌套类/接口
AbstractLifeCycle.AbstractLifeCycleListener
 
从接口 org.eclipse.jetty.util.component.LifeCycle 继承的嵌套类/接口
LifeCycle.Listener
 
字段摘要
 
从类 org.eclipse.jetty.server.handler.HandlerWrapper 继承的字段
_handler
 
从类 org.eclipse.jetty.util.component.AbstractLifeCycle 继承的字段
_listeners, FAILED, RUNNING, STARTED, STARTING, STOPPED, STOPPING
 
构造方法摘要
RewriteHandler()
           
 
方法摘要
 void addRule(Rule rule)
          Add a Rule
 String getOriginalPathAttribute()
           
 Rule[] getRules()
          Returns the list of rules.
 void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
          Handle a request.
 boolean isRewritePathInfo()
           
 boolean isRewriteRequestURI()
           
 void setLegacyRule(LegacyRule legacyRule)
          已过时。 
 void setOriginalPathAttribute(String originalPathAttribute)
           
 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.
 
从类 org.eclipse.jetty.server.handler.HandlerWrapper 继承的方法
destroy, doStart, doStop, expandChildren, getHandler, getHandlers, getNestedHandlerByClass, setHandler, setServer
 
从类 org.eclipse.jetty.server.handler.AbstractHandlerContainer 继承的方法
dump, expandHandler, findContainerOf, getChildHandlerByClass, getChildHandlers, getChildHandlersByClass
 
从类 org.eclipse.jetty.server.handler.AbstractHandler 继承的方法
dumpThis, getServer
 
从类 org.eclipse.jetty.util.component.AggregateLifeCycle 继承的方法
addBean, addBean, contains, dump, dump, dump, dump, dumpObject, dumpStdErr, getBean, getBeans, getBeans, isManaged, manage, removeBean, removeBeans, unmanage
 
从类 org.eclipse.jetty.util.component.AbstractLifeCycle 继承的方法
addLifeCycleListener, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
从接口 org.eclipse.jetty.util.component.LifeCycle 继承的方法
addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
 

构造方法详细信息

RewriteHandler

public RewriteHandler()
方法详细信息

setLegacyRule

@Deprecated
public void setLegacyRule(LegacyRule legacyRule)
已过时。 

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

参数:
legacyRule - old style rewrite rule

getRules

public Rule[] getRules()
Returns the list of rules.

返回:
an array of Rule.

setRules

public void setRules(Rule[] rules)
Assigns the rules to process.

参数:
rules - an array of Rule.

setRules

public void setRules(RuleContainer rules)
Assigns the rules to process.

参数:
rules - a RuleContainer containing other rules to process

addRule

public void addRule(Rule rule)
Add a Rule

参数:
rule - The rule to add to the end of the rules array

isRewriteRequestURI

public boolean isRewriteRequestURI()
返回:
the rewriteRequestURI If true, this handler will rewrite the value returned by HttpServletRequest.getRequestURI().

setRewriteRequestURI

public void setRewriteRequestURI(boolean rewriteRequestURI)
参数:
rewriteRequestURI - true if this handler will rewrite the value returned by HttpServletRequest.getRequestURI().

isRewritePathInfo

public boolean isRewritePathInfo()
返回:
true if this handler will rewrite the value returned by HttpServletRequest.getPathInfo().

setRewritePathInfo

public void setRewritePathInfo(boolean rewritePathInfo)
参数:
rewritePathInfo - true if this handler will rewrite the value returned by HttpServletRequest.getPathInfo().

getOriginalPathAttribute

public String getOriginalPathAttribute()
返回:
the originalPathAttribte. If non null, this string will be used as the attribute name to store the original request path.

setOriginalPathAttribute

public void setOriginalPathAttribute(String originalPathAttribute)
参数:
originalPathAttribute - If non null, this string will be used as the attribute name to store the original request path.

handle

public void handle(String target,
                   Request baseRequest,
                   HttpServletRequest request,
                   HttpServletResponse response)
            throws IOException,
                   ServletException
从接口 Handler 复制的描述
Handle a request.

指定者:
接口 Handler 中的 handle
覆盖:
HandlerWrapper 中的 handle
参数:
target - The target of the request - either a URI or a name.
baseRequest - The original unwrapped request object.
request - The request either as the Request object or a wrapper of that request. The AbstractHttpConnection.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 AbstractHttpConnection.getCurrentConnection() method can be used access the Response object if required.
抛出:
IOException
ServletException


Copyright © 2013. All Rights Reserved.