Filtering

Filters are Java components that allow on the fly transformations of payload and header information in both the request into a resource and the response from a resource.A filter is a reusable piece of code that can transform the content of HTTP requests, responses, and header information. Filters do not generally create a response or respond to a request as servlets do, rather they modify or adapt the requests for a resource, and modify or adapt responses from a resource. Filters can act on dynamic or static content. For the purposes of this chapter, dynamic and static content are referred to as Web resources. Among the types of functionality available to the developer needing to use
filters are the following:

  • The accessing of a resource before a request to it is invoked.
  • The processing of the request for a resource before it is invoked.
  • The modification of request headers and data by wrapping the request in customized versions of the request object.
  • The modification of response headers and response data by providing customized versions of the response object.
  • The interception of an invocation of a resource after its call.Actions on a servlet, on groups of servlets, or static content by zero, one, or more filters in a specifiable order.