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:


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.
 
Constructor Summary
AppAvailabilityFilter()
           
 
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
 

Field Detail

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.

Constructor Detail

AppAvailabilityFilter

public AppAvailabilityFilter()
Method Detail

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