File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Filter doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Filter doubt" Watch "Filter doubt" New topic

Filter doubt

philip johnson
Ranch Hand

Joined: Dec 25, 2007
Posts: 40
In my filter if I get res.getOutputStream(); and I modify it and then flush it, what will happen to the next filter part of same app accessing the same outputstream and trying to modify , since it closed , will it throw illegalStateException, or the webcontainer keep the stream open till all the filters finished.

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63866

What happened when you tried it?

[Asking smart questions] [About Bear] [Books by Bear]
Angel J Gama
Ranch Hand

Joined: Jun 28, 2007
Posts: 36
Once you commit the response, there is no other thing to commit later.
And when you've commited the response, it'll be sent back to the client. But if you commit the response and then you try to do something with it, then you'll get the IlegalStateException.
If you stop the chain -no call to chain.doFilter()- no other filters are executed, and that makes sense because the chain object knows what resource is in stack (filter, servlet, ...)
[ August 31, 2008: Message edited by: Angel J Gama ]
philip johnson
Ranch Hand

Joined: Dec 25, 2007
Posts: 40
Why I asked I am using third party jars for couple of filters, they are writing to the ServletOutputStream and flushinh it, in two filters it is happening, when you chain it I could not predict the behaviour, sometime it work, sometime it crashed with the outputsteram is already obtained exception. SO my questionis what is the standard way to chain filters, how you change the source if you want to modify the jars.I think the filter provider think you are usingonly this filter.
I agree. Here's the link:
subject: Filter doubt
It's not a secret anymore!