@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { HttpServletRequest requestLocal = request; // Determine if this is the first request or not. We only want to wrap the request to log on the first request. boolean isFirstRequest = !isAsyncDispatch(requestLocal); if (isFirstRequest) { requestLocal = new RequestLoggingFilterWrapper(requestLocal); ((RequestLoggingFilterWrapper) requestLocal).logRequest(request); } // Move onto the next filter while wrapping the request with our own custom logging class. try { filterChain.doFilter(requestLocal, response); } finally { // Log the request after it is processed. We only log the first request. if (!isAsyncStarted(requestLocal) && requestLocal instanceof RequestLoggingFilterWrapper) { ((RequestLoggingFilterWrapper) requestLocal).logAfterRequest(request, response); } } }
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { HttpServletRequest requestLocal = request; // Determine if this is the first request or not. We only want to wrap the request to log on the first request. boolean isFirstRequest = !isAsyncDispatch(requestLocal); if (isFirstRequest) { requestLocal = new RequestLoggingFilterWrapper(requestLocal); ((RequestLoggingFilterWrapper) requestLocal).logRequest(request); } // Move onto the next filter while wrapping the request with our own custom logging class. try { filterChain.doFilter(requestLocal, response); } finally { // Log the request after it is processed. We only log the first request. if (!isAsyncStarted(requestLocal) && requestLocal instanceof RequestLoggingFilterWrapper) { ((RequestLoggingFilterWrapper) requestLocal).logAfterRequest(request, response); } } }
/** * Test to get the coverage for unused implemented methods of RequestLoggingFilterWrapper. */ @Test public void testRequestLoggingFilterWrapper() throws Exception { HttpServletRequest servletRequest = createServletRequest(); servletRequest.setCharacterEncoding(WebUtils.DEFAULT_CHARACTER_ENCODING); RequestLoggingFilter requestLoggingFilter = new RequestLoggingFilter(); RequestLoggingFilter.RequestLoggingFilterWrapper wrapper = requestLoggingFilter.new RequestLoggingFilterWrapper(servletRequest); wrapper.logRequest(servletRequest); wrapper.getContentLength(); wrapper.getCharacterEncoding(); wrapper.getReader(); wrapper.getReader(); }