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 -
Method Summary
Modifier and TypeMethodDescriptionexceptionHandler(Class<T> exceptionType, ExceptionHandler<T> handler) Set a handler for exceptions withexceptionType.findExceptionHandler(Class<? extends Throwable> exceptionType) Find the best match exception handler for the givenexceptionType.match(HttpRequest request) Find a handler for the given request according to registered routes.notFound(HttpRequestHandler handler) Set resource not found handler.Register a handler for the request that matched rule.default Routerroute(io.netty.handler.codec.http.HttpMethod method, String path, HttpRequestHandler handler) static Routerrouter()Create a default Router instance.staticResource(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, 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
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
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.
-