public class RouterHandler extends GenericHandler
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 } }Note that scanInterval is defined in seconds. If -1 (or any negative value) is provided, only an initial scan is performed at startup, synchronously.
Modifier and Type | Class and Description |
---|---|
static class |
RouterHandler.Heaplet
Creates and initializes a routing handler in a heap environment.
|
logger, storage
Constructor and Description |
---|
RouterHandler(org.forgerock.openig.handler.router.RouteBuilder builder,
org.forgerock.openig.handler.router.DirectoryScanner scanner)
Builds a router that loads its configuration from the given directory.
|
Modifier and Type | Method and Description |
---|---|
void |
handle(Exchange exchange)
Called to request the handler respond to the request.
|
void |
onChanges(org.forgerock.openig.handler.router.FileChangeSet changes)
Notify that changes has been detected in the monitored directory.
|
void |
setDefaultHandler(Handler handler)
Sets the handler which should be invoked when no routes match the
request.
|
void |
setRouteComparator(Comparator<org.forgerock.openig.handler.router.Route> comparator)
Changes the ordering of the managed routes.
|
void |
start()
Starts this handler, executes an initial directory scan.
|
void |
stop()
Stops this handler, shutting down and clearing all the managed routes.
|
public RouterHandler(org.forgerock.openig.handler.router.RouteBuilder builder, org.forgerock.openig.handler.router.DirectoryScanner scanner)
builder
- route builderscanner
- DirectoryScanner
that will be invoked at each incoming requestpublic void setRouteComparator(Comparator<org.forgerock.openig.handler.router.Route> comparator)
comparator
- route comparatorpublic void setDefaultHandler(Handler handler)
handler
- the handler which should be invoked when no routes match the
requestpublic void start()
public void stop()
public void onChanges(org.forgerock.openig.handler.router.FileChangeSet changes)
changes
- Content of the change setpublic void handle(Exchange exchange) throws HandlerException, IOException
Handler
A handler that doesn't hand-off an exchange to another handler downstream is responsible for creating the response in the exchange object.
Important note: If an existing response exists in the exchange object
and the handler intends to replace it with its own, it must first check to see if the
existing response has an entity, and if it does, must call its close
method in
order to signal that the processing of the response from a remote server is complete.
handle
in interface Handler
exchange
- the exchange containing the request to handle.HandlerException
- if an exception occurs that prevents handling of the request.IOException
- if an I/O exception occurs.Copyright © 2014 ForgeRock AS. All rights reserved.