@Test public void testInputStream() throws IOException, ServletException { ServletInputStream mockStream = mock(ServletInputStream.class); when(mockReq.getInputStream()).thenReturn(mockStream); when(mockStream.read()).thenReturn(1); FilterChain mockFilterChain = new FilterChain() { @Override public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException { request.getInputStream().read(); } }; new RequestLoggingFilter().doFilter(mockReq, mockResp, mockFilterChain); assertThat(getField(Fields.REQUEST), is(Defaults.UNKNOWN)); assertThat(getField(Fields.CORRELATION_ID), not(isEmptyOrNullString())); assertThat(getField(Fields.REQUEST_ID), is(Defaults.UNKNOWN)); assertThat(getField(Fields.REMOTE_HOST), is(Defaults.UNKNOWN)); assertThat(getField(Fields.COMPONENT_ID), is(Defaults.UNKNOWN)); assertThat(getField(Fields.CONTAINER_ID), is(Defaults.UNKNOWN)); assertThat(getField(Fields.REQUEST_SIZE_B), is("1")); }
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (HttpServletRequest.class.isAssignableFrom(request.getClass()) && HttpServletResponse.class.isAssignableFrom(response.getClass())) { doFilterRequest((HttpServletRequest) request, (HttpServletResponse) response, chain); } else { chain.doFilter(request, response); } }
RequestLoggingFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (HttpServletRequest.class.isAssignableFrom(request.getClass()) && HttpServletResponse.class.isAssignableFrom(response.getClass())) { doFilterRequest((HttpServletRequest) request, (HttpServletResponse) response, chain); } else { chain.doFilter(request, response); } } }
RequestLoggingFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (HttpServletRequest.class.isAssignableFrom(request.getClass()) && HttpServletResponse.class.isAssignableFrom(response.getClass())) { doFilterRequest((HttpServletRequest) request, (HttpServletResponse) response, chain); } else { chain.doFilter(request, response); } } RequestLoggingFilter();   RequestLoggingFilter(RequestRecordFactory requestRecordFactory); }
RequestLoggingFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (HttpServletRequest.class.isAssignableFrom(request.getClass()) && HttpServletResponse.class.isAssignableFrom(response.getClass())) { doFilterRequest((HttpServletRequest) request, (HttpServletResponse) response, chain); } else { chain.doFilter(request, response); } } RequestLoggingFilter();   RequestLoggingFilter(RequestRecordFactory requestRecordFactory); @Override void init(FilterConfig filterConfig); @Override void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); @Override void destroy(); }
RequestLoggingFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (HttpServletRequest.class.isAssignableFrom(request.getClass()) && HttpServletResponse.class.isAssignableFrom(response.getClass())) { doFilterRequest((HttpServletRequest) request, (HttpServletResponse) response, chain); } else { chain.doFilter(request, response); } } RequestLoggingFilter();   RequestLoggingFilter(RequestRecordFactory requestRecordFactory); @Override void init(FilterConfig filterConfig); @Override void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); @Override void destroy(); static final String LOG_PROVIDER; static final String WRAP_RESPONSE_INIT_PARAM; static final String WRAP_REQUEST_INIT_PARAM; }