Package net.bjmsw.hda.vs.helper
Class RouteHandler
java.lang.Object
net.bjmsw.hda.vs.helper.RouteHandler
The RouteHandler class is responsible for managing routes and executing corresponding methods.
Uses reflection to find methods annotated with the @Route annotation.
To parse for routes, the RouteHandler class uses reflection to find methods annotated with the @Route annotation.
Supply classes to the constructor to search for routes in them.
See Route for more information on how to define routes.
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionRouteHandler(Class<?>... classes) Constructs a new RouteHandler object and initializes the routes map by searching for methods annotated with the @Route annotation in the supplied classes. -
Method Summary
Modifier and TypeMethodDescriptionvoidexecuteRoute(String path, Request request) Executes a route based on the given path and request.booleanCheck if a route path exists.
-
Field Details
-
routes
-
-
Constructor Details
-
RouteHandler
Constructs a new RouteHandler object and initializes the routes map by searching for methods annotated with the @Route annotation in the supplied classes.- Parameters:
classes- the classes to search for route methods in- Throws:
RuntimeException- if there is a duplicate route, a route does not start with "/", a method does not have exactly one parameter of type Request, or a method does not have a return type of void- See Also:
-
-
Method Details
-
hasRoute
Check if a route path exists.- Parameters:
path- the path to check- Returns:
- true if the route path exists, false otherwise
-
executeRoute
Executes a route based on the given path and request.- Parameters:
path- the path of the route to executerequest- the request object associated with the route- Throws:
RuntimeException- if an exception occurs while invoking the route method
-