I ended up parsing the request manually depending on the RequestType:
String contentType = getContentType();
if(contentType == null){
reader = request.getReader();
} else if (contentType.startsWith("multipart/")) {
getMultipartParameters();
} else if (contentType.startsWith("application/x-www-form-urlencoded")) {
getNameValueParameters();
} else {
reader = request.getReader();
}
If the type is something else, i get a reference to the request reader for parsing later.
If it's multipart, i parse it with Apache Commons FileUpload. If it's form-urlencoded, i parse a name-value string from the body.
private void getMultipartParameters(){
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
try {
for (FileItem fi : upload.parseRequest(request)) {
if(fi.isFormField()){
Funciones.putInArrayMap(POST, fi.getFieldName(), fi.getString());
} else {
Funciones.putInArrayMap(FILES, fi.getFieldName(), fi);
}
}
} catch(FileUploadException e){
Log.write(e);
}
}
_
private void getNameValueParameters(){
try {
StringBuilder sb = new StringBuilder();
BufferedReader br = request.getReader();
String line = br.readLine();
while(line != null){
sb.append(line);
line = br.readLine();
}
POST = Funciones.getQueryMap(sb.toString(), getCharset());
} catch (IOException ex) {
Log.write(ex);
}
}
_
private void getParameters(){
String qs = request.getQueryString();
GET = Funciones.getQueryMap(qs, getCharset());
}
In all cases, i parse the query string using the same name-value code.
All of that gets saved in these variables:
protected Map<String, List<String>> GET = new HashMap<>();
protected Map<String, List<String>> POST = new HashMap<>();
protected Map<String, List<FileItem>> FILES = new HashMap<>();
I'm still open to better ways of doing this.