3

I use Spring MVC and webflow. There are time where I am obliged to write to the response object directly. Specifically I have a keep-alive class that continuously sends an empty response back to the browser while the server does some slow running operations, and I write to the response directly. This class is used in a part of my application that is built on webflow and also in parts of our site that just use spring MVC. When we introduced webflow, our keep-alive class broke. Apparently when webflow sends a response to the browser it calls:

response.getWriter().print(stuff)

But when the spring MVC part of our app sends responses to the browser, it uses

response.getOutputStream().print(stuff)

Response is an HttpServletResponse object. You cannot call getWriter and getOutputStream on the same response. An illegal state exception will be thrown.

How can I override this behavior in either webflow or spring mvc so that they handle responses the same way?

aamiri
  • 2,420
  • 4
  • 38
  • 58

1 Answers1

1

You can use a servlet filter. A filter can intercept all output and rewrite in another way. A good example of this is with the jsonp filter: http://jpgmr.wordpress.com/2010/07/28/tutorial-implementing-a-servlet-filter-for-jsonp-callback-with-springs-delegatingfilterproxy/

Solubris
  • 3,603
  • 2
  • 22
  • 37
  • 1
    this will probably help me achieve my goal, but I was hoping to gain a better understanding as to what was causing this problem, and thus gaining a better understanding of spring. – aamiri May 01 '13 at 14:10