Class RequestIdMdcFilter

java.lang.Object
org.springframework.web.filter.GenericFilterBean
org.springframework.web.filter.OncePerRequestFilter
ubic.gemma.rest.servlet.RequestIdMdcFilter
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 class RequestIdMdcFilter extends org.springframework.web.filter.OncePerRequestFilter
Per-request filter that populates two MDC keys for the duration of a REST request:
  • requestId — the inbound X-Request-Id header if present, otherwise a freshly generated UUID. Echoed back on the response.
  • userId — the authenticated principal name from SecurityContextHolder, or "anonymous" when no authentication is in scope.

This is the gemma-rest module's counterpart to ubic.gemma.web.logging.RequestIdMdcFilter (gemma-web). The two classes are deliberately separate because gemma-rest does not depend on gemma-web. When running inside gemma-web's WAR, the gemma-web copy is registered in gemma-web/WEB-INF/web.xml and is the one that fires for Jersey requests (Jersey is mounted under the same web.xml). When gemma-rest is built as a standalone WAR (the gemma-rest-war profile of GEMMA_REST_STANDALONE_ROADMAP.md), this copy is the one registered in gemma-rest/WEB-INF/web.xml.

See LOGGING_MODERNIZATION_RECCE.md §3 Phase 2 for context. ThreadContext propagation across async executors is already handled by the DelegatingThreadContext* layer in ubic.gemma.core.logging.log4j.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
    static final String
     
    static final String
     
    static final String
     

    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
     
  • Method Summary

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

    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 Object

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

  • Constructor Details

    • RequestIdMdcFilter

      public RequestIdMdcFilter()
  • Method Details

    • doFilterInternal

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