HttpServletResponse httpResponse = (HttpServletResponse) response;
HttpServletRequest httpRequest = (HttpServletRequest) request;
// Serve resources
AddResource addResource;
try
{
addResource = AddResourceFactory.getInstance(httpRequest,_servletContext);
if( addResource.isResourceUri(_servletContext, httpRequest ) ){
addResource.serveResource(_servletContext, httpRequest, httpResponse);
return;
}
}
catch(Throwable th)
{
log.error("Exception wile retrieving addResource",th);
throw new ServletException(th);
}
HttpServletRequest extendedRequest = httpRequest;
// For multipart/form-data requests
// This is done by TomahawkFacesContextWrapper
if (ServletFileUpload.isMultipartContent(httpRequest)) {
extendedRequest = new MultipartRequestWrapper(httpRequest, _uploadMaxFileSize,
_uploadThresholdSize, _uploadRepositoryPath, _uploadMaxSize, _cacheFileSizeErrors);
}
try
{
addResource.responseStarted();
//This case is necessary when is used
//org.apache.myfaces.renderkit.html.util.DefaultAddResource
//Buffers the output and add to the header the necessary stuff
//In other case this is simply ignored (NonBufferingAddResource and
//StreamingAddResource), because this not require buffering
//and the chaining continues.
if (addResource.requiresBuffer())
{
ExtensionsResponseWrapper extendedResponse = new ExtensionsResponseWrapper((HttpServletResponse) response);
// Standard request
chain.doFilter(extendedRequest, extendedResponse);
extendedResponse.finishResponse();
// write the javascript stuff for myfaces and headerInfo, if needed
HttpServletResponse servletResponse = (HttpServletResponse)response;
// only parse HTML responses
if (extendedResponse.getContentType() != null && isValidContentType(extendedResponse.getContentType()))
{
addResource.parseResponse(extendedRequest, extendedResponse.toString(),
servletResponse);
addResource.writeMyFacesJavascriptBeforeBodyEnd(extendedRequest,
servletResponse);
if( ! addResource.hasHeaderBeginInfos() ){
// writes the response if no header info is needed
addResource.writeResponse(extendedRequest, servletResponse);
return;
}
// Some headerInfo has to be added
addResource.writeWithFullHeader(extendedRequest, servletResponse);
// writes the response
addResource.writeResponse(extendedRequest, servletResponse);
}
else
{
byte[] responseArray = extendedResponse.getBytes();
if(responseArray.length > 0)
{
// When not filtering due to not valid content-type, deliver the byte-array instead of a charset-converted string.
// Otherwise a binary stream gets corrupted.
servletResponse.getOutputStream().write(responseArray);
}
}
}
else
{
chain.doFilter(extendedRequest, response);
}
}
finally
{
addResource.responseFinished();
}
//chain.doFilter(extendedRequest, response);
}