Time filter ver. 1.4


This is a Java servlet filter (as per Servlet API 2.3). This filter lets you redirect incoming requests depending on time. So, you may use it for example as an access restriction tool, for load balancing etc.

Package contains the filter itself (TimeRouteFilter) and servlet (TimeRouteServlet) you may use for the interactive data management.

How to use it:

a) download timeflt.jar and save it in WEB-INF/lib

b) create a data file with the routing information. It is a text file, each line describes an action for one time interval. Empty lines and any line starts with // or # are ignored. Path to this file should be provided as a parameter for both TimeRouteFilter and TimeRouteServlet. Action looks like:
 


time_interval \t some_url

or

time_interval \t list_of_days \t some_url

where \t is a tabulator, time_interval is a string that looks like start_time - end_time, start_time and end_time define a time in hh:mm format, list_of_days describes a commas separated list of numbers for days (Monday is first). For the each request in the given interval (for described days) filter redirects request to the given URL. For example:
 


# redirects all the requests from 11 pm till 12 pm:
23:00-24:00       /late_users.jsp

# redirects all the requets from 11:00 till 13:00 during the Monday and Tuesday
11:00-13:00   1,2    http://www.acme.com

Actually you may use TimeRouteServlet for creating/updating such file (files).

c) describe this filter in web.xml.
 


<filter>
  <filter-name>TimeRouteFilter</filter-name>
  <filter-class>com.cj.timeflt.TimeRouteFilter</filter-class>
  <init-param>
    <param-name>config</param-name>
    <param-value>your_data_file</param-value>
  </init-param>
</filter>

d) describe a mapping for this filter in web.xml
 


<filter-mapping>
  <filter-name>TimeRouteFilter</filter-name>
  <url-pattern>*.jsp</url-pattern>
</filter-mapping>

in this case filter will be on for the each .jsp file

And now when some .jsp page is requested TimeRouteFilter may redirect incoming request to the specified URL. If target URL starts with http than filter redirects request, otherwise filter assumes a local resource and forwards request.

e) describe TimeRouteServlet you will use for access to your data_file:
 


<servlet>
  <servlet-name>TimeRouteServlet</servlet-name>
  <servlet-class>com.cj.timeflt.TimeRouteServele</servlet-class>
  <init-param>
    <param-name>config</param-name>
    <param-value>your_data_file</param-value>
  </init-param>
</servlet>

f) describe a mapping for TimeRouteServlet
 


<servlet-mapping>
  <servlet-name>TimeRouteServlet</servlet-name>
  <url-pattern>/servlet/TimeRouteServlet</url-pattern>
</servlet-mapping>

Now you may run this servlet http://your_host/servlet/TimeRouteServlet and work with your data file.

   For downloading:

    Time filter:  timeflt.jar
 

 ©  Coldbeans     Comments?

See also JSOS - the largest collection of servlets and filters.

Also in JSOS: