From ebbc3d82ab8eeec363d26258c2fefb832ce912be Mon Sep 17 00:00:00 2001 From: Scott Andrews Date: Sat, 5 Apr 2008 00:19:04 +0000 Subject: [PATCH] always check that the response has not been committed before sending a redirect --- .../webflow/mvc/servlet/FlowController.java | 22 +++++++++++-------- .../mvc/servlet/FlowHandlerAdapter.java | 22 +++++++++++-------- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/spring-webflow/src/main/java/org/springframework/webflow/mvc/servlet/FlowController.java b/spring-webflow/src/main/java/org/springframework/webflow/mvc/servlet/FlowController.java index bd09162d..e3489a64 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/mvc/servlet/FlowController.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/mvc/servlet/FlowController.java @@ -173,22 +173,26 @@ public class FlowController extends AbstractController { protected ModelAndView defaultHandleFlowOutcome(String flowId, String outcome, AttributeMap endedOutput, HttpServletRequest request, HttpServletResponse response) throws IOException { - // by default, just start the flow over passing the output as input - if (logger.isDebugEnabled()) { - logger.debug("Restarting a new execution of ended flow '" + flowId + "'"); + if (!response.isCommitted()) { + // by default, just start the flow over passing the output as input + if (logger.isDebugEnabled()) { + logger.debug("Restarting a new execution of ended flow '" + flowId + "'"); + } + response.sendRedirect(urlHandler.createFlowDefinitionUrl(flowId, endedOutput, request)); } - response.sendRedirect(urlHandler.createFlowDefinitionUrl(flowId, endedOutput, request)); return null; } protected ModelAndView defaultHandleFlowException(String flowId, FlowException e, HttpServletRequest request, HttpServletResponse response) throws IOException { if (e instanceof NoSuchFlowExecutionException && flowId != null) { - // by default, attempt to restart the flow - if (logger.isDebugEnabled()) { - logger.debug("Restarting a new execution of previously expired/ended flow '" + flowId + "'"); + if (!response.isCommitted()) { + // by default, attempt to restart the flow + if (logger.isDebugEnabled()) { + logger.debug("Restarting a new execution of previously expired/ended flow '" + flowId + "'"); + } + response.sendRedirect(urlHandler.createFlowDefinitionUrl(flowId, null, request)); } - response.sendRedirect(urlHandler.createFlowDefinitionUrl(flowId, null, request)); return null; } else { throw e; @@ -246,7 +250,7 @@ public class FlowController extends AbstractController { String targetUrl) throws IOException { if (context.isAjaxRequest()) { ajaxHandler.sendAjaxRedirect(getServletContext(), request, response, targetUrl, context.redirectInPopup()); - } else { + } else if (!response.isCommitted()) { response.sendRedirect(response.encodeRedirectURL(targetUrl)); } } diff --git a/spring-webflow/src/main/java/org/springframework/webflow/mvc/servlet/FlowHandlerAdapter.java b/spring-webflow/src/main/java/org/springframework/webflow/mvc/servlet/FlowHandlerAdapter.java index 7ccfd6f1..f9c928c7 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/mvc/servlet/FlowHandlerAdapter.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/mvc/servlet/FlowHandlerAdapter.java @@ -160,22 +160,26 @@ public class FlowHandlerAdapter extends WebApplicationObjectSupport implements H protected ModelAndView defaultHandleFlowOutcome(String flowId, String outcome, AttributeMap endedOutput, HttpServletRequest request, HttpServletResponse response) throws IOException { - // by default, just start the flow over passing the output as input - if (logger.isDebugEnabled()) { - logger.debug("Restarting a new execution of ended flow '" + flowId + "'"); + if (!response.isCommitted()) { + // by default, just start the flow over passing the output as input + if (logger.isDebugEnabled()) { + logger.debug("Restarting a new execution of ended flow '" + flowId + "'"); + } + response.sendRedirect(urlHandler.createFlowDefinitionUrl(flowId, endedOutput, request)); } - response.sendRedirect(urlHandler.createFlowDefinitionUrl(flowId, endedOutput, request)); return null; } protected ModelAndView defaultHandleFlowException(String flowId, FlowException e, HttpServletRequest request, HttpServletResponse response) throws IOException { if (e instanceof NoSuchFlowExecutionException && flowId != null) { - if (logger.isDebugEnabled()) { - logger.debug("Restarting a new execution of previously expired/ended flow '" + flowId + "'"); + if (!response.isCommitted()) { + if (logger.isDebugEnabled()) { + logger.debug("Restarting a new execution of previously expired/ended flow '" + flowId + "'"); + } + // by default, attempt to restart the flow + response.sendRedirect(urlHandler.createFlowDefinitionUrl(flowId, null, request)); } - // by default, attempt to restart the flow - response.sendRedirect(urlHandler.createFlowDefinitionUrl(flowId, null, request)); return null; } else { throw e; @@ -234,7 +238,7 @@ public class FlowHandlerAdapter extends WebApplicationObjectSupport implements H String targetUrl) throws IOException { if (context.isAjaxRequest()) { ajaxHandler.sendAjaxRedirect(getServletContext(), request, response, targetUrl, context.isAjaxRequest()); - } else { + } else if (!response.isCommitted()) { response.sendRedirect(response.encodeRedirectURL(targetUrl)); } }