Skip to content

Commit

Permalink
Merge pull request #16 from jpkrohling/JPK-PBR-570-HandleExceptionInR…
Browse files Browse the repository at this point in the history
…enderResponse

PBR-570 BZ1162145 - Added special handling for exceptions in RenderResponse phase
  • Loading branch information
kenfinnigan committed Nov 11, 2014
2 parents 42d0c62 + f49fa02 commit fc17795
Showing 1 changed file with 21 additions and 3 deletions.
Expand Up @@ -31,6 +31,7 @@
import javax.faces.context.FacesContext;
import javax.faces.event.ExceptionQueuedEvent;
import javax.faces.event.ExceptionQueuedEventContext;
import javax.faces.event.PhaseId;
import javax.servlet.ServletException;

import org.jboss.portletbridge.bridge.context.BridgeContext;
Expand Down Expand Up @@ -71,10 +72,27 @@ public void handle() throws FacesException {
String errorView = getErrorView(t, errorViews);
if (null != errorView) {
FacesContext fc = FacesContext.getCurrentInstance();
NavigationHandler nav = fc.getApplication().getNavigationHandler();
try {
nav.handleNavigation(fc, null, errorView);
fc.renderResponse();
if (fc.getCurrentPhaseId().equals(PhaseId.RENDER_RESPONSE)) {
// if we are already redirecting from this error
// to this error, just skip
// this would happen if there's an error on the
// errorView and would cause an infinite loop
if (!errorView.equals(bridgeContext.getRedirectViewId())) {
// browser has seen already some content, so, we can't
// reset the buffer/response
if (!fc.getExternalContext().isResponseCommitted()) {
fc.getExternalContext().responseReset();
fc.getExternalContext().setResponseBufferSize(-1);
}
bridgeContext.setRedirectViewId(errorView);
bridgeContext.setRenderRedirect(true);
}
} else {
NavigationHandler nav = fc.getApplication().getNavigationHandler();
nav.handleNavigation(fc, null, errorView);
fc.renderResponse();
}
} finally {
i.remove();
}
Expand Down

0 comments on commit fc17795

Please sign in to comment.