use of io.undertow.server.handlers.form.MultiPartParserDefinition in project undertow by undertow-io.
the class ManagedServlet method setupMultipart.
public void setupMultipart(ServletContextImpl servletContext) {
FormEncodedDataDefinition formDataParser = new FormEncodedDataDefinition().setDefaultEncoding(servletContext.getDeployment().getDefaultCharset().name());
MultipartConfigElement multipartConfig = servletInfo.getMultipartConfig();
if (multipartConfig == null) {
multipartConfig = servletContext.getDeployment().getDeploymentInfo().getDefaultMultipartConfig();
}
this.multipartConfig = multipartConfig;
if (multipartConfig != null) {
//todo: fileSizeThreshold
MultipartConfigElement config = multipartConfig;
if (config.getMaxRequestSize() != -1) {
maxRequestSize = config.getMaxRequestSize();
} else {
maxRequestSize = -1;
}
final Path tempDir;
if (config.getLocation() == null || config.getLocation().isEmpty()) {
tempDir = servletContext.getDeployment().getDeploymentInfo().getTempPath();
} else {
String location = config.getLocation();
Path locFile = Paths.get(location);
if (locFile.isAbsolute()) {
tempDir = locFile;
} else {
tempDir = servletContext.getDeployment().getDeploymentInfo().getTempPath().resolve(location);
}
}
MultiPartParserDefinition multiPartParserDefinition = new MultiPartParserDefinition(tempDir);
if (config.getMaxFileSize() > 0) {
multiPartParserDefinition.setMaxIndividualFileSize(config.getMaxFileSize());
}
multiPartParserDefinition.setDefaultEncoding(servletContext.getDeployment().getDefaultCharset().name());
formParserFactory = FormParserFactory.builder(false).addParser(formDataParser).addParser(multiPartParserDefinition).build();
} else {
//no multipart config we don't allow multipart requests
formParserFactory = FormParserFactory.builder(false).addParser(formDataParser).build();
maxRequestSize = -1;
}
}
Aggregations