public void doFilter(ServletRequest request,
ServletResponse response,
FilterChain chain) throws IOException, ServletException {
//Execute the filter services
if (!_filters.isEmpty())
chain = new FilterListChain(_filters, chain);
// 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);
if(addedParams != null)
{
FileUploadConfiguratorImpl.apply(externalContext);
request = new UploadRequestWrapper((HttpServletRequest)request, addedParams);
}
try
{
_doFilterImpl(request, response, chain);
}
// For PPR errors, handle the request specially
catch (Throwable t)
{
boolean isPartialRequest;
if (addedParams != null)
{
isPartialRequest = CoreRenderKit.isPartialRequest(addedParams);
}
else
{
isPartialRequest = CoreRenderKit.isPartialRequest(externalContext);
}
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);
}
}
|