if (query != null) {
for (Iterator<RequestParameter> i = Lexers.queryParser(query);i.hasNext();) {
if (requestParameters.isEmpty()) {
requestParameters = new HashMap<String, RequestParameter>();
}
RequestParameter parameter = i.next();
parameter.appendTo(requestParameters);
}
}
//
if ("POST".equals(req.getMethod())) {
String contentType = req.getContentType();
if (contentType != null && contentType.length() > 0) {
Spliterator i = new Spliterator(contentType, ';');
if ("application/x-www-form-urlencoded".equals(i.next().trim())) {
Charset charset = defaultEncoding;
while (i.hasNext()) {
String v = i.next().trim();
if (v.startsWith("charset=")) {
charset = Charset.forName(v.substring("charset=".length()));
}
}
try {
byte[] bytes = Tools.copy(req.getInputStream(), new ByteArrayOutputStream()).toByteArray();
String form = new String(bytes, charset);
FormURLEncodedParser parser = new FormURLEncodedParser(defaultEncoding, form, 0, form.length());
for (RequestParameter parameter : parser) {
if (requestParameters.isEmpty()) {
requestParameters = new HashMap<String, RequestParameter>();
}
parameter.appendTo(requestParameters);
}
}
catch (IOException e) {
log.error("Cannot parse form post", e);
}