Class ServerCachingFilter

java.lang.Object
de.businesscode.bcdui.web.cacheControl.AbstractCacheFilter
de.businesscode.bcdui.web.cacheControl.ServerCachingFilter
All Implemented Interfaces:
jakarta.servlet.Filter

public class ServerCachingFilter extends AbstractCacheFilter
Implements server side caching. This Filter caches the server response to the given store.
Only the url's from the init-param will be cached.
The store will be get from the JNDI and must be declare by user.
The name of the expected store object is BCD-UI/ServerCacheControl
This filter support all expires from ClientCachingFilter excepts CacheRequestDirective.
For further information please consult your BCD-UI documentation
  • Field Details

    • log

      protected org.apache.logging.log4j.Logger log
  • Constructor Details

    • ServerCachingFilter

      public ServerCachingFilter()
  • Method Details

    • getInstance

      public static ServerCachingFilter getInstance(jakarta.servlet.ServletRequest request)
      Returns an instance bound to given request. May return null if request is not cached. To enable caching for request - please set up such rule in your web descriptor.
      Parameters:
      request -
      Returns:
      NULL or the instance for given request
    • destroy

      public void destroy()
      See Also:
      • Filter.destroy()
    • doFilter

      public void doFilter(jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response, jakarta.servlet.FilterChain chain) throws IOException, jakarta.servlet.ServletException
      Throws:
      IOException
      jakarta.servlet.ServletException
      See Also:
      • Filter.doFilter(jakarta.servlet.ServletRequest, jakarta.servlet.ServletResponse, jakarta.servlet.FilterChain)
    • generateRequestKey

      protected String generateRequestKey(jakarta.servlet.http.HttpServletRequest httpRequest) throws MalformedURLException
      generates request URL which will be used to map request to cache, implementation can decide whether only the url part or parameters forms the key
      Parameters:
      httpRequest -
      Returns:
      URL describing current request
      Throws:
      MalformedURLException
    • doResponseFromCache

      protected boolean doResponseFromCache(String requestUrl)
      default return value is TRUE, hence caching responses
      Parameters:
      requestUrl -
      Returns:
      TRUE if caching facility should be bypassed, the response is not cached
    • getUrls

      public Set<String> getUrls()
      Returns:
      the urls
    • init

      public void init(jakarta.servlet.FilterConfig fc) throws jakarta.servlet.ServletException
      Specified by:
      init in interface jakarta.servlet.Filter
      Overrides:
      init in class AbstractCacheFilter
      Throws:
      jakarta.servlet.ServletException
      See Also:
      • Filter.init(jakarta.servlet.FilterConfig)
    • wrap

      protected org.apache.commons.io.output.TeeOutputStream wrap(String key, jakarta.servlet.ServletOutputStream outputStream) throws Exception
      Parameters:
      key -
      outputStream -
      Returns:
      ServletOutputStream which supports teeing to another stream
      Throws:
      IOException
      Exception
    • getServerCacheControl

      protected IServerCachePersist getServerCacheControl()
      Returns:
      the serverCacheControl
    • wrap

      protected PrintWriter wrap(String key, PrintWriter writer) throws Exception
      Parameters:
      key -
      writer -
      Returns:
      Throws:
      IOException
      Exception
    • flushCachedResponse

      public void flushCachedResponse(String key, OutputStream os) throws Exception
      flushes previously saved response to the stream
      Parameters:
      key -
      os -
      Throws:
      IOException
      Exception
    • getFilterName

      protected String getFilterName()
      Returns:
      the filterName
    • setFilterName

      protected void setFilterName(String filterName)
      Parameters:
      filterName - the filterName to set
    • deployCachingResponse

      protected jakarta.servlet.http.HttpServletResponse deployCachingResponse(jakarta.servlet.http.HttpServletResponse response, String key)
      Parameters:
      response -
      key -
      Returns: