public final class SessionControlFilter
implements Filter
{
private String attribute =
null;
private FilterConfig filterConfig = null;
public void
init(FilterConfig filterConfig) throws ServletException
{
this.filterConfig =
filterConfig;
this.attribute =
filterConfig.getInitParameter("attribute");
sessionController = SessionController.getInstance();
}
public void doFilter(ServletRequest request, ServletResponse
response, FilterChain chain)
throws
IOException, ServletException
{
if (attribute != null)
request.setAttribute(attribute, this);
if(getCookie((HttpServletRequest)request, "CHOCLATE_CHIP") ==
null)
{
makeCookie((HttpServletResponse)response, "CHOCLATE_CHIP", "CLIENT",
"666");
}
chain.doFilter(request,
response);
}
public static Cookie
getCookie(HttpServletRequest request, String name)
{
Cookie[] cookies =
request.getCookies();
Cookie myCookie =
null;
for (int
i=0;i<cookies.length ;i++ )
{
if
(cookies[i].getName().equals(name))
{
myCookie =
cookies[i];
break;
}
}
return
myCookie;
}
public void
makeCookie(HttpServletResponse response, String name, String channel, String
visitorId)
{
String value = channel + "|" +
visitorId;
Cookie newCookie = new
Cookie(name, value);
newCookie.setPath("/");
newCookie.setComment("No comment.");
newCookie.setMaxAge(315360000);
newCookie.setVersion(1);
response.addCookie(newCookie);
}
public void
destroy()
{
this.attribute = null;
this.filterConfig = null;
}
}
This electronic mail transmission may contain confidential information and
is intended only for the person(s) named. Any use, copying or disclosure by
any other person is strictly prohibited. If you have received this
transmission in error, please notify the sender via
e-mail.