{
HashMapImpl<String,String[]> form = _request.getForm();
try {
String query = getQueryString();
CharSegment contentType = _request.getContentTypeBuffer();
if (query == null && contentType == null)
return form;
Form formParser = _request.getFormParser();
long contentLength = _request.getLongContentLength();
String charEncoding = getCharacterEncoding();
if (charEncoding == null) {
charEncoding = (String) getAttribute(CAUCHO_CHAR_ENCODING);
if (charEncoding == null)
charEncoding = (String) getAttribute(CHAR_ENCODING);
if (charEncoding == null) {
Locale locale = (Locale) getAttribute(FORM_LOCALE);
if (locale != null)
charEncoding = Encoding.getMimeName(locale);
}
}
if (query != null) {
String queryEncoding = charEncoding;
if (queryEncoding == null && getServer() != null)
queryEncoding = getServer().getURLCharacterEncoding();
if (queryEncoding == null)
queryEncoding = CharacterEncoding.getLocalEncoding();
String javaEncoding = Encoding.getJavaName(queryEncoding);
formParser.parseQueryString(form, query, javaEncoding, true);
}
if (charEncoding == null)
charEncoding = CharacterEncoding.getLocalEncoding();
String javaEncoding = Encoding.getJavaName(charEncoding);
if (contentType == null || ! "POST".equalsIgnoreCase(getMethod())) {
}
else if (contentType.startsWith("application/x-www-form-urlencoded")) {
formParser.parsePostData(form, getInputStream(), javaEncoding);
}
else if (getWebApp().doMultipartForm()
&& contentType.startsWith("multipart/form-data")) {
int length = contentType.length();
int i = contentType.indexOf("boundary=");
if (i < 0)
return form;
long formUploadMax = getWebApp().getFormUploadMax();
Object uploadMax = getAttribute("caucho.multipart.form.upload-max");
if (uploadMax instanceof Number)
formUploadMax = ((Number) uploadMax).longValue();
// XXX: should this be an error?
if (formUploadMax >= 0 && formUploadMax < contentLength) {
setAttribute("caucho.multipart.form.error",
L.l("Multipart form upload of '{0}' bytes was too large.",
String.valueOf(contentLength)));
setAttribute("caucho.multipart.form.error.size",
new Long(contentLength));
return form;
}
MultipartConfigElement multipartConfig
= _invocation.getMultipartConfig();
long fileUploadMax = -1;
if (multipartConfig != null) {
formUploadMax = multipartConfig.getMaxRequestSize();
fileUploadMax = multipartConfig.getMaxFileSize();
}
if (multipartConfig != null
&& formUploadMax > 0
&& formUploadMax < contentLength)
throw new IllegalStateException(L.l(
"multipart form data request's Content-Length '{0}' is greater then configured in @MultipartConfig.maxRequestSize value: '{1}'",
contentLength,
formUploadMax));
i += "boundary=".length();
char ch = contentType.charAt(i);
CharBuffer boundary = new CharBuffer();
if (ch == '\'') {
for (i++; i < length && contentType.charAt(i) != '\''; i++)
boundary.append(contentType.charAt(i));
}
else if (ch == '\"') {
for (i++; i < length && contentType.charAt(i) != '\"'; i++)
boundary.append(contentType.charAt(i));
}
else {
for (;
i < length && (ch = contentType.charAt(i)) != ' ' &&
ch != ';';
i++) {
boundary.append(ch);
}
}