Class RestapidocsIndexRewriteFilter

java.lang.Object
org.springframework.web.filter.GenericFilterBean
org.springframework.web.filter.OncePerRequestFilter
ubic.gemma.rest.servlet.RestapidocsIndexRewriteFilter
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 RestapidocsIndexRewriteFilter extends org.springframework.web.filter.OncePerRequestFilter
Rewrites the path to the index file.

The filter sets Content-Type itself, because the forward loses it. Tomcat's DefaultServlet emits the file with no Content-Type header at all when it is reached through a FORWARD dispatch: the direct URL /resources/restapidocs/index.html comes back as text/html; charset=UTF-8, while the forwarded directory URL comes back with byte-identical content and no such header. The deployment sends X-Content-Type-Options: nosniff, so a typeless response may not be sniffed and the browser renders the Swagger UI page as plain text. Setting the type here also survives the forward, since DefaultServlet skips its own setContentType when one is already set.

Author:
poirigui
  • 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
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    doFilterInternal(jakarta.servlet.http.HttpServletRequest servletRequest, jakarta.servlet.http.HttpServletResponse servletResponse, 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
  • Constructor Details

    • RestapidocsIndexRewriteFilter

      public RestapidocsIndexRewriteFilter()
  • Method Details

    • doFilterInternal

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