Package com.robothy.netty.router
Interface Router
- All Known Implementing Classes:
AbstractRouter,SpringWebRouter
public interface Router
A Router is a S3RequestHandler container. The route path must starts with a '/'.
"/", "//", "" matches route("/")
"/a" matches route("/a") firstly, then match "/{param}" and pass 'a' as value of `param`.
-
Field Summary
Fields Modifier and Type Field Description static HttpRequestHandlerDEFAULT_NOT_FOUND_HANDLER -
Method Summary
Modifier and Type Method Description <T extends java.lang.Throwable>
RouterexceptionHandler(java.lang.Class<T> exceptionType, ExceptionHandler<T> handler)Set a handler for exceptions withexceptionType.ExceptionHandler<java.lang.Throwable>findExceptionHandler(java.lang.Class<? extends java.lang.Throwable> exceptionType)Find the best match exception handler for the givenexceptionType.HttpRequestHandlermatch(HttpRequest request)Find a handler for the given request according to registered routes.RouternotFound(HttpRequestHandler handler)Set resource not found handler.Routerroute(Route rule)Register a handler for the request that matched rule.default Routerroute(io.netty.handler.codec.http.HttpMethod method, java.lang.String path, HttpRequestHandler handler)static Routerrouter()Create a default Router instance.RouterstaticResource(java.lang.String rootPath)The router will map the request uri to the relative path of files under therootPathdirectory.
-
Field Details
-
DEFAULT_NOT_FOUND_HANDLER
-
-
Method Details
-
router
Create a default Router instance. -
route
Register a handler for the request that matched rule.- Parameters:
rule- match conditions- Returns:
- this
-
route
default Router route(io.netty.handler.codec.http.HttpMethod method, java.lang.String path, HttpRequestHandler handler) -
notFound
Set resource not found handler.- Returns:
- this
-
staticResource
The router will map the request uri to the relative path of files under therootPathdirectory. By default, the router loads static resources from `classpath:static`.- The
rootPathmust be a valid directory, the router will map the request uri to relative path of files under therootPathdirectory. - If static resource paths conflict with routes registered via
route(), the router will ignore static resources.
- Parameters:
rootPath- static resources root directory or resource path.- Returns:
- this.
- The
-
exceptionHandler
<T extends java.lang.Throwable> Router exceptionHandler(java.lang.Class<T> exceptionType, ExceptionHandler<T> handler)Set a handler for exceptions withexceptionType.- Type Parameters:
T- type of the exception to handle..- Parameters:
exceptionType- subtype of Throwable.handler- handle specific exception.- Returns:
- this.
-
findExceptionHandler
ExceptionHandler<java.lang.Throwable> findExceptionHandler(java.lang.Class<? extends java.lang.Throwable> exceptionType)Find the best match exception handler for the givenexceptionType. -
match
Find a handler for the given request according to registered routes. And set the extracted path parameters to HttpRequest.parameters(String).- Parameters:
request- HTTP request.- Returns:
- a matched handler; or
nullif no matched handlers.
-