Search in sources :

Example 46 with MultipartConfigElement

use of javax.servlet.MultipartConfigElement in project spring-framework by spring-projects.

the class WebRequestDataBinderIntegrationTests method startJettyServer.

@BeforeClass
public static void startJettyServer() throws Exception {
    // Let server pick its own random, available port.
    jettyServer = new Server(0);
    ServletContextHandler handler = new ServletContextHandler();
    MultipartConfigElement multipartConfig = new MultipartConfigElement("");
    ServletHolder holder = new ServletHolder(partsServlet);
    holder.getRegistration().setMultipartConfig(multipartConfig);
    handler.addServlet(holder, "/parts");
    holder = new ServletHolder(partListServlet);
    holder.getRegistration().setMultipartConfig(multipartConfig);
    handler.addServlet(holder, "/partlist");
    jettyServer.setHandler(handler);
    jettyServer.start();
    Connector[] connectors = jettyServer.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(javax.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) BeforeClass(org.junit.BeforeClass)

Example 47 with MultipartConfigElement

use of javax.servlet.MultipartConfigElement in project spring-boot by spring-projects.

the class MultipartConfigFactoryTests method sensibleDefaults.

@Test
public void sensibleDefaults() {
    MultipartConfigFactory factory = new MultipartConfigFactory();
    MultipartConfigElement config = factory.createMultipartConfig();
    assertThat(config.getLocation()).isEqualTo("");
    assertThat(config.getMaxFileSize()).isEqualTo(-1L);
    assertThat(config.getMaxRequestSize()).isEqualTo(-1L);
    assertThat(config.getFileSizeThreshold()).isEqualTo(0);
}
Also used : MultipartConfigElement(javax.servlet.MultipartConfigElement) Test(org.junit.Test)

Example 48 with MultipartConfigElement

use of javax.servlet.MultipartConfigElement in project spring-boot by spring-projects.

the class MultipartConfigFactoryTests method createWithStringSizes.

@Test
public void createWithStringSizes() throws Exception {
    MultipartConfigFactory factory = new MultipartConfigFactory();
    factory.setMaxFileSize("1");
    factory.setMaxRequestSize("2kB");
    factory.setFileSizeThreshold("3Mb");
    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(javax.servlet.MultipartConfigElement) Test(org.junit.Test)

Example 49 with MultipartConfigElement

use of javax.servlet.MultipartConfigElement in project spring-boot by spring-projects.

the class MultipartConfigFactoryTests method create.

@Test
public void create() throws Exception {
    MultipartConfigFactory factory = new MultipartConfigFactory();
    factory.setLocation("loc");
    factory.setMaxFileSize(1);
    factory.setMaxRequestSize(2);
    factory.setFileSizeThreshold(3);
    MultipartConfigElement config = factory.createMultipartConfig();
    assertThat(config.getLocation()).isEqualTo("loc");
    assertThat(config.getMaxFileSize()).isEqualTo(1L);
    assertThat(config.getMaxRequestSize()).isEqualTo(2L);
    assertThat(config.getFileSizeThreshold()).isEqualTo(3);
}
Also used : MultipartConfigElement(javax.servlet.MultipartConfigElement) Test(org.junit.Test)

Example 50 with MultipartConfigElement

use of javax.servlet.MultipartConfigElement in project spring-boot by spring-projects.

the class ServletContextInitializerBeans method addAdaptableBeans.

@SuppressWarnings("unchecked")
private void addAdaptableBeans(ListableBeanFactory beanFactory) {
    MultipartConfigElement multipartConfig = getMultipartConfig(beanFactory);
    addAsRegistrationBean(beanFactory, Servlet.class, new ServletRegistrationBeanAdapter(multipartConfig));
    addAsRegistrationBean(beanFactory, Filter.class, new FilterRegistrationBeanAdapter());
    for (Class<?> listenerType : ServletListenerRegistrationBean.getSupportedTypes()) {
        addAsRegistrationBean(beanFactory, EventListener.class, (Class<EventListener>) listenerType, new ServletListenerRegistrationBeanAdapter());
    }
}
Also used : MultipartConfigElement(javax.servlet.MultipartConfigElement) EventListener(java.util.EventListener)

Aggregations

MultipartConfigElement (javax.servlet.MultipartConfigElement)51 Test (org.junit.Test)35 ByteArrayInputStream (java.io.ByteArrayInputStream)30 Part (javax.servlet.http.Part)27 MultiPart (org.eclipse.jetty.util.MultiPartInputStreamParser.MultiPart)24 ByteArrayOutputStream (java.io.ByteArrayOutputStream)13 IOException (java.io.IOException)8 File (java.io.File)7 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)5 ServletException (javax.servlet.ServletException)4 ServletInputStream (javax.servlet.ServletInputStream)4 InputStream (java.io.InputStream)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Servlet (javax.servlet.Servlet)2 ServletRegistration (javax.servlet.ServletRegistration)2 MultipartConfig (javax.servlet.annotation.MultipartConfig)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 MultiPartInputStreamParser (org.eclipse.jetty.util.MultiPartInputStreamParser)2 DbxException (com.dropbox.core.DbxException)1