Class SpaRoutingFilter

  • All Implemented Interfaces:
    jakarta.servlet.Filter

    public class SpaRoutingFilter
    extends java.lang.Object
    implements jakarta.servlet.Filter
    Filter must be mapped to assets servlet, serving spa application. Bypass all calls to servlet, but if servlet returns 404, tries to redirect to application main page.

    This is important to properly handle html5 client routing (without hashbang).

    In order to route, filter checks request accept header: if it's compatible with "text/html" - routing is performed. If not, 404 error sent. Also, regex pattern is used to prevent routing (for example, for html templates). This is important for all other assets, which absence must be indicated.

    Since:
    02.04.2017
    • Constructor Summary

      Constructors 
      Constructor Description
      SpaRoutingFilter​(java.lang.String target, java.lang.String noRedirectRegex)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void destroy()  
      void doFilter​(jakarta.servlet.ServletRequest servletRequest, jakarta.servlet.ServletResponse servletResponse, jakarta.servlet.FilterChain chain)  
      void init​(jakarta.servlet.FilterConfig filterConfig)  
      • Methods inherited from class java.lang.Object

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

      • SpaRoutingFilter

        public SpaRoutingFilter​(java.lang.String target,
                                java.lang.String noRedirectRegex)
    • Method Detail

      • init

        public void init​(jakarta.servlet.FilterConfig filterConfig)
                  throws jakarta.servlet.ServletException
        Specified by:
        init in interface jakarta.servlet.Filter
        Throws:
        jakarta.servlet.ServletException
      • doFilter

        public void doFilter​(jakarta.servlet.ServletRequest servletRequest,
                             jakarta.servlet.ServletResponse servletResponse,
                             jakarta.servlet.FilterChain chain)
                      throws java.io.IOException,
                             jakarta.servlet.ServletException
        Specified by:
        doFilter in interface jakarta.servlet.Filter
        Throws:
        java.io.IOException
        jakarta.servlet.ServletException
      • destroy

        public void destroy()
        Specified by:
        destroy in interface jakarta.servlet.Filter