Top Description Fields Constructors Methods
org.mortbay.jetty.handler

public Class RewriteHandler

extends HandlerWrapper
Class Inheritance
Imports
java.io.IOException, java.util.Map, javax.servlet.ServletException, javax.servlet.http.HttpServletRequest, .HttpServletResponse, org.mortbay.jetty.Request, org.mortbay.jetty.servlet.PathMap, org.mortbay.util.URIUtil

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>
 

Field Summary

Modifier and TypeField and Description
private String
private PathMap
private boolean
private boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
addRewriteRule(String
The path pattern to match. The pattern must start with / and may use a trailing /* as a wildcard.
pattern
,
String
The path prefix which will replace the matching part of the path.
prefix
)

Add a path rewriting rule

public String

Returns:

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

public PathMap

Returns:

A PathMap of the rewriting rules.
getRewrite
()

public void
handle(String
The target of the request - either a URI or a name.
target
,
HttpServletRequest
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.
request
,
HttpServletResponse
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.
response
,
int
The dispatch mode: REQUEST, FORWARD, INCLUDE, ERROR
dispatch
)

Overrides org.mortbay.jetty.handler.HandlerWrapper.handle.

Implements org.mortbay.jetty.Handler.handle.

Handle a request.
public boolean

Returns:

true if this handler will rewrite the value returned by HttpServletRequest#getPathInfo().
isRewritePathInfo
()

public boolean

Returns:

the rewriteRequestURI If true, this handler will rewrite the value returned by HttpServletRequest#getRequestURI().
isRewriteRequestURI
()

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

public void
setRewrite(PathMap
A PathMap of the rewriting rules. Only prefix paths should be included.
rewrite
)

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

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

Inherited from org.mortbay.jetty.handler.HandlerWrapper:
addHandlerdoStartdoStopexpandChildrengetHandlerremoveHandlersetHandlersetServer

Field Detail

_originalPathAttributeback to summary
private String _originalPathAttribute
_rewriteback to summary
private PathMap _rewrite
_rewritePathInfoback to summary
private boolean _rewritePathInfo
_rewriteRequestURIback to summary
private boolean _rewriteRequestURI

Constructor Detail

RewriteHandlerback to summary
public RewriteHandler()

Method Detail

addRewriteRuleback to summary
public void addRewriteRule(String pattern, String prefix)

Add a path rewriting rule

Parameters
pattern:String

The path pattern to match. The pattern must start with / and may use a trailing /* as a wildcard.

prefix:String

The path prefix which will replace the matching part of the path.

getOriginalPathAttributeback to summary
public String getOriginalPathAttribute()
Returns:String

the originalPathAttribte. If non null, this string will be used as the attribute name to store the original request path.

getRewriteback to summary
public PathMap getRewrite()
Returns:PathMap

A PathMap of the rewriting rules.

handleback to summary
public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException, ServletException

Overrides org.mortbay.jetty.handler.HandlerWrapper.handle.

Implements org.mortbay.jetty.Handler.handle.

Doc from org.mortbay.jetty.Handler.handle.

Handle a request.

Parameters
target:String

The target of the request - either a URI or a name.

request:HttpServletRequest

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:HttpServletResponse

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:int

The dispatch mode: REQUEST, FORWARD, INCLUDE, ERROR

isRewritePathInfoback to summary
public boolean isRewritePathInfo()
Returns:boolean

true if this handler will rewrite the value returned by HttpServletRequest#getPathInfo().

isRewriteRequestURIback to summary
public boolean isRewriteRequestURI()
Returns:boolean

the rewriteRequestURI If true, this handler will rewrite the value returned by HttpServletRequest#getRequestURI().

setOriginalPathAttributeback to summary
public void setOriginalPathAttribute(String originalPathAttribte)
Parameters
originalPathAttribte:String

If non null, this string will be used as the attribute name to store the original request path.

setRewriteback to summary
public void setRewrite(PathMap rewrite)
Parameters
rewrite:PathMap

A PathMap of the rewriting rules. Only prefix paths should be included.

setRewritePathInfoback to summary
public void setRewritePathInfo(boolean rewritePathInfo)
Parameters
rewritePathInfo:boolean

true if this handler will rewrite the value returned by HttpServletRequest#getPathInfo().

setRewriteRequestURIback to summary
public void setRewriteRequestURI(boolean rewriteRequestURI)
Parameters
rewriteRequestURI:boolean

true if this handler will rewrite the value returned by HttpServletRequest#getRequestURI().