String uid = httpRequest.getParameter(UPLOAD_FILES_ID);
if (uid != null) {
if (isMultipartRequest(httpRequest)) {
MultipartRequest multipartRequest = new MultipartRequest(httpRequest, createTempFiles, maxRequestSize, uid);
Map<String, MultipartRequest> sessionsMap = null;
Map<String, Object> percentMap = null;
try {
if (isFileSizeRestricted(request, maxRequestSize)) {
boolean sendError = Boolean.parseBoolean(request.getParameter(SEND_HTTP_ERROR));
if (sendError) {
response.sendError(HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE);
System.err.println("ERROR " + HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE + "request entity is larger than the server is willing or able to process.");
return;
} else {
printResponse(response, "<html id=\"_richfaces_file_upload_size_restricted\"></html>");
}
} else if (!checkFileCount(httpRequest)) {
printResponse(response, "<html id=\"_richfaces_file_upload_forbidden\"></html>");
} else {
HttpSession session = httpRequest.getSession();
synchronized (session) {
sessionsMap = (Map<String, MultipartRequest>) session.getAttribute(REQUESTS_SESSIONS_BEAN_NAME);
percentMap = (Map<String, Object>) session.getAttribute(PERCENT_BEAN_NAME);
if (sessionsMap == null) {
sessionsMap = Collections.synchronizedMap(new HashMap<String, MultipartRequest>());
session.setAttribute(REQUESTS_SESSIONS_BEAN_NAME, sessionsMap);
}
if (percentMap == null) {
percentMap = new HashMap<String, Object>();
session.setAttribute(PERCENT_BEAN_NAME, percentMap);
}
}
/* associate percent value with file entry uid */
percentMap.put(uid, 0);
sessionsMap.put(uid, multipartRequest);
if (multipartRequest.parseRequest()) {
handleRequest(multipartRequest, multipartRequest.isFormUpload() ? response :
new HttpServletResponseWrapper(response){
@Override
public void setContentType(String type) {
super.setContentType(BaseXMLFilter.TEXT_HTML + ";charset=UTF-8");
}
}, chain);
} else {
printResponse(response, "<html id=\"_richfaces_file_upload_stopped\"></html>");
}
}
} finally {
if (sessionsMap != null) {
sessionsMap.remove(uid);
percentMap.remove(uid);
}
}
} else {
if ("richfaces_file_upload_action_stop".equals(httpRequest.getParameter("action"))) {
HttpSession session = httpRequest.getSession();
Map<String, MultipartRequest> sessions = (Map<String, MultipartRequest>) session.getAttribute(REQUESTS_SESSIONS_BEAN_NAME);
if (sessions != null) {
MultipartRequest multipartRequest = sessions.get(uid);
if (multipartRequest != null) {
multipartRequest.stop();
}
handleRequest(request, response, chain);
}
} else {