wood burning stoves*
The moose likes Servlets and the fly likes Problem with HttpServletResponseWrapper Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "Problem with HttpServletResponseWrapper " Watch "Problem with HttpServletResponseWrapper " New topic
Author

Problem with HttpServletResponseWrapper

Daniel Del Moral
Ranch Hand

Joined: May 24, 2008
Posts: 32
Hi ranchers:

I've been stucked with a problem, I'm trying to implement HttpServletResponseWrapper, so I can get a hold of the response outputstream from a filter. I'm just implementing the example from the following webpage: http://download-uk.oracle.com/docs/cd/A97329_03/web.902/a95878/filters.htm#998358 (Example 3 at the bottom), but it doesn't work if my request is a JSP page, the stream that I get from the wrapper is empty, but it does work if it is a outputstream from a Servlet (using getOutputStream()). I'm using Apache Tomcat 5.5. Has anybody had a similar problem? I guess it must be an additional method from HttpServletResponseWrapper that needs to be overriden, I just can't find which one it is.

Thanks!


SCJP 5, SCWCD 5
Daniel Del Moral
Ranch Hand

Joined: May 24, 2008
Posts: 32
I've been researching around. I override getOutputStream and getWriter in my HttpServletResponseWrapper:



and



This is my implementation of FilterServletOutputStream



I've noticed that JspWriter does calls getWriter from my HttpServletResponseWrapper, so I'm sure that JspWriter has my ServletOutputStream wrapper, the problem is that later, JspWriter doesn't call any of my overriden write methods, so I never get the output from jsp. Any ideas why this could be happening?

Thanks!
Daniel Del Moral
Ranch Hand

Joined: May 24, 2008
Posts: 32
Done!

I just need to flush the PrintWriter that I returned at getWriter method of my HttpServletResponseWrapper. I just had to flush it after the Servlets have donde the writing, I did it after the doFilter on my filter.
 
GeeCON Prague 2014
 
subject: Problem with HttpServletResponseWrapper