@Test public void testWithSuppressedOptionalFields() throws IOException, ServletException { when(mockReq.getRequestURI()).thenReturn(REQUEST); when(mockReq.getQueryString()).thenReturn(QUERY_STRING); when(mockReq.getRemoteHost()).thenReturn(REMOTE_HOST); mockGetHeader(HttpHeaders.X_VCAP_REQUEST_ID, REQUEST_ID); mockGetHeader(HttpHeaders.REFERER, REFERER); FilterChain mockFilterChain = mock(FilterChain.class); LogOptionalFieldsSettings mockLogOptionalFieldsSettings = mock(LogOptionalFieldsSettings.class); when(mockLogOptionalFieldsSettings.isLogSensitiveConnectionData()).thenReturn(false); when(mockLogOptionalFieldsSettings.isLogRemoteUserField()).thenReturn(false); when(mockLogOptionalFieldsSettings.isLogRefererField()).thenReturn(false); RequestRecordFactory requestRecordFactory = new RequestRecordFactory(mockLogOptionalFieldsSettings); RequestLoggingFilter requestLoggingFilter = new RequestLoggingFilter(requestRecordFactory); requestLoggingFilter.doFilter(mockReq, mockResp, mockFilterChain); assertThat(getField(Fields.REQUEST), is(FULL_REQUEST)); assertThat(getField(Fields.CORRELATION_ID), is(REQUEST_ID)); assertThat(getField(Fields.REQUEST_ID), is(REQUEST_ID)); assertThat(getField(Fields.REMOTE_IP), is(Defaults.UNKNOWN)); assertThat(getField(Fields.REMOTE_HOST), is(Defaults.REDACTED)); assertThat(getField(Fields.COMPONENT_ID), is(Defaults.UNKNOWN)); assertThat(getField(Fields.CONTAINER_ID), is(Defaults.UNKNOWN)); assertThat(getField(Fields.TENANT_ID), is(Defaults.UNKNOWN)); }
@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; }