Class RegexRule

java.lang.Object
org.eclipse.jetty.rewrite.handler.Rule
org.eclipse.jetty.rewrite.handler.RegexRule
Direct Known Subclasses:
HeaderRegexRule, RedirectRegexRule, RewriteRegexRule, TerminatingRegexRule

public abstract class RegexRule extends Rule
Abstract rule to use as a base class for rules that match with a regular expression.
  • Field Details

    • _regex

      protected Pattern _regex
  • Constructor Details

    • RegexRule

      protected RegexRule()
    • RegexRule

      protected RegexRule(String pattern)
  • Method Details

    • setRegex

      public void setRegex(String regex)
      Sets the regular expression string used to match with string URI.
      Parameters:
      regex - the regular expression.
    • getRegex

      public String getRegex()
      Returns:
      get the regular expression
    • matchAndApply

      public String matchAndApply(String target, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException
      Description copied from class: Rule
      This method calls tests the rule against the request/response pair and if the Rule applies, then the rule's action is triggered.
      Specified by:
      matchAndApply in class Rule
      Parameters:
      target - The target of the request
      request - the request
      response - the response
      Returns:
      The new target if the rule has matched, else null
      Throws:
      IOException - if unable to match the rule
    • apply

      protected abstract String apply(String target, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Matcher matcher) throws IOException
      Apply this rule to the request/response pair. Called by matchAndApply(String, HttpServletRequest, HttpServletResponse) if the regex matches.
      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
    • toString

      public String toString()
      Returns the regular expression string.
      Overrides:
      toString in class Rule