View Javadoc

1   /*
2    * WebFlow Navigation Manager: webflow definiton, server side navigation history and automatic session cleaning.
3    * Distributed under LGPL license at web site http://wfnm.sourceforge.net .
4    */
5   package net.sf.wfnm.web;
6   
7   import java.io.IOException;
8   
9   import javax.servlet.Filter;
10  import javax.servlet.FilterChain;
11  import javax.servlet.FilterConfig;
12  import javax.servlet.ServletException;
13  import javax.servlet.ServletRequest;
14  import javax.servlet.ServletResponse;
15  import javax.servlet.http.HttpServletRequest;
16  import javax.servlet.http.HttpServletResponse;
17  
18  
19  /***
20   * This filter replaces the http session with a wrapper which notify to the WFNM framework the binding/unbinding of
21   * objects to/from the original session.
22   *
23   * @author <a href="mailto:malbari@users.sourceforge.net">Maurizio Albari</a>
24   * @version 1.0.6
25   */
26  public class SessionBindingFilter implements Filter {
27      /***
28       * Destroy the filter.
29       */
30      public void destroy() {
31      }
32  
33      /***
34       * Filter the request by replacing the request with a wrapper that returns the HttpSessionWrapper as a session
35       * implementation.
36       *
37       * @param servletRequest the servlet request
38       * @param servletResponse the servlet response
39       * @param filterChain the filter chain
40       *
41       * @throws IOException if an I/O exception ocours
42       * @throws ServletException if a servlet exception ocours
43       */
44      public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
45          throws IOException, ServletException {
46          ServletRequest sessionBindingRequest = new HttpServletRequestWrapper((HttpServletRequest) servletRequest);
47          HttpServletResponse response = (HttpServletResponse) servletResponse;
48          ResponseFactory.addNoCacheHeaderDirective(response);
49          filterChain.doFilter(sessionBindingRequest, servletResponse);
50      }
51  
52      /***
53       * Initialize the filter.
54       *
55       * @param filterConfig the filter configuration
56       *
57       * @throws ServletException if a servlet exception ocours
58       */
59      public void init(FilterConfig filterConfig) throws ServletException {
60      }
61  }