use of io.milton.servlet.upload.UploadListener in project lobcder by skoulouzis.
the class ServletRequest method parseRequestParameters.
@Override
public void parseRequestParameters(Map<String, String> params, Map<String, io.milton.http.FileItem> files) throws RequestParseException {
try {
if (isMultiPart()) {
log.trace("parseRequestParameters: isMultiPart");
UploadListener listener = new UploadListener();
MonitoredDiskFileItemFactory factory = new MonitoredDiskFileItemFactory(listener);
ServletFileUpload upload = new ServletFileUpload(factory);
List items = upload.parseRequest(request);
parseQueryString(params);
for (Object o : items) {
FileItem item = (FileItem) o;
if (item.isFormField()) {
params.put(item.getFieldName(), item.getString());
} else {
// See http://jira.ettrema.com:8080/browse/MIL-118 - ServletRequest#parseRequestParameters overwrites multiple file uploads when using input type="file" multiple="multiple"
String itemKey = item.getFieldName();
if (files.containsKey(itemKey)) {
int count = 1;
while (files.containsKey(itemKey + count)) {
count++;
}
itemKey = itemKey + count;
}
files.put(itemKey, new FileItemWrapper(item));
}
}
} else {
for (Enumeration en = request.getParameterNames(); en.hasMoreElements(); ) {
String nm = (String) en.nextElement();
String[] vals = request.getParameterValues(nm);
if (vals.length == 1) {
params.put(nm, vals[0]);
} else {
StringBuilder sb = new StringBuilder();
for (String s : vals) {
sb.append(s).append(",");
}
if (sb.length() > 0) {
// remove last comma
sb.deleteCharAt(sb.length() - 1);
}
params.put(nm, sb.toString());
}
}
}
} catch (FileUploadException ex) {
throw new RequestParseException("FileUploadException", ex);
} catch (Throwable ex) {
throw new RequestParseException(ex.getMessage(), ex);
}
}
Aggregations