Return-Path: Delivered-To: apmail-tomcat-users-archive@www.apache.org Received: (qmail 7697 invoked from network); 4 Jan 2008 21:55:08 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 4 Jan 2008 21:55:08 -0000 Received: (qmail 34467 invoked by uid 500); 4 Jan 2008 21:54:45 -0000 Delivered-To: apmail-tomcat-users-archive@tomcat.apache.org Received: (qmail 34450 invoked by uid 500); 4 Jan 2008 21:54:45 -0000 Mailing-List: contact users-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Users List" Delivered-To: mailing list users@tomcat.apache.org Received: (qmail 34439 invoked by uid 99); 4 Jan 2008 21:54:45 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 04 Jan 2008 13:54:45 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of len.popp@gmail.com designates 209.85.146.183 as permitted sender) Received: from [209.85.146.183] (HELO wa-out-1112.google.com) (209.85.146.183) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 04 Jan 2008 21:54:23 +0000 Received: by wa-out-1112.google.com with SMTP id m38so11372069waf.16 for ; Fri, 04 Jan 2008 13:54:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=sUQP5+HDt7Ax5Tyw/1QaAnmkQkumriSMNsL8Xf5+KSU=; b=sCbKqqeZ9lfUgjKolQIwqDXLEiZqa/Ky3CfSXTKb3RyPLHz/Ipa4Gfu5k2EZl5YujYgAKajeMWUy6A2tczFy7tdYu4hgIx9WshdJs0JphlZB1dmqVIIMnZNto0eKEi5mtBCp5XoEoaQ+ZClYeB6ehY2yxzrjEcZvTAk+R0cob/E= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=f9E4KmRxcIC7ldIbFaKJKFdCD0bQNItl01hu1jNwTH27WdwdMrv31HN/SZDT9tyRhTPGekD3rUGY2KBx7m+q4demeS2mcMx2LMYwgnYq7WAQ9scqsuvQZhupPxRHFB42g+HJYE46kKO50MWlm8I0IdVJ3hWVtIMkbh3FAMDgQB0= Received: by 10.114.121.1 with SMTP id t1mr12380252wac.67.1199483668182; Fri, 04 Jan 2008 13:54:28 -0800 (PST) Received: by 10.115.59.15 with HTTP; Fri, 4 Jan 2008 13:54:28 -0800 (PST) Message-ID: <497fac690801041354s1020ab0fkb621b68bd45c7b95@mail.gmail.com> Date: Fri, 4 Jan 2008 16:54:28 -0500 From: "Len Popp" To: "Tomcat Users List" Subject: Re: Avoiding same server to server HTTP calls to generate HTML pages via JSPs In-Reply-To: <001c01c84eb2$4aa1c4c0$dfe54e40$@com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <477D6C03.1040001@readytalk.com> <477DEAE9.2000803@ceti.pl> <001c01c84eb2$4aa1c4c0$dfe54e40$@com> X-Virus-Checked: Checked by ClamAV on apache.org Here's some code that does what Gennady suggested, using RequestDispatcher and wrapping the response object to capture the output in a String. public class JSPFormatter { public String formatPage(String stJSPFile, HttpServletRequest request, HttpServletResponse response, ServletContext ctx) throws ServletException, IOException { // Make a wrapper for the response, to capture the output. ResponseWrapper rw = new ResponseWrapper(response); // Call the JSP page and capture its output. RequestDispatcher rd = ctx.getRequestDispatcher(stJSPFile); rd.include(request, rw); return rw.getOutputString(); } /** * Nested class ResponseWrapper: Wrapper for the response to capture the servlet output. */ public class ResponseWrapper extends HttpServletResponseWrapper { protected StringWriter writer = null; protected ByteArrayOutputStream stream = null; public ResponseWrapper(HttpServletResponse response) { super(response); } public String getOutputString() { if (writer != null) return writer.toString(); else if (stream != null) return stream.toString(); else return null; } public ServletOutputStream getOutputStream() throws IOException { stream = new ByteArrayOutputStream(); return new OutputStreamWrapper(); } public PrintWriter getWriter() throws IOException { writer = new StringWriter(); return new PrintWriter(writer); } /** * Nested class OutputStreamWrapper: Wrapper for the OutputStream to turn it * into a ServletOutputStream for getOutputStream. */ public class OutputStreamWrapper extends ServletOutputStream { public void write(int b) throws IOException { stream.write(b); } } } } -- Len On Jan 4, 2008 4:15 AM, Gennady Shumakher wrote: > If you cannot replace your jsps with velocity (or freemarker) you could > still use RequestDispatcher. Just provide your own implementation of > ServletResponse that mostly will be just wrapper based on servlet response > instance ( Tomcat implementation), but will buffer response output as > string rather than write it to output stream. > > Gennady. > > -----Original Message----- > From: Mikolaj Rydzewski [mailto:miki@ceti.pl] > Sent: Friday, January 04, 2008 10:15 > To: Tomcat Users List > Subject: Re: Avoiding same server to server HTTP calls to generate HTML > pages via JSPs > > > Adam Gordon wrote: > > Right now we basically have a URL dispatcher that when a specific > > request comes in, we make another request to retrieve the contents of > > a URI (a JSP page to generate HTML) via a server-to-server HTTP call > > and then essentially slap that into a MimeBodyPart for sending > > text/html email messages. > Simply do not use JSP. Use Velocity for example. > > -- > Mikolaj Rydzewski > > > > > --------------------------------------------------------------------- > To start a new topic, e-mail: users@tomcat.apache.org > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org > For additional commands, e-mail: users-help@tomcat.apache.org > > --------------------------------------------------------------------- To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org For additional commands, e-mail: users-help@tomcat.apache.org