org.ibisph.filter.artifact
Class Filter
java.lang.Object
org.ibisph.filter.AbstractPathPatternFilter
org.ibisph.filter.artifact.Filter
- All Implemented Interfaces:
- javax.servlet.Filter
public class Filter
- extends AbstractPathPatternFilter
Controls creation and distribution of requested pages which are artifacted/
cached to a disk files. If the request does not match a specified URI pattern
then normal downstream filter/servlet request/response processing is performed.
Else if the URI's path does match the path patterns then the artifact directory
is checked for the requested resource. If found it simply streams back the file
and short circuits the rest of the downstream filter/servlet request/response
processing. If it matches and the resource is not found then the current
response is replaced with a wrapped response and normal processing continues.
When the normal processing of the request/response has been completed, the wrapped
response's contents are then saved to the artifact directory and streamed back to
the user.
NOTE: Two path adjustments are needed for artifacting: 1) compressed content and
2) pages that contain SVG charts or maps. The prior is needed because a request
may or may not come from a browser that does not accept compressed (gzipped)
responses. The latter is similar as some users might not have the SVG plugin or
want their charts/maps delivered as a JPEG image. In either case these artifacts
need to be stored in different directories so that the correct content is returned.
The graphic type request parameter is used to control the way the SVG/JPEG pages
are generated. This value is specified in two ways: 1) as a cookie which means the
user specified that they always want SVG or JPEG. 2) on the URL which overrides the
default graphic type - e.g. explicitly set by the user when making the request.
Listed below are the filter init params that specify how this filter is controlled.
| PARAMETER NAME | INIT-PARAM DESCRIPTION |
| _URIPatternFilter | Standard _URIPatternFilter "init-param"s |
| Artifact.RequestPathType |
Optional type of artifact path to use to save/retrieve files from. This
controls if the filter uses the request's URI or the request's path info for
where to get/put the artifacted files from/to. Valid values are "URI" or
"PathInfo". If nothing is specified then the "URI" is used. URI allows for
handling deployments that have mulitple context entry points defined with
separate caches. This is needed so that other local page resource link
addressing works properly.
|
| Artifact.BasePath |
Optional path of where to save/get the artifacted files to/from. If nothing
is specified, the default is the root path of either the application's context
if the Base.PathType is set to "C"ontext, or the application server's working
directory if it is anything else. See the "Base.PathType" description for
optional control of the path type.
|
| Artifact.BasePathType |
Optional type of base path specified. This controls if the path
is based on the servlet context path (value of "C"), or an absolute
file path (as would be needed for a clustered environment - shared
file server). Value values are: "C", "F". If not specified the
default is "C". If something other than "C" is used then it counts
as "F".
|
| CompressedAtrifact.BasePathSuffix |
Required if the compression filter is implemented. This value is
appended to the base path and specifies where to save/get compressed
artifacted files to/from. If no value specified then the filter will
NOT check for the user's browser supporting compression. If the
compression is then used then the resultant artifact may or may not be
compressed and will be returned to the user as it exists. See the optional
Compressed.FileExtension.List for a further refinement of files that should
be compressed.
|
| ArtifactGraphicTypePage.BasePathSuffix |
Required if the system implements SVG and any other type of graphic
chart/map. This value is appended to the base path (after the compressed
path) and specifies where to save/get SVG artifacted page files to/from. If
no value specified then the filter will NOT check for the user's browser
supporting SVG. This has huge issues if the system produces both JPEG and
SVG pages. The resultant artifact will either be SVG or JPEG and will be
returned to the user as it is first created. See the optional "SVG.List"
for a further refinement of files that contain SVG or JPEG graphics.
|
| GraphicType.RequestParameterName |
Request parameter name (key) that is used by the system. |
| GraphicType.RequestParameterValue |
Request parameter value that is specified by the system. If this value
matches the request's value then the GraphicTypePage.Base.PathSuffix will
be added to the base path.
|
| CompressedFilePattern.MatchList |
List of file extensions that are compressed (if client supports).
This controls two things 1) If client supports and found in the
compressed directory then the response is streamed back based on the
disk file and the clients header is set to content gzip. 2) If
content not found then wrap the response and when received back
save to a disk file (according to if compressed or not).
IMPORTANT NOTE: This is a configuration dependency with the
compression filter. The extensions must match and the compression
filter must be present for this to work properly.
|
| CompressedFilePattern.MatchListSeperator |
Optional list separator character used to delimit the Match List items. |
| CompressedFilePattern.RequestPathType |
Controls the type of path to check against URI or PathInfo. |
| CompressedFilePattern.MatchType |
Controls the type of match to test - "c"ontains or "p"refix. |
| ArtifactFile.LifeDuration |
Value which controls how long a file can exist before it should
be refreshed/rebuilt by the system. The value is seconds. The
value is added to the file's last modified time. If the value+
last modified are greater than the current time the file is
refreshed. Else it's within the cache window and it's contents
are streamed back. If no value is specified or if any negative
value is specified the value is the Java max long (e.g. 2^64 =
very long time even in ms).
|
| Path Patterns |
Typical pattern path list properties. |
- Author:
- Garth Braithwaite.
- See Also:
- Most of the code lifted from JSP Book (www.jspbook.com).,
AbstractPathPatternFilter
|
Method Summary |
void |
destroy()
Required filter method. |
void |
doFilter(javax.servlet.ServletRequest req,
javax.servlet.ServletResponse res,
javax.servlet.FilterChain chain)
Handles saving and returning requests cached to/from a disk file. |
void |
init(javax.servlet.FilterConfig filterConfig)
Sets the filter's control properties via the init-parameters (located
in the application's deployment web.xml file). |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
MIN_TEMP_FILE_SIZE_TO_QUALIFY_AS_GOOD_FILE
protected int MIN_TEMP_FILE_SIZE_TO_QUALIFY_AS_GOOD_FILE
DEFAULT_BASE_PATH
protected java.lang.String DEFAULT_BASE_PATH
DEFAULT_COMPRESSED_BASE_PATH_SUFFIX
protected java.lang.String DEFAULT_COMPRESSED_BASE_PATH_SUFFIX
DEFAULT_GRAPHIC_TYPE_BASE_PATH_SUFFIX
protected java.lang.String DEFAULT_GRAPHIC_TYPE_BASE_PATH_SUFFIX
DEFAULT_GRAPHIC_TYPE_PARAMETER_NAME
protected java.lang.String DEFAULT_GRAPHIC_TYPE_PARAMETER_NAME
DEFAULT_GRAPHIC_TYPE_PARAMETER_VALUE
protected java.lang.String DEFAULT_GRAPHIC_TYPE_PARAMETER_VALUE
servletContext
protected javax.servlet.ServletContext servletContext
lifeOfFile
protected long lifeOfFile
tempFilenameCounter
protected int tempFilenameCounter
isArtifactPathTypeURI
protected boolean isArtifactPathTypeURI
basePath
protected java.lang.String basePath
compressedBasePathSuffix
protected java.lang.String compressedBasePathSuffix
graphicTypePageBasePathSuffix
protected java.lang.String graphicTypePageBasePathSuffix
graphicTypeParameterName
protected java.lang.String graphicTypeParameterName
graphicTypeParameterValue
protected java.lang.String graphicTypeParameterValue
compressedPathPattern
protected AbstractPathPatternFilter.PathPattern compressedPathPattern
Filter
public Filter()
init
public void init(javax.servlet.FilterConfig filterConfig)
- Sets the filter's control properties via the init-parameters (located
in the application's deployment web.xml file).
- Specified by:
init in interface javax.servlet.Filter- Overrides:
init in class AbstractPathPatternFilter
- Parameters:
filterConfig - Standard FilterConfig object passed to this filter
from the container after object creation. The main info
contained with the init parameters are the filtering patterns on
which this filter acts on, and the base paths needed to save and
retrieve the artifacted files, and the life duration of the
artifact file before it becomes stale.
doFilter
public void doFilter(javax.servlet.ServletRequest req,
javax.servlet.ServletResponse res,
javax.servlet.FilterChain chain)
throws java.io.IOException,
javax.servlet.ServletException
- Handles saving and returning requests cached to/from a disk file. If
the request is a candidate for artifacting e.g. matches the path patterns
specified, then build the artifact path according to compression support
and GraphicType. Next, concat the path with the resource's path (URI or
pathinfo). Then check to see if an atrifacted file (same requested
resource) exists. If it has, then check the file's creation date and time
and check against the life value. If within the value then simply stream
back. If not then wrap the response so that the returned response stream
can be captured and saved to a file for future request responses.
Basic Logic: Check path patterns and query string. If no match or query
string then do normal. If the compressable path is set AND if request
supports gzip AND if the extension is in the list then adjust the base
path.
Next if the request
contains a graphic type parameter and the value matches then append the
graphic type path suffix to the base path. Finally, if using the URI
artifacting path then get the request's URI else get the request's
Path Info. Append that path to the base path for the artifact filename.
If file exists, check for the file to be exipred. If expired or not found
then wrap the response and do normal processing. When normal processing is
finished save the wrapped response's content to the artifact filename. If
found and not expired then simply stream the artifact file's contents back
to the requestor.
- Parameters:
req - Original request.res - Original response.chain - Filter chain to call for normal filter/servlet request/
response handling.
- Throws:
java.io.IOException
javax.servlet.ServletException
destroy
public void destroy()
- Required filter method. Clears the Servlet Context and Filter Config objects.
- Specified by:
destroy in interface javax.servlet.Filter- Overrides:
destroy in class AbstractPathPatternFilter