Package kieker.monitoring.probe.servlet
Class SessionAndTraceRegistrationFilter
java.lang.Object
kieker.monitoring.probe.servlet.SessionAndTraceRegistrationFilter
- All Implemented Interfaces:
javax.servlet.Filter,IMonitoringProbe
public class SessionAndTraceRegistrationFilter
extends Object
implements javax.servlet.Filter, IMonitoringProbe
For each incoming request via
doFilter(ServletRequest, ServletResponse, FilterChain), this class
(i) registers session and trace information into the thread-local data structures SessionRegistry and
TraceRegistry accessible to other probes in
the control-flow of this request, (ii) executes the given FilterChain and subsequently (iii) unregisters the thread-local
data. If configured in the FilterConfig (see below), the execution of the doFilter(ServletRequest, ServletResponse, FilterChain) method
is also part of the trace and logged to the IMonitoringController (note that this is the default behavior when no property is found).
The filter can be integrated into the web.xml as follows:
<filter>
<filter-name>sessionAndTraceRegistrationFilter</filter-name>
<filter-class>kieker.monitoring.probe.servlet.SessionAndTraceRegistrationFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>sessionAndTraceRegistrationFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
- Since:
- 1.5
- Author:
- Andre van Hoorn, Marco Luebcke, Jan Waller
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final ControlFlowRegistrystatic final Stringprotected static final IMonitoringControllerprotected static final SessionRegistryprotected static final ITimeSourceprotected static final String -
Constructor Summary
ConstructorsConstructorDescriptionCreate an SessionAndTraceRegistrationFilter and initialize the filter operation signature.SessionAndTraceRegistrationFilter(boolean logFilterExecution) Create an SessionAndTraceRegistrationFilter and initialize the filter operation signature. -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()voiddoFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain) Register thread-local session and trace information, executes the givenFilterChainand unregisters the session/trace information.protected StringReturns the operation signature of this filter'sdoFilter(ServletRequest, ServletResponse, FilterChain)operation to be used when logging executions of this operation.voidinit(javax.servlet.FilterConfig config) protected StringregisterSessionInformation(javax.servlet.ServletRequest request) If the givenServletRequestis an instance ofHttpServletRequest, this methods extracts the session ID and registers it in theSESSION_REGISTRYin order to be accessible for other probes in this thread.
-
Field Details
-
CONFIG_PROPERTY_NAME_LOG_FILTER_EXECUTION
- See Also:
-
MONITORING_CTRL
-
SESSION_REGISTRY
-
CF_REGISTRY
-
TIMESOURCE
-
VM_NAME
-
-
Constructor Details
-
SessionAndTraceRegistrationFilter
public SessionAndTraceRegistrationFilter()Create an SessionAndTraceRegistrationFilter and initialize the filter operation signature. -
SessionAndTraceRegistrationFilter
public SessionAndTraceRegistrationFilter(boolean logFilterExecution) Create an SessionAndTraceRegistrationFilter and initialize the filter operation signature.- Parameters:
logFilterExecution- true enables logging of the filter execution
-
-
Method Details
-
getFilterOperationSignatureString
Returns the operation signature of this filter'sdoFilter(ServletRequest, ServletResponse, FilterChain)operation to be used when logging executions of this operation. Extending classes may override this method in order to provide an alternative signature. However, note that this method is executed on each filter execution. Hence, you should return a final value here instead of executing expensive String operations.- Returns:
- The operation signature as a string.
-
init
public void init(javax.servlet.FilterConfig config) throws javax.servlet.ServletException - Specified by:
initin interfacejavax.servlet.Filter- Throws:
javax.servlet.ServletException
-
doFilter
public void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain) throws IOException, javax.servlet.ServletException Register thread-local session and trace information, executes the givenFilterChainand unregisters the session/trace information. If configured, the execution of this filter is also logged to theIMonitoringController. This method returns immediately if monitoring is not enabled.- Specified by:
doFilterin interfacejavax.servlet.Filter- Parameters:
request- The request.response- The response.chain- The filter chain to be used.- Throws:
IOException- on io errorsjavax.servlet.ServletException- on servlet errors
-
destroy
public void destroy()- Specified by:
destroyin interfacejavax.servlet.Filter
-
registerSessionInformation
If the givenServletRequestis an instance ofHttpServletRequest, this methods extracts the session ID and registers it in theSESSION_REGISTRYin order to be accessible for other probes in this thread. In case no session is associated with this request (or if the request is not an instance ofHttpServletRequest), this method returns without any further actions and returnsOperationExecutionRecord.NO_SESSION_ID.- Parameters:
request- The request.- Returns:
- The session ID.
-