// multipart form upload
ServletFileUpload up = new ServletFileUpload();
up.setFileItemFactory(new DiskFileItemFactory());
// treat regular form fields as additional kvp parameters
Map<String,FileItem> kvpFileItems = new CaseInsensitiveMap(new LinkedHashMap());
try {
for (FileItem item : (List<FileItem>) up.parseRequest(httpRequest)) {
if (item.isFormField()) {
kvpFileItems.put(item.getFieldName(), item);
}
else {
request.setInput(fileItemReader(item));
}
}
} catch (Exception e) {
throw new ServiceException("Error handling multipart/form-data content", e);
}
// if no file fields were found, look for one named "body"
if (request.getInput() == null) {
FileItem body = kvpFileItems.get("body");
if (body != null) {
request.setInput(fileItemReader(body));
kvpFileItems.remove("body");
}
}
Map<String,String> kvpItems = new LinkedHashMap();
for (Map.Entry<String,FileItem> e : kvpFileItems.entrySet()) {
kvpItems.put(e.getKey(), e.getValue().toString());
}
request.setOrAppendKvp(parseKVP(request, kvpFileItems));
}