You can create a plug-in to filter a request that is made
to a service or to filter a response that is received from a service.
For example, you might create a request filter to modify the parameters
that are sent to a service to provide custom validations and error
handling. You can also create a request filter to override a service.
For example, you might create a response filter to apply custom formatting
to the data that is received from a service before the data is displayed.
About this task
The external data service plug-in uses request and response
filters to enable a service to provide custom choice lists and validation.
To
use a filter, a plug-in must handle the
JSONArtifact object
that is sent in the request or the
JSONObject object
that is returned in the response.
Important: The JSON format
that is used for request and response filters is subject to change
without notice. If you create request and response filters for plug-ins,
you might need to make updates to your code if a new version of the IBM® Content
Navigator Java™ application programming interface is released.
Procedure
To create a request or response filter:
- If you are creating a request filter, extend
the PluginRequestFilter class:
- Implement the getFilteredServices method
to return the names of the services for which this filter is used.
- Implement the filter method to define
the filter that is to be applied to the request.
Tip: Examine the JSON object that is sent to the service to
determine the requirements for the filter method.
- If you are creating a response filter, extend
the PluginResponseFilter class:
- Implement the getFilteredServices method
to return the names of the services for which this filter is used.
- Implement the filter method to define
the filter that is to be applied to the request.
Tip: Examine the JSON object that is returned by the service
to determine the requirements for the filter method.
- Add the filter as a component in your Plugin.java subclass:
Type of filter |
Add to the Plugin.java subclass |
Request |
Implement the getRequestFilters method
to return an instance of the PluginRequestFilter.java class
that you created in step 1. |
Response |
Implement the getResponseFilters method
to return an instance of the PluginResponseFilter.java class
that you created in step 2. |
Sample plug-in files for a custom response filter
The
following files in the sample plug-in define a response filter.
Table 1. Sample files that define a plug-in
response filterFile |
Description |
SamplePluginResponseFilter.java |
This file extends the PluginResponseFilter class
to define a filter that applies custom property formatting to search
results. |