Filtering Requests and Responses
Filtering Requests and Responses
A filter is an object that can transform the header or content or both of a request or response. Filters differ
from Web components in that they usually do not themselves create a response. Instead, a filter provides
functionality that can be "attached" to any kind of Web resource. As a consequence, a filter should not
have any dependencies on a Web resource for which it is acting as a filter, so that it can be composable
with more than one type of Web resource. The main tasks that a filter can perform are as follows:
Query the request and act accordingly.
Block the request-and-response pair from passing any further.
Modify the request headers and data. You do this by providing a customized version of the
request.
Modify the response headers and data. You do this by providing a customized version of the
response.
Interact with external resources.
Applications of filters include authentication, logging, image conversion, data compression, encryption,
tokenizing streams, and XML transformations.
You can configure a Web resource to be filtered by a chain of zero, one, or more filters in a specific order.
This chain is specified when the Web application containing the component is deployed and is
instantiated when a Web container loads the component.
In summary, the tasks involved in using filters include
Programming the filter
Programming customized requests and responses
Specifying the filter chain for each Web resource