Example usage for javax.servlet MultipartConfigElement MultipartConfigElement

List of usage examples for javax.servlet MultipartConfigElement MultipartConfigElement

Introduction

In this page you can find the example usage for javax.servlet MultipartConfigElement MultipartConfigElement.

Prototype

public MultipartConfigElement(MultipartConfig annotation) 

Source Link

Document

Constructs an instance from a MultipartConfig annotation value.

Usage

From source file:org.joinfaces.primefaces.MockPrimefacesFileUploadAutoConfiguration.java

@Bean
public MultipartConfigElement multipartConfigElement() {
    return new MultipartConfigElement("myLocation");
}

From source file:com.github.bysrhq.belajar.config.init.WebAppInitializer.java

@Override
protected void customizeRegistration(ServletRegistration.Dynamic registration) {
    registration.setMultipartConfig(new MultipartConfigElement("/"));
}

From source file:br.com.alura.casadocodigo.conf.ServletSpringMVC.java

@Override
protected void customizeRegistration(Dynamic registration) {
    registration.setMultipartConfig(new MultipartConfigElement(""));
}

From source file:br.com.semanticwot.cd.conf.ServletSpringMVC.java

@Override
protected void customizeRegistration(ServletRegistration.Dynamic registration) { // Esse mtodo regista onde colocar o arquivo em upload enquanto ele est sendo carregado
    super.customizeRegistration(registration);
    registration.setMultipartConfig(new MultipartConfigElement(""));
}

From source file:com.orangeandbronze.jblubble.sample.BlobstoreSampleInitializer.java

@Override
protected void customizeRegistration(Dynamic registration) {
    registration.setMultipartConfig(new MultipartConfigElement((String) null));
}

From source file:com.aerospike.client.rest.AerospikeRESTfulService.java

@Bean
public MultipartConfigElement multipartConfigElement() {
    return new MultipartConfigElement("");
}

From source file:io.undertow.servlet.test.security.basic.ServletCertAndDigestAuthTestCase.java

@BeforeClass
public static void startSSL() throws Exception {
    DefaultServer.startSSLServer(OptionMap.create(SSL_CLIENT_AUTH_MODE, NOT_REQUESTED));
    clientSSLContext = DefaultServer.getClientSSLContext();

    final PathHandler path = new PathHandler();

    final ServletContainer container = ServletContainer.Factory.newInstance();
    ServletInfo multipartServlet = new ServletInfo("Multipart Accepting Servlet",
            MultipartAcceptingServlet.class).addMapping("/secured/multipart")
                    .setMultipartConfig(new MultipartConfigElement(""));

    ServletIdentityManager identityManager = new ServletIdentityManager();
    identityManager.addUser("user1", "password1", "role1");
    identityManager.addUser("charsetUser", "password-", "role1");

    LoginConfig loginConfig = new LoginConfig(REALM_NAME);
    loginConfig.addFirstAuthMethod(new AuthMethodConfig("BASIC"));
    loginConfig.addFirstAuthMethod(new AuthMethodConfig("CLIENT_CERT"));
    DeploymentInfo builder = new DeploymentInfo().setClassLoader(SimpleServletTestCase.class.getClassLoader())
            .setContextPath("/servletContext").setClassIntrospecter(TestClassIntrospector.INSTANCE)
            .setDeploymentName("servletContext.war").setIdentityManager(identityManager)
            .setLoginConfig(loginConfig).addServlets(multipartServlet);

    builder.addSecurityConstraint(new SecurityConstraint()
            .addWebResourceCollection(new WebResourceCollection().addUrlPattern("/secured/*"))
            .addRoleAllowed("role1").setEmptyRoleSemantic(SecurityInfo.EmptyRoleSemantic.DENY));

    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();/*from  w  ww.j ava2  s.  co m*/
    path.addPrefixPath(builder.getContextPath(), manager.start());

    DefaultServer.setRootHandler(path);
}

From source file:br.pucminas.ri.jsearch.rest.controller.ApiController.java

public static Object fileUpload(Request req, Response res) {
    req.attribute("org.eclipse.jetty.multipartConfig", new MultipartConfigElement("/temp"));
    Path out = Paths.get("result/queries.txt");

    try (InputStream is = req.raw().getPart("uploaded_file").getInputStream()) {
        Path folder = Paths.get("result");
        if (Files.exists(folder)) {
            Files.delete(out);/*  w ww.java2s. co  m*/
        }
        Files.createDirectories(Paths.get("result"));
        Files.copy(is, out);
        return evalTests(req, res);
    } catch (IOException | ServletException e) {
        e.printStackTrace();
        return "Error on upload file";
    }
}

From source file:eionet.transfer.TransferWebAppInitializer.java

@Override
public void onStartup(ServletContext container) {
    XmlWebApplicationContext appContext = new XmlWebApplicationContext();
    appContext.setConfigLocation("/WEB-INF/classes/spring-db-config.xml "
            + "/WEB-INF/classes/spring-init-config.xml " + "/WEB-INF/classes/spring-mvc-config.xml");

    // Listeners//from   w w w  .  j a va2  s. co  m
    //SingleSignOutHttpSessionListener ssoListener = new SingleSignOutHttpSessionListener(appContext);
    //container.addListener(ssoListener);

    //ContextLoaderListener contextLoaderListener = new ContextLoaderListener(appContext);
    //container.addListener(contextLoaderListener);

    ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher",
            new DispatcherServlet(appContext));

    String location = null;
    try {
        location = System.getProperty("upload.dir", null);
    } catch (Exception e) {
        location = null;
    }

    logger.info("Upload directory configured to: " + (location == null ? "[default]" : location));

    //long maxFileSize = 5000000L;
    //long maxRequestSize = 5000000L;
    //int fileSizeThreshold = 0;
    MultipartConfigElement multipartConfigElement = new MultipartConfigElement(location);
    //MultipartConfigElement multipartConfigElement = new MultipartConfigElement(location, maxFileSize, maxRequestSize, fileSizeThreshold);
    dispatcher.setMultipartConfig(multipartConfigElement);

    dispatcher.setLoadOnStartup(1);
    dispatcher.addMapping("/");
}

From source file:com.sketchy.server.HttpServer.java

public void start() throws Exception {
    if (!IMAGE_UPLOAD_DIRECTORY.exists()) {
        if (!IMAGE_UPLOAD_DIRECTORY.mkdir()) {
            throw new Exception(
                    "Error Creating Upload Directory '" + IMAGE_UPLOAD_DIRECTORY.getAbsolutePath() + "!");
        }/*from  w  ww.j a  v  a 2  s .  co m*/
    }

    Server server = new Server(80);

    // File Upload Handler
    ServletHolder imageUploadHolder = new ServletHolder(new ImageUploadServlet());
    MultipartConfigElement multipartConfig = new MultipartConfigElement(FileUtils.getTempDirectory().getPath());
    imageUploadHolder.getRegistration().setMultipartConfig(multipartConfig);

    // File Upgrade Handler
    ServletHolder upgradeUploadHolder = new ServletHolder(new UpgradeUploadServlet());
    multipartConfig = new MultipartConfigElement(FileUtils.getTempDirectory().getPath());
    upgradeUploadHolder.getRegistration().setMultipartConfig(multipartConfig);

    ServletHandler servletHandler = new ServletHandler();
    ServletContextHandler servletContext = new ServletContextHandler();
    servletContext.setHandler(servletHandler);
    servletContext.addServlet(new ServletHolder(new JsonServlet()), "/servlet/*");
    servletContext.addServlet(imageUploadHolder, "/imageUpload/*");
    servletContext.addServlet(upgradeUploadHolder, "/upgradeUpload/*");

    // if we are developing, we shouldn't have the Sketchy.jar file in our classpath.
    // in this case, pull from the filesystem, not the .jar

    ContextHandler resourceContext = new ContextHandler();

    URL url = server.getClass().getClassLoader().getResource("html");
    if (url != null) {
        ResourceHandler resourceHandler = new ResourceHandler();
        resourceHandler.setDirectoriesListed(false);
        resourceContext.setWelcomeFiles(new String[] { "index.html" });
        resourceContext.setContextPath("/");
        String resourceBase = url.toExternalForm();
        resourceContext.setResourceBase(resourceBase);
        resourceContext.setHandler(resourceHandler);
    } else {
        ResourceHandler resourceHandler = new ResourceHandler();
        resourceHandler.setDirectoriesListed(false);
        resourceContext.setWelcomeFiles(new String[] { "index.html" });
        resourceContext.setContextPath("/");
        resourceContext.setResourceBase(SOURCE_HTML_FILES_DIRECTORY.getCanonicalPath());
        resourceContext.setHandler(resourceHandler);
    }

    ResourceHandler uploadResourceHandler = new ResourceHandler();
    uploadResourceHandler.setDirectoriesListed(true);
    ContextHandler uploadResourceContext = new ContextHandler();
    uploadResourceContext.setContextPath("/upload");
    uploadResourceContext.setResourceBase("./upload");
    uploadResourceContext.setHandler(uploadResourceHandler);

    ContextHandlerCollection contexts = new ContextHandlerCollection();
    contexts.setHandlers(new Handler[] { resourceContext, servletContext, uploadResourceContext });
    server.setHandler(contexts);

    server.start();
    server.join();
}