Search in sources :

Example 1 with MultipartConfigElement

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();
}
Also used : NetworkConnector(org.eclipse.jetty.server.NetworkConnector) Connector(org.eclipse.jetty.server.Connector) MultipartConfigElement(jakarta.servlet.MultipartConfigElement) Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) NetworkConnector(org.eclipse.jetty.server.NetworkConnector) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 2 with MultipartConfigElement

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);
}
Also used : MultipartConfigElement(jakarta.servlet.MultipartConfigElement) Test(org.junit.jupiter.api.Test)

Example 3 with MultipartConfigElement

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);
}
Also used : MultipartConfigElement(jakarta.servlet.MultipartConfigElement) Test(org.junit.jupiter.api.Test)

Example 4 with MultipartConfigElement

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);
}
Also used : MultipartConfigElement(jakarta.servlet.MultipartConfigElement) AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) Test(org.junit.jupiter.api.Test)

Example 5 with MultipartConfigElement

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);
}
Also used : MultipartConfigElement(jakarta.servlet.MultipartConfigElement) AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) Test(org.junit.jupiter.api.Test)

Aggregations

MultipartConfigElement (jakarta.servlet.MultipartConfigElement)19 StandardWrapper (org.apache.catalina.core.StandardWrapper)6 MultipartDef (org.apache.tomcat.util.descriptor.web.MultipartDef)6 Test (org.junit.Test)6 Test (org.junit.jupiter.api.Test)6 ServletException (jakarta.servlet.ServletException)3 AnnotationConfigServletWebServerApplicationContext (org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext)3 ServletContext (jakarta.servlet.ServletContext)2 File (java.io.File)2 IOException (java.io.IOException)2 Connector (org.eclipse.jetty.server.Connector)2 NetworkConnector (org.eclipse.jetty.server.NetworkConnector)2 Server (org.eclipse.jetty.server.Server)2 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)2 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)2 BeforeAll (org.junit.jupiter.api.BeforeAll)2 AsyncContext (jakarta.servlet.AsyncContext)1 Servlet (jakarta.servlet.Servlet)1 Dynamic (jakarta.servlet.ServletRegistration.Dynamic)1 SessionCookieConfig (jakarta.servlet.SessionCookieConfig)1