Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to configure Filter so that it will only process request but not response

 
James Tharakan
Ranch Hand
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to know how to configure a filter so that it will process only the incoming request but not the response going from the server.
Any suggestion or corresponding links would be helpful


I read in Filter docs that we can have "A filter is an object that performs filtering tasks on either the request to a resource (a servlet or static content), or on the response from a resource, or both"
Thanks
 
Ankit Garg
Sheriff
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your filter after you call filter.doFilter();, don't do any further processing. Filters are not separately applied to request and response...
 
James Tharakan
Ranch Hand
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sorry to say that i did not understand when you said "don't do any further processing". Can you explain that ?
 
Paul Clapham
Sheriff
Pie
Posts: 20771
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't want to process the response, just don't write any code. You have to call "filter.doFilter()" and then after that don't do anything. Write zero lines of code. Return immediately. "Don't do anything" isn't really very complicated, but here's an example if you still need one:
 
James Tharakan
Ranch Hand
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply...
suppose if i want to do the filter even when response is sent then what should i do ?
I am asking this because my filters are not called when response is sent (Even though i currently don't need this feature in my app i would like to know.)
 
Ankit Garg
Sheriff
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
James filters are not called separately for request and response. When the book said request or response or both, this is what they meant

 
James Tharakan
Ranch Hand
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ankit, i got it this time...
Thank you , will get back if need(i guess i don't have to).
 
amit punekar
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi James,

My 2 cents !!

Response Filters

Regds,
Amit
 
James Tharakan
Ranch Hand
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Amit , i got that.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic