// Set a flag so that we can detect if the filter has been
// properly installed.
request.setAttribute(_FILTER_EXECUTED_KEY, Boolean.TRUE);
ExternalContext externalContext = new ServletExternalContext(_servletContext, request, response);
GlobalConfiguratorImpl config = GlobalConfiguratorImpl.getInstance();
config.beginRequest(externalContext);
//To maintain backward compatibilty, wrap the request at the filter level
Map<String, String[]> addedParams = FileUploadConfiguratorImpl.getAddedParameters(externalContext);
boolean isPartialRequest;
if(addedParams != null)
{
FileUploadConfiguratorImpl.apply(externalContext);
request = new UploadRequestWrapper((HttpServletRequest)request, addedParams);
isPartialRequest = CoreRenderKit.isPartialRequest(addedParams);
}
else
{
// Only test for AJAX request, since file uploads *should* be
// handled by the above test. NOTE: this will not necessarily
// work if someone is using Trinidad PPR with non-Trinidad
// file upload! I've no idea currently how to cleanly handle
// that combination in JSF 1.1. We don't want to ask if
// its a partial request here, as this requires getting a
// query parameter, but that could block setting
// the character set later in the request in some app servers!
isPartialRequest = CoreRenderKit.isAjaxRequest(externalContext);
if (isPartialRequest)
{
request = XmlHttpConfigurator.getAjaxServletRequest(request);
}
}
if (isPartialRequest)
{
XmlHttpConfigurator.beginRequest(externalContext);
response = XmlHttpConfigurator.getWrappedServletResponse(response);
}
try
{
_doFilterImpl(request, response, chain);
}
catch (Throwable t)
{
if (isPartialRequest)
{
XmlHttpConfigurator.handleError(externalContext, t);
}
else
{
// For non-partial requests, just re-throw. It is not
// our responsibility to catch these
if (t instanceof RuntimeException)
throw ((RuntimeException) t);
if (t instanceof Error)
throw ((Error) t);
if (t instanceof IOException)
throw ((IOException) t);
if (t instanceof ServletException)
throw ((ServletException) t);
// Should always be one of those four types to have
// gotten here.
_LOG.severe(t);
}
}
finally
{
config.endRequest(externalContext);
}
}