Interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>

All Known Subinterfaces:
AppRouter, AppRouter, DefaultRouter
All Known Implementing Classes:
AppRouterDefault, AppRouterDefault, DefaultRouterDefault, SpincastRouter

public interface Router<R extends RequestContext<?>,W extends WebsocketContext<?>>
The router.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The default path used when Spincast creates routes by itself.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addRoute(Route<R> route)
    Adds a route, directly.
    void
    Adds an alias for a path pattern.
    void
    Adds a static resource route, directly.
    void
    Adds a Websocket route, directly.
    ALL()
    Starts the creation of a route matching any HTTP method, and on any path.
    ALL(String path)
    Starts the creation of a route matching any HTTP method.
    void
    Enables Cross-Origin Resource Sharing (Cors) on all matching requests (except the static resources, for whom cors has to be activated directly!)
    void
    cors(String path)
    Enables Cross-Origin Resource Sharing (Cors) on all requests matching the specified path (except the static resources, for whom cors has to be activated directly!)
    void
    cors(String path, Set<String> allowedOrigins)
    Enables Cross-Origin Resource Sharing (Cors) on requests matching the specified path (except the static resources, for whom cors has to be activated directly!)
    void
    cors(String path, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead)
    Enables Cross-Origin Resource Sharing (Cors) on requests matching the specified path (except the static resources, for whom cors has to be activated directly!)
    void
    cors(String path, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent)
    Enables Cross-Origin Resource Sharing (Cors) on requests matching the specified path (except the static resources, for whom cors has to be activated directly!)
    void
    cors(String path, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies)
    Enables Cross-Origin Resource Sharing (Cors) on requests matching the specified path (except the static resources, for whom cors has to be activated directly!)
    void
    cors(String path, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies, Set<HttpMethod> allowedMethods)
    Enables Cross-Origin Resource Sharing (Cors) on requests matching the specified path (except the static resources, for whom cors has to be activated directly!)
    void
    cors(String path, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies, Set<HttpMethod> allowedMethods, int maxAgeInSeconds)
    Enables Cross-Origin Resource Sharing (Cors) on requests matching the specified path (except the static resources, for whom cors has to be activated directly!)
    void
    cors(Set<String> allowedOrigins)
    Enables Cross-Origin Resource Sharing (Cors) on matching requests (except the static resources, for whom cors has to be activated directly!)
    void
    cors(Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead)
    Enables Cross-Origin Resource Sharing (Cors) on matching requests (except the static resources, for whom cors has to be activated directly!)
    void
    cors(Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent)
    Enables Cross-Origin Resource Sharing (Cors) on matching requests (except the static resources, for whom cors has to be activated directly!)
    void
    cors(Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies)
    Enables Cross-Origin Resource Sharing (Cors) on matching requests (except the static resources, for whom cors has to be activated directly!)
    void
    cors(Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies, Set<HttpMethod> allowedMethods)
    Enables Cross-Origin Resource Sharing (Cors) on matching requests (except the static resources, for whom cors has to be activated directly!)
    void
    cors(Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies, Set<HttpMethod> allowedMethods, int maxAgeInSeconds)
    Enables Cross-Origin Resource Sharing (Cors) on matching requests (except the static resources, for whom cors has to be activated directly!)
    Starts the creation of a DELETE route, for all path.
    DELETE(String path)
    Starts the creation of a DELETE route.
    dir(String url)
    Start the creation of a static resource directory.
    void
    exception(String path, Handler<R> handler)
    Creates a route considered during an "Exception" routing process.
    void
    exception(Handler<R> handler)
    Creates a route considered during an "Exception" routing process.
    file(String url)
    Start the creation of a static resource file.
    GET()
    Starts the creation of a GET route, for all path.
    GET(String path)
    Starts the creation of a GET route.
    Gets the global "after" filters.
    Gets the global "before" filters.
    Gets the main routes.
    getRoute(String routeId)
    Gets a route using its routeId.
    The path patterns' aliases.
    Starts the creation of a HEAD route, for all path.
    HEAD(String path)
    Starts the creation of a HEAD route.
    void
    httpAuth(String pathPrefix, String realmName)
    Creates HTTP authentication protection (realm) for the specified path prefix.
    methods(String path, Set<HttpMethod> httpMethods)
    Starts the creation of a route matching the specified HTTP methods.
    methods(String path, HttpMethod... httpMethods)
    Starts the creation of a route matching the specified HTTP methods.
    methods(Set<HttpMethod> httpMethods)
    Starts the creation of a route matching the specified HTTP methods and on any path.
    methods(HttpMethod... httpMethods)
    Starts the creation of a route matching the specified HTTP methods and on any path.
    void
    notFound(String path, Handler<R> handler)
    Creates a route considered during an "Not Found" routing process.
    void
    notFound(Handler<R> handler)
    Creates a route considered during an "Not Found" routing process.
    Starts the creation of a OPTIONS route, for all path.
    Starts the creation of a OPTIONS route.
    Starts the creation of a PATCH route, for all path.
    PATCH(String path)
    Starts the creation of a PATCH route.
    Starts the creation of a POST route, for all path.
    POST(String path)
    Starts the creation of a POST route.
    PUT()
    Starts the creation of a PUT route, for all path.
    PUT(String path)
    Starts the creation of a PUT route.
    redirect(String oldPath)
    Starts the creation of a redirection rule.
    void
    Removes all application routes (not the ones added by Spincast and plugins).
    void
    removeAllRoutes(boolean removeSpincastAndPluginsRoutesToo)
    Removes all routes.
    void
    Removes a route using its routeId.
    route(R requestContext)
    Find the route to use to handle the current request.
    route(R requestContext, RoutingType routingType)
    Find the route to use to handle the current request, given the specified routing type.
    Starts the creation of a TRACE route, for all path.
    TRACE(String path)
    Starts the creation of a TRACE route, at the specified position.
    Starts the creation of a Websocket route.
  • Field Details

    • DEFAULT_ROUTE_PATH

      static final String DEFAULT_ROUTE_PATH
      The default path used when Spincast creates routes by itself.
      See Also:
  • Method Details

    • GET

      RouteBuilder<R> GET()
      Starts the creation of a GET route, for all path. Same as GET("/*{path}").
    • GET

      RouteBuilder<R> GET(String path)
      Starts the creation of a GET route.
    • POST

      RouteBuilder<R> POST()
      Starts the creation of a POST route, for all path. Same as POST("/*{path}").
    • POST

      RouteBuilder<R> POST(String path)
      Starts the creation of a POST route.
    • PUT

      RouteBuilder<R> PUT()
      Starts the creation of a PUT route, for all path. Same as PUT("/*{path}").
    • PUT

      RouteBuilder<R> PUT(String path)
      Starts the creation of a PUT route.
    • DELETE

      RouteBuilder<R> DELETE()
      Starts the creation of a DELETE route, for all path. Same as DELETE("/*{path}").
    • DELETE

      RouteBuilder<R> DELETE(String path)
      Starts the creation of a DELETE route.
    • OPTIONS

      RouteBuilder<R> OPTIONS()
      Starts the creation of a OPTIONS route, for all path. Same as OPTIONS("/*{path}").
    • OPTIONS

      RouteBuilder<R> OPTIONS(String path)
      Starts the creation of a OPTIONS route.
    • TRACE

      RouteBuilder<R> TRACE()
      Starts the creation of a TRACE route, for all path. Same as TRACE("/*{path}").
    • TRACE

      RouteBuilder<R> TRACE(String path)
      Starts the creation of a TRACE route, at the specified position.
    • HEAD

      RouteBuilder<R> HEAD()
      Starts the creation of a HEAD route, for all path. Same as HEAD("/*{path}").
    • HEAD

      RouteBuilder<R> HEAD(String path)
      Starts the creation of a HEAD route.
    • PATCH

      RouteBuilder<R> PATCH()
      Starts the creation of a PATCH route, for all path. Same as PATCH("/*{path}").
    • PATCH

      RouteBuilder<R> PATCH(String path)
      Starts the creation of a PATCH route.
    • ALL

      RouteBuilder<R> ALL()
      Starts the creation of a route matching any HTTP method, and on any path. Same as ALL("/*{path}").
    • ALL

      RouteBuilder<R> ALL(String path)
      Starts the creation of a route matching any HTTP method.
    • methods

      RouteBuilder<R> methods(Set<HttpMethod> httpMethods)
      Starts the creation of a route matching the specified HTTP methods and on any path. Same as methods("/*{path}", httpMethods).
    • methods

      RouteBuilder<R> methods(String path, Set<HttpMethod> httpMethods)
      Starts the creation of a route matching the specified HTTP methods.
    • methods

      RouteBuilder<R> methods(HttpMethod... httpMethods)
      Starts the creation of a route matching the specified HTTP methods and on any path. Same as methods("/*{path}", httpMethods).
    • methods

      RouteBuilder<R> methods(String path, HttpMethod... httpMethods)
      Starts the creation of a route matching the specified HTTP methods.
    • exception

      void exception(Handler<R> handler)
      Creates a route considered during an "Exception" routing process.

      Synonym of :

      ALL("/*{path}").exception().handle(handler)

    • exception

      void exception(String path, Handler<R> handler)
      Creates a route considered during an "Exception" routing process.

      Synonym of :

      ALL(path).exception().handle(handler)

    • notFound

      void notFound(Handler<R> handler)
      Creates a route considered during an "Not Found" routing process.

      Synonym of :

      ALL("/*{path}").notFound().handle(handler)

    • notFound

      void notFound(String path, Handler<R> handler)
      Creates a route considered during an "Not Found" routing process.

      Synonym of :

      ALL(path).notFound().handle(handler)

    • file

      Start the creation of a static resource file.

      Only a GET or a HEAD request will be able to access this resource.

      No "before" and "after" filters will be applied to those, since the request won't even reach the framework.

      Parameters:
      url - The url which will trigger the output of this static resource.
    • dir

      Start the creation of a static resource directory.

      Only a GET or a HEAD request will be able to access the resources below this directory.

      No "before" and "after" filters will be applied to those, since the request won't even reach the framework.

      Parameters:
      url - The url which will trigger the output of this static resource.
    • cors

      void cors()
      Enables Cross-Origin Resource Sharing (Cors) on all matching requests (except the static resources, for whom cors has to be activated directly!)
      See Also:
      • SpincastFilters#cors(R context)
    • cors

      void cors(Set<String> allowedOrigins)
      Enables Cross-Origin Resource Sharing (Cors) on matching requests (except the static resources, for whom cors has to be activated directly!)
      See Also:
      • SpincastFilters#cors(R context, Set<String> allowedOrigins)
    • cors

      void cors(Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead)
      Enables Cross-Origin Resource Sharing (Cors) on matching requests (except the static resources, for whom cors has to be activated directly!)
      See Also:
      • SpincastFilters#cors(R context, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeReadt)
    • cors

      void cors(Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent)
      Enables Cross-Origin Resource Sharing (Cors) on matching requests (except the static resources, for whom cors has to be activated directly!)
      See Also:
      • SpincastFilters#cors(R context, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent)
    • cors

      void cors(Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies)
      Enables Cross-Origin Resource Sharing (Cors) on matching requests (except the static resources, for whom cors has to be activated directly!)
      See Also:
      • SpincastFilters#cors(R context, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies)
    • cors

      void cors(Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies, Set<HttpMethod> allowedMethods)
      Enables Cross-Origin Resource Sharing (Cors) on matching requests (except the static resources, for whom cors has to be activated directly!)
      See Also:
      • SpincastFilters#cors(R context, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies, Set<HttpMethod> allowedMethods)
    • cors

      void cors(Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies, Set<HttpMethod> allowedMethods, int maxAgeInSeconds)
      Enables Cross-Origin Resource Sharing (Cors) on matching requests (except the static resources, for whom cors has to be activated directly!)
      See Also:
      • SpincastFilters#cors(R context, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies, Set<HttpMethod> allowedMethods, int maxAgeInSeconds)
    • cors

      void cors(String path)
      Enables Cross-Origin Resource Sharing (Cors) on all requests matching the specified path (except the static resources, for whom cors has to be activated directly!)
      See Also:
      • SpincastFilters#cors(R context)
    • cors

      void cors(String path, Set<String> allowedOrigins)
      Enables Cross-Origin Resource Sharing (Cors) on requests matching the specified path (except the static resources, for whom cors has to be activated directly!)
      See Also:
      • SpincastFilters#cors(R context, Set<String> allowedOrigins)
    • cors

      void cors(String path, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead)
      Enables Cross-Origin Resource Sharing (Cors) on requests matching the specified path (except the static resources, for whom cors has to be activated directly!)
      See Also:
      • SpincastFilters#cors(R context, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead)
    • cors

      void cors(String path, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent)
      Enables Cross-Origin Resource Sharing (Cors) on requests matching the specified path (except the static resources, for whom cors has to be activated directly!)
      See Also:
      • SpincastFilters#cors(R context, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent)
    • cors

      void cors(String path, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies)
      Enables Cross-Origin Resource Sharing (Cors) on requests matching the specified path (except the static resources, for whom cors has to be activated directly!)
      See Also:
      • SpincastFilters#cors(R context, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies)
    • cors

      void cors(String path, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies, Set<HttpMethod> allowedMethods)
      Enables Cross-Origin Resource Sharing (Cors) on requests matching the specified path (except the static resources, for whom cors has to be activated directly!)
      See Also:
      • SpincastFilters#cors(R context, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies, Set<HttpMethod> allowedMethods)
    • cors

      void cors(String path, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies, Set<HttpMethod> allowedMethods, int maxAgeInSeconds)
      Enables Cross-Origin Resource Sharing (Cors) on requests matching the specified path (except the static resources, for whom cors has to be activated directly!)
      See Also:
      • SpincastFilters#cors(R context, Set<String> allowedOrigins, Set<String> extraHeadersAllowedToBeRead, Set<String> extraHeadersAllowedToBeSent, boolean allowCookies, Set<HttpMethod> allowedMethods, int maxAgeInSeconds)
    • addStaticResource

      void addStaticResource(StaticResource<R> staticResource)
      Adds a static resource route, directly.
    • route

      RoutingResult<R> route(R requestContext)
      Find the route to use to handle the current request. The result contains all handlers to use.
      Returns:
      the routing result or null if no route matches.
    • route

      RoutingResult<R> route(R requestContext, RoutingType routingType)
      Find the route to use to handle the current request, given the specified routing type. The result contains all handlers to use.
      Returns:
      the routing result or null if no route matches.
    • addRoute

      void addRoute(Route<R> route)
      Adds a route, directly.
    • removeAllRoutes

      void removeAllRoutes()
      Removes all application routes (not the ones added by Spincast and plugins).
    • removeAllRoutes

      void removeAllRoutes(boolean removeSpincastAndPluginsRoutesToo)
      Removes all routes.
      Parameters:
      removeSpincastAndPluginsRoutesToo - Should the routes added by Spincast and plugins be removed too?
    • removeRoute

      void removeRoute(String routeId)
      Removes a route using its routeId.
    • getRoute

      Route<R> getRoute(String routeId)
      Gets a route using its routeId.
    • getGlobalBeforeFiltersRoutes

      List<Route<R>> getGlobalBeforeFiltersRoutes()
      Gets the global "before" filters.
    • getMainRoutes

      List<Route<R>> getMainRoutes()
      Gets the main routes.
    • getGlobalAfterFiltersRoutes

      List<Route<R>> getGlobalAfterFiltersRoutes()
      Gets the global "after" filters.
    • addRouteParamPatternAlias

      void addRouteParamPatternAlias(String alias, String pattern)
      Adds an alias for a path pattern. For example, the path of a route may be "/${param1:<XXX>}" : here "XXX" is the alias for the regular expression pattern to use.
    • getRouteParamPatternAliases

      Map<String,String> getRouteParamPatternAliases()
      The path patterns' aliases. The map is mutable.
    • httpAuth

      void httpAuth(String pathPrefix, String realmName)
      Creates HTTP authentication protection (realm) for the specified path prefix.
    • websocket

      WebsocketRouteBuilder<R,W> websocket(String path)
      Starts the creation of a Websocket route.
    • addWebsocketRoute

      void addWebsocketRoute(WebsocketRoute<R,W> websocketRoute)
      Adds a Websocket route, directly.
    • redirect

      RedirectRuleBuilder<R,W> redirect(String oldPath)
      Starts the creation of a redirection rule.

      Redirecttion rule are ran at position "0", as a regular route. Therefore the order in which they are added to the router is very important! As soon as a redirect rule matches, the request is redirected.

      Parameters:
      oldPath - The old path that needs to be redirected.