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

chain.doFilter() being called twice.

 
chandrakant karale
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While tracing the root cause for IllegalStateException, I encountered following code for a gzip filter.
I suspect that chain.doFilter() should not be called multiple times in any flow, and there should be a return statement after wrappedResponse.finishResponse(); .
Please comment on this; I am new to filters.

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without knowing more, I'd agree.
 
avi sinha
Ranch Hand
Posts: 453
Google Web Toolkit Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
of course here chain.doFilter can be called twice . you can correct the logic by using a boolean flag which will take care of it .
for ex:


avi sinha
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For me, adding a flag for this purpose unnecessarily complicates the method and makes it harder to understand.
 
Paul Clapham
Sheriff
Pie
Posts: 20771
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:For me, adding a flag for this purpose unnecessarily complicates the method and makes it harder to understand.


I agree. Just write it as a series of if's and else's. And if you get rid of this line:

which surely can't represent the real-life requirement to have a filter which expects both HTTP requests and non-HTTP requests, it makes the if-else code much more obvious.
 
cow clarke
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The times being called of this method depends on the web.xml config file on my opinion.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic