Class HTTPServer.UriResource
java.lang.Object
ch.autumo.beetroot.server.HTTPServer.UriResource
- All Implemented Interfaces:
Comparable<HTTPServer.UriResource>
- Enclosing class:
HTTPServer
public static class HTTPServer.UriResource
extends Object
implements Comparable<HTTPServer.UriResource>
A single route: URI pattern, handler class, priority and init parameters.
URI parameters such as
:id are parsed into a regular expression.-
Constructor Summary
ConstructorsConstructorDescriptionUriResource(String uri, int priority, Class<?> handler, Object... initParameter) Creates a route with an explicit priority.UriResource(String uri, Class<?> handler, Object... initParameter) Creates a route whose priority is derived from its parameter count. -
Method Summary
Modifier and TypeMethodDescriptionintgetUri()Returns the URI pattern of this route.booleanHas this URI an language in it or not? Unused atm.<T> TinitParameter(int parameterIndex, Class<T> paramClazz) Returns the init parameter at the given index.<T> TinitParameter(Class<T> paramClazz) Returns the first init parameter of the requested type.Matches a URL against this route.org.nanohttpd.protocols.http.response.ResponseInstantiates the handler of this route and dispatches the request.voidsetPriority(int priority) Sets the priority of this route; lower values match first.toString()
-
Constructor Details
-
UriResource
Creates a route with an explicit priority.- Parameters:
uri- the URI patternpriority- the route priority; lower values match firsthandler- the handler classinitParameter- constructor parameters for the handler
-
UriResource
-
-
Method Details
-
process
public org.nanohttpd.protocols.http.response.Response process(Map<String, String> urlParams, org.nanohttpd.protocols.http.IHTTPSession session) Instantiates the handler of this route and dispatches the request.- Parameters:
urlParams- the parameters extracted from the URIsession- the HTTP session- Returns:
- the response, or an internal error response if the handler could not be created or invoked
-
toString
-
getUri
Returns the URI pattern of this route.- Returns:
- the URI pattern, or
nullfor the not-found route
-
initParameter
Returns the first init parameter of the requested type.- Type Parameters:
T- the parameter type- Parameters:
paramClazz- the expected type- Returns:
- the init parameter, or
nullif it is not available
-
initParameter
Returns the init parameter at the given index.- Type Parameters:
T- the parameter type- Parameters:
parameterIndex- the index of the parameterparamClazz- the expected type- Returns:
- the init parameter, or
nullif the index is not available
-
match
-
compareTo
- Specified by:
compareToin interfaceComparable<HTTPServer.UriResource>
-
setPriority
public void setPriority(int priority) Sets the priority of this route; lower values match first.- Parameters:
priority- the priority
-
hasLanguage
public boolean hasLanguage()Has this URI an language in it or not? Unused atm.- Returns:
- true if this URI has a language route, otherwise false
-