Multipart Resolver
MultipartResolver from the infra.web.multipart package is a strategy
for parsing multipart requests including file uploads. There is a container-based
StandardServletMultipartResolver implementation for Servlet multipart request parsing.
Note that the outdated CommonsMultipartResolver based on Apache Commons FileUpload is
not available anymore, as of TODAY Framework 6.0 with its new Servlet 5.0+ baseline.
To enable multipart handling, you need to declare a MultipartResolver bean in your
MockDispatcher Infra configuration with a name of multipartResolver.
The MockDispatcher detects it and applies it to the incoming request. When a POST
with a content type of multipart/form-data is received, the resolver parses the
content wraps the current HttpMockRequest as a MultipartHttpServletRequest to
provide access to resolved files in addition to exposing parts as request parameters.
Servlet Multipart Parsing
Servlet multipart parsing needs to be enabled through Servlet container configuration. To do so:
-
In Java, set a
MultipartConfigElementon the Servlet registration. -
In
web.xml, add a"<multipart-config>"section to the mockApi declaration.
The following example shows how to set a MultipartConfigElement on the Servlet registration:
-
Java
public class AppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
// ...
@Override
protected void customizeRegistration(ServletRegistration.Dynamic registration) {
// Optionally also set maxFileSize, maxRequestSize, fileSizeThreshold
registration.setMultipartConfig(new MultipartConfigElement("/tmp"));
}
}
Once the Servlet multipart configuration is in place, you can add a bean of type
StandardServletMultipartResolver with a name of multipartResolver.
|
This resolver variant uses your Servlet container’s multipart parser as-is,
potentially exposing the application to container implementation differences.
By default, it will try to parse any |