This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

chain.doFilter() being called twice.

 
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.

 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without knowing more, I'd agree.
 
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
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.
 
Marshal
Posts: 25671
69
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.
 
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.
 
    Bookmark Topic Watch Topic
  • New Topic