always check that the response has not been committed before sending a redirect

This commit is contained in:
Scott Andrews
2008-04-05 00:19:04 +00:00
parent 4751dcfca4
commit ebbc3d82ab
2 changed files with 26 additions and 18 deletions

View File

@@ -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));
}
}

View File

@@ -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));
}
}