Class PathHandler

  • All Implemented Interfaces:
    HttpHandler

    public class PathHandler
    extends Object
    implements HttpHandler
    Handler that dispatches to a given handler based of a prefix match of the path.

    This only matches a single level of a request, e.g if you have a request that takes the form:

    /foo/bar

    Author:
    Stuart Douglas
    • Constructor Detail

      • PathHandler

        public PathHandler​(HttpHandler defaultHandler)
      • PathHandler

        public PathHandler​(HttpHandler defaultHandler,
                           int cacheSize)
      • PathHandler

        public PathHandler()
      • PathHandler

        public PathHandler​(int cacheSize)
    • Method Detail

      • addPrefixPath

        public PathHandler addPrefixPath​(String path,
                                         HttpHandler handler)
        Adds a path prefix and a handler for that path. If the path does not start with a / then one will be prepended.

        The match is done on a prefix bases, so registering /foo will also match /foo/bar. Though exact path matches are taken into account before prefix path matches. So if an exact path match exists its handler will be triggered.

        If / is specified as the path then it will replace the default handler.

        Parameters:
        path - If the request contains this prefix, run handler.
        handler - The handler which is activated upon match.
        Returns:
        The resulting PathHandler after this path has been added to it.
      • addExactPath

        public PathHandler addExactPath​(String path,
                                        HttpHandler handler)
        If the request path is exactly equal to the given path, run the handler.

        Exact paths are prioritized higher than prefix paths.

        Parameters:
        path - If the request path is exactly this, run handler.
        handler - Handler run upon exact path match.
        Returns:
        The resulting PathHandler after this path has been added to it.