in wicket-core/src/main/java/org/apache/wicket/protocol/http/servlet/MultipartServletWebRequestImpl.java [142:236]
public void parseFileParts() throws FileUploadException
{
HttpServletRequest request = getContainerRequest();
// The encoding that will be used to decode the string parameters
// It should NOT be null at this point, but it may be
// especially if the older Servlet API 2.2 is used
String encoding = request.getCharacterEncoding();
// The encoding can also be null when using multipart/form-data encoded forms.
// In that case we use the [application-encoding] which we always demand using
// the attribute 'accept-encoding' in wicket forms.
if (encoding == null)
{
encoding = Application.get().getRequestCycleSettings().getResponseRequestEncoding();
}
AbstractFileUpload fileUpload = newFileUpload(encoding);
List<FileItem> items;
if (wantUploadProgressUpdates())
{
JakartaServletRequestContext ctx = new JakartaServletRequestContext(request)
{
@Override
public InputStream getInputStream() throws IOException
{
return new CountingInputStream(super.getInputStream());
}
};
totalBytes = request.getContentLength();
onUploadStarted(totalBytes);
try
{
items = fileUpload.parseRequest(ctx);
}
finally
{
onUploadCompleted();
}
}
else
{
// try to parse the file uploads by using Apache Commons FileUpload APIs
// because they are feature richer (e.g. progress updates, cleaner)
items = fileUpload.parseRequest(new JakartaServletRequestContext(request));
if (items.isEmpty())
{
// fallback to Servlet 3.0 APIs
items = readServlet3Parts(request);
}
}
// Loop through items
for (final FileItem item : items)
{
// Get next item
// If item is a form field
if (item.isFormField())
{
// Set parameter value
final String value;
if (encoding != null)
{
try
{
value = item.getString(Charset.forName(encoding));
}
catch (IOException e)
{
throw new WicketRuntimeException(e);
}
}
else
{
value = item.getString();
}
addParameter(item.getFieldName(), value);
}
else
{
List<FileItem> fileItems = files.get(item.getFieldName());
if (fileItems == null)
{
fileItems = new ArrayList<>();
files.put(item.getFieldName(), fileItems);
}
// Add to file list
fileItems.add(item);
}
}
}