Agent filter ver. 1.9

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

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

How to use it:

a) download agentflt.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 header's template. Empty lines and any line starts with // or # are ignored. Path to this file should be provided as a parameter for both AgentRouteFilter and AgentRouteServlet. Action looks like:

R \t referer template \t some_url


A \t user agent template \t some_url

where \t is a tabulator, R indicates template for referer field, A indicates template for User-Agent header. If header contains template than filter redirects incoming request. For example:

# redirects all vistors from Google:
R   google    /forgoogle.jsp

# redirects all visitors with MS IE

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

For user agent templates you can provide a list of alternatives (use | as a separator):

# redirects all visitors with iPhone and Sony Ericsson K320
A   iPhone | K320

You can use regular expressions in templates.

c) describe this filter in web.xml.


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


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

And now when some .jsp page is requested AgentRouteFilter 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 AgentRouteServlet you will use for access to your data_file:


f) describe a mapping for this servlet in web.xml


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

   For downloading:

    Agent filter:  agentflt.jar

 ©  Coldbeans     Comments?

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


Also in JSOS: