File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

filter response

 
alexander zevenbergen
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all

i need to rewrite an inputstream as an outputstream and send it out with the response in my filter. Can any body help me with this?

this is what i have and i'm not sure where i'm going wrong





What i'm trying to do is send a resource to a html page that requested it(in most cases a picture but can also be a style sheet)

Am i right in assuming that the wrapper stops the response and the printwriter sends my bytearray instead?

or did i miss some logic somewhere?

thanks
Alex
 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you wanted the Filter to write back the response, you shouldnt have the doFilter() call on the FilterChain. doFilter() would invoke the next entity in the chain (which may be another Filter or a Servlet or a Jsp)

Having said that, I would recommend that you take a step back and have a careful look at your design. Filter blocking requests are a rarity. And in most cases, it would be conditional - an example would be to check for a certain attribute in session or the session itself (this can be done easily enough in the Controller too). Filters generally augment request and response handling (eg zipping up the response, adding a request parameter etc).

And finally the purpose of a ResponseWrapper is to prevent the Servlets or Jsp from writing to the response directly. Instead the Filter wraps the response object adding it's own custom OutputStream and then passes the request along. Now a Servlet or a Jsp would write to the Filter's output stream and when the Filter receives the response on its way back, it can extract the contents, make necessary changes (say zip it up) and then send the output to the browser.

Does that help?

ram.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic