Class RouteHandler

java.lang.Object
net.bjmsw.hda.vs.helper.RouteHandler

public class RouteHandler extends Object
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 Details

  • Constructor Details

    • RouteHandler

      public RouteHandler(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.
      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

      public boolean hasRoute(String path)
      Check if a route path exists.
      Parameters:
      path - the path to check
      Returns:
      true if the route path exists, false otherwise
    • executeRoute

      public void executeRoute(String path, Request request)
      Executes a route based on the given path and request.
      Parameters:
      path - the path of the route to execute
      request - the request object associated with the route
      Throws:
      RuntimeException - if an exception occurs while invoking the route method