Skip to content
Snippets Groups Projects
Commit 59736f1c authored by Rick Herrick's avatar Rick Herrick
Browse files

Added support for multipart form resolver, as well as the multipart...

Added support for multipart form resolver, as well as the multipart configuration for the DispatcherServlet.
parent e3fcf3a4
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,8 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.support.StandardServletMultipartResolver;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
......@@ -33,6 +35,11 @@ public class WebConfig extends WebMvcConfigurerAdapter {
.addResourceLocations("classpath:/META-INF/resources/webjars/");
}
@Bean
public MultipartResolver multipartResolver() {
return new StandardServletMultipartResolver();
}
@Bean
public ViewResolver viewResolver() {
return new InternalResourceViewResolver() {{
......
......@@ -5,6 +5,7 @@ import org.apache.axis.transport.http.AxisHTTPSessionListener;
import org.apache.axis.transport.http.AxisServlet;
import org.apache.commons.lang3.StringUtils;
import org.apache.turbine.Turbine;
import org.nrg.framework.exceptions.NrgServiceRuntimeException;
import org.nrg.framework.processors.XnatModuleBean;
import org.nrg.xdat.servlet.XDATAjaxServlet;
import org.nrg.xdat.servlet.XDATServlet;
......@@ -21,6 +22,9 @@ import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatche
import javax.servlet.*;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
public class XnatWebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
......@@ -74,6 +78,35 @@ public class XnatWebAppInitializer extends AbstractAnnotationConfigDispatcherSer
return new Class<?>[0];
}
@Override
protected void customizeRegistration(ServletRegistration.Dynamic registration) {
registration.setMultipartConfig(getMultipartConfigElement());
}
private MultipartConfigElement getMultipartConfigElement() {
final String temp;
if (StringUtils.isNotBlank(System.getProperty("xnat.home"))) {
temp = System.getProperty("xnat.home");
} else {
temp = System.getProperty("java.io.tmpdir");
}
final String prefix = "xnat_" + Long.toString(System.nanoTime());
try {
final Path path = Paths.get(temp);
path.toFile().mkdirs();
final Path tmpDir = Files.createTempDirectory(path, prefix);
return new MultipartConfigElement(tmpDir.toAbsolutePath().toString(), MAX_FILE_SIZE, MAX_REQUEST_SIZE, FILE_SIZE_THRESHOLD);
} catch (IOException e) {
throw new NrgServiceRuntimeException("An error occurred trying to create the temp folder " + prefix + " in the containing folder "+ temp);
}
}
private static final long MAX_FILE_SIZE = 1048576 * 20; // 20 MB max file size.
private static final long MAX_REQUEST_SIZE = 20971520; // 20MB max request size.
private static final int FILE_SIZE_THRESHOLD = 0; // Threshold turned off.
private List<Class<?>> getModuleConfigs() {
final List<Class<?>> moduleConfigs = new ArrayList<>();
try {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment