Servlet Filters

Servlet filters are Java programs that can be wrapped around a J2EE servlet in order to modify:

  • Inbound requests

  • Outbound responses

Servlet filters are easy to write and provide a simple mechanism by which common functionality can be encapsulated for re-use in different contexts. They have standardized input/output interfaces which allows them to be assembled into chains. An inbound request can be passed through a chain of filters to prepare it for processing by a servlet. The response generated by the servlet is then passed back as a return value through the same filter chain. This means that each filter in the chain can be used to modify the inbound request or the outbound response or both.

The servlet filters used by a particular web application and the order in which they are called is defined in the application's WEB.XML.

Servlet filters play an important role in Escenic applications. Most importantly, servlet filters are used to:

  • Parse incoming request URLs

  • Create the section and article beans needed to generate appropriate responses

  • Add the created beans to the request as request scope attributes

A standard set of filters is supplied with the Content Engine, along with a default WEB.XML file that specifies:

  • The filters to be used

  • The parameters required by the filters

  • The order in which the filters are to be called

You can modify the default filter chain by inserting filters of your own, either in addition to the standard filters or as replacements for them. Some possible reasons for modifying the filter chain might be:

  • You want to use a custom algorithm to derive the publication name from the content of the request URI

  • You want to transform responses returned to certain types of devices (reformat them for small screens, for example)

  • You want to carry out cache filtering

In order to be able to do this successfully, you need to know what the standard filters delivered with the Content Engine do, and how they are organized.

If you look in the default WEB.XML supplied with the Content Engine, you will see that the Escenic filter chain contains the following filters:

  • ECEProfileFilter

  • BootstrapFilter

  • TimerFilter

  • EscenicStandardFilterChain

  • CacheFilter

They are described in the following sections.