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());
}
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);
}
}
}
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(""));
}
Aggregations