• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

filter response

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 489
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic