From dd9d9df6903ac325326893517e00ea6848778014 Mon Sep 17 00:00:00 2001 From: mdb Date: Mon, 24 Sep 2007 16:42:37 +0000 Subject: [PATCH] Catch IOException when writing our response so that we don't freak out if the client ungracefully stops listening to us. git-svn-id: https://samskivert.googlecode.com/svn/trunk@2227 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../samskivert/velocity/DispatcherServlet.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/java/com/samskivert/velocity/DispatcherServlet.java b/src/java/com/samskivert/velocity/DispatcherServlet.java index 26bb4f5f..af390bc1 100644 --- a/src/java/com/samskivert/velocity/DispatcherServlet.java +++ b/src/java/com/samskivert/velocity/DispatcherServlet.java @@ -448,14 +448,14 @@ public class DispatcherServlet extends HttpServlet protected void doRequest (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - Context context = null; + InvocationContext context = null; try { context = new InvocationContext(request, response); setContentType(request, response); Template template = handleRequest(request, response, context); if (template != null) { - mergeTemplate(template, context, response); + mergeTemplate(template, context); } } catch (Exception e) { @@ -524,12 +524,12 @@ public class DispatcherServlet extends HttpServlet * * @param template template object returned by the {@link #handleRequest} method. * @param context context created by the {@link #createContext} method. - * @param response servlet reponse (use this to get the output stream or writer). */ - protected void mergeTemplate (Template template, Context context, HttpServletResponse response) + protected void mergeTemplate (Template template, InvocationContext context) throws ResourceNotFoundException, ParseErrorException, MethodInvocationException, - IOException, UnsupportedEncodingException, Exception + UnsupportedEncodingException, IOException, Exception { + HttpServletResponse response = context.getResponse(); ServletOutputStream output = response.getOutputStream(); // ASSUMPTION: response.setContentType() has been called. String encoding = response.getCharacterEncoding(); @@ -544,6 +544,11 @@ public class DispatcherServlet extends HttpServlet } template.merge(context, vw); + } catch (IOException ioe) { + // the client probably crashed or aborted the connection ungracefully, so use log.info + log.info("Failed to write response [uri=" + context.getRequest().getRequestURI() + + ", error=" + ioe + "]"); + } finally { if (vw != null) { try {