Class ServerCachingFilter
- java.lang.Object
-
- de.businesscode.bcdui.web.cacheControl.AbstractCacheFilter
-
- de.businesscode.bcdui.web.cacheControl.ServerCachingFilter
-
- All Implemented Interfaces:
javax.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 Summary
Fields Modifier and Type Field Description protected org.apache.logging.log4j.Logger
log
-
Constructor Summary
Constructors Constructor Description ServerCachingFilter()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected javax.servlet.http.HttpServletResponse
deployCachingResponse(javax.servlet.http.HttpServletResponse response, java.lang.String key)
void
destroy()
void
doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)
protected boolean
doResponseFromCache(java.lang.String requestUrl)
default return value is TRUE, hence caching responsesvoid
flushCachedResponse(java.lang.String key, java.io.OutputStream os)
flushes previously saved response to the streamprotected java.lang.String
generateRequestKey(javax.servlet.http.HttpServletRequest httpRequest)
generates request URL which will be used to map request to cache, implementation can decide whether only the url part or parameters forms the keyprotected java.lang.String
getFilterName()
static ServerCachingFilter
getInstance(javax.servlet.ServletRequest request)
Returns an instance bound to given request.protected IServerCachePersist
getServerCacheControl()
java.util.Set<java.lang.String>
getUrls()
void
init(javax.servlet.FilterConfig fc)
protected void
setFilterName(java.lang.String filterName)
protected java.io.PrintWriter
wrap(java.lang.String key, java.io.PrintWriter writer)
protected org.apache.commons.io.output.TeeOutputStream
wrap(java.lang.String key, javax.servlet.ServletOutputStream outputStream)
-
Methods inherited from class de.businesscode.bcdui.web.cacheControl.AbstractCacheFilter
getDefinedExpires, getExpiresValue
-
-
-
-
Method Detail
-
getInstance
public static ServerCachingFilter getInstance(javax.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(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain) throws java.io.IOException, javax.servlet.ServletException
- Throws:
java.io.IOException
javax.servlet.ServletException
- See Also:
Filter.doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
-
generateRequestKey
protected java.lang.String generateRequestKey(javax.servlet.http.HttpServletRequest httpRequest) throws java.net.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:
java.net.MalformedURLException
-
doResponseFromCache
protected boolean doResponseFromCache(java.lang.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 java.util.Set<java.lang.String> getUrls()
- Returns:
- the urls
-
init
public void init(javax.servlet.FilterConfig fc) throws javax.servlet.ServletException
- Specified by:
init
in interfacejavax.servlet.Filter
- Overrides:
init
in classAbstractCacheFilter
- Throws:
javax.servlet.ServletException
- See Also:
Filter.init(javax.servlet.FilterConfig)
-
wrap
protected org.apache.commons.io.output.TeeOutputStream wrap(java.lang.String key, javax.servlet.ServletOutputStream outputStream) throws java.lang.Exception
- Parameters:
key
-outputStream
-- Returns:
- ServletOutputStream which supports teeing to another stream
- Throws:
java.io.IOException
java.lang.Exception
-
getServerCacheControl
protected IServerCachePersist getServerCacheControl()
- Returns:
- the serverCacheControl
-
wrap
protected java.io.PrintWriter wrap(java.lang.String key, java.io.PrintWriter writer) throws java.lang.Exception
- Parameters:
key
-writer
-- Returns:
- Throws:
java.io.IOException
java.lang.Exception
-
flushCachedResponse
public void flushCachedResponse(java.lang.String key, java.io.OutputStream os) throws java.lang.Exception
flushes previously saved response to the stream- Parameters:
key
-os
-- Throws:
java.io.IOException
java.lang.Exception
-
getFilterName
protected java.lang.String getFilterName()
- Returns:
- the filterName
-
setFilterName
protected void setFilterName(java.lang.String filterName)
- Parameters:
filterName
- the filterName to set
-
deployCachingResponse
protected javax.servlet.http.HttpServletResponse deployCachingResponse(javax.servlet.http.HttpServletResponse response, java.lang.String key)
- Parameters:
response
-key
-- Returns:
-
-