Search in sources :

Example 56 with MultipartConfigElement

use of javax.servlet.MultipartConfigElement in project meecrowave by apache.

the class ProxyServletSetup method accept.

@Override
public void accept(final Context context) {
    final Configuration config = instance.getConfiguration().getExtension(Configuration.class);
    if (config.skip) {
        return;
    }
    context.addServletContainerInitializer((c, ctx) -> {
        final ServletRegistration.Dynamic servlet = ctx.addServlet("meecrowave-proxy-servlet", CDIProxyServlet.class);
        servlet.setLoadOnStartup(1);
        servlet.setAsyncSupported(true);
        servlet.addMapping(config.mapping);
        if (config.multipart) {
            servlet.setMultipartConfig(new MultipartConfigElement(config.multipartLocation, config.multipartMaxFileSize, config.multipartMaxRequestSize, config.multipartFileSizeThreshold));
        }
        servlet.setInitParameter("mapping", config.mapping);
        servlet.setInitParameter("configuration", config.configuration);
    }, null);
}
Also used : ServletRegistration(javax.servlet.ServletRegistration) MultipartConfigElement(javax.servlet.MultipartConfigElement)

Example 57 with MultipartConfigElement

use of javax.servlet.MultipartConfigElement in project qpid-broker-j by apache.

the class HttpManagement method addRestServlet.

private void addRestServlet(final ServletContextHandler root) {
    final Map<String, ManagementControllerFactory> factories = ManagementControllerFactory.loadFactories();
    final long maxFileSize = getContextValue(Long.class, MAX_HTTP_FILE_UPLOAD_SIZE_CONTEXT_NAME);
    final int maxRequestSize = getContextValue(Integer.class, MAX_HTTP_FILE_UPLOAD_SIZE_CONTEXT_NAME);
    final List<String> supportedVersions = new ArrayList<>();
    supportedVersions.add("latest");
    String currentVersion = BrokerModel.MODEL_VERSION;
    ManagementController managementController = null;
    ManagementControllerFactory factory;
    do {
        factory = factories.get(currentVersion);
        if (factory != null) {
            managementController = factory.createManagementController(this, managementController);
            final RestServlet managementServlet = new RestServlet();
            final Collection<String> categories = managementController.getCategories();
            for (String category : categories) {
                final String name = category.toLowerCase();
                final String path = managementController.getCategoryMapping(name);
                final ServletHolder servletHolder = new ServletHolder(path, managementServlet);
                servletHolder.setInitParameter("qpid.controller.version", managementController.getVersion());
                servletHolder.getRegistration().setMultipartConfig(new MultipartConfigElement("", maxFileSize, -1L, maxRequestSize));
                root.addServlet(servletHolder, path + (path.endsWith("/") ? "*" : "/*"));
                if (BrokerModel.MODEL_VERSION.equals(managementController.getVersion())) {
                    root.addServlet(servletHolder, "/api/latest/" + name + "/*");
                }
            }
            supportedVersions.add("v" + currentVersion);
            currentVersion = factory.getPreviousVersion();
        }
    } while (factory != null);
    root.getServletContext().setAttribute("qpid.controller.chain", managementController);
    final Map<String, List<String>> supported = Collections.singletonMap("supportedVersions", supportedVersions);
    final ServletHolder versionsServletHolder = new ServletHolder(new JsonValueServlet(supported));
    root.addServlet(versionsServletHolder, "/api");
    root.addServlet(versionsServletHolder, "/api/");
}
Also used : JsonValueServlet(org.apache.qpid.server.management.plugin.servlet.rest.JsonValueServlet) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ArrayList(java.util.ArrayList) RestServlet(org.apache.qpid.server.management.plugin.servlet.rest.RestServlet) MultipartConfigElement(javax.servlet.MultipartConfigElement) ArrayList(java.util.ArrayList) List(java.util.List)

Example 58 with MultipartConfigElement

use of javax.servlet.MultipartConfigElement in project BroadleafCommerce by BroadleafCommerce.

the class AdminMultipartUploadConfig method multipartConfigElement.

@Bean
public MultipartConfigElement multipartConfigElement(Environment env) {
    MultipartConfigElement multipartConfig = this.multipartProperties.createMultipartConfig();
    // If a user has configured the max file size from Broadleaf to be anything,
    // override it here
    String blcAssetUploadSizeProperty = "asset.server.max.uploadable.file.size";
    Long blcMaxFileSize = env.getProperty(blcAssetUploadSizeProperty, Long.class);
    if (blcMaxFileSize != null) {
        LOG.info(String.format("The %s has been set to %s, using this as the file upload limit and ignoring the Spring Boot settings", blcAssetUploadSizeProperty, blcMaxFileSize));
        multipartConfig = new MultipartConfigElement(multipartConfig.getLocation(), multipartConfig.getMaxRequestSize(), blcMaxFileSize, multipartConfig.getFileSizeThreshold());
    }
    return multipartConfig;
}
Also used : MultipartConfigElement(javax.servlet.MultipartConfigElement) Bean(org.springframework.context.annotation.Bean)

Example 59 with MultipartConfigElement

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

the class TestUploadConfig method getMultipartConfig_config.

@Test
public void getMultipartConfig_config() {
    ArchaiusUtils.setProperty(RestConst.UPLOAD_DIR, "upload");
    ArchaiusUtils.setProperty(RestConst.UPLOAD_MAX_FILE_SIZE, 1);
    ArchaiusUtils.setProperty(RestConst.UPLOAD_MAX_SIZE, 2);
    ArchaiusUtils.setProperty(RestConst.UPLOAD_FILE_SIZE_THRESHOLD, 3);
    UploadConfig uploadConfig = new UploadConfig();
    MultipartConfigElement multipartConfigElement = uploadConfig.toMultipartConfigElement();
    Assert.assertEquals("upload", uploadConfig.getLocation());
    Assert.assertEquals(1, uploadConfig.getMaxFileSize());
    Assert.assertEquals(2, uploadConfig.getMaxSize());
    Assert.assertEquals(3, uploadConfig.getFileSizeThreshold());
    Assert.assertEquals("upload", multipartConfigElement.getLocation());
    Assert.assertEquals(1, multipartConfigElement.getMaxFileSize());
    Assert.assertEquals(2, multipartConfigElement.getMaxRequestSize());
    Assert.assertEquals(3, multipartConfigElement.getFileSizeThreshold());
}
Also used : MultipartConfigElement(javax.servlet.MultipartConfigElement) Test(org.junit.Test)

Example 60 with MultipartConfigElement

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

the class TestUploadConfig method getMultipartConfig_default.

@Test
public void getMultipartConfig_default() {
    ArchaiusUtils.setProperty(RestConst.UPLOAD_DIR, "upload");
    UploadConfig uploadConfig = new UploadConfig();
    MultipartConfigElement multipartConfigElement = uploadConfig.toMultipartConfigElement();
    Assert.assertEquals("upload", uploadConfig.getLocation());
    Assert.assertEquals(-1L, uploadConfig.getMaxFileSize());
    Assert.assertEquals(-1L, uploadConfig.getMaxSize());
    Assert.assertEquals(0, uploadConfig.getFileSizeThreshold());
    Assert.assertEquals("upload", multipartConfigElement.getLocation());
    Assert.assertEquals(-1L, multipartConfigElement.getMaxFileSize());
    Assert.assertEquals(-1L, multipartConfigElement.getMaxRequestSize());
    Assert.assertEquals(0, multipartConfigElement.getFileSizeThreshold());
}
Also used : MultipartConfigElement(javax.servlet.MultipartConfigElement) Test(org.junit.Test)

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