upload.setSizeMax(maxSize);
FileItemIterator iterator = upload.getItemIterator(request);
while (iterator.hasNext()) {
FileItemStream itemStream = iterator.next();
InputStream in = itemStream.openStream();
if (LOG.isDebugEnabled())
LOG.debug("Found item " + itemStream.getFieldName());
if (itemStream.isFormField()) {
LOG.debug("Item is a normal form field");
List<String> values;
if (params.get(itemStream.getFieldName()) != null) {
values = params.get(itemStream.getFieldName());
} else {
values = new ArrayList<String>();
}
values.add(IOUtils.toString(in, "ISO-8859-1"));
params.put(itemStream.getFieldName(), values);
} else {
LOG.debug("Item is a file upload");
// Skip file uploads that don't have a file name - meaning
// that no file was selected.
if (itemStream.getName() == null
|| itemStream.getName().trim().length() < 1) {
LOG.debug("No file has been uploaded for the field: "
+ itemStream.getFieldName());
continue;
}
List<FileItemStream> values;
List<String> fileValues;
if (files.get(itemStream.getFieldName()) != null) {
values = files.get(itemStream.getFieldName());
fileValues = fileContents
.get(itemStream.getFieldName());
} else {
values = new ArrayList<FileItemStream>();
fileValues = new ArrayList<String>();
}
values.add(itemStream);
fileValues.add(IOUtils.toString(itemStream.openStream(),
"ISO-8859-1"));
files.put(itemStream.getFieldName(), values);
fileContents.put(itemStream.getFieldName(), fileValues);
}
}
} catch (FileUploadException e) {
LOG.error("Unable to parse request", e);
errors.add(e.getMessage());