Return-Path: Delivered-To: apmail-jakarta-tomcat-user-archive@www.apache.org Received: (qmail 83674 invoked from network); 3 Aug 2004 14:35:43 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 3 Aug 2004 14:35:43 -0000 Received: (qmail 4886 invoked by uid 500); 3 Aug 2004 14:35:08 -0000 Delivered-To: apmail-jakarta-tomcat-user-archive@jakarta.apache.org Received: (qmail 4866 invoked by uid 500); 3 Aug 2004 14:35:07 -0000 Mailing-List: contact tomcat-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Tomcat Users List" Reply-To: "Tomcat Users List" Delivered-To: mailing list tomcat-user@jakarta.apache.org Received: (qmail 4853 invoked by uid 99); 3 Aug 2004 14:35:07 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received: from [146.187.128.22] (HELO OWL.ewu.edu) (146.187.128.22) by apache.org (qpsmtpd/0.27.1) with ESMTP; Tue, 03 Aug 2004 07:35:03 -0700 Received: from kinux.ewu.edu ([146.187.120.20]) by mail.ewu.edu (PMDF V6.2-X10 #30562) with ESMTP id <01LD7X6X5W52005VW7@mail.ewu.edu> for tomcat-user@jakarta.apache.org; Tue, 03 Aug 2004 07:34:55 -0800 (PST) Date: Tue, 03 Aug 2004 07:34:54 -0700 From: Kaleb Pederson Subject: Re: Subclassing ServletOutputStream/PrintWriter In-reply-to: <9C5166762F311146951505C6790A9CF80229BDC9@US-VS1.corp.mpi.com> To: Tomcat Users List Message-id: <200408030734.54775.kpederson@mail.ewu.edu> Organization: Eastern Washington University MIME-version: 1.0 Content-type: text/plain; charset=iso-8859-1 Content-transfer-encoding: 7bit Content-disposition: inline User-Agent: KMail/1.6.2 References: <9C5166762F311146951505C6790A9CF80229BDC9@US-VS1.corp.mpi.com> X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N I probably have the terminology wrong then as this is my first time dealing with servlets. I'm writing an error page that get's called in response to a different servlet that we have issuing an error with sendError(). The output stream has been written to, but was never sent to the client. I suppose therefore, that it's been written to but not committed? Thus, I can't use the incoming response object to write to. As there doesn't seem to be a default means of getting at a new outputStream object, or printWriter, I presume that I have to subclass ServletOutputStream or PrintWriter - correct? Assuming that's the case, I need to know what functions need to be implemented in the two above classes for it to work. I have actually already extended the ServletOutputStream using a very basic class, but it doesn't work in that any content written to it, doesn't get pulled into the client browser, even after flush is called. Note that there might be many errors in terms of following the specs, as I have yet been able to find any good specs on the ServletOutputStream or its interaction with servlets: import java.io.IOException; import java.io.ByteArrayOutputStream; import javax.servlet.ServletOutputStream; public class CustomServletOutputStream extends ServletOutputStream { private ByteArrayOutputStream out = null; public CustomServletOutputStream() { out = new ByteArrayOutputStream(); } public byte[] getBuffer() { return out.toByteArray(); } public void write(int data) { out.write(data); } public void flush() throws IOException { out.flush(); } public String toString(String enc) throws IOException { return out.toString(enc); } public String toString() { return out.toString(); } public void close() throws IOException { out.close(); } } Thanks for the feedback and help. --Kaleb On Tuesday 03 August 2004 6:15 am, Shapira, Yoav wrote: > Hi, > Why are you doing this at all? Even if your approach worked you'd be at > a strange place as far as the Servlet Spec is concerned. Once a > response is committed, it should be done. No more writing. > > Yoav Shapira > Millennium Research Informatics > > >-----Original Message----- > >From: Kaleb Pederson [mailto:kpederson@mail.ewu.edu] > >Sent: Monday, August 02, 2004 6:25 PM > >To: Tomcat Users List > >Subject: Subclassing ServletOutputStream/PrintWriter > > > >I'm receiving a committed response object in an Servlet that I wrote. > > As > > >the > >response is committed, as far as I can tell, I need to create a custom > >HttpServletResponseWrapper. But as the response object is committed, it > >needs > >to use a new print writer or output stream. So, as far as I can tell I > >need > >to do the following steps: > > > >1) Subclass HttpServletResponse wrapper which overrides getWriter() and > >getOutputStream(). > >2) Subclass PrintWriter (so getWriter will return a non-committed > > object) > > >3) Subclass ServletOutputStream (so getOutputStream will return a > >non-committed object.) > > > >Although I know write(int) needs to be implemented by > > ServletOutputStream, > > >I > >don't see how that would be nearly sufficient? How does Tomcat get at > > the > > >buffer associated with an output stream so that it can send it to the > >client? > >What should my required steps be? > > > >Thanks for the help. > > > >--Kaleb > > > >--------------------------------------------------------------------- > >To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org > >For additional commands, e-mail: tomcat-user-help@jakarta.apache.org > > This e-mail, including any attachments, is a confidential business > communication, and may contain information that is confidential, > proprietary and/or privileged. This e-mail is intended only for the > individual(s) to whom it is addressed, and may not be saved, copied, > printed, disclosed or used by anyone else. If you are not the(an) intended > recipient, please immediately delete this e-mail from your computer system > and notify the sender. Thank you. > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: tomcat-user-help@jakarta.apache.org