org.mortbay.jetty.handler
public class RewriteHandler extends HandlerWrapper
This path uses the pattern matching of PathMap
to rewrite URI's
of received requests. A typical jetty.xml configuration would be:
<Set name="handler"> <New id="Handlers" class="org.mortbay.jetty.handler.RewriteHandler"> <Set name="rewriteRequestURI">false</Set> <Set name="rewritePathInfo">false</Set> <Set name="originalPathAttribute">requestedPath</Set> <Call name="addRewriteRule"><Arg>/other/*</Arg><Arg>/test</Arg></Call> <Call name="addRewriteRule"><Arg>/test/*</Arg><Arg></Arg></Call> <Call name="addRewriteRule"><Arg>/*</Arg><Arg>/test</Arg></Call> <Set name="handler"> <New id="Handlers" class="org.mortbay.jetty.handler.HandlerCollection"> <Set name="handlers"> <Array type="org.mortbay.jetty.Handler"> <Item> <New id="Contexts" class="org.mortbay.jetty.handler.ContextHandlerCollection"/> </Item> <Item> <New id="DefaultHandler" class="org.mortbay.jetty.handler.DefaultHandler"/> </Item> <Item> <New id="RequestLog" class="org.mortbay.jetty.handler.RequestLogHandler"/> </Item> </Array> </Set> </New> </Set> </New> </Set>
_string
Constructor and Description |
---|
RewriteHandler() |
Modifier and Type | Method and Description |
---|---|
void |
addRewriteRule(String pattern,
String prefix)
Add a path rewriting rule
|
String |
getOriginalPathAttribute() |
PathMap |
getRewrite() |
void |
handle(String target,
HttpServletRequest request,
HttpServletResponse response,
int dispatch)
Handle a request.
|
boolean |
isRewritePathInfo() |
boolean |
isRewriteRequestURI() |
void |
setOriginalPathAttribute(String originalPathAttribte) |
void |
setRewrite(PathMap rewrite) |
void |
setRewritePathInfo(boolean rewritePathInfo) |
void |
setRewriteRequestURI(boolean rewriteRequestURI) |
addHandler, doStart, doStop, expandChildren, getHandler, removeHandler, setHandler, setServer
expandHandler, getChildHandlerByClass, getChildHandlers, getChildHandlersByClass
destroy, getServer, toString
addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
public 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 originalPathAttribte)
originalPathAttribte
- If non null, this string will be used
as the attribute name to store the original request path.public void setRewrite(PathMap rewrite)
rewrite
- A PathMap
of the rewriting rules. Only
prefix paths should be included.public void addRewriteRule(String pattern, String prefix)
pattern
- The path pattern to match. The pattern must start with / and may use
a trailing /* as a wildcard.prefix
- The path prefix which will replace the matching part of the path.public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException, ServletException
Handler
handle
in interface Handler
handle
in class HandlerWrapper
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
IOException
ServletException
Copyright © 2009 Mortbay Consulting Pty. Ltd. All Rights Reserved.