• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Peter Rooke
  • Himai Minh
Bartenders:
  • Piet Souris
  • Mikalai Zaikin

Doubt on Filters

 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to understand "How a response filter works ?".
A wrraper object is passed to chain.doFilter(req,resp);
Could someone explain me the flow of code from here..? :roll:
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Once you pass the wrapped response object from filter1, the next filter (filter2) in the list, filter2 writes to this response object, (by calling getWriter() or whatever the overloaded method is, assuming that is the last filter).

Once filter2 is done with writing, the control returns to the calling filter1, which already has access to the Wrapped response object. The important aspect is that, the final response has not yet been sent to the client. It is still in the container, safely tucked inside the wrapped response object. Filter1, which has this response object, can do whatever it wants to do with it and then send it to the client.
 
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

There is nothing like Request Filter/response Filter...

there are only Filters....that act on request object before it is processed and response before it is sent back to client..

Client->Browser->Server->Filter
Code prior to chain.doFilter()
this code generally contains what we want to do with the request..any manipulations before it is processed


chain.doFilter()..
Filter->Servlet
This calls takes the flow to the actual resource requested(servlet...)
performs the actual logic

Servlet->Filter
And now the flow comes back to the code we might have put after
chain.doFilter() to manipulate the response using any wrapper object..

Filter->Client
Response goes to client

I havent mentioned here multiple filter/Request or Response Wrapper...

Regards
 
Swati Udas
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok thanks for the replies..
But..say there is only 1 filter

the req and wrapped_resp are sent to the servlet after calling
chain.doFilter(req,wrapped_response);

now after the servlet is done implementing its logic does the control come back to filter..so that the code written after chain.doFilter could be executed.. ?? and if it does..then what purpose is served by using wraped response instead of direct response object ?? :roll:
 
Swati Udas
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Found this info online-- this solves my doubt to a certain extent
http://edocs.bea.com/wls/docs61/webapp/filters.html

Filtering the Servlet Response Object

You can use filters to post-process the output of a servlet by appending data to the output generated by the servlet. However, in order to capture the output of the servlet, you must create a wrapper for the response. (You cannot use the original response object, because the output buffer of the servlet is automatically flushed and sent to the client when the servlet completes executing and before control is returned to the last filter in the chain.) When you create such a wrapper, WebLogic Server must manipulate an additional copy of the output in memory, which can degrade performance.
 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

now after the servlet is done implementing its logic does the control come back to filter..so that the code written after chain.doFilter could be executed.. ??



yes....the flow does go through .....


and if it does..then what purpose is served by using wraped response instead of direct response object ??



Your last post ....addresses this point...for the need for a response wrapper
[ January 08, 2007: Message edited by: A Kumar ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic