Class SpaSupport

java.lang.Object
ru.vyarus.guicey.gsp.app.filter.redirect.SpaSupport

public class SpaSupport extends 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, String rootMapping, String target, String noRedirectRegex)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    markPossibleSpaRoute(jakarta.servlet.http.HttpServletRequest req, jakarta.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(jakarta.servlet.http.HttpServletRequest req, jakarta.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 Details

    • SpaSupport

      public SpaSupport(boolean enabled, String rootMapping, String target, String noRedirectRegex)
  • Method Details

    • markPossibleSpaRoute

      public void markPossibleSpaRoute(jakarta.servlet.http.HttpServletRequest req, jakarta.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(jakarta.servlet.http.HttpServletRequest req, jakarta.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)