org.mortbay.jetty.handler
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.RewriteHandler
- All Implemented Interfaces:
- LifeCycle, Handler, HandlerContainer
public class RewriteHandler
- extends HandlerWrapper
Path Rewrite Handler
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>
RewriteHandler
public RewriteHandler()
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 String getOriginalPathAttribute()
- Returns:
- 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 originalPathAttribte)
- Parameters:
originalPathAttribte
- If non null, this string will be used
as the attribute name to store the original request path.
getRewrite
public PathMap getRewrite()
- Returns:
- A
PathMap
of the rewriting rules.
setRewrite
public void setRewrite(PathMap rewrite)
- Parameters:
rewrite
- A PathMap
of the rewriting rules. Only
prefix paths should be included.
addRewriteRule
public void addRewriteRule(String pattern,
String prefix)
- Add a path rewriting rule
- Parameters:
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.
handle
public void handle(String target,
HttpServletRequest request,
HttpServletResponse response,
int dispatch)
throws IOException,
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:
IOException
ServletException