|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.eclipse.jetty.util.component.AbstractLifeCycle org.eclipse.jetty.server.handler.AbstractHandler org.eclipse.jetty.server.handler.AbstractHandlerContainer org.eclipse.jetty.server.handler.HandlerWrapper org.eclipse.jetty.rewrite.handler.RewriteHandler
public class RewriteHandler
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 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:
<Set name="handler"> <New id="Handlers" 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="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> <Set name="handler"> <New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection"> <Set name="handlers"> <Array type="org.eclipse.jetty.server.Handler"> <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> </New> </Set>
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle |
---|
LifeCycle.Listener |
Field Summary |
---|
Fields inherited from class org.eclipse.jetty.server.handler.HandlerWrapper |
---|
_handler |
Fields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle |
---|
_listeners, FAILED, RUNNING, STARTED, STARTING, STOPPED, STOPPING |
Constructor Summary | |
---|---|
RewriteHandler()
|
Method Summary | |
---|---|
void |
addRewriteRule(String pattern,
String prefix)
Deprecated. |
void |
addRule(Rule rule)
Add a Rule |
String |
getOriginalPathAttribute()
|
PathMap |
getRewrite()
Deprecated. |
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)
To enable configuration from jetty.xml on rewriteRequestURI, rewritePathInfo and originalPathAttribute |
void |
setOriginalPathAttribute(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.eclipse.jetty.server.handler.HandlerWrapper |
---|
doStart, doStop, expandChildren, getHandler, getHandlers, setHandler, setServer |
Methods inherited from class org.eclipse.jetty.server.handler.AbstractHandlerContainer |
---|
dump, expandHandler, getChildHandlerByClass, getChildHandlers, getChildHandlersByClass |
Methods inherited from class org.eclipse.jetty.server.handler.AbstractHandler |
---|
destroy, dump, getServer, toString |
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle |
---|
addLifeCycleListener, getState, 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.eclipse.jetty.util.component.LifeCycle |
---|
addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop |
Constructor Detail |
---|
public RewriteHandler()
Method Detail |
---|
public void setLegacyRule(LegacyRule legacyRule)
legacyRule
- old style rewrite rulepublic Rule[] getRules()
Rule
.public void setRules(Rule[] rules)
rules
- an array of Rule
.public void setRules(RuleContainer rules)
rules
- a RuleContainer
containing other rules to processpublic void addRule(Rule rule)
rule
- The rule to add to the end of the rules arraypublic boolean isRewriteRequestURI()
HttpServletRequest.getRequestURI()
.public void setRewriteRequestURI(boolean rewriteRequestURI)
rewriteRequestURI
- true if this handler will rewrite the value
returned by HttpServletRequest.getRequestURI()
.public boolean isRewritePathInfo()
HttpServletRequest.getPathInfo()
.public void setRewritePathInfo(boolean rewritePathInfo)
rewritePathInfo
- true if this handler will rewrite the value
returned by HttpServletRequest.getPathInfo()
.public String getOriginalPathAttribute()
public void setOriginalPathAttribute(String originalPathAttribute)
originalPathAttribte
- If non null, this string will be used
as the attribute name to store the original request path.public PathMap getRewrite()
public void setRewrite(PathMap rewrite)
public void addRewriteRule(String pattern, String prefix)
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
Handler
handle
in interface Handler
handle
in class HandlerWrapper
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 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.
IOException
ServletException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |