use of org.apache.struts.upload.MultipartRequestWrapper in project cu-kfs by CU-CommunityApps.
the class WebUtils method getFileParametersForMultipartRequest.
private static Map getFileParametersForMultipartRequest(HttpServletRequest request, MultipartRequestHandler multipartHandler) {
Map parameters = new HashMap();
Hashtable elements = multipartHandler.getFileElements();
Enumeration e = elements.keys();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
parameters.put(key, elements.get(key));
}
if (request instanceof MultipartRequestWrapper) {
request = (HttpServletRequest) ((MultipartRequestWrapper) request).getRequest();
e = request.getParameterNames();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
parameters.put(key, request.getParameterValues(key));
}
} else {
LOG.debug("Gathering multipart parameters for unwrapped request");
}
return parameters;
}
use of org.apache.struts.upload.MultipartRequestWrapper in project sonarqube by SonarSource.
the class RequestUtils method getAllParametersForMultipartRequest.
/**
* <p>Create a <code>Map</code> containing all of the parameters supplied
* for a multipart request, keyed by parameter name. In addition to text
* and file elements from the multipart body, query string parameters are
* included as well.</p>
*
* @param request The (wrapped) HTTP request whose parameters are
* to be added to the map.
* @param multipartHandler The multipart handler used to parse the
* request.
* @return the map containing all parameters for this multipart request.
*/
private static Map getAllParametersForMultipartRequest(HttpServletRequest request, MultipartRequestHandler multipartHandler) {
Map parameters = new HashMap();
Hashtable elements = multipartHandler.getAllElements();
Enumeration e = elements.keys();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
parameters.put(key, elements.get(key));
}
if (request instanceof MultipartRequestWrapper) {
request = (HttpServletRequest) ((MultipartRequestWrapper) request).getRequest();
e = request.getParameterNames();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
parameters.put(key, request.getParameterValues(key));
}
} else {
log.debug("Gathering multipart parameters for unwrapped request");
}
return parameters;
}
use of org.apache.struts.upload.MultipartRequestWrapper in project jaffa-framework by jaffa-projects.
the class CustomRequestProcessor method getAllParametersForMultipartRequest.
/**
*<p>Create a <code>Map</code> containing all of the parameters supplied for a multipart
* request, keyed by parameter name. In addition to text and file elements
* from the multipart body, query string parameters are included as well.</p>
*
* @param request The (wrapped) HTTP request whose parameters are to be
* added to the map.
* @param multipartHandler The multipart handler used to parse the request.
*
* @return the map containing all parameters for this multipart request.
*/
private static Map getAllParametersForMultipartRequest(HttpServletRequest request, MultipartRequestHandler multipartHandler) {
Map parameters = new HashMap();
Hashtable elements = multipartHandler.getAllElements();
Enumeration e = elements.keys();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
parameters.put(key, elements.get(key));
}
if (request instanceof MultipartRequestWrapper) {
request = ((MultipartRequestWrapper) request).getRequest();
e = request.getParameterNames();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
parameters.put(key, request.getParameterValues(key));
}
} else {
log.debug("Gathering multipart parameters for unwrapped request");
}
return parameters;
}
use of org.apache.struts.upload.MultipartRequestWrapper in project sonar-java by SonarSource.
the class RequestUtils method getAllParametersForMultipartRequest.
/**
* <p>Create a <code>Map</code> containing all of the parameters supplied
* for a multipart request, keyed by parameter name. In addition to text
* and file elements from the multipart body, query string parameters are
* included as well.</p>
*
* @param request The (wrapped) HTTP request whose parameters are
* to be added to the map.
* @param multipartHandler The multipart handler used to parse the
* request.
* @return the map containing all parameters for this multipart request.
*/
private static Map getAllParametersForMultipartRequest(HttpServletRequest request, MultipartRequestHandler multipartHandler) {
Map parameters = new HashMap();
Hashtable elements = multipartHandler.getAllElements();
Enumeration e = elements.keys();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
parameters.put(key, elements.get(key));
}
if (request instanceof MultipartRequestWrapper) {
request = (HttpServletRequest) ((MultipartRequestWrapper) request).getRequest();
e = request.getParameterNames();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
parameters.put(key, request.getParameterValues(key));
}
} else {
log.debug("Gathering multipart parameters for unwrapped request");
}
return parameters;
}
use of org.apache.struts.upload.MultipartRequestWrapper in project xwiki-platform by xwiki.
the class Utils method handleMultipart.
/**
* Process a multi-part request, extracting all the uploaded files.
*
* @param request the current request to process
* @param context the current context
* @return the instance of the {@link FileUploadPlugin} used to parse the uploaded files
*/
public static FileUploadPlugin handleMultipart(HttpServletRequest request, XWikiContext context) {
FileUploadPlugin fileupload = null;
try {
if (request instanceof MultipartRequestWrapper) {
fileupload = new FileUploadPlugin("fileupload", "fileupload", context);
context.put("fileuploadplugin", fileupload);
fileupload.loadFileList(context);
MultipartRequestWrapper mpreq = (MultipartRequestWrapper) request;
List<FileItem> fileItems = fileupload.getFileItems(context);
for (FileItem item : fileItems) {
if (item.isFormField()) {
String sName = item.getFieldName();
String sValue = item.getString(context.getWiki().getEncoding());
mpreq.setParameter(sName, sValue);
}
}
}
} catch (Exception e) {
if ((e instanceof XWikiException) && (((XWikiException) e).getCode() == XWikiException.ERROR_XWIKI_APP_FILE_EXCEPTION_MAXSIZE)) {
context.put("exception", e);
} else {
LOGGER.error("Failed to process MultiPart request", e);
}
}
return fileupload;
}
Aggregations