title: How to do post-matching filter in webflux?
body: <p>As we know, in jersey we have pre-matching filter and post-matching filter.</p>
  
  <p>I'm wondering how can I get similar behavior with WebFilter in webflux application.</p>
  
  <p>It seems the WebFilter is sort of like a pre-matching filter which will be executed for sure, no matter a resource in @RestController found or not.</p>
  
  <p>My filter like this (copied from metrics filter in spring actuator):</p>
  
  <pre><code>@Component
  @Order(100)
  public class AppFilter1 implements WebFilter {
  
  @Override
  public Mono&lt;Void&gt; filter(ServerWebExchange exchange, WebFilterChain chain) {
  
      return chain.filter(exchange).compose((call) -&gt; filter(exchange, call));
  }
  
  private Publisher&lt;Void&gt; filter(ServerWebExchange exchange, Mono&lt;Void&gt; call) {
  
      System.out.println("Start AppFilter1 in thread:" + Thread.currentThread().getId() + "..........");
      ServerHttpResponse response = exchange.getResponse();
      return call.doOnSuccess((done) -&gt; success(exchange)).doOnError((cause) -&gt; {
          if (response.isCommitted()) {
              error(exchange, cause);
          } else {
              response.beforeCommit(() -&gt; {
                  error(exchange, cause);
                  return Mono.empty();
              });
          }
      });
  }
  
  private void success(ServerWebExchange exchange) {
  
      System.out.println("End AppFilter1 in thread:" + Thread.currentThread().getId() + "..............");
  
  }
  
  private void error(ServerWebExchange exchange, Throwable cause) {
      System.out.println("End AppFilter1 with Error in thread:" + Thread.currentThread().getId() + "...............");
  }
  
  }
  </code></pre>
  
  <p>Add my controller is like:</p>
  
  <pre><code>@RestController
  public class ExampleController {
  
  @GetMapping("/example")
  public String example() {
      System.out.println("Example in thread:" + Thread.currentThread().getId());
      return "Example";
  }
  }
  </code></pre>
  
  <p>What I can see is the filter will be executed for sure no matter I access /example or /notexist</p>
  
  <p>Actually I'd like my filter to do post-matching, only executed for /example.</p>
  
  <p>To be more specific, I'd like to see console output for /example:</p>
  
  <pre><code>Start AppFilter1 in thread:....
  Example in thread:.....
  End AppFilter1 in thread:....
  </code></pre>
  
  <p>and for a not matched resource like /notexist, there's no console output at all. </p>
  
  <p>Thanks</p>
  
  <p>Leon</p>