Package spark.route
Class Routes
java.lang.Object
spark.route.Routes
- Direct Known Subclasses:
SimpleRouteMatcher
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 Summary
FieldsModifier and TypeFieldDescriptionprivate static final org.slf4j.Loggerprivate List<RouteEntry> private static final char -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidDeprecated.private voidadd(HttpMethod method, String url, String acceptedType, Object target) voidadd(HttpMethod httpMethod, FilterImpl filter) Add a filtervoidadd(HttpMethod httpMethod, RouteImpl route) Add a routevoidclear()¨Clear all routesstatic Routescreate()find(HttpMethod httpMethod, String path, String acceptType) finds target for a requested routefindAll()findMultiple(HttpMethod httpMethod, String path, String acceptType) Finds multiple targets for a requested route.private List<RouteEntry> findTargetsForRequestedRoute(HttpMethod httpMethod, String path) private RouteEntryfindTargetWithGivenAcceptType(List<RouteEntry> routeMatches, String acceptType) private Map<String, RouteEntry> getAcceptedMimeTypes(List<RouteEntry> routes) booleanRemoves a particular route from the collection of those that have been previously routed.booleanRemoves a particular route from the collection of those that have been previously routed.private booleanremoveRoute(HttpMethod httpMethod, String path) private booleanrouteWithGivenAcceptType(String bestMatch)
-
Field Details
-
LOG
private static final org.slf4j.Logger LOG -
SINGLE_QUOTE
private static final char SINGLE_QUOTE- See Also:
-
routes
-
-
Constructor Details
-
Routes
protected Routes()Constructor
-
-
Method Details
-
create
-
add
Add a route- Parameters:
httpMethod- the http-method of the routeroute- the route to add
-
add
Add a filter- Parameters:
httpMethod- the http-method of the routefilter- the filter to add
-
find
finds target for a requested route- Parameters:
httpMethod- the http methodpath- the pathacceptType- the accept type- Returns:
- the target
-
findMultiple
Finds multiple targets for a requested route.- Parameters:
httpMethod- the http methodpath- the route pathacceptType- the accept type- Returns:
- the targets
-
findAll
- Returns:
- the targets
-
clear
public void clear()¨Clear all routes -
remove
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 pathhttpMethod- the http method- Returns:
- true if this a matching route has been previously routed
- Throws:
IllegalArgumentException- if path is null or blank or if httpMethod is null, blank or an invalid HTTP method- Since:
- 2.2
-
remove
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:
IllegalArgumentException- if path is null or blank- Since:
- 2.2
-
add
-
getAcceptedMimeTypes
-
routeWithGivenAcceptType
-
findTargetsForRequestedRoute
-
findTargetWithGivenAcceptType
-
removeRoute
-
add
Deprecated.Parse and validates a route and adds it- Parameters:
route- the route pathacceptType- the accept typetarget- the invocation target
-