Search in sources :

Example 61 with MultipartConfigElement

use of javax.servlet.MultipartConfigElement in project java-chassis by ServiceComb.

the class TestServletUtils method setServletParameters_supportUpload.

@Test
public void setServletParameters_supportUpload(@Mocked ServletContext servletContext, @Mocked Dynamic d1, @Mocked ServletRegistration d2) throws IOException {
    Map<String, ServletRegistration> servletRegistrations = new HashMap<>();
    servletRegistrations.put("d1", d1);
    servletRegistrations.put("d2", d2);
    new Expectations() {

        {
            servletContext.getServletRegistrations();
            result = servletRegistrations;
            d1.getClassName();
            result = RestServlet.class.getName();
            d2.getClassName();
            result = HttpServlet.class.getName();
        }
    };
    List<MultipartConfigElement> multipartConfigs = new ArrayList<>();
    new MockUp<Dynamic>(d1) {

        @Mock
        void setMultipartConfig(MultipartConfigElement multipartConfig) {
            multipartConfigs.add(multipartConfig);
        }
    };
    File tempDir = Files.createTempDirectory("temp").toFile();
    File uploadDir = new File(tempDir, "upload");
    ArchaiusUtils.setProperty(RestConst.UPLOAD_DIR, uploadDir.getAbsolutePath());
    ServletUtils.setServletParameters(servletContext);
    Assert.assertEquals(1, multipartConfigs.size());
    MultipartConfigElement multipartConfigElement = multipartConfigs.get(0);
    Assert.assertEquals(uploadDir.getAbsolutePath(), multipartConfigElement.getLocation());
    Assert.assertEquals(-1, multipartConfigElement.getMaxFileSize());
    Assert.assertEquals(-1, multipartConfigElement.getMaxRequestSize());
    Assert.assertEquals(0, multipartConfigElement.getFileSizeThreshold());
    uploadDir.delete();
    tempDir.delete();
    Assert.assertFalse(tempDir.exists());
}
Also used : Expectations(mockit.Expectations) ServletRegistration(javax.servlet.ServletRegistration) MultipartConfigElement(javax.servlet.MultipartConfigElement) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) HttpServlet(javax.servlet.http.HttpServlet) ArrayList(java.util.ArrayList) MockUp(mockit.MockUp) File(java.io.File) Test(org.junit.Test)

Example 62 with MultipartConfigElement

use of javax.servlet.MultipartConfigElement in project openolat by klemens.

the class OlatJerseyTestCase method instantiateServer.

/**
 * Instantiates the server
 */
private void instantiateServer() {
    if (webServer == null) {
        try {
            DeploymentInfo servletBuilder = deployment().setClassLoader(OlatJerseyTestCase.class.getClassLoader()).setContextPath("/" + CONTEXT_PATH).setDeploymentName("rest.war").addServlets(servlet("REST Servlet", com.sun.jersey.spi.container.servlet.ServletContainer.class).addInitParam("javax.ws.rs.Application", OlatRestApplication.class.getName()).setMultipartConfig(new MultipartConfigElement((String) null)).addMapping("/*")).addFilters(filter("REST security filter", RestApiLoginFilter.class)).addFilterUrlMapping("REST security filter", "/*", DispatcherType.REQUEST);
            DeploymentManager manager = defaultContainer().addDeployment(servletBuilder);
            manager.deploy();
            webServer = Undertow.builder().addHttpListener(PORT, HOST).setHandler(manager.start()).build();
            webServer.start();
            webServerStarted = true;
        } catch (ServletException e) {
            log.error("", e);
        }
    }
}
Also used : ServletException(javax.servlet.ServletException) MultipartConfigElement(javax.servlet.MultipartConfigElement) DeploymentManager(io.undertow.servlet.api.DeploymentManager) Servlets.servlet(io.undertow.servlet.Servlets.servlet) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo)

Example 63 with MultipartConfigElement

use of javax.servlet.MultipartConfigElement in project reactor-netty by reactor.

the class TomcatServer method createDefaultContext.

public void createDefaultContext() {
    Context ctx = this.tomcat.addContext("", null);
    addServlet(ctx, new DefaultServlet(), "/");
    addServlet(ctx, new StatusServlet(), "/status/*");
    addServlet(ctx, new MultipartServlet(), "/multipart").setMultipartConfigElement(new MultipartConfigElement(""));
}
Also used : Context(org.apache.catalina.Context) MultipartConfigElement(javax.servlet.MultipartConfigElement)

Aggregations

MultipartConfigElement (javax.servlet.MultipartConfigElement)63 Test (org.junit.Test)37 ByteArrayInputStream (java.io.ByteArrayInputStream)30 Part (javax.servlet.http.Part)28 MultiPart (org.eclipse.jetty.util.MultiPartInputStreamParser.MultiPart)24 ByteArrayOutputStream (java.io.ByteArrayOutputStream)13 File (java.io.File)9 IOException (java.io.IOException)9 ServletException (javax.servlet.ServletException)6 ServletRegistration (javax.servlet.ServletRegistration)6 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)5 ServletInputStream (javax.servlet.ServletInputStream)4 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)4 DeploymentManager (io.undertow.servlet.api.DeploymentManager)3 InputStream (java.io.InputStream)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Servlets.servlet (io.undertow.servlet.Servlets.servlet)2 ServletInfo (io.undertow.servlet.api.ServletInfo)2 ArrayList (java.util.ArrayList)2