Package spark.route

Class Routes

  • Direct Known Subclasses:
    SimpleRouteMatcher

    public class Routes
    extends java.lang.Object
    Holds the routes and performs matching from HTTP requests to routes. Works as Sinatra's, ie. if there are more than one match the one that was mapped first is chosen.
    • Field Detail

      • LOG

        private static final org.slf4j.Logger LOG
      • routes

        private java.util.List<RouteEntry> routes
    • Constructor Detail

      • Routes

        protected Routes()
        Constructor
    • Method Detail

      • create

        public static Routes create()
      • add

        public void add​(HttpMethod httpMethod,
                        RouteImpl route)
        Add a route
        Parameters:
        httpMethod - the http-method of the route
        route - the route to add
      • add

        public void add​(HttpMethod httpMethod,
                        FilterImpl filter)
        Add a filter
        Parameters:
        httpMethod - the http-method of the route
        filter - the filter to add
      • find

        public RouteMatch find​(HttpMethod httpMethod,
                               java.lang.String path,
                               java.lang.String acceptType)
        finds target for a requested route
        Parameters:
        httpMethod - the http method
        path - the path
        acceptType - the accept type
        Returns:
        the target
      • findMultiple

        public java.util.List<RouteMatch> findMultiple​(HttpMethod httpMethod,
                                                       java.lang.String path,
                                                       java.lang.String acceptType)
        Finds multiple targets for a requested route.
        Parameters:
        httpMethod - the http method
        path - the route path
        acceptType - the accept type
        Returns:
        the targets
      • findAll

        public java.util.List<RouteMatch> findAll()
        Returns:
        the targets
      • clear

        public void clear()
        ¨Clear all routes
      • remove

        public boolean remove​(java.lang.String path,
                              java.lang.String httpMethod)
        Removes a particular route from the collection of those that have been previously routed. Search for a previously established routes using the given path and HTTP method, removing any matches that are found.
        Parameters:
        path - the route path
        httpMethod - the http method
        Returns:
        true if this a matching route has been previously routed
        Throws:
        java.lang.IllegalArgumentException - if path is null or blank or if httpMethod is null, blank or an invalid HTTP method
        Since:
        2.2
      • remove

        public boolean remove​(java.lang.String path)
        Removes a particular route from the collection of those that have been previously routed. Search for a previously established routes using the given path and removes any matches that are found.
        Parameters:
        path - the route path
        Returns:
        true if this a matching route has been previously routed
        Throws:
        java.lang.IllegalArgumentException - if path is null or blank
        Since:
        2.2
      • add

        private void add​(HttpMethod method,
                         java.lang.String url,
                         java.lang.String acceptedType,
                         java.lang.Object target)
      • getAcceptedMimeTypes

        private java.util.Map<java.lang.String,​RouteEntry> getAcceptedMimeTypes​(java.util.List<RouteEntry> routes)
      • routeWithGivenAcceptType

        private boolean routeWithGivenAcceptType​(java.lang.String bestMatch)
      • findTargetsForRequestedRoute

        private java.util.List<RouteEntry> findTargetsForRequestedRoute​(HttpMethod httpMethod,
                                                                        java.lang.String path)
      • findTargetWithGivenAcceptType

        private RouteEntry findTargetWithGivenAcceptType​(java.util.List<RouteEntry> routeMatches,
                                                         java.lang.String acceptType)
      • removeRoute

        private boolean removeRoute​(HttpMethod httpMethod,
                                    java.lang.String path)
      • add

        @Deprecated
        public void add​(java.lang.String route,
                        java.lang.String acceptType,
                        java.lang.Object target)
        Deprecated.
        Parse and validates a route and adds it
        Parameters:
        route - the route path
        acceptType - the accept type
        target - the invocation target