-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Michael,
Michael Ludwig wrote: > [Handing out multiple objects] seems to have caused the effect observed, > which was the absence of > the HTML file included via RequestDispatcher.include() in both the > buffer used to capture the response and the output itself. > > Might this have to do with the fact that the PrintWriter is buffered? Yes. But you want all client code to be working on the same wrapper object as well as underlying object. There's no compelling reason to create additional objects. >>> public void flushBuffer() throws IOException { >>> this.buffer.flush(); >>> } >> Flushing a ByteArrayOutputStream doesn't do anything. What you really >> want to do is flush all the OutputStream and Writer objects you've >> created when calls to getOutputStream and getWriter come in. > > I dropped this method. I would put it back. You want the Response.flushBuffer method to work and actually flush the buffer being used. You should add this method back. > public HttpResponseCatcher( HttpServletResponse res) { > super( res); > this.buffer = new ByteArrayOutputStream(); > this.stream = new CapturedServletOutputStream( this.buffer); > this.writer = new PrintWriter( new OutputStreamWriter( this.stream)); ! No character encoding! > } I would lazily instantiate these objects -- at least the stream and writer. There's no need to create a writer if the caller doesn't ask for one. Also, the caller might want to set the character encoding on the response, and you have to allow that to occur before you create your writer. > public ServletOutputStream getOutputStream() throws IOException { > getResponse().getOutputStream(); > return stream; > } Here's where you'd create your stream (or writer). public ServletOutputStream getOutputStream() throws IOException { getResponse().getOutputStream(); if(null == stream) stream = new CapturedServletOutputStream(this.buffer); return stream; } I would do the same with the PrintWriter. I still think that using a unified buffer is non-ideal. But hey... if it works, it works. > public String getCapturedOutput() { return buffer.toString(); } > public byte[] getByteArray() { return buffer.toString().getBytes(); } Yikes! You aren't checking the character encoding of the response! You definitely need to do this in order to properly implement this method. - -chris -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkk0KbwACgkQ9CaO5/Lv0PCeKACgnbfYEZveOuhu8C2THl8oaUg+ uOcAnjcYQImpXYmQoY5BAdKsyUf7Bgwm =f1dV -----END PGP SIGNATURE----- --------------------------------------------------------------------- To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]