Class RouterHandler

  • All Implemented Interfaces:
    org.forgerock.http.Handler

    public class RouterHandler
    extends Object
    implements org.forgerock.http.Handler
    Auto-configured DispatchHandler. It looks for route configuration files (very similar to the usual general config file) in a defined directory (by default it looks in config/routes/).
       
       {
         "name": "Router",
         "type": "Router",
         "config": {
           "directory": "/tmp/routes",
           "defaultHandler": "404NotFound",
           "scanInterval": 2 or "2 seconds"
         }
       }
       
     
    Note that scanInterval can be defined in 2 ways :
    • as an integer, which defines the number of seconds. If -1 (or any negative value) is provided, only an initial scan is performed at startup, synchronously.
    • as a duration. If "disabled" or "zero" is provided, only an initial scan is performed at startup, synchronously.
    In both cases, the default value is 10 seconds.
    Since:
    2.2
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  RouterHandler.Heaplet
      Creates and initializes a routing handler in a heap environment.
    • Constructor Summary

      Constructors 
      Constructor Description
      RouterHandler​(org.forgerock.openig.handler.router.RouteBuilder builder, org.forgerock.openig.handler.router.DirectoryMonitor directoryMonitor)
      Builds a router that loads its configuration from the given directory.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void deploy​(String routeId, String routeName, org.forgerock.json.JsonValue routeConfig)
      Deploy a route, meaning that it loads it but also stores it in a file.
      org.forgerock.util.promise.Promise<org.forgerock.http.protocol.Response,​org.forgerock.util.promise.NeverThrowsException> handle​(org.forgerock.services.context.Context context, org.forgerock.http.protocol.Request request)  
      void onChanges​(org.forgerock.openig.handler.router.FileChangeSet changes)  
      void stop()
      Stops this handler, shutting down and clearing all the managed routes.
      org.forgerock.json.JsonValue undeploy​(String routeId)
      Undeploy a route, meaning that it unloads it but also deletes the associated file.
      void update​(String routeId, String routeName, org.forgerock.json.JsonValue routeConfig)
      Update a route.
    • Constructor Detail

      • RouterHandler

        public RouterHandler​(org.forgerock.openig.handler.router.RouteBuilder builder,
                             org.forgerock.openig.handler.router.DirectoryMonitor directoryMonitor)
        Builds a router that loads its configuration from the given directory.
        Parameters:
        builder - route builder
        directoryMonitor - the directory monitor
    • Method Detail

      • stop

        public void stop()
        Stops this handler, shutting down and clearing all the managed routes.
      • deploy

        public void deploy​(String routeId,
                           String routeName,
                           org.forgerock.json.JsonValue routeConfig)
                    throws RouterHandlerException
        Deploy a route, meaning that it loads it but also stores it in a file.
        Parameters:
        routeId - the id of the route to deploy
        routeName - the name of the route to deploy
        routeConfig - the configuration of the route to deploy
        Throws:
        RouterHandlerException - if the given routeConfig is not valid
      • undeploy

        public org.forgerock.json.JsonValue undeploy​(String routeId)
                                              throws RouterHandlerException
        Undeploy a route, meaning that it unloads it but also deletes the associated file.
        Parameters:
        routeId - the id of the route to remove
        Returns:
        the configuration of the undeployed route
        Throws:
        RouterHandlerException - if the given routeId is not valid
      • update

        public void update​(String routeId,
                           String routeName,
                           org.forgerock.json.JsonValue routeConfig)
                    throws RouterHandlerException
        Update a route.
        Parameters:
        routeId - the id of the route to update
        routeName - the name of the route to update
        routeConfig - the new route's configuration
        Throws:
        RouterHandlerException - if the given routeConfig is not valid
      • handle

        public org.forgerock.util.promise.Promise<org.forgerock.http.protocol.Response,​org.forgerock.util.promise.NeverThrowsException> handle​(org.forgerock.services.context.Context context,
                                                                                                                                                     org.forgerock.http.protocol.Request request)
        Specified by:
        handle in interface org.forgerock.http.Handler
      • onChanges

        public void onChanges​(org.forgerock.openig.handler.router.FileChangeSet changes)