Class RewritePatternRule

  • All Implemented Interfaces:
    Rule.ApplyURI

    public class RewritePatternRule
    extends PatternRule
    implements Rule.ApplyURI
    Rewrite the URI by replacing the matched PathMap path with a fixed string.
    • Constructor Detail

      • RewritePatternRule

        public RewritePatternRule()
      • RewritePatternRule

        public RewritePatternRule​(@Name("pattern")
                                  String pattern,
                                  @Name("replacement")
                                  String replacement)
    • Method Detail

      • 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)
                     throws IOException
        Description copied from class: PatternRule
        Apply the rule to the request
        Specified by:
        apply in class PatternRule
        Parameters:
        target - field to attempt match
        request - request object
        response - response object
        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
        This method will add _query to the requests's queryString and also combine it with existing queryStrings in the request. However it won't take care for duplicate. E.g. if request.getQueryString contains a parameter param1 = true and _query will contain param1=false the result will be param1=true&param1=false. To cover this use case some more complex pattern matching is necessary. We can implement this if there's use cases.
        Specified by:
        applyURI in interface Rule.ApplyURI
        Parameters:
        request - the request
        oldURI - the old URI
        newURI - the new URI
        Throws:
        IOException - if unable to apply the URI