In an async scenario a filter may be invoked again in additional threads
as part of an ASYNC dispatch.
Sub-classes may decide whether to be invoked once per request or once per
request thread for as long as the same request is being processed.
See shouldFilterAsyncDispatches().

The getAlreadyFilteredAttributeName() method determines how
to identify that a request is already filtered. The default implementation
is based on the configured name of the concrete filter instance.

shouldNotFilter

Can be overridden in subclasses for custom filtering control,
returning true to avoid filtering of the given request.

The default implementation always returns false.

Parameters:

request - current HTTP request

Returns:

whether the given request should not be filtered

Throws:

javax.servlet.ServletException - in case of errors

shouldFilterAsyncDispatches

protected boolean shouldFilterAsyncDispatches()

Whether to filter once per request or once per request thread. The dispatcher
type javax.servlet.DispatcherType.ASYNC introduced in Servlet 3.0
means a filter can be invoked in more than one thread (and exited) over the
course of a single request. Some filters only need to filter the initial
thread (e.g. request wrapping) while others may need to be invoked at least
once in each additional thread for example for setting up thread locals or
to perform final processing at the very end.

Note that although a filter can be mapped to handle specific dispatcher
types via web.xml or in Java through the ServletContext,
servlet containers may enforce different defaults with regards to dispatcher
types. This flag enforces the design intent of the filter.

The default setting is "false", which means the filter will be invoked
once only per request and only on the initial request thread. If "true", the
filter will also be invoked once only on each additional thread.

isAsyncDispatch

Whether the request was dispatched to complete processing of results produced
in another thread. This aligns with the Servlet 3.0 dispatcher type
javax.servlet.DispatcherType.ASYNC and can be used by filters that
return "true" from shouldFilterAsyncDispatches() to detect when
the filter is being invoked subsequently in additional thread(s).

isLastRequestThread

Whether this is the last thread processing the request. Note the returned
value may change from true to false if the method is
invoked before and after delegating to the next filter, since the next filter
or servlet may begin concurrent processing. Therefore this method is most
useful after delegation for final, end-of-request type processing.

Parameters:

request - the current request

Returns:

true if the response will be committed when the current
thread exits; false if the response will remain open.