title: How to set implementation of OncePerRequestFilter to filter only one endpoint
body: <p>Im using this Filter to log my requests and responses, it works very well, but I noticed that I didnt need actualy this filter for all my endpoints - it will be more efficient and enough to filtering and logging requests from only one endpoint.
  Is it possible without making if statement in <code>afterRequest</code> method? 
  Im searching this a lot, but almost every example is with spring security :(</p>
  
  <pre><code>@Slf4j
  @Component
  public class RequestAndResponseLoggingFilter extends OncePerRequestFilter {
      @Override
      protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
          if (isAsyncDispatch(request)) {
              filterChain.doFilter(request, response);
          } else {
              doFilterWrapped(wrapRequest(request), wrapResponse(response), filterChain);
          }
      }
  
      protected void doFilterWrapped(ContentCachingRequestWrapper request, ContentCachingResponseWrapper response, FilterChain filterChain) throws ServletException, IOException {
          beforeRequest(request, response);
          try {
              filterChain.doFilter(request, response);
          }
          finally {
              afterRequest(request, response);
              response.copyBodyToResponse();
          }
      }
  
      protected void beforeRequest(ContentCachingRequestWrapper request, ContentCachingResponseWrapper response) {
          if (log.isInfoEnabled()) {
              val address = request.getRemoteAddr();
              val queryString = request.getQueryString();
              if (queryString == null) {
                  log.info("{}&gt; {} {}", address, request.getMethod(), request.getRequestURI());
              } else {
                  log.info("{}&gt; {} {}?{}", address, request.getMethod(), request.getRequestURI(), queryString);
              }
              Collections.list(request.getHeaderNames()).forEach(headerName -&gt;
                  Collections.list(request.getHeaders(headerName)).forEach(headerValue -&gt;
                      log.info("{}&gt; {}: {}", address, headerName, headerValue)));
              val content = request.getContentAsByteArray();
              if (content.length &gt; 0) {
                  log.info("{}&gt;", address);
                  try {
                      val contentString = new String(content, request.getCharacterEncoding());
                      Stream.of(contentString.split("\r\n|\r|\n")).forEach(line -&gt; log.info("{}&gt; {}", address, line));
                  } catch (UnsupportedEncodingException e) {
                      log.info("{}&gt; [{} bytes body]", address, content.length);
                  }
              }
              log.info("{}&gt;", address);
          }
      }
  
      protected void afterRequest(ContentCachingRequestWrapper request, ContentCachingResponseWrapper response) {
          if (log.isInfoEnabled()) {
              val address = request.getRemoteAddr();
              val status = response.getStatus();
              log.info("{}&lt; {} {}", address, status, HttpStatus.valueOf(status).getReasonPhrase());
              response.getHeaderNames().forEach(headerName -&gt;
                  response.getHeaders(headerName).forEach(headerValue -&gt;
                      log.info("{}&lt; {}: {}", address, headerName, headerValue)));
              val content = response.getContentAsByteArray();
              if (content.length &gt; 0) {
                  log.info("{}&lt;", address);
                  try {
                      val contentString = new String(content, request.getCharacterEncoding());
                      Stream.of(contentString.split("\r\n|\r|\n")).forEach(line -&gt; log.info("{}&lt; {}", address, line));
                  } catch (UnsupportedEncodingException e) {
                      log.info("{}&lt; [{} bytes body]", address, content.length);
                  }
              }
          }
      }
  
      private static ContentCachingRequestWrapper wrapRequest(HttpServletRequest request) {
          if (request instanceof ContentCachingRequestWrapper) {
              return (ContentCachingRequestWrapper) request;
          } else {
              return new ContentCachingRequestWrapper(request);
          }
      }
  
      private static ContentCachingResponseWrapper wrapResponse(HttpServletResponse response) {
          if (response instanceof ContentCachingResponseWrapper) {
              return (ContentCachingResponseWrapper) response;
          } else {
              return new ContentCachingResponseWrapper(response);
          }
      }
  }
  </code></pre>