Class RegexPipeline


  • class RegexPipeline
    extends UrlPipeline
    Selects requests by matching the URI against a regular expression.

    The pattern is bound and matched against the path info of the servlet request, as this class assumes it is invoked by MetaServlet.

    If there are capture groups in the regular expression, the matched ranges of the capture groups are stored as an array of modified HttpServetRequests, into the request attribute MetaFilter.REGEX_GROUPS. Using a capture group that may not capture, e.g. "(/foo)?", will cause an error at request handling time.

    Each servlet request has been altered to have its getServletPath() method return the original path info up to the beginning of the corresponding capture group, and its getPathInfo() method return the matched text. A RegexGroupFilter can be applied in the pipeline to switch the current HttpServletRequest to reference a different capture group before running additional filters, or the final servlet.

    Note that for getPathInfo() to start with a leading "/" as described in the servlet documentation, capture groups must actually capture the leading "/".

    This class dispatches the remainder of the pipeline using the first capture group as the current request, making RegexGroupFilter required only to access capture groups beyond the first.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      (package private) static class  RegexPipeline.Binder  
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.regex.Pattern pattern  
    • Constructor Summary

      Constructors 
      Constructor Description
      RegexPipeline​(java.util.regex.Pattern pattern, javax.servlet.Filter[] filters, javax.servlet.http.HttpServlet servlet)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) boolean match​(javax.servlet.http.HttpServletRequest req)
      Determine if this pipeline handles the request's URL.
      (package private) void service​(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse rsp)
      Execute the filters and the servlet on the request.
      java.lang.String toString()
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • pattern

        private final java.util.regex.Pattern pattern
    • Constructor Detail

      • RegexPipeline

        RegexPipeline​(java.util.regex.Pattern pattern,
                      javax.servlet.Filter[] filters,
                      javax.servlet.http.HttpServlet servlet)
    • Method Detail

      • match

        boolean match​(javax.servlet.http.HttpServletRequest req)
        Description copied from class: UrlPipeline
        Determine if this pipeline handles the request's URL.

        This method should match on the request's getPathInfo() method, as MetaServlet passes the request along as-is to each pipeline's match method.

        Specified by:
        match in class UrlPipeline
        Parameters:
        req - current HTTP request being considered by MetaServlet.
        Returns:
        true if this pipeline is configured to handle the request; false otherwise.
      • service

        void service​(javax.servlet.http.HttpServletRequest req,
                     javax.servlet.http.HttpServletResponse rsp)
              throws javax.servlet.ServletException,
                     java.io.IOException
        Description copied from class: UrlPipeline
        Execute the filters and the servlet on the request.

        Invoked by MetaServlet once UrlPipeline.match(HttpServletRequest) has determined this pipeline is the correct pipeline to handle the current request.

        Overrides:
        service in class UrlPipeline
        Parameters:
        req - current HTTP request.
        rsp - current HTTP response.
        Throws:
        javax.servlet.ServletException - request cannot be completed.
        java.io.IOException - IO error prevents the request from being completed.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object