Class ResyncDetectionFilter

java.lang.Object
com.vaadin.observability.micrometer.ResyncDetectionFilter
All Implemented Interfaces:
jakarta.servlet.Filter

public final class ResyncDetectionFilter extends Object implements jakarta.servlet.Filter
Portable, framework-agnostic servlet filter that observes UIDL message resends and resynchronization requests (prototype, kit-only, no Flow changes). It depends only on the servlet API and Micrometer, so it is meant for plain (non-Spring) deployments; a Spring application does not need this class and should use SpringResyncDetectionFilter instead.

Registering it in a plain servlet app. There is no auto-configuration outside Spring, so register the filter yourself against every request. It should run early (before anything else consumes the request body). For example, in a ServletContextListener or ServletContainerInitializer:


 FilterRegistration.Dynamic reg = servletContext.addFilter(
         "vaadinResyncDetection", new ResyncDetectionFilter(meterRegistry));
 // isMatchAfter=false so it precedes already-registered filters
 reg.addMappingForUrlPatterns(null, false, "/*");
 
or the equivalent <filter>/<filter-mapping> in web.xml. The MeterRegistry is whichever instance the application records into.

Flow recovers from lost responses entirely inside UidlRequestHandler by catching ClientResentPayloadException (replay the cached response) and ResynchronizationRequiredException (rebuild the UI state); neither surfaces to any Flow listener SPI the kit uses. This filter reconstructs the same signal by buffering the UIDL body (via CachedBodyHttpServletRequest so Flow can still read it) and handing it to a ResyncInspector.

Because it has no Spring APIs available it buffers the body eagerly; the Spring variant instead captures the bytes lazily as Flow reads them and only counts requests Flow actually consumed. Instrumentation never fails the request: any error while inspecting is swallowed.

  • Constructor Summary

    Constructors
    Constructor
    Description
    ResyncDetectionFilter(io.micrometer.core.instrument.MeterRegistry registry)
    Creates the filter recording into the given registry.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    doFilter(jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response, jakarta.servlet.FilterChain chain)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface jakarta.servlet.Filter

    destroy, init
  • Constructor Details

    • ResyncDetectionFilter

      public ResyncDetectionFilter(io.micrometer.core.instrument.MeterRegistry registry)
      Creates the filter recording into the given registry.
      Parameters:
      registry - the meter registry, not null
  • Method Details

    • doFilter

      public void doFilter(jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response, jakarta.servlet.FilterChain chain) throws IOException, jakarta.servlet.ServletException
      Specified by:
      doFilter in interface jakarta.servlet.Filter
      Throws:
      IOException
      jakarta.servlet.ServletException