Just add a listener to automatically flush non-flushed entities after the response has been sent.