Friday, November 7, 2014

FILTER vs INTERCEPTOR

FILTERS
0)  Filter is an Interface
1)  Filters are Java Components. somewhat equivalent to servlet.
2)  Filters intercepts and process the request before it sent to the actual servlet.
- on request object filter can do security checks
- filter can do some log work
- filter can change the request parameter
- filter can reformat the request headers 
- filter can take some decision based on request parameters
3)  Filter intercepts the response received from the servlet before it sent to the end user.
- filter can do some log work for the response
- filter can change the response stream

4)  Filters are configurable in DD (Deployement Descriptor)
5)  Container decides when to invoke which filter
6)  Filters have init(), destroy() and doFilter() methods
7)  One request can be intercepted by multiple filters
8)  Every filter must implemens the Filter Interface
9)  Filter interface is in package "import javax.servlet.Filter;"
10) doFilter(ServletRequest request, ServletResponse response, FilterChain fchain) 
11) As per the declaration of filter in the DD the filter chain will be prepared for the similar url-mapping and servlet-names.
12) The Filter chain concept can also be called a filter stack.

INTERCEPTORS
0)  Interceptor is an Interface
1)  Interceptors are struts2 components similar to Filter
2)  Interceptors intercepts the request before it reach to the servlet and can do the same      
     work as filter can do.
3)  Interceptors intercepts the respons before it reach to the end user and can perform the 
     same work as filter can do.
4)  Interceptors can be declared in the struts specific configuration file (struts.xml)
5)  Interceptors are can be called action specific
6)  Programmer can be define in specific order to create stack of the interceptor. (as filter 
    chaining )
7)  Prepared stack can be used at multiple times for the specified actions
8)  Struts2 provides many useful interceptors (i.e 
     http://struts.apache.org/release/2.3.x/docs/interceptors.html)
9)  To create interceptor we need to implement Interceptor interface
10) Interceptor have three methods void init(),  void destroy() and Strinng 
      intercept(ActionInvocation acIn)
11) package : "import com.opensymphony.xwork2.interceptor.Interceptor;"
12) Interceptor can exclude and include specific method's execution.

I think this is enough basic information about FILTER and INTERCEPTOR :)

KEEP VISITING :) GIVE YOUR RATING AND COMMENTS

No comments:

Post a Comment

Scrum and Scrum master

Scrum  Scrum is a framework which helps a team to work together.  It is like a rugby team (the scrum name comes from rugby game). Scrum enco...