use of jakarta.servlet.MultipartConfigElement in project spring-framework by spring-projects.
the class RequestPartIntegrationTests method startServer.
@BeforeAll
public static void startServer() throws Exception {
// Let server pick its own random, available port.
server = new Server(0);
ServletContextHandler handler = new ServletContextHandler();
handler.setContextPath("/");
ServletHolder standardResolverServlet = new ServletHolder(DispatcherServlet.class);
standardResolverServlet.setInitParameter("contextConfigLocation", StandardMultipartResolverTestConfig.class.getName());
standardResolverServlet.setInitParameter("contextClass", AnnotationConfigWebApplicationContext.class.getName());
standardResolverServlet.getRegistration().setMultipartConfig(new MultipartConfigElement(""));
handler.addServlet(standardResolverServlet, "/standard-resolver/*");
server.setHandler(handler);
server.start();
Connector[] connectors = server.getConnectors();
NetworkConnector connector = (NetworkConnector) connectors[0];
baseUrl = "http://localhost:" + connector.getLocalPort();
}
use of jakarta.servlet.MultipartConfigElement in project spring-boot by spring-projects.
the class MultipartConfigFactoryTests method createWithNegativeDataSizes.
@Test
void createWithNegativeDataSizes() {
MultipartConfigFactory factory = new MultipartConfigFactory();
factory.setMaxFileSize(DataSize.ofBytes(-1));
factory.setMaxRequestSize(DataSize.ofKilobytes(-2));
factory.setFileSizeThreshold(DataSize.ofMegabytes(-3));
MultipartConfigElement config = factory.createMultipartConfig();
assertThat(config.getMaxFileSize()).isEqualTo(-1L);
assertThat(config.getMaxRequestSize()).isEqualTo(-1);
assertThat(config.getFileSizeThreshold()).isEqualTo(0);
}
use of jakarta.servlet.MultipartConfigElement in project spring-boot by spring-projects.
the class MultipartConfigFactoryTests method createWithDataSizes.
@Test
void createWithDataSizes() {
MultipartConfigFactory factory = new MultipartConfigFactory();
factory.setMaxFileSize(DataSize.ofBytes(1));
factory.setMaxRequestSize(DataSize.ofKilobytes(2));
factory.setFileSizeThreshold(DataSize.ofMegabytes(3));
MultipartConfigElement config = factory.createMultipartConfig();
assertThat(config.getMaxFileSize()).isEqualTo(1L);
assertThat(config.getMaxRequestSize()).isEqualTo(2 * 1024L);
assertThat(config.getFileSizeThreshold()).isEqualTo(3 * 1024 * 1024);
}
use of jakarta.servlet.MultipartConfigElement in project spring-boot by spring-projects.
the class MultipartAutoConfigurationTests method configureMultipartPropertiesWithRawLongValues.
@Test
void configureMultipartPropertiesWithRawLongValues() {
this.context = new AnnotationConfigServletWebServerApplicationContext();
TestPropertyValues.of("spring.servlet.multipart.max-file-size=512", "spring.servlet.multipart.max-request-size=2048").applyTo(this.context);
this.context.register(WebServerWithNothing.class, BaseConfiguration.class);
this.context.refresh();
MultipartConfigElement multipartConfigElement = this.context.getBean(MultipartConfigElement.class);
assertThat(multipartConfigElement.getMaxFileSize()).isEqualTo(512);
assertThat(multipartConfigElement.getMaxRequestSize()).isEqualTo(2048);
}
use of jakarta.servlet.MultipartConfigElement in project spring-boot by spring-projects.
the class MultipartAutoConfigurationTests method configureMultipartProperties.
@Test
void configureMultipartProperties() {
this.context = new AnnotationConfigServletWebServerApplicationContext();
TestPropertyValues.of("spring.servlet.multipart.max-file-size=2048KB", "spring.servlet.multipart.max-request-size=15MB").applyTo(this.context);
this.context.register(WebServerWithNothing.class, BaseConfiguration.class);
this.context.refresh();
MultipartConfigElement multipartConfigElement = this.context.getBean(MultipartConfigElement.class);
assertThat(multipartConfigElement.getMaxFileSize()).isEqualTo(2048 * 1024);
assertThat(multipartConfigElement.getMaxRequestSize()).isEqualTo(15 * 1024 * 1024);
}
Aggregations