Class SpaSupport


  • public class SpaSupport
    extends java.lang.Object
    SPA routes support (HTML5 client routing). Support rely on errors handling: when 404 error appear (no matter in assets or views), spa support is checked (if enabled) and spa redirection performed instead of error handling.

    Error based approach does not influence normal processing: all checks appear only after error appearance (so enabling SPA support will not influence application).

    Also, SPA support forcefully sets no cache header for index page (or any route, redirected to index page).

    Since:
    16.01.2019
    • Constructor Summary

      Constructors 
      Constructor Description
      SpaSupport​(boolean enabled, java.lang.String rootMapping, java.lang.String target, java.lang.String noRedirectRegex)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void markPossibleSpaRoute​(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
      Simple to check for root page: if current request is already root request then no SPA route could be performed.
      boolean redirect​(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, int code)
      Perform redirection of SPA into index page (so browser receive index html on spa routing url) if conditions match.
      • Methods inherited from class java.lang.Object

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

      • SpaSupport

        public SpaSupport​(boolean enabled,
                          java.lang.String rootMapping,
                          java.lang.String target,
                          java.lang.String noRedirectRegex)
    • Method Detail

      • markPossibleSpaRoute

        public void markPossibleSpaRoute​(javax.servlet.http.HttpServletRequest req,
                                         javax.servlet.http.HttpServletResponse res)
        Simple to check for root page: if current request is already root request then no SPA route could be performed. Also, applies no cache header for the root page.
        Parameters:
        req - request instance
        res - response instance
      • redirect

        public boolean redirect​(javax.servlet.http.HttpServletRequest req,
                                javax.servlet.http.HttpServletResponse res,
                                int code)
        Perform redirection of SPA into index page (so browser receive index html on spa routing url) if conditions match.
        Parameters:
        req - request instance
        res - response instance
        code - error code (http)
        Returns:
        true if redirection performed, false otherwise (SPA route not recognized)