public class URIRegexFilter extends BaseFilter
rulesinit-param) or in a seprate file referenced in web.xml via the
Rules take the following form: Where
block, ignore, match and the regular expression is one that is acceptable to the Java Pattern class. 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|
| || |
You can specify the set of rules governing this filter as an init-param in web.xml.
| || |
If specified, The filter uses the regex rules defined in this file.
| || |
Specifies the size of the URICache.
| || |
This parameter controls whether the URICache is enabled or not.
|Modifier and Type||Method and Description|
| || |
End user override point that provides the
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.
public int uriCacheSize
public java.lang.String rulesFile
rulesto 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.
protected java.util.List rules
rulesand 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>
public void matchedRule(RegexRule rule, javax.servlet.ServletRequest req, javax.servlet.ServletResponse res, javax.servlet.FilterChain chain) throws javax.servlet.ServletException, java.io.IOException
RegexRuleobject which allows you to inspect the action of the rule and the rule itself.