Class SpringResyncDetectionFilter

java.lang.Object
org.springframework.web.filter.GenericFilterBean
org.springframework.web.filter.OncePerRequestFilter
com.vaadin.observability.spring.SpringResyncDetectionFilter
All Implemented Interfaces:
jakarta.servlet.Filter, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.context.EnvironmentAware, org.springframework.core.env.EnvironmentCapable, org.springframework.web.context.ServletContextAware

public final class SpringResyncDetectionFilter extends org.springframework.web.filter.OncePerRequestFilter
Spring-optimized servlet filter that observes UIDL message resends and resynchronization requests (prototype, kit-only, no Flow changes). Shares its detection logic with the portable ResyncDetectionFilter via ResyncInspector, but is preferred wherever Spring is on the classpath.

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.

Rather than buffer the body eagerly, this filter wraps the request in a ContentCachingRequestWrapper and inspects after the chain has run: ordering is irrelevant for a counter, and this way we read exactly the bytes Flow read and only count requests Flow actually consumed. The per-UI read-modify-write is guarded by the session mutex. Instrumentation never fails the request: any error while inspecting is swallowed.

  • Field Summary

    Fields inherited from class org.springframework.web.filter.OncePerRequestFilter

    ALREADY_FILTERED_SUFFIX

    Fields inherited from class org.springframework.web.filter.GenericFilterBean

    logger
  • Constructor Summary

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

    Modifier and Type
    Method
    Description
    protected void
    doFilterInternal(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, jakarta.servlet.FilterChain chain)
     

    Methods inherited from class org.springframework.web.filter.OncePerRequestFilter

    doFilter, doFilterNestedErrorDispatch, getAlreadyFilteredAttributeName, isAsyncDispatch, isAsyncStarted, shouldNotFilter, shouldNotFilterAsyncDispatch, shouldNotFilterErrorDispatch

    Methods inherited from class org.springframework.web.filter.GenericFilterBean

    addRequiredProperty, afterPropertiesSet, createEnvironment, destroy, getEnvironment, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setEnvironment, setServletContext

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SpringResyncDetectionFilter

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

    • doFilterInternal

      protected void doFilterInternal(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, jakarta.servlet.FilterChain chain) throws jakarta.servlet.ServletException, IOException
      Specified by:
      doFilterInternal in class org.springframework.web.filter.OncePerRequestFilter
      Throws:
      jakarta.servlet.ServletException
      IOException