Return-Path: Delivered-To: apmail-jakarta-tomcat-dev-archive@apache.org Received: (qmail 48817 invoked from network); 4 Feb 2003 15:05:37 -0000 Received: from exchange.sun.com (192.18.33.10) by daedalus.apache.org with SMTP; 4 Feb 2003 15:05:37 -0000 Received: (qmail 831 invoked by uid 97); 4 Feb 2003 15:07:05 -0000 Delivered-To: qmlist-jakarta-archive-tomcat-dev@nagoya.betaversion.org Received: (qmail 824 invoked from network); 4 Feb 2003 15:07:05 -0000 Received: from daedalus.apache.org (HELO apache.org) (208.185.179.12) by nagoya.betaversion.org with SMTP; 4 Feb 2003 15:07:05 -0000 Received: (qmail 46892 invoked by uid 500); 4 Feb 2003 15:05:08 -0000 Mailing-List: contact tomcat-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Tomcat Developers List" Reply-To: "Tomcat Developers List" Delivered-To: mailing list tomcat-dev@jakarta.apache.org Received: (qmail 46868 invoked from network); 4 Feb 2003 15:05:07 -0000 Received: from exchange.sun.com (192.18.33.10) by daedalus.apache.org with SMTP; 4 Feb 2003 15:05:07 -0000 Received: (qmail 791 invoked by uid 50); 4 Feb 2003 15:06:35 -0000 Date: 4 Feb 2003 15:06:35 -0000 Message-ID: <20030204150635.790.qmail@nagoya.betaversion.org> From: bugzilla@apache.org To: tomcat-dev@jakarta.apache.org Cc: Subject: DO NOT REPLY [Bug 16760] New: - Wrapping response in filter not possible X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT . ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE. http://nagoya.apache.org/bugzilla/show_bug.cgi?id=16760 Wrapping response in filter not possible Summary: Wrapping response in filter not possible Product: Tomcat 4 Version: 4.1.18 Platform: PC OS/Version: Windows NT/2K Status: NEW Severity: Blocker Priority: Other Component: Catalina AssignedTo: tomcat-dev@jakarta.apache.org ReportedBy: bernd.krannich@gmx.de The usage of a wrapped response which is derived from HttpServletResponseWrapper is no longer possible with Tomcat 4.1.18. In Tomcat 4.1.12 however, the following coding works fine: // -- Response wrapper class class ResponseWrapper extends HttpServletResponseWrapper { private PrintWriter printWriter; private ReplaceContentOutputStream outputStream; public ResponseWrapper(HttpServletResponse response) throws IOException { super(response); this.outputStream = new ReplaceContentOutputStream(response.getOutputStream ()); this.printWriter = new PrintWriter(this.outputStream); } public ServletOutputStream getOutputStream() throws IOException { return this.outputStream; } public PrintWriter getWriter() throws IOException { return this.printWriter; } } // -- Wrapped output stream class ReplaceContentOutputStream extends ServletOutputStream { private OutputStream outputStream; private ByteArrayOutputStream byteArrayOutputStream; private boolean closed = false; private boolean transformOnCloseOnly = false; public ReplaceContentOutputStream(OutputStream outputStream) { this.outputStream = outputStream; this.byteArrayOutputStream = new ByteArrayOutputStream(); } public void write(int i) throws IOException { this.byteArrayOutputStream.write(i); } public void close() throws IOException { if (!closed) { processStream(); this.outputStream.close(); closed = true; } } public void flush() throws IOException { if (this.byteArrayOutputStream.size() != 0) { if (!this.transformOnCloseOnly) { processStream(); this.byteArrayOutputStream = new ByteArrayOutputStream(); } } } public byte[] replaceContent(byte[] bytes) throws IOException { String newString = new String(bytes); int replacePosition = newString.indexOf("<%placeholder%>"); if (replacePosition != -1) { newString = newString.substring(0, replacePosition) + "replaced" + newString.substring(replacePosition + "<%placeholder%>".length()); } return newString.getBytes(); } public void processStream() throws IOException { byte[] bytes = replaceContent(this.byteArrayOutputStream.toByteArray()); this.outputStream.write(bytes); } public void setTransformOnCloseOnly() { this.transformOnCloseOnly = true; } } The filter itself is set up to process each request on *.jsp. When the wrapped response is passed in to the doFilter method, neither getServletOutputStream() nor getWriter() is called (extract from doFilter()): ... ResponseWrapper wrappedResponse = new ResponseWrapper(this.response); this.filterChain.doFilter(this.request, wrappedResponse); wrappedResponse.getOutputStream().close(); ... Thus, the wrapped response itself is entirely empty. --------------------------------------------------------------------- To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org