HttpServletResponseWrapper httpServletResponseWrapper = (HttpServletResponseWrapper) response;
ServletResponse wrappedServletResponse = httpServletResponseWrapper.getResponse();
if (wrappedServletResponse instanceof BridgeAfterViewContentResponse) {
BridgeAfterViewContentResponse bridgeAfterViewContentPreResponse = (BridgeAfterViewContentResponse)
wrappedServletResponse;
PortletResponse wrappedPortletResponse = bridgeAfterViewContentPreResponse.getWrapped();
BridgeWriteBehindSupportFactory bridgeWriteBehindSupportFactory = (BridgeWriteBehindSupportFactory)
FactoryExtensionFinder.getFactory(BridgeWriteBehindSupportFactory.class);
BridgeWriteBehindResponse bridgeWriteBehindResponse =
bridgeWriteBehindSupportFactory.getBridgeWriteBehindResponse((MimeResponse)
wrappedPortletResponse, facesImplementationServletResponse);
// Note: See comments in BridgeContextImpl#dispatch(String) regarding Liferay's inability to
// accept a wrapped response. This is indeed supported in Pluto.
this.portletResponse = (PortletResponse) bridgeWriteBehindResponse;
}
else {
// Since we're unable to determine the wrapped PortletResponse, the following line will throw an
// intentional ClassCastException. Note that this case should never happen.
this.portletResponse = (PortletResponse) response;
}
}
// Otherwise, the specified response is of type BridgeAfterViewContentResponse, then Mojarra's
// JspViewHandlingStrategy#executePageToBuildView(FacesContext, UIViewRoot) method is trying to restore the
// bridge's response object that it originally got from calling the ExternalContext#getResponse() method
// prior to wrapping with it's ViewHandlerResponseWrapper.
else if (response instanceof BridgeAfterViewContentResponse) {
BridgeAfterViewContentResponse bridgeAfterViewContentResponse = (BridgeAfterViewContentResponse)
response;
this.portletResponse = bridgeAfterViewContentResponse.getWrapped();
}
// Otherwise, assume that the specified response is a PortletResponse.
else {
this.portletResponse = (PortletResponse) response;