Class AbstractRouter

java.lang.Object
com.robothy.netty.router.AbstractRouter
All Implemented Interfaces:
Router
Direct Known Subclasses:
SpringWebRouter

public abstract class AbstractRouter
extends java.lang.Object
implements Router
  • Field Summary

    Fields inherited from interface com.robothy.netty.router.Router

    DEFAULT_NOT_FOUND_HANDLER
  • Constructor Summary

    Constructors
    Constructor Description
    AbstractRouter()  
  • Method Summary

    Modifier and Type Method Description
    <T extends java.lang.Throwable>
    Router
    exceptionHandler​(java.lang.Class<T> exceptionType, ExceptionHandler<T> handler)
    Set a handler for exceptions with exceptionType.
    ExceptionHandler<java.lang.Throwable> findExceptionHandler​(java.lang.Class<? extends java.lang.Throwable> exceptionType)
    Find the best match exception handler for the given exceptionType.
    Router notFound​(HttpRequestHandler handler)
    Set resource not found handler.
    protected HttpRequestHandler notFoundHandler()  
    Router staticResource​(java.lang.String rootPath)
    The router will map the request uri to the relative path of files under the rootPath directory.
    protected com.robothy.netty.router.StaticResourceMatcher staticResourceMatcher()  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.robothy.netty.router.Router

    match, route, route
  • Constructor Details

    • AbstractRouter

      public AbstractRouter()
  • Method Details

    • notFound

      public Router notFound​(HttpRequestHandler handler)
      Description copied from interface: Router
      Set resource not found handler.
      Specified by:
      notFound in interface Router
      Returns:
      this
    • staticResource

      public Router staticResource​(java.lang.String rootPath)
      Description copied from interface: Router
      The router will map the request uri to the relative path of files under the rootPath directory. By default, the router loads static resources from `classpath:static`.
      • The rootPath must be a valid directory, the router will map the request uri to relative path of files under the rootPath directory.
      • If static resource paths conflict with routes registered via route(), the router will ignore static resources.
      Specified by:
      staticResource in interface Router
      Parameters:
      rootPath - static resources root directory or resource path.
      Returns:
      this.
    • notFoundHandler

      protected HttpRequestHandler notFoundHandler()
    • staticResourceMatcher

      protected com.robothy.netty.router.StaticResourceMatcher staticResourceMatcher()
    • exceptionHandler

      public <T extends java.lang.Throwable> Router exceptionHandler​(java.lang.Class<T> exceptionType, ExceptionHandler<T> handler)
      Description copied from interface: Router
      Set a handler for exceptions with exceptionType.
      Specified by:
      exceptionHandler in interface Router
      Type Parameters:
      T - type of the exception to handle..
      Parameters:
      exceptionType - subtype of Throwable.
      handler - handle specific exception.
      Returns:
      this.
    • findExceptionHandler

      public ExceptionHandler<java.lang.Throwable> findExceptionHandler​(java.lang.Class<? extends java.lang.Throwable> exceptionType)
      Description copied from interface: Router
      Find the best match exception handler for the given exceptionType.
      Specified by:
      findExceptionHandler in interface Router