Class RouterHandler
java.lang.Object
org.forgerock.openig.handler.router.RouterHandler
- All Implemented Interfaces:
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",
"delayRouteMetrics": true
}
}
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.
- Since:
- 2.2
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Creates and initializes a routing handler in a heap environment. -
Constructor Summary
ConstructorDescriptionRouterHandler
(org.forgerock.openig.handler.router.RouteBuilder builder, org.forgerock.openig.handler.router.DirectoryMonitor directoryMonitor, org.forgerock.monitoring.api.instrument.MeterRegistry routerMeterRegistry) Builds a router that loads its configuration from the given directory.RouterHandler
(org.forgerock.openig.handler.router.RouteBuilder builder, org.forgerock.openig.handler.router.DirectoryMonitor directoryMonitor, org.forgerock.monitoring.api.instrument.MeterRegistry routerMeterRegistry, Handler defaultHandler) Builds a router that loads its configuration from the given directory. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Deploy a route, meaning that it loads it but also stores it in a file.void
void
stop()
Stops this handler, shutting down and clearing all the managed routes.Undeploy a route, meaning that it unloads it but also deletes the associated file.void
Update a route.
-
Constructor Details
-
RouterHandler
public RouterHandler(org.forgerock.openig.handler.router.RouteBuilder builder, org.forgerock.openig.handler.router.DirectoryMonitor directoryMonitor, org.forgerock.monitoring.api.instrument.MeterRegistry routerMeterRegistry) Builds a router that loads its configuration from the given directory.- Parameters:
builder
- route builderdirectoryMonitor
- the directory monitorrouterMeterRegistry
- The router's meter registry
-
RouterHandler
public RouterHandler(org.forgerock.openig.handler.router.RouteBuilder builder, org.forgerock.openig.handler.router.DirectoryMonitor directoryMonitor, org.forgerock.monitoring.api.instrument.MeterRegistry routerMeterRegistry, Handler defaultHandler) Builds a router that loads its configuration from the given directory.- Parameters:
builder
- route builderdirectoryMonitor
- the directory monitorrouterMeterRegistry
- The router's meter registrydefaultHandler
- the handler which should be invoked when no route matches the request
-
-
Method Details
-
stop
public void stop()Stops this handler, shutting down and clearing all the managed routes. -
deploy
public void deploy(String routeId, String routeName, 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 deployrouteName
- the name of the route to deployrouteConfig
- the configuration of the route to deploy- Throws:
RouterHandlerException
- if the given routeConfig is not valid
-
undeploy
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, JsonValue routeConfig) throws RouterHandlerException Update a route.- Parameters:
routeId
- the id of the route to updaterouteName
- the name of the route to updaterouteConfig
- the new route's configuration- Throws:
RouterHandlerException
- if the given routeConfig is not valid
-
handle
Description copied from interface:Handler
Returns aPromise
representing the asynchronousResponse
of the givenrequest
. If any (asynchronous) processing goes wrong, the promise still contains aResponse
(probably from the 4xx or 5xx status code family).A handler that doesn't hand-off the processing to another downstream handler is responsible for creating the response.
The returned
Promise
contains the response returned from the server as-is. This is responsibility of the handler to produce the appropriate error response (404, 500, ...) in case of processing error.Note: As of Promise 2.0 implementation, it is not permitted to throw any runtime exception here. Doing so produce unexpected behaviour (most likely a server-side hang of the processing thread).
-
onChanges
-