As Aria Templates is using a central
core class to manage all IO asynchronous requests, we added the ability to write IO Filters.
Filters can be compared to servlet filters in the J2EE world because they can be used to intercept requests and/or responses as they are sent out/received in.
They may be used to alter the content of the request, or even stop an actual XHR, XDR or JSON-P call and redirect to an alternate resource.
They are also globally set for a whole application, but you can restrict them to a particular package.
Creating a filter is done by extending a base class and overriding one or two methods, like so:
Once a custom filter class has been written, it can be registered on the
IOFiltersMgr singleton to be used at run-time.
Check the API documentation to know the different types of parameters accepted (e.g. it is possible to specify an initialization parameter, passed to the constructor of the filter).
It is possible to add a filter delay in two different locations, either on the request or on the response. There are also 2 different ways to add delays.
When adding delays within the filter simply add two properties:
By default every filter inheriting from the filter base class IOFilter has delay capabilities, and both the requestDelay and responseDelay are set to null or (no influence on the delay). This would be all that is needed to add a delay to a filter, providing the filter doesn't overwrite the inherited onRequest and onResponse methods.
If the filter has overwritten the inherited onRequest and onResponse methods then the following code will need to be added:
It is possible to specify the delay parameters directly within the
addFilter() call through the
Here is an example: