Class RewriteRegexRule

All Implemented Interfaces:
Rule.ApplyURI

public class RewriteRegexRule extends RegexRule implements Rule.ApplyURI
Rewrite the URI by matching with a regular expression. The replacement string may use $n" to replace the nth capture group. If the replacement string contains ? character, then it is split into a path and query string component. The replacement query string may also contain $Q, which is replaced with the original query string. The returned target contains only the path.
  • Constructor Details

    • RewriteRegexRule

      public RewriteRegexRule()
    • RewriteRegexRule

      public RewriteRegexRule(@Name("regex") String regex, @Name("replacement") String replacement)
  • Method Details

    • setReplacement

      public void setReplacement(String replacement)
      Whenever a match is found, it replaces with this value.
      Parameters:
      replacement - the replacement string.
    • apply

      public String apply(String target, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Matcher matcher) throws IOException
      Description copied from class: RegexRule
      Apply this rule to the request/response pair. Called by RegexRule.matchAndApply(String, HttpServletRequest, HttpServletResponse) if the regex matches.
      Specified by:
      apply in class RegexRule
      Parameters:
      target - field to attempt match
      request - request object
      response - response object
      matcher - The Regex matcher that matched the request (with capture groups available for replacement).
      Returns:
      The target (possible updated).
      Throws:
      IOException - exceptions dealing with operating on request or response objects
    • applyURI

      public void applyURI(Request request, String oldURI, String newURI) throws IOException
      Specified by:
      applyURI in interface Rule.ApplyURI
      Throws:
      IOException
    • toString

      public String toString()
      Returns the replacement string.
      Overrides:
      toString in class RegexRule