mod_servlet
C++Servlets
|
A filter is an object that performs filtering tasks on either the request to a resource (a servlet or static content), or on the response from a resource, or both. More...
#include <filter.h>
Public Member Functions | |
virtual void | init () |
A convenience method which can be overridden so that there's no need to call init(filter_config) . More... | |
virtual void | init (filter_config &cfg) |
Called by the web container to indicate to a filter that it is being placed into service. More... | |
virtual void | do_filter (http_request &request, http_response &response, filter_chain &chain)=0 |
The do_filter method of the http_filter is called by the container each time a request/response pair is passed through the chain due to a client request for a resource at the end of the chain. More... | |
const filter_config & | get_filter_config () const |
Returns a filter_config object, which contains initialization and startup parameters for this filter. More... | |
const std::string & | get_filter_name () const |
Returns the name of this filter instance. More... | |
const std::map< std::string, std::string, std::less<> > & | get_init_parameters () const |
Returns the all of the filter's initialization parameters as an tree_map of std::string objects, or an empty tree_map if the servlet has no initialization parameters. More... | |
template<typename KeyType > | |
optional_ref< const std::string > | get_init_parameter (const KeyType &name) const |
Returns an optional std::string containing the value of the named initialization parameter, or null if the parameter does not exist. More... | |
A filter is an object that performs filtering tasks on either the request to a resource (a servlet or static content), or on the response from a resource, or both.
Filters perform filtering in the doFilter
method. Every Filter has access to a FilterConfig object from which it can obtain its initialization parameters, a reference to the ServletContext which it can use, for example, to load resources needed for filtering tasks.
Filters are configured in the deployment descriptor of a web application
Examples that have been identified for this design are
1) Authentication Filters
2) Logging and Auditing Filters
3) Image conversion Filters
4) Data compression Filters
5) Encryption Filters
6) Tokenizing Filters
7) Filters that trigger resource access events
8) XSL/T filters
9) Mime-type chain Filter
In order to make the filter available to mod_servlet
a factory method should be provided and exported. The easiest way to do this is to use FILTER_EXPORT
like this:
If the filter cannot be trivially created or requires special preparation before it is available to mod_servlet
container than factory method should be coded manually:
|
pure virtual |
The do_filter
method of the http_filter is called by the container each time a request/response pair is passed through the chain due to a client request for a resource at the end of the chain.
The filter_chain passed in to this method allows the Filter to pass on the request and response to the next entity in the chain.
A typical implementation of this method would follow the following pattern:-
chain.do_filter()
), request | The request to process |
response | The response associated with the request |
chain | Provides access to the next filter in the chain for this filter to pass the request and response to for further processing |
|
inline |
Returns a filter_config
object, which contains initialization and startup parameters for this filter.
The filter_config
object returned is the one passed to the init
method.
Method init
is responsible for storing the filter_config
object so that this method can return it.
filter_config
object that initializes this filter
|
inline |
Returns the name of this filter instance.
The name may be provided via server administration, assigned in the web application deployment descriptor, or for an unregistered (and thus unnamed) filter instance it will be the filter's class name.
|
inline |
Returns an optional std::string
containing the value of the named initialization parameter, or null
if the parameter does not exist.
This method is supplied for convenience. It gets the value of the named parameter from the servlet's filter_config
object.
name | a string specifying the name of the initialization parameter |
std::string
containing the value of the initialization parameter
|
inline |
Returns the all of the filter's initialization parameters as an tree_map
of std::string
objects, or an empty tree_map
if the servlet has no initialization parameters.
See filter_config::get_init_parameters.
This method is supplied for convenience. It gets the parameter names from the servlet's filter_config
object.
std::string
objects containing all of the filter's initialization parameters
|
inlinevirtual |
A convenience method which can be overridden so that there's no need to call init(filter_config)
.
Instead of overriding init(filter_config&), simply override this method and it will be called by init(filter_config config)
. The filter_config
object can still be retrieved via get_filter_config.
|
virtual |
Called by the web container to indicate to a filter that it is being placed into service.
The servlet container calls the init method exactly once after instantiating the filter. The init method must complete successfully before the filter is asked to do any filtering work.
The web container cannot place the filter into service if the init method either:
cfg | The configuration information associated with the filter instance being initialised |