javawebparts.filter
Class AppAvailabilityFilter
java.lang.Object
|
+--javawebparts.filter.AppAvailabilityFilter
- All Implemented Interfaces:
- javax.servlet.Filter
- public class AppAvailabilityFilter
- extends java.lang.Object
- implements javax.servlet.Filter
This filter allows for defining a time window for each day of the week
during which the application is available. It allows for including or
excluding paths from filter functionality. It also also allows for
bypassing filter functionality based on an application-defined criteria.
It allows for forwarding or redirecting to a defined page when the
application is not available.
Init parameters are:
- pathSpec - Either "include" or "exclude". This determines whether
the list of paths in the pathList parameter is a list of paths to include in
filter functionality, or a list of paths to exclude. Required: No.
Default: None.
- pathList - This is a comma-separated list of paths, which can use
asterisk for wildcard support, that denotes either paths to include or
exclude from the functioning of this filter (depending on what pathSpec
is set to). The paths ARE case-senitive! There is no limit to how many
items can be specified, although for performance reasons a developer will
probably want to specify as few as possible to get the job done (each
requested path is matched via regex). Note also that you are of course
still required to specify a path for the filter itself as per the servlet
spec. This parameter however, together with pathSpec, gives you more control
and flexibility than that setting alone. Required: No. Default: None.
General note on pathSpec and pathList: If pathSpec is not specified but
pathList IS, then 'exclude' is assumed for pathSpec. If pathSpec is
specified by pathList IS NOT, then the filter WILL NEVER EXECUTE (this is
technically a misconfiguration). If NEITHER is defined then the generic
filter mapping will be in effect only.
- bypassCheckClass - This is a class you can optionally provide that
must implement the AppAvailabilityBypassCheck interface, to allow for the
capability to override the function of this filter. For instance, you may
want a particular user to always be allowed in. By supplying this class,
you can do that in whatever fashion is appropriate for your application
(i.e., maybe you need to grab a particular parameter from request and look
up the user in a database). Required: Yes. Default: None.
- redirectTo - The URL to redirect to if the app is not available.
You can either redirect to this URL or forward to it, but not both.
Required: Yes (either this or forwardTo). Default: None.
- forwardTo - The URL to forward to if the app is not available.
You can either redirect to this URL or forward to it, but not both.
Required: Yes (either this or redirectTo). Default: None.
- monday - The time range within which the application is
available on a Monday. Required: Yes. Default: None.
- tuesday - The time range within which the application is
available on a Tuesday. Required: Yes. Default: None.
- wednesday - The time range within which the application is
available on a Wednesday. Required: Yes. Default: None.
- thursday - The time range within which the application is
available on a Thursday. Required: Yes. Default: None.
- friday - The time range within which the application is
available on a Friday. Required: Yes. Default: None.
- saturday - The time range within which the application is
available on a Saturday. Required: Yes. Default: None.
- sunday - The time range within which the application is
available on a Sunday. Required: Yes. Default: None.
General notes on the time ranges... the times are specified in 24-hour
format and the value of the parameter for each day is in the form 8888-9999,
where 8888 is the start time and 999 is the end time. Start and end times
CAN span days, i.e., you can define that the application is available
from 11pm on Friday to 6am on Saturday (by setting friday to 2300-0600).
Example configuration in web.xml:
<filter>
<filter-name>AppAvailabilityFilter</filter-name>
<filter-class>javawebparts.filter.
AppAvailabilityFilter</filter-class>
<init-param>
<param-name>pathSpec</param-name>
<param-value>include</param-value>
</init-param>
<init-param>
<param-name>pathList</param-name>
<param-value>*/AAFTestTarget.jsp
</param-value>
</init-param>
<init-param>
<param-name>monday</param-name>
<param-value>0600-2359</param-value>
</init-param>
<init-param>
<param-name>tuesday</param-name>
<param-value>0600-2359</param-value>
</init-param>
<init-param>
<param-name>wednesday</param-name>
<param-value>0600-2359</param-value>
</init-param>
<init-param>
<param-name>thursday</param-name>
<param-value>0600-2359</param-value>
</init-param>
<init-param>
<param-name>friday</param-name>
<param-value>0600-2359</param-value>
</init-param>
<init-param>
<param-name>saturday</param-name>
<param-value>0600-2359</param-value>
</init-param>
<init-param>
<param-name>sunday</param-name>
<param-value>0600-2359</param-value>
</init-param>
<init-param>
<param-name>redirectTo</param-name>
<param-value>AAFReject.jsp<
/param-value>
</init-param>
<init-param>
<param-name>bypassCheckClass<
/param-name>
<param-value>javawebparts.sampleapp.
AAFBypassCheck</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>AppAvailabilityFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
- Author:
- Frank W. Zammetti.
Field Summary |
private java.lang.String |
bypassCheckClass
A class that will be used to allow for bypassing this filter. |
private java.lang.String |
forwardTo
A path to forward to when access is denied. |
private int |
fridayEnd
The end of the time window the app is available during on Friday. |
private int |
fridayStart
The start of the time window the app is available during on Friday. |
private static org.apache.commons.logging.Log |
log
Log instance. |
private int |
mondayEnd
The end of the time window the app is available during on Monday. |
private int |
mondayStart
The start of the time window the app is available during on Monday. |
private java.util.ArrayList |
pathList
List of paths for filter functionality determination. |
private java.lang.String |
pathSpec
Whether pathList includes or excludes. |
private java.lang.String |
redirectTo
A path to redirect to when access is denied. |
private int |
saturdayEnd
The end of the time window the app is available during on Saturday. |
private int |
saturdayStart
The start of the time window the app is available during on Saturday. |
private int |
sundayEnd
The end of the time window the app is available during on Sunday. |
private int |
sundayStart
The start of the time window the app is available during on Sunday. |
private int |
thursdayEnd
The end of the time window the app is available during on Thursday. |
private int |
thursdayStart
The start of the time window the app is available during on Thursday. |
private static int |
TIME_END
Flag to retrieve end time for a date. |
private static int |
TIME_START
Flag to retrieve start time for a date. |
private int |
tuesdayEnd
The end of the time window the app is available during on Tuesday. |
private int |
tuesdayStart
The start of the time window the app is available during on Tuesday. |
private int |
wednesdayEnd
The end of the time window the app is available during on Wednesday. |
private int |
wednesdayStart
The start of the time window the app is available during on Wednesday. |
Method Summary |
void |
destroy()
Destroy. |
void |
doFilter(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response,
javax.servlet.FilterChain filterChain)
Do filter's work. |
private int |
getDayStartEnd(javax.servlet.FilterConfig filterConfig,
java.lang.String day,
int whatPart)
Retrieves the start or stop time, as specified, from a time range in
the form 8888-9999 where 8888 is the start time in 24-hour time and
9999 is the end time in 24-hour time. |
void |
init(javax.servlet.FilterConfig filterConfig)
Initialize this filter. |
private boolean |
isAppAvailable()
This is called to determine if the app is available. |
private boolean |
isTimeInRange(int rangeStart,
int rangeEnd,
int timeToCheck)
This method checks if a given 24-hour time is within a given 24-hour
time. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
log
private static org.apache.commons.logging.Log log
- Log instance.
TIME_START
private static final int TIME_START
- Flag to retrieve start time for a date.
- See Also:
- Constant Field Values
TIME_END
private static final int TIME_END
- Flag to retrieve end time for a date.
- See Also:
- Constant Field Values
pathSpec
private java.lang.String pathSpec
- Whether pathList includes or excludes.
pathList
private java.util.ArrayList pathList
- List of paths for filter functionality determination.
redirectTo
private java.lang.String redirectTo
- A path to redirect to when access is denied.
forwardTo
private java.lang.String forwardTo
- A path to forward to when access is denied.
bypassCheckClass
private java.lang.String bypassCheckClass
- A class that will be used to allow for bypassing this filter.
mondayStart
private int mondayStart
- The start of the time window the app is available during on Monday.
mondayEnd
private int mondayEnd
- The end of the time window the app is available during on Monday.
tuesdayStart
private int tuesdayStart
- The start of the time window the app is available during on Tuesday.
tuesdayEnd
private int tuesdayEnd
- The end of the time window the app is available during on Tuesday.
wednesdayStart
private int wednesdayStart
- The start of the time window the app is available during on Wednesday.
wednesdayEnd
private int wednesdayEnd
- The end of the time window the app is available during on Wednesday.
thursdayStart
private int thursdayStart
- The start of the time window the app is available during on Thursday.
thursdayEnd
private int thursdayEnd
- The end of the time window the app is available during on Thursday.
fridayStart
private int fridayStart
- The start of the time window the app is available during on Friday.
fridayEnd
private int fridayEnd
- The end of the time window the app is available during on Friday.
saturdayStart
private int saturdayStart
- The start of the time window the app is available during on Saturday.
saturdayEnd
private int saturdayEnd
- The end of the time window the app is available during on Saturday.
sundayStart
private int sundayStart
- The start of the time window the app is available during on Sunday.
sundayEnd
private int sundayEnd
- The end of the time window the app is available during on Sunday.
AppAvailabilityFilter
public AppAvailabilityFilter()
destroy
public void destroy()
- Destroy.
- Specified by:
destroy
in interface javax.servlet.Filter
init
public void init(javax.servlet.FilterConfig filterConfig)
throws javax.servlet.ServletException
- Initialize this filter.
- Specified by:
init
in interface javax.servlet.Filter
- Parameters:
filterConfig
- The configuration information for this filter.
- Throws:
javax.servlet.ServletException
- ServletException.
getDayStartEnd
private int getDayStartEnd(javax.servlet.FilterConfig filterConfig,
java.lang.String day,
int whatPart)
throws javax.servlet.ServletException
- Retrieves the start or stop time, as specified, from a time range in
the form 8888-9999 where 8888 is the start time in 24-hour time and
9999 is the end time in 24-hour time.
- Parameters:
filterConfig
- The configuration information for this filter.day
- What day of the week to retrieve.whatPart
- Which part of the range to return (start or end).
- Returns:
- The start or stop time, as specified, as an
int (24-hour form).
- Throws:
javax.servlet.ServletException
- If any problems occur, this gets thrown.
doFilter
public void doFilter(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response,
javax.servlet.FilterChain filterChain)
throws javax.servlet.ServletException,
java.io.IOException
- Do filter's work.
- Specified by:
doFilter
in interface javax.servlet.Filter
- Parameters:
request
- The current request object.response
- The current response object.filterChain
- The current filter chain.
- Throws:
javax.servlet.ServletException
- ServletException.
java.io.IOException
- IOException.
isAppAvailable
private boolean isAppAvailable()
- This is called to determine if the app is available. It does this by
determining if the current time on the server is within the availability
window configured for the current day of the week.
- Returns:
- True if the app is available, false if not.
isTimeInRange
private boolean isTimeInRange(int rangeStart,
int rangeEnd,
int timeToCheck)
- This method checks if a given 24-hour time is within a given 24-hour
time. Note that this should properly handle ranges that span days, i.e.,
if the start time is 2000 and the end time is 800 (8pm-8am the following
day), this should still work fine.
- Parameters:
rangeStart
- Beginning of range.rangeEnd
- End of range.timeToCheck
- The time to check against the range.
- Returns:
- True if the checked time is within the range, false
if it isn't.
Copyright © 2005 Frank W. Zammetti