Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package de.holisticon.util.tracee.servlet;
 
 
 import javax.servlet.*;
Servlet filter to detect uncaught exceptions and to provide some contextual error logs. Created by Tobias Gindler, holisticon AG on 11.12.13.
public class TraceeErrorLoggingFilter implements Filter {
    private TraceeBackend traceeBackend = null;
    @Override
    public final void init(FilterConfig filterConfigthrows ServletException {
         = Tracee.getBackend();
    }
    @Override
    public final void doFilter(ServletRequest servletRequestServletResponse servletResponseFilterChain filterChainthrows IOExceptionServletException {
        try {
            filterChain.doFilter(servletRequestservletResponse);
        } catch (Exception e) {
			if (servletRequest instanceof HttpServletRequest) {
                handleHttpServletRequest((HttpServletRequestservletRequest, (HttpServletResponseservletResponsee);
            }
			if (e instanceof RuntimeException) {
				throw (RuntimeExceptione;
else if (e instanceof ServletException) {
				throw (ServletException)e;
else if (e instanceof IOException) {
				throw (IOException)e;
			}
        }
    }
    private void handleHttpServletRequest(
            HttpServletRequest servletRequest,
            HttpServletResponse servletResponse,
            Exception e) {
        TraceeContextLoggerJsonBuilder errorJsonCreator = TraceeContextLoggerJsonBuilder.createJsonCreator()
                .addServletCategory(ServletDataWrapper.wrap(servletRequestservletResponse))
                .addPrefixedMessage("TraceeErrorLoggingFilter - FAULT :")
                .addCommonCategory()
                .addExceptionCategory(e)
                .addTraceeCategory();
        // write message to connectors
        ConnectorFactory.sendErrorReportToConnectors(errorJsonCreator);
    }
    @Override
    public final void destroy() {
    }
New to GrepCode? Check out our FAQ X