public class URIRegexFilter
rules
init-param) or in a seprate file referenced in web.xml via the
rulesFile
init-param.
Rules take the following form:
Where block, ignore, match
and the regular expression is one
that is acceptable to the Jakarta ORO Perl5Util class, inside delimiters of your choosing.
The following are valid regular exprssions: /foo/ |foo| #foo#
.
Rules are evaluated in the order they appear, and the first match wins. If no rules match,
the outcome is determined by the value of defaultAction
. Once the action is
determined, one of the following methods is called:
Modifier and Type | Field and Description |
---|---|
protected java.util.List |
rules
You can specify the set of rules governing this filter as an init-param in web.xml.
|
java.lang.String |
rulesFile
If specified, The filter uses the regex rules defined in this file.
|
int |
uriCacheSize
Specifies the size of the URICache.
|
boolean |
useURICache
This parameter controls whether the URICache is enabled or not.
|
Modifier and Type | Method and Description |
---|---|
void |
matchedRule(RegexRule rule,
javax.servlet.ServletRequest req,
javax.servlet.ServletResponse res,
javax.servlet.FilterChain chain)
End user override point that provides the
RegexRule object which allows you
to inspect the action of the rule and the rule itself. |
public boolean useURICache
rulesFile
, the URI Cache will
cache the result of the application of relevant rules for any given URI. The URI Cache
drastically speeds up subsequent rule applications at the cost of memory.
Note: the cache is automatically disabled if there are no rules to apply
(rulesFile
is unset this typically
means the user is managing the mappings through web.xml).
Performance: The URI cache is an LRU Map. If you're using this filter on a large-scale site
with a lot of unique URIs, you may want to tune its size via the
uriCacheSize
parameter to balance between memory
usage and performance. Note that the memory usage problem can be exacerbated by
crawlers if there are a log of directly-accessible unique URIs. Another thing you can
do to help performance is reorder the regex rules in the config file to have the
most-used/most-encompassing ones appear first to reduce the total number of regexes required
per URI.
URIRegexFilter.uriCacheSize
public int uriCacheSize
public java.lang.String rulesFile
rules
to specify the rules in web.xml.
The format of the rulesFile is a list of regular expressions in a JSON array, like this:
var rules = [ "block:#/bar/.*#", "ignore:|/foo/.*|", "match:#.*#", ];Note: The rulesFile path is treated as relative to webRoot.
URIRegexFilter.rules
protected java.util.List rules
rules
and the value is a newline delimited list of
rules. For example:
<filter> <filter-name>CacheFilter</filter-name> <filter-class>com.isomorphic.servlet.CacheFilter</filter-class> <init-param> <param-name>rules</param-name> <param-value> block:|/foo| match:#zoo/bar# ignore:|/xxx| </param-value> </init-param> </filter>
URIRegexFilter.rulesFile
public void matchedRule(RegexRule rule, javax.servlet.ServletRequest req, javax.servlet.ServletResponse res, javax.servlet.FilterChain chain) throws javax.servlet.ServletException, java.io.IOException
RegexRule
object which allows you
to inspect the action of the rule and the rule itself.javax.servlet.ServletException
java.io.IOException