next up previous contents
Next: Using Filters Up: Filter API Previous: Filter Factory   Contents

Example

This section provides a complete example of a filter based on the Filter API covered in the previous sections. This filter is called CookieMonster and it consists of two parts: the filter factory named CookieMonster and the filter named CookieMonsterFilter. Figures 4.12 and 4.13 show the Java code used to implement the factory and the filter, respectively. The createFilter() method in the CookieMonster factory class is called by the filtering system when a new filter is needed to process a Request and Reply. In this example the factory creates a CookieMonsterFilter object which is both a RequestFilter and ReplyFilter. When given a Request, the CookieMonsterFilter will look for a HTTP Cookie header and remove it if found. Similarly, the HTTP Set-Cookie header is removed from a Reply.

Figure 4.12: CookieMonster Factory
\begin{figure}
\begin{center}
\ssp
\begin{verbatim}public class CookieMonster ...
...;
}public void shutdown() {}
}\end{verbatim}\dsp
\end{center}\end{figure}

Figure 4.13: CookieMonster Filter
\begin{figure}
\begin{center}
\ssp
\begin{verbatim}public class CookieMonsterF...
...eHeaderField(''Set-Cookie'');
}
}\end{verbatim}\dsp
\end{center}\end{figure}



Mark R. Boyns
1999-01-12