1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| private FilterConfig config = null;
private ArrayList list = null;
private final static String FILTER_APPLIED = "TrackingFilter_already_applied";
public void setFilterConfig(FilterConfig _config) {
this.config = _config;
}
public void init(FilterConfig _config) {
this.config = _config;
}
public FilterConfig getFilterConfig() {
return this.config;
}
//Clean up resources
public void destroy() {
this.config=null;
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
if(request.getAttribute(FILTER_APPLIED)==null){
request.setAttribute(FILTER_APPLIED,Boolean.TRUE);
String hostname = InetAddress.getLocalHost().getHostName();
Cookie serversCookie = new Cookie("trackingServer",hostname);
// envoi du cookie vers le navigateur du client
((HttpServletResponse)response).addCookie(serversCookie);
chain.doFilter(request, response);
}else {
chain.doFilter(request, response);
}
}
} |